Skip to content

Commit 56aad20

Browse files
committed
do binding in remapIdentifiers
1 parent 270db5f commit 56aad20

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/plugin.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,6 @@ export function makePlugin<EnvSpecificOptions>(loadOptions: (opts: EnvSpecificOp
174174
},
175175
},
176176

177-
Identifier(path: NodePath<t.Identifier>) {
178-
if (path.node.name) {
179-
const binding = path.scope.getBinding(path.node.name);
180-
if (binding && binding.path.node !== path.parent) {
181-
binding.reference(path);
182-
}
183-
}
184-
},
185-
186177
TaggedTemplateExpression(
187178
path: NodePath<t.TaggedTemplateExpression>,
188179
state: State<EnvSpecificOptions>
@@ -455,13 +446,18 @@ function buildPrecompileOptions<EnvSpecificOptions>(
455446
// if scope has different keys and values, this function will remap the keys to the values
456447
// you can see an example of this in the test "correctly handles scope if it contains keys and values"
457448
function remapIdentifiers(ast: Babel.types.File, babel: typeof Babel, scopeLocals: ScopeLocals) {
458-
if (!scopeLocals.needsRemapping()) {
459-
// do nothing if all keys are the same as their values
460-
return;
461-
}
462-
463449
babel.traverse(ast, {
464450
Identifier(path: NodePath<t.Identifier>) {
451+
if (path.node.name) {
452+
const binding = path.scope.getBinding(path.node.name);
453+
if (binding && binding.path.node !== path.parent) {
454+
binding.reference(path);
455+
}
456+
}
457+
if (!scopeLocals.needsRemapping()) {
458+
// do nothing if all keys are the same as their values
459+
return;
460+
}
465461
if (scopeLocals.has(path.node.name) && path.node.name !== scopeLocals.get(path.node.name)) {
466462
// replace the path only if the key is different from the value
467463
path.replaceWith(babel.types.identifier(scopeLocals.get(path.node.name)));

0 commit comments

Comments
 (0)