-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Dynamic import with webpackChunkName comment fails #1489
Comments
Thanks for reporting this error! We need to fix it. In the meantime, there are a few options for you:
|
Great, thanks. I thought I had to use the flow parser if I was using flow. The babylon parser does seem to work just fine, so I'll switch over to using that. Thanks! |
Yeah, sorry about that, it's confusing a lot of people and we're not doing a good job at explaining. Both parsers support the same set of language features, the main reason to have both is mostly insurance. So if one gets behind, we have a fallback. Good news is that both teams are very responsive on issues :) |
For some reason, the traversal logic to find comment doesn't go through the same path where the name of CallExpression is of type Literal vs Import. What happens currently is that it attaches the comment as a dangling comment to the Import node, which doesn't know how to print it. |
I started digging into this issue and took minimal example:
vs
They are parsed completely differently by flow-parser:
vs
Thus comment is contained by |
btw, another case
doesn't throw but it has wrong output:
Here |
It seems like I fixed this issue in #2748 but some cases are not handled:
is working but output is
Is this ok? |
That's fine, much better than how we were previously handling it. Thanks! |
Prettier dies when trying to format a file that has a dynamic import with a webpackChunkName magic comment as described in the Webpack docs. For example, the following code:
fails with this error:
This is happening with Prettier v1.3.0
https://prettier.github.io/prettier/#%7B%22content%22%3A%22const%20foo%20%3D%20%20import(%2F*%20webpackChunkName%3A%20%5C%22foo%5C%22%20*%2F%20'.%2Ffoo')%3B%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22parser%22%3A%22flow%22%2C%22semi%22%3Afalse%2C%22useTabs%22%3Afalse%2C%22doc%22%3Afalse%7D%7D
The text was updated successfully, but these errors were encountered: