@@ -13,11 +13,6 @@ function isAbsolute(path: string): boolean {
13
13
return ABSOLUTE_PATH_REGEX . test ( path )
14
14
}
15
15
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
-
21
16
export type PluginFilter = ( input : string ) => boolean
22
17
export type TransformHookFilter = ( id : string , code : string ) => boolean
23
18
@@ -67,7 +62,7 @@ function patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {
67
62
function createFilter (
68
63
exclude : PluginFilter [ ] | undefined ,
69
64
include : PluginFilter [ ] | undefined ,
70
- ) : PluginFilterWithFallback | undefined {
65
+ ) : PluginFilter | undefined {
71
66
if ( ! exclude && ! include ) {
72
67
return
73
68
}
@@ -79,7 +74,7 @@ function createFilter(
79
74
if ( include ?. some ( filter => filter ( input ) ) ) {
80
75
return true
81
76
}
82
- return ! ! include && include . length > 0 ? FALLBACK_FALSE : FALLBACK_TRUE
77
+ return ! ( include && include . length > 0 )
83
78
}
84
79
}
85
80
@@ -100,7 +95,7 @@ function normalizeFilter(filter: StringFilter): NormalizedStringFilter {
100
95
}
101
96
}
102
97
103
- function createIdFilter ( filter : StringFilter | undefined ) : PluginFilterWithFallback | undefined {
98
+ function createIdFilter ( filter : StringFilter | undefined ) : PluginFilter | undefined {
104
99
if ( ! filter )
105
100
return
106
101
const { exclude, include } = normalizeFilter ( filter )
@@ -109,7 +104,7 @@ function createIdFilter(filter: StringFilter | undefined): PluginFilterWithFallb
109
104
return createFilter ( excludeFilter , includeFilter )
110
105
}
111
106
112
- function createCodeFilter ( filter : StringFilter | undefined ) : PluginFilterWithFallback | undefined {
107
+ function createCodeFilter ( filter : StringFilter | undefined ) : PluginFilter | undefined {
113
108
if ( ! filter )
114
109
return
115
110
const { exclude, include } = normalizeFilter ( filter )
@@ -134,18 +129,14 @@ function createFilterForTransform(
134
129
return ( id , code ) => {
135
130
let fallback = true
136
131
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
142
136
}
137
+
143
138
if ( codeFilterFunction ) {
144
- const codeResult = codeFilterFunction ( code )
145
- if ( typeof codeResult === 'boolean' ) {
146
- return codeResult
147
- }
148
- fallback &&= ! ! codeResult
139
+ fallback &&= codeFilterFunction ( code )
149
140
}
150
141
return fallback
151
142
}
0 commit comments