Skip to content

Commit

Permalink
Merge pull request #486 from kahless/master
Browse files Browse the repository at this point in the history
Recognize destructured assignment to a new name (fixes #485)
  • Loading branch information
trotzig committed Mar 16, 2018
2 parents 6d90ded + 7e1e4c0 commit 0ba5fec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/__tests__/findUndefinedIdentifiers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ it('recognizes destructured assignment', () => {
`))).toEqual(new Set([]));
});

it('recognizes destructured assignment to a new name', () => {
expect(findUndefinedIdentifiers(parse(`
import Foo from 'foo';
const { bar: scar } = Foo;
scar();
`))).toEqual(new Set([]));
});

it('knows about scope', () => {
expect(findUndefinedIdentifiers(parse(`
() => {
Expand Down
5 changes: 4 additions & 1 deletion lib/visitIdentifierNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ function normalizeNode(node, context) {
const isAssignment = KEYS_USED_FOR_ASSIGNMENT.has(key) ||
(key === 'key' && parent.parent.type === 'ObjectPattern') ||
(key === 'left' && parent.type === 'AssignmentPattern') ||
(key === 'elements' && parent.type === 'ArrayPattern');
(key === 'elements' && parent.type === 'ArrayPattern') ||
(key === 'value' &&
parent.parent.type === 'ObjectPattern' &&
parent.parent.parent.type === 'VariableDeclarator');
if (isAssignment) {
context.definedInScope.add(node.name);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "import-js",
"version": "2.10.0",
"version": "2.10.1",
"description": "Simplifies importing JavaScript modules",
"bin": {
"importjs": "./bin/importjs.js",
Expand Down

0 comments on commit 0ba5fec

Please sign in to comment.