Skip to content

Commit 829e003

Browse files
committed
Expand debug statements in place to permit subsequent Babel plugins (e.g. from @embroider/macros) to perform further translation
1 parent dde2d5b commit 829e003

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/utils/builder.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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([
150+
this.expandMacro(
153151
path,
154152
this._buildLogicalExpressions(prefixedIdentifiers, callExpression),
155-
]);
153+
);
156154
}
157155

158156
/**
@@ -211,18 +209,12 @@ export default class Builder {
211209
}
212210

213211
/**
214-
* Performs the actually expansion of macros
212+
* Performs the actually expansion of macro
215213
*/
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-
}
214+
expandMacro(exp: CallStatementPath, logicalExp: (debugIdentifier: t.Expression) => t.Expression) {
215+
const flag = this._debugExpression(exp);
216+
exp.replaceWith(this.t.parenthesizedExpression(logicalExp(flag)));
217+
exp.scope.crawl();
226218
}
227219

228220
_debugExpression(target: NodePath) {

src/utils/macros.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ export default class Macros {
3131
* adds the debug binding if missing from the env-flags module.
3232
*/
3333
expand() {
34-
this.builder.expandMacros();
35-
3634
this._cleanImports();
3735
}
3836

0 commit comments

Comments
 (0)