@@ -30,8 +30,6 @@ export default class Builder {
3030 private isDebug : boolean | '@embroider/macros' ;
3131 private util : ImportUtil ;
3232
33- private expressions : [ CallStatementPath , ( debugIdentifier : t . Expression ) => t . Expression ] [ ] = [ ] ;
34-
3533 constructor (
3634 readonly t : typeof Babel . types ,
3735 util : ImportUtil ,
@@ -149,10 +147,10 @@ export default class Builder {
149147 prefixedIdentifiers . push ( negatedPredicate ) ;
150148 }
151149
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 ( ) ;
156154 }
157155
158156 /**
@@ -210,21 +208,6 @@ export default class Builder {
210208 } ) ;
211209 }
212210
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-
228211 _debugExpression ( target : NodePath ) {
229212 if ( typeof this . isDebug === 'boolean' ) {
230213 return this . t . booleanLiteral ( this . isDebug ) ;
@@ -252,26 +235,25 @@ export default class Builder {
252235
253236 _buildLogicalExpressions (
254237 identifiers : t . Expression [ ] ,
255- callExpression : t . Expression
256- ) : ( debugIdentifier : t . Expression ) => t . Expression {
238+ callExpression : t . Expression ,
239+ debugIdentifier : t . Expression
240+ ) : t . Expression {
257241 let t = this . t ;
258242
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 ;
263246
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 ) ;
272254 }
255+ }
273256
274- return logicalExpressions ! ;
275- } ;
257+ return t . parenthesizedExpression ( logicalExpressions ! ) ;
276258 }
277259}
0 commit comments