the-simian / es6-plato

JavaScript source code visualization, static analysis, and complexity tool
MIT License
205 stars 40 forks source link

Fails on dynamic import #72

Open seanohue opened 5 years ago

seanohue commented 5 years ago

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

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

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

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

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

@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 commented 5 years ago

I see the issue and the latest version of the underlying parser will fix this: https://github.com/es-analysis/plato/issues/214

the-simian commented 5 years ago

@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.

seanohue commented 5 years ago

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

the-simian commented 5 years ago

@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