@@ -13,11 +13,6 @@ function isAbsolute(path: string): boolean {
1313 return ABSOLUTE_PATH_REGEX . test ( path )
1414}
1515
16- const FALLBACK_TRUE = 1
17- const FALLBACK_FALSE = 0
18- type FallbackValues = typeof FALLBACK_TRUE | typeof FALLBACK_FALSE
19- type PluginFilterWithFallback = ( input : string ) => boolean | FallbackValues
20-
2116export type PluginFilter = ( input : string ) => boolean
2217export type TransformHookFilter = ( id : string , code : string ) => boolean
2318
@@ -67,7 +62,7 @@ function patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {
6762function createFilter (
6863 exclude : PluginFilter [ ] | undefined ,
6964 include : PluginFilter [ ] | undefined ,
70- ) : PluginFilterWithFallback | undefined {
65+ ) : PluginFilter | undefined {
7166 if ( ! exclude && ! include ) {
7267 return
7368 }
@@ -79,7 +74,7 @@ function createFilter(
7974 if ( include ?. some ( filter => filter ( input ) ) ) {
8075 return true
8176 }
82- return ! ! include && include . length > 0 ? FALLBACK_FALSE : FALLBACK_TRUE
77+ return ! ( include && include . length > 0 )
8378 }
8479}
8580
@@ -100,7 +95,7 @@ function normalizeFilter(filter: StringFilter): NormalizedStringFilter {
10095 }
10196}
10297
103- function createIdFilter ( filter : StringFilter | undefined ) : PluginFilterWithFallback | undefined {
98+ function createIdFilter ( filter : StringFilter | undefined ) : PluginFilter | undefined {
10499 if ( ! filter )
105100 return
106101 const { exclude, include } = normalizeFilter ( filter )
@@ -109,7 +104,7 @@ function createIdFilter(filter: StringFilter | undefined): PluginFilterWithFallb
109104 return createFilter ( excludeFilter , includeFilter )
110105}
111106
112- function createCodeFilter ( filter : StringFilter | undefined ) : PluginFilterWithFallback | undefined {
107+ function createCodeFilter ( filter : StringFilter | undefined ) : PluginFilter | undefined {
113108 if ( ! filter )
114109 return
115110 const { exclude, include } = normalizeFilter ( filter )
@@ -134,18 +129,14 @@ function createFilterForTransform(
134129 return ( id , code ) => {
135130 let fallback = true
136131 if ( idFilterFunction ) {
137- const idResult = idFilterFunction ( id )
138- if ( typeof idResult === 'boolean' ) {
139- return idResult
140- }
141- fallback &&= ! ! idResult
132+ fallback &&= idFilterFunction ( id )
133+ }
134+ if ( ! fallback ) {
135+ return false
142136 }
137+
143138 if ( codeFilterFunction ) {
144- const codeResult = codeFilterFunction ( code )
145- if ( typeof codeResult === 'boolean' ) {
146- return codeResult
147- }
148- fallback &&= ! ! codeResult
139+ fallback &&= codeFilterFunction ( code )
149140 }
150141 return fallback
151142 }
0 commit comments