Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Conversation

@yurydelendik
Copy link
Contributor

Associated Issue: #624

Summary of Changes

Copy link
Contributor

@jasonLaster jasonLaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. A couple of style comments.

const { sourceId } = location;
const visitor = createParseJSScopeVisitor(sourceId);
traverseAst(source, visitor.traverseVisitor);
const parsedScopes = visitor.toParsedScopes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you pull in the test traverseAst helper

}
tree.params.forEach(param => {
parseDeclarator(param, scope, "param");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
tree.params.forEach(param => parseDeclarator(param, scope, "param")))

});
} else if (isNode(declaratorId, "RestElement")) {
parseDeclarator(declaratorId.argument, targetScope, type);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll want some tests for these cases

let zero = 0;
function fn(a, b) {
for (let i of [1, 2]) {
const i = a + i + zero;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be nice if i were index so that we can have another minifier check

// Find nearest outer scope with the specifed name and add reference.
for (let s = scope; s; s = s.parent) {
if (name in s.names) {
s.names[name].refs.push(loc.start);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if this function avoided mutating scope and instead returned the found location:

return;
}
if (path.isVariableDeclaration()) {
const hoistAt =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat. I imagine this might be one of the more interesting considerations because babel is free to add other hoisting rules in the future:

perhaps we want to try looking for the ref:

path.findParent((path) => path.scope.bindings.include(?));

NOTE: just guessing based on reading the code, i could be mis-reading this

if (hasLet) {
savedParents.set(path, parent);
parent = createTempScope("Block", parent, location);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats this doing?

return false;
}
return node.kind === "let" || node.kind === "const";
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we move this function up top?

      function hasLet(path) {
         return path.node.body.some(node => {
           if (!isNode(node, "VariableDeclaration")) {
             return false;
           }
           return node.kind === "let" || node.kind === "const";
         });
       }

Copy link
Contributor

@jasonLaster jasonLaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@yurydelendik yurydelendik merged commit ee7c373 into firefox-devtools:master Sep 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants