@@ -22,7 +22,7 @@ module.exports = class Macros {
22
22
this . builder = new Builder ( t , {
23
23
module : this . debugHelpers . module ,
24
24
global : this . debugHelpers . global ,
25
- assertPredicateIndex : options . debugTools . assertPredicateIndex
25
+ assertPredicateIndex : options . debugTools . assertPredicateIndex ,
26
26
} ) ;
27
27
}
28
28
@@ -35,7 +35,7 @@ module.exports = class Macros {
35
35
36
36
this . _inlineFeatureFlags ( path ) ;
37
37
this . _inlineSvelteFlags ( path ) ;
38
- this . _inlineEnvFlags ( path )
38
+ this . _inlineEnvFlags ( path ) ;
39
39
this . builder . expandMacros ( this . envFlags . DEBUG ) ;
40
40
41
41
if ( this . _hasDebugModule ( debugBinding ) ) {
@@ -48,9 +48,11 @@ module.exports = class Macros {
48
48
_inlineFeatureFlags ( path ) {
49
49
let featuresMap = this . featuresMap ;
50
50
51
- if ( this . envFlags . DEBUG ) { return ; }
52
- Object . keys ( featuresMap ) . forEach ( ( source ) => {
53
- Object . keys ( featuresMap [ source ] ) . forEach ( ( flag ) => {
51
+ if ( this . envFlags . DEBUG ) {
52
+ return ;
53
+ }
54
+ Object . keys ( featuresMap ) . forEach ( source => {
55
+ Object . keys ( featuresMap [ source ] ) . forEach ( flag => {
54
56
let flagValue = featuresMap [ source ] [ flag ] ;
55
57
let binding = path . scope . getBinding ( flag ) ;
56
58
@@ -71,13 +73,16 @@ module.exports = class Macros {
71
73
let envFlags = this . envFlags ;
72
74
73
75
Object . keys ( envFlags ) . forEach ( flag => {
74
- let binding = path . scope . getBinding ( flag ) ;
75
- if ( binding &&
76
- binding . path . isImportSpecifier ( ) &&
77
- binding . path . parent . source . value === this . envFlagsSource ) {
78
-
79
- binding . referencePaths . forEach ( p => p . replaceWith ( this . builder . t . booleanLiteral ( envFlags [ flag ] ) ) ) ;
80
- }
76
+ let binding = path . scope . getBinding ( flag ) ;
77
+ if (
78
+ binding &&
79
+ binding . path . isImportSpecifier ( ) &&
80
+ binding . path . parent . source . value === this . envFlagsSource
81
+ ) {
82
+ binding . referencePaths . forEach ( p =>
83
+ p . replaceWith ( this . builder . t . booleanLiteral ( envFlags [ flag ] ) )
84
+ ) ;
85
+ }
81
86
} ) ;
82
87
}
83
88
@@ -87,19 +92,28 @@ module.exports = class Macros {
87
92
let builder = this . builder ;
88
93
89
94
let sources = Object . keys ( svelteMap ) ;
90
- sources . forEach ( ( source ) => {
91
- Object . keys ( svelteMap [ source ] ) . forEach ( ( flag ) => {
95
+ sources . forEach ( source => {
96
+ Object . keys ( svelteMap [ source ] ) . forEach ( flag => {
92
97
let binding = path . scope . getBinding ( flag ) ;
93
98
if ( binding !== undefined ) {
94
- binding . referencePaths . forEach ( ( p ) => {
99
+ binding . referencePaths . forEach ( p => {
95
100
let t = builder . t ;
96
101
if ( envFlags . DEBUG ) {
97
102
if ( svelteMap [ source ] [ flag ] === false ) {
98
- if ( ! p . parentPath . isIfStatement ( ) ) { return ; }
103
+ if ( ! p . parentPath . isIfStatement ( ) ) {
104
+ return ;
105
+ }
99
106
let consequent = p . parentPath . get ( 'consequent' ) ;
100
- consequent . unshiftContainer ( 'body' , t . throwStatement (
101
- t . newExpression ( t . identifier ( 'Error' ) , [ t . stringLiteral ( `You indicated you don't have any deprecations, however you are relying on ${ flag } .` ) ] )
102
- ) ) ;
107
+ consequent . unshiftContainer (
108
+ 'body' ,
109
+ t . throwStatement (
110
+ t . newExpression ( t . identifier ( 'Error' ) , [
111
+ t . stringLiteral (
112
+ `You indicated you don't have any deprecations, however you are relying on ${ flag } .`
113
+ ) ,
114
+ ] )
115
+ )
116
+ ) ;
103
117
}
104
118
} else {
105
119
if ( p . parentPath . isIfStatement ( ) ) {
@@ -135,14 +149,17 @@ module.exports = class Macros {
135
149
build ( path ) {
136
150
let expression = path . node . expression ;
137
151
138
- if ( this . builder . t . isCallExpression ( expression ) && this . localDebugBindings . some ( ( b ) => b . node . name === expression . callee . name ) ) {
152
+ if (
153
+ this . builder . t . isCallExpression ( expression ) &&
154
+ this . localDebugBindings . some ( b => b . node . name === expression . callee . name )
155
+ ) {
139
156
let imported = path . scope . getBinding ( expression . callee . name ) . path . node . imported . name ;
140
157
this . builder [ `${ imported } ` ] ( path ) ;
141
158
}
142
159
}
143
160
144
161
_collectImportBindings ( specifiers , buffer ) {
145
- specifiers . forEach ( ( specifier ) => {
162
+ specifiers . forEach ( specifier => {
146
163
if ( specifier . node . imported && SUPPORTED_MACROS . indexOf ( specifier . node . imported . name ) > - 1 ) {
147
164
buffer . push ( specifier . get ( 'local' ) ) ;
148
165
}
@@ -156,9 +173,11 @@ module.exports = class Macros {
156
173
}
157
174
158
175
_detectForeignFeatureFlag ( specifiers , source ) {
159
- specifiers . forEach ( ( specifier ) => {
176
+ specifiers . forEach ( specifier => {
160
177
if ( specifier . imported && this . featuresMap [ source ] [ specifier . imported . name ] !== null ) {
161
- throw new Error ( `Imported ${ specifier . imported . name } from ${ source } which is not a supported flag.` ) ;
178
+ throw new Error (
179
+ `Imported ${ specifier . imported . name } from ${ source } which is not a supported flag.`
180
+ ) ;
162
181
}
163
182
} ) ;
164
183
}
@@ -186,16 +205,16 @@ module.exports = class Macros {
186
205
187
206
if ( ! this . debugHelpers . module ) {
188
207
if ( this . localDebugBindings . length > 0 ) {
189
- this . localDebugBindings [ 0 ] . parentPath . parentPath
208
+ this . localDebugBindings [ 0 ] . parentPath . parentPath ;
190
209
let importPath = this . localDebugBindings [ 0 ] . findParent ( p => p . isImportDeclaration ( ) ) ;
191
210
let specifiers = importPath . get ( 'specifiers' ) ;
192
211
193
212
if ( specifiers . length === this . localDebugBindings . length ) {
194
213
this . localDebugBindings [ 0 ] . parentPath . parentPath . remove ( ) ;
195
214
} else {
196
- this . localDebugBindings . forEach ( ( binding ) => binding . parentPath . remove ( ) ) ;
215
+ this . localDebugBindings . forEach ( binding => binding . parentPath . remove ( ) ) ;
197
216
}
198
217
}
199
218
}
200
219
}
201
- }
220
+ } ;
0 commit comments