Repository navigation
Closed
Labels
area:commentsIssues with how Prettier prints commentslocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!
Description
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:
const foo = import(/* webpackChunkName: "foo" */ './foo');fails with this error:
src/client/pages/trace/Page.js: Error: Comment "webpackChunkName: "foo"" was not printed. Please report this error!
at astComments.forEach.comment (/Users/parma36/projects/hugo/node_modules/prettier/index.js:69:13)
at Array.forEach (native)
at ensureAllCommentsPrinted (/Users/parma36/projects/hugo/node_modules/prettier/index.js:67:15)
at format (/Users/parma36/projects/hugo/node_modules/prettier/index.js:85:3)
at formatWithShebang (/Users/parma36/projects/hugo/node_modules/prettier/index.js:91:12)
at Object.format (/Users/parma36/projects/hugo/node_modules/prettier/index.js:105:12)
at format (/Users/parma36/projects/hugo/node_modules/prettier/bin/prettier.js:234:19)
at err (/Users/parma36/projects/hugo/node_modules/prettier/bin/prettier.js:328:16)
at filenames.forEach.filename (/Users/parma36/projects/hugo/node_modules/prettier/bin/prettier.js:385:9)
at Array.forEach (native)
This is happening with Prettier v1.3.0
Reacted by Alessandro Di Felice, Nick Gushchin and Jarrod Mosen
Metadata
Metadata
Assignees
Labels
area:commentsIssues with how Prettier prints commentslocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!
Activity
vjeux commentedon May 2, 2017
Thanks for reporting this error! We need to fix it. In the meantime, there are a few options for you:
// prettier-ignorein the line beforepbomb commentedon May 2, 2017
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!
vjeux commentedon May 3, 2017
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 :)
vjeux commentedon May 22, 2017
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.
rkurbatov commentedon Sep 4, 2017
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
Importnode with no preceding and following node while in prompt case it hasIdentifierandLiteralas preceding and following.I cannot write special handler as (in any case) I have only
enclosingNodeso comment attaching can be done only before or after 'import' function name. It seems likeflow-parserbug that requires special handling bydecorateCommentfunction and that's too much as for me.rkurbatov commentedon Sep 4, 2017
btw, another case
doesn't throw but it has wrong output:
Here
enclosingNodeisExpressionStatementandprecedingNodeisCallExpressioninstead ofLiteral.rkurbatov commentedon Sep 4, 2017
It seems like I fixed this issue in #2748 but some cases are not handled:
is working but output is
Is this ok?
azz commentedon Sep 5, 2017
That's fine, much better than how we were previously handling it. Thanks!