Skip to content

Commit 889e8fa

Browse files
committed
Avoid unnecessarily analyzing scope
1 parent 4432e5b commit 889e8fa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/assignment-visitor.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,22 @@ function assignmentHelper(visitor, path, childName) {
7979
const child = path.getValue()[childName];
8080
const assignedNames = utils.getNamesFromPattern(child);
8181
const nameCount = assignedNames.length;
82-
const scope = path.getScope();
82+
83+
let scope = null;
84+
function inModuleScope(name) {
85+
if (scope === null) {
86+
scope = path.getScope();
87+
}
88+
89+
return !scope || scope.find_owner(name).parent === null;
90+
}
8391

8492
// Wrap assignments to exported identifiers with `module.runSetters`.
8593
for (let i = 0; i < nameCount; ++i) {
8694
let name = assignedNames[i];
8795
if (
8896
visitor.exportedLocalNames[name] === true &&
89-
(!scope || scope.find_owner(name).parent === null)
97+
inModuleScope(name)
9098
) {
9199
wrap(visitor, path);
92100
break;

0 commit comments

Comments
 (0)