@@ -30,8 +30,6 @@ export default class Builder {
30
30
private isDebug : boolean | '@embroider/macros' ;
31
31
private util : ImportUtil ;
32
32
33
- private expressions : [ CallStatementPath , ( debugIdentifier : t . Expression ) => t . Expression ] [ ] = [ ] ;
34
-
35
33
constructor (
36
34
readonly t : typeof Babel . types ,
37
35
util : ImportUtil ,
@@ -149,10 +147,10 @@ export default class Builder {
149
147
prefixedIdentifiers . push ( negatedPredicate ) ;
150
148
}
151
149
152
- this . expressions . push ( [
153
- path ,
154
- this . _buildLogicalExpressions ( prefixedIdentifiers , callExpression ) ,
155
- ] ) ;
150
+ // Expand the macro!
151
+ let replacementPath = this . _buildLogicalExpressions ( prefixedIdentifiers , callExpression , this . _debugExpression ( path ) ) ;
152
+ path . replaceWith ( replacementPath ) ;
153
+ path . scope . crawl ( ) ;
156
154
}
157
155
158
156
/**
@@ -210,21 +208,6 @@ export default class Builder {
210
208
} ) ;
211
209
}
212
210
213
- /**
214
- * Performs the actually expansion of macros
215
- */
216
- expandMacros ( ) {
217
- let t = this . t ;
218
- for ( let i = 0 ; i < this . expressions . length ; i ++ ) {
219
- let expression = this . expressions [ i ] ;
220
- let exp = expression [ 0 ] ;
221
- let flag = this . _debugExpression ( exp ) ;
222
- let logicalExp = expression [ 1 ] ;
223
- exp . replaceWith ( t . parenthesizedExpression ( logicalExp ( flag ) ) ) ;
224
- exp . scope . crawl ( ) ;
225
- }
226
- }
227
-
228
211
_debugExpression ( target : NodePath ) {
229
212
if ( typeof this . isDebug === 'boolean' ) {
230
213
return this . t . booleanLiteral ( this . isDebug ) ;
@@ -252,26 +235,25 @@ export default class Builder {
252
235
253
236
_buildLogicalExpressions (
254
237
identifiers : t . Expression [ ] ,
255
- callExpression : t . Expression
256
- ) : ( debugIdentifier : t . Expression ) => t . Expression {
238
+ callExpression : t . Expression ,
239
+ debugIdentifier : t . Expression
240
+ ) : t . Expression {
257
241
let t = this . t ;
258
242
259
- return ( debugIdentifier : t . Expression ) => {
260
- identifiers . unshift ( debugIdentifier ) ;
261
- identifiers . push ( callExpression ) ;
262
- let logicalExpressions ;
243
+ identifiers . unshift ( debugIdentifier ) ;
244
+ identifiers . push ( callExpression ) ;
245
+ let logicalExpressions ;
263
246
264
- for ( let i = 0 ; i < identifiers . length ; i ++ ) {
265
- let left = identifiers [ i ] ;
266
- let right = identifiers [ i + 1 ] ;
267
- if ( ! logicalExpressions ) {
268
- logicalExpressions = t . logicalExpression ( '&&' , left , right ) ;
269
- } else if ( right ) {
270
- logicalExpressions = t . logicalExpression ( '&&' , logicalExpressions , right ) ;
271
- }
247
+ for ( let i = 0 ; i < identifiers . length ; i ++ ) {
248
+ let left = identifiers [ i ] ;
249
+ let right = identifiers [ i + 1 ] ;
250
+ if ( ! logicalExpressions ) {
251
+ logicalExpressions = t . logicalExpression ( '&&' , left , right ) ;
252
+ } else if ( right ) {
253
+ logicalExpressions = t . logicalExpression ( '&&' , logicalExpressions , right ) ;
272
254
}
255
+ }
273
256
274
- return logicalExpressions ! ;
275
- } ;
257
+ return t . parenthesizedExpression ( logicalExpressions ! ) ;
276
258
}
277
259
}
0 commit comments