nkt / atom-autocomplete-modules

Autocomplete for require/import statements
https://atom.io/packages/autocomplete-modules
MIT License
114 stars 35 forks source link

Lookups are assuming source file is CJS when actually ES6, under certain conditions #101

Closed jonboiser closed 6 years ago

jonboiser commented 6 years ago

Description

If I have files in this structure:

.
├── lib.js
├── main
│   └── main.js
└── main.js

Where all of the JS files use ES6 import, attempting to import a named export foo in lib.js from within the nested main/main.js does not work since it is falling into the the lookupCommonJS utility (https://github.com/nkt/atom-autocomplete-modules/blob/master/src/utils/export-module-completion.js#L86) and fails because of the import keywords in lib.js

Ostensibly, lib.js should be handled as an ES6 module.

However, doing the same thing from the unnested main.js does not have this problem.

Steps to Reproduce

  1. Clone this repo https://github.com/jonboiser/simple-repo/
  2. In https://github.com/jonboiser/simple-repo/blob/master/main/main.js, attempt to get an autocompletion for named export foo in lib.js
  3. Get the Error in the console

Conversely, try the same thing on this file:

https://github.com/jonboiser/simple-repo/blob/master/main.js

And get the expected behavior.

Expected behavior: [What you expect to happen]

No error in the console; get autocompletion suggestion in buffer

Actual behavior: [What actually happens]

Error in the console; no autocompletion suggestion in buffer

Reproduces how often: [What percentage of the time does it reproduce?]

100%

Console errors

// /Users/jon/github/simple-repo/lib.js:1 Uncaught (in promise) SyntaxError: Unexpected token export
//     at Module.get_Module._compile (/Applications/Atom.app/Contents/Resources/app/src/native-compile-cache.js:94:52)
//     at Object.value [as .js] (/Applications/Atom.app/Contents/Resources/app/src/compile-cache.js:240:29)
//     at Module.load (module.js:488:32)
//     at tryModuleLoad (module.js:447:12)
//     at Function.Module._load (module.js:439:3)
//     at Module.require (file:///Applications/Atom.app/Contents/Resources/app.asar/static/index.js:47:45)
//     at require (/Applications/Atom.app/Contents/Resources/app/src/native-compile-cache.js:66:33)
//     at lookupCommonJs (/Users/jon/.atom/packages/autocomplete-modules/src/utils/export-module-completion.js:88:23)
//     at parseFile.then.catch (/Users/jon/.atom/packages/autocomplete-modules/src/utils/export-module-completion.js:82:14)
//     at <anonymous>

Versions

apm  1.19.0
npm  3.10.10
node 6.9.5 x64
atom 1.27.0
python 3.6.5
git 2.15.1

macOS 10.13.14

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

jonyeezs commented 6 years ago

Hi @jonboiser a new version 2.1.1 has been published. This has a massive refactor work and during that time there were some bugs found and squashed.

One of them sounds like what you're experiencing. Could you upgrade and test to see if it is still an issue.

Thanks!

jonboiser commented 6 years ago

@jonyeezs I just tried it out and it seems to be working now. Thanks!