microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.85k stars 12.46k forks source link

Import hints not working when using export default after class definition #19115

Closed mjbvz closed 6 years ago

mjbvz commented 7 years ago

From @methyl on October 10, 2017 7:25

Steps to Reproduce:

  1. Open a JS project with jsconfig.json having checkJs: true in compilerOptions
  2. Create a test.js with following content:
    class Test {}
    export default Test
  3. Create a test2.js with following content:
    class Test2 extends Test {}

Actual behavior:

Correct behavior

Copied from original issue: Microsoft/vscode#35966

mjbvz commented 7 years ago

Confirmed this happens with TypeScript 2.5.3 and 2.6.0-20171011

amcasey commented 6 years ago

isExportDefaultSymbol is returning false because the declaration has no default modifier.

amcasey commented 6 years ago

Related case: export { Test as default };

amcasey commented 6 years ago

@andy-ms, I'm told you've been working in this area and might have some thoughts on what these default export helpers should do (i.e. how to divide the fix between the compiler and the services).

amcasey commented 6 years ago

Here's a hackish solution to the cases we've identified so far. https://github.com/amcasey/TypeScript/tree/Scratch19115

amcasey commented 6 years ago

I see four other callers to getLocalSymbolForExportDefault and they basically all just want the local name of the default export. Possibly a helper returning that value is in order.

ghost commented 6 years ago

@amcasey That branch looks like it will work.

amcasey commented 6 years ago

@andy-ms so don't update the other callers?

ghost commented 6 years ago
amcasey commented 6 years ago

The change in findAllReferences.ts broke some tests. I'm still investigating. The failures looked like regressions, which makes me think that we might want to go the other way and pull out the default-export handling that's already there (because it's not clear why that one form would be special).

amcasey commented 6 years ago

As far as I can tell, the occurrence in services/utilities.ts doesn't matter - it's only used by rename and you can't rename default.

amcasey commented 6 years ago

For findAllReferences, I tested all three implementations (current, special case all default exports, special case no default exports) against all three types of default exports and the current implementation had the best behavior. Presumably, this means that the other two types of default exports (i.e. not handled by getLocalSymbolForExportDefault) are handled downstream.

methyl commented 6 years ago

Thanks a lot @amcasey, excellent work!