@@ -3,12 +3,6 @@ import type { StringFilter, StringOrRegExp } from '../rollup/types';
3
3
import { ensureArray } from './ensureArray' ;
4
4
import { isAbsolute , normalize , resolve } from './path' ;
5
5
6
- const FALLBACK_TRUE = 1 ;
7
- const FALLBACK_FALSE = 0 ;
8
- type FallbackValues = typeof FALLBACK_TRUE | typeof FALLBACK_FALSE ;
9
-
10
- type PluginFilterWithFallback = ( input : string ) => boolean | FallbackValues ;
11
-
12
6
export type PluginFilter = ( input : string ) => boolean ;
13
7
export type TransformHookFilter = ( id : string , code : string ) => boolean ;
14
8
@@ -58,7 +52,7 @@ function patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {
58
52
function createFilter (
59
53
exclude : PluginFilter [ ] | undefined ,
60
54
include : PluginFilter [ ] | undefined
61
- ) : PluginFilterWithFallback | undefined {
55
+ ) : PluginFilter | undefined {
62
56
if ( ! exclude && ! include ) {
63
57
return ;
64
58
}
@@ -70,7 +64,7 @@ function createFilter(
70
64
if ( include ?. some ( filter => filter ( input ) ) ) {
71
65
return true ;
72
66
}
73
- return ! ! include && include . length > 0 ? FALLBACK_FALSE : FALLBACK_TRUE ;
67
+ return ! ( include && include . length > 0 ) ;
74
68
} ;
75
69
}
76
70
@@ -82,7 +76,7 @@ function normalizeFilter(filter: StringFilter): NormalizedStringFilter {
82
76
}
83
77
if ( Array . isArray ( filter ) ) {
84
78
return {
85
- include : ensureArray ( filter )
79
+ include : filter
86
80
} ;
87
81
}
88
82
return {
@@ -91,15 +85,15 @@ function normalizeFilter(filter: StringFilter): NormalizedStringFilter {
91
85
} ;
92
86
}
93
87
94
- function createIdFilter ( filter : StringFilter | undefined ) : PluginFilterWithFallback | undefined {
88
+ function createIdFilter ( filter : StringFilter | undefined ) : PluginFilter | undefined {
95
89
if ( ! filter ) return ;
96
90
const { exclude, include } = normalizeFilter ( filter ) ;
97
91
const excludeFilter = exclude ?. map ( patternToIdFilter ) ;
98
92
const includeFilter = include ?. map ( patternToIdFilter ) ;
99
93
return createFilter ( excludeFilter , includeFilter ) ;
100
94
}
101
95
102
- function createCodeFilter ( filter : StringFilter | undefined ) : PluginFilterWithFallback | undefined {
96
+ function createCodeFilter ( filter : StringFilter | undefined ) : PluginFilter | undefined {
103
97
if ( ! filter ) return ;
104
98
const { exclude, include } = normalizeFilter ( filter ) ;
105
99
const excludeFilter = exclude ?. map ( patternToCodeFilter ) ;
@@ -122,18 +116,14 @@ export function createFilterForTransform(
122
116
return ( id , code ) => {
123
117
let fallback = true ;
124
118
if ( idFilterFunction ) {
125
- const idResult = idFilterFunction ( id ) ;
126
- if ( typeof idResult === 'boolean' ) {
127
- return idResult ;
128
- }
129
- fallback &&= ! ! idResult ;
119
+ fallback &&= idFilterFunction ( id ) ;
130
120
}
121
+ if ( ! fallback ) {
122
+ return false ;
123
+ }
124
+
131
125
if ( codeFilterFunction ) {
132
- const codeResult = codeFilterFunction ( code ) ;
133
- if ( typeof codeResult === 'boolean' ) {
134
- return codeResult ;
135
- }
136
- fallback &&= ! ! codeResult ;
126
+ fallback &&= codeFilterFunction ( code ) ;
137
127
}
138
128
return fallback ;
139
129
} ;
0 commit comments