Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object destruction with assigning to new names #485

Closed
GeneZharov opened this issue Mar 16, 2018 · 2 comments
Closed

Object destruction with assigning to new names #485

GeneZharov opened this issue Mar 16, 2018 · 2 comments

Comments

@GeneZharov
Copy link

If my code contains an object destruction with assigning to new constant name:

const { id: langForeignID } = findByName(LANG_FOREIGN, en.langs);
console.log(langForeignID);

Then import-js does not recognize this syntax and tries to import the already defined langForeignID constant:

import { langForeignID } from "P/src/comp/learn/sel-domains";

This destruction syntax is a part of ES2015:
https://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

@trotzig
Copy link
Collaborator

trotzig commented Mar 16, 2018

Ah, sounds like you caught a bug in findUndefinedIdentifiers.js. Basically, it needs to pass this test:

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

I have limited time right now so any help here would be appreciated!

@GeneZharov
Copy link
Author

I will try. Not sure if I succeed. But I will report the results.

trotzig added a commit that referenced this issue Mar 16, 2018
Recognize destructured assignment to a new name (fixes #485)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants