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

Not able to parse dynamic import #48

Closed
maxmilton opened this issue Sep 1, 2018 · 7 comments
Closed

Not able to parse dynamic import #48

maxmilton opened this issue Sep 1, 2018 · 7 comments
Assignees

Comments

@maxmilton
Copy link

What's the issue?

In trying to add this package in https://github.com/MaxMilton/sapper-template-rollup/tree/feat/use-closure-compiler I ran into the issue of import() not able to be be parsed processed by acorn, which is used through this package.

How do we reproduce the issue?

  1. Clone repo branch https://github.com/MaxMilton/sapper-template-rollup/tree/feat/use-closure-compiler.
  2. Install deps; yarn install.
  3. Run build; yarn run build.

Result:

yarn run v1.9.4
warning package.json: No license field
$ sapper build
> Building...
> Error transforming chunk with 'closure-compiler' plugin: baseVisitor[type] is not a function
error Command failed with exit code 1.

After some debugging you'll find acorn is trying to do baseVisitor['Import'], which is not available in acorn at the moment.

Additional context

By adding the acorn-dynamic-import package it's possible to support parsing import(). In fact this is exactly what closure-webpack-plugin is doing, as well as others like buble.

One other critical part of this is support in Closure Compiler itself for parser support for dynamic import: google/closure-compiler#2770. Although, it is possible for a rollup plugin to rewrite the import() into something else before it ever hits Closure so this issue is not necessarily dependant upon Closure parser support.

@kristoferbaxter
Copy link
Contributor

Happy to move over, I planned to move to the next major version of Acorn with the next release but will attempt to address this sooner.

@kristoferbaxter
Copy link
Contributor

I created a local branch using acorn-dynamic-import, but am running into issues with acorn's walk functionality when injecting the dynamic import plugin.

Going to wait on either kesne/acorn-dynamic-import#14, or look at extracting the version used in https://github.com/standard-things/esm/blob/master/src/acorn/internal/walk.js.

@kristoferbaxter
Copy link
Contributor

If anyone else wants to take a look at this before I have a chance to return to it, here's the branch with the progress I made.

https://github.com/ampproject/rollup-plugin-closure-compiler/tree/dynamic-import

@kristoferbaxter
Copy link
Contributor

Opened an issue on the acorn repo, acornjs/acorn#746

It appears that acorn-walk doesn't fully function when injecting plugins.

@kristoferbaxter
Copy link
Contributor

Created a repo with workaround for acorn-walk not working as expected with plugin injection: https://github.com/kristoferbaxter/dynamic-walk

Found another root issue preventing this from working: Each Plugin invocation creates a singluar set of transforms and applies them to source. When experimentalCodeSplitting is enabled in rollup, the plugin is invoked once causing the singleton transforms to be used on multiple outputs.

This means a parsed AST for one file is used to perform transformations on others. Whoops!

@kristoferbaxter
Copy link
Contributor

Released 0.8.0 with dynamic import support for simple optimizations.

@mckravchyk
Copy link

@kristoferbaxter I'm getting the same error message on 0.27.0 (simple optimizations) when I try to use MobX, points to acorn-walk/dist/walk.js:29:24 -

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

No branches or pull requests

3 participants