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

Fails on dynamic import #72

Open
seanohue opened this issue Nov 16, 2018 · 9 comments
Open

Fails on dynamic import #72

seanohue opened this issue Nov 16, 2018 · 9 comments
Assignees
Labels

Comments

@seanohue
Copy link

Hello,

When using this to analyze source code for a Vue project, it fails on coming across a Webpack dynamic import.

With tools like ESLint, this is solvable by using babel-eslint as a parser.

Even though I have my ESLint config with babel-eslint plugged into Plato, I still get an Unexpected token error.

This may be solvable by using the parser described by the ESLint options or potentially offering another way to provide one's own parser. Either that, or I am configuring it wrong.

It looks like the work done in #5 may support this, rather than using typhonjs for parsing which fails to parse dynamic imports.

@the-simian
Copy link
Owner

That is interesting, I am currently using splitchunks on some projects, which is not causing this error for me. Can you lead me to a (very small) repo that reproduces this? Maybe some more information about your configuration?

Did you make some changes that got things working? Any info you have will help, I'd love to get you up and running here!

@seanohue
Copy link
Author

I will try to make a minimal reproduction as well, but here is one repo that I have had this trouble on:
https://github.com/seanohue/myelin-client

I will make a branch that attempts to implement es6-plato (I scrapped my earlier attempt at it).

Is there a difference between splitchunks and webpack's import() ?

@the-simian
Copy link
Owner

Well if by import you mean the es6 import specification, then webpack reads these imports to determine how to divide up the js file into 'chunks'.

The import syntax is not specifically a webpack thing, more like an es6 thing. I am using this extensively in lots of projects and without issues with es6-plato (which is what I am confused about)

unless you mean the import like as a return from a function, and written as a function and uses a promise syntax... im guessing you mean this? (https://github.com/airbnb/babel-plugin-dynamic-import-webpack) (https://github.com/tc39/proposal-dynamic-import)

might hit up the author of https://github.com/typhonjs-node-escomplex/typhonjs-escomplex the underlying module I am parsing with

@seanohue
Copy link
Author

seanohue commented Dec 4, 2018

Yes -- I was using the dynamic import() with Webpack. Plato works fine with any other kind of imports. I'll see if TyphonJS allows for parsing dynamic imports, since swapping out parsers or allowing for swappable parsers would be a lot of work. Thanks for pointing me in the right direction.

@the-simian
Copy link
Owner

@seanohue some time ago when I migrated this project to ES6 that was one of the better parsers (for complexity analysis) there was. If there's a better one, point me to it for sure.

@the-simian
Copy link
Owner

I see the issue and the latest version of the underlying parser will fix this:
es-analysis#214

@the-simian
Copy link
Owner

@seanohue Just popping in to say that I'm going to be implementing a fix related to project dependencies. I'll be removing Grunt as much as I can, updating globby and also updating the underplaying parser. This, among some other issues, will go away. I'll post in here when that is done and also THANK YOU for opening this issue and discussing it over this time.

@the-simian the-simian self-assigned this Feb 5, 2019
@the-simian the-simian added the bug label Feb 5, 2019
@seanohue
Copy link
Author

seanohue commented Feb 5, 2019

Amazing! Thanks for doing some research on this. Ping me if you need any more info.

@the-simian
Copy link
Owner

@seanohue ok I am still working on this. all I can say is that I can repro it. I get
SyntaxError: Unexpected token (18:21) when I hit the first 'inline' import statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants