Galooshi / import-js

A tool to simplify importing JS modules
MIT License
526 stars 70 forks source link

Object destruction with assigning to new names #485

Closed GeneZharov closed 6 years ago

GeneZharov commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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