Skip to content

Commit

Permalink
Extract an extendMap function as an attempt to create an optimization…
Browse files Browse the repository at this point in the history
… boundary
  • Loading branch information
jayaddison committed Jul 7, 2020
1 parent 6da36af commit 85689f2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/babel-plugin-transform-block-scoping/src/index.js
Expand Up @@ -338,6 +338,12 @@ const loopVisitor = {
},
};

function extendMap(map, obj) {
for (const key of Object.keys(obj)) {
map.set(key, obj[key]);
}
}

class BlockScoping {
constructor(
loopPath?: NodePath,
Expand Down Expand Up @@ -700,10 +706,7 @@ class BlockScoping {
const init = this.loop.left || this.loop.init;
if (isBlockScoped(init)) {
declarators.push(init);
const names = t.getBindingIdentifiers(init);
for (const name of Object.keys(names)) {
this.outsideLetReferences.set(name, names[name]);
}
extendMap(this.outsideLetReferences, t.getBindingIdentifiers(init));
}
}

Expand Down Expand Up @@ -752,9 +755,7 @@ class BlockScoping {
// declaration, rather than (for example) mistakenly including the
// parameters of a function declaration. Fixes #4880.
const keys = t.getBindingIdentifiers(declar, false, true);
for (const key of Object.keys(keys)) {
this.letReferences.set(key, keys[key]);
}
extendMap(this.letReferences, keys);
this.hasLetReferences = true;
}

Expand Down

0 comments on commit 85689f2

Please sign in to comment.