-
Notifications
You must be signed in to change notification settings - Fork 344
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
Template expressions are incorrectly indented #216
Comments
Oh, interesting. I'm not sure the spaces inside the back-ticks are even considered as indentation, as far as Recast is currently concerned. So part of the double indentation is coming from the pretty printer, and the other half is coming from the original template string expression. GraphQL template strings can be reindented harmlessly, but I think in general we need to avoid adding or removing "indentation" from multi-line template strings. |
A heuristic that could be used: if all lines are indented, assume it's some sort of markup and okay to re-indent. Preserving the same indent would already be better and solve most cases (when changes don't affect indentation). |
Started looking into this again: http://felix-kling.de/esprima_ast_explorer/#/N2D8hbBQ3I/1 |
Thanks! |
Looks like this still exhibits a bug after 9e6fdb8: http://felix-kling.de/esprima_ast_explorer/#/N2D8hbBQ3I/1 (I tested using a local install of |
@benjamn Should I file a new issue for this? |
This was still broken due to a combination of incomplete indentation-locking logic (4de9390) and some bad Just published v0.10.39 to NPM: https://www.npmjs.com/package/recast |
There's a handful of files inside of Nuclide that throw exceptions because an assertion is raised. ``` { AssertionError: ']' === '`' at fixTemplateLiteral (/Users/vjeux/random/prettier/src/util.js:105:10) at Object.util.fixFaultyLocations (/Users/vjeux/random/prettier/src/util.js:45:5) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:25:8) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:61:5) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:71:20) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at /Users/vjeux/random/prettier/src/comments.js:129:5 ``` When trying https://github.com/facebook/nuclide/blob/master/pkg/nuclide-task-runner/lib/main.js#L174 It throws in the fixTemplateLiteral method. That method was added to fix benjamn/recast#216 more than a year ago ```js var x = { y: () => Relay.QL` query { ${foo}, field, } ` }; ``` I've checked (and added a test) and it now parses and prints correctly without that method. So it should be safe to remove.
There's a handful of files inside of Nuclide that throw exceptions because an assertion is raised. ``` { AssertionError: ']' === '`' at fixTemplateLiteral (/Users/vjeux/random/prettier/src/util.js:105:10) at Object.util.fixFaultyLocations (/Users/vjeux/random/prettier/src/util.js:45:5) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:25:8) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:61:5) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:71:20) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at /Users/vjeux/random/prettier/src/comments.js:129:5 ``` When trying https://github.com/facebook/nuclide/blob/master/pkg/nuclide-task-runner/lib/main.js#L174 It throws in the fixTemplateLiteral method. That method was added to fix benjamn/recast#216 more than a year ago ```js var x = { y: () => Relay.QL` query { ${foo}, field, } ` }; ``` I've checked (and added a test) and it now parses and prints correctly without that method. So it should be safe to remove.
There's a handful of files inside of Nuclide that throw exceptions because an assertion is raised. ``` { AssertionError: ']' === '`' at fixTemplateLiteral (/Users/vjeux/random/prettier/src/util.js:105:10) at Object.util.fixFaultyLocations (/Users/vjeux/random/prettier/src/util.js:45:5) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:25:8) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:61:5) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:71:20) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at /Users/vjeux/random/prettier/src/comments.js:129:5 ``` When trying https://github.com/facebook/nuclide/blob/master/pkg/nuclide-task-runner/lib/main.js#L174 It throws in the fixTemplateLiteral method. That method was added to fix benjamn/recast#216 more than a year ago ```js var x = { y: () => Relay.QL` query { ${foo}, field, } ` }; ``` I've checked (and added a test) and it now parses and prints correctly without that method. So it should be safe to remove.
…ide (#218) There's a handful of files inside of Nuclide that throw exceptions because an assertion is raised. ``` { AssertionError: ']' === '`' at fixTemplateLiteral (/Users/vjeux/random/prettier/src/util.js:105:10) at Object.util.fixFaultyLocations (/Users/vjeux/random/prettier/src/util.js:45:5) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:25:8) at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:61:5) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:71:20) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7) at /Users/vjeux/random/prettier/src/comments.js:129:5 ``` When trying https://github.com/facebook/nuclide/blob/master/pkg/nuclide-task-runner/lib/main.js#L174 It throws in the fixTemplateLiteral method. That method was added to fix benjamn/recast#216 more than a year ago ```js var x = { y: () => Relay.QL` query { ${foo}, field, } ` }; ``` I've checked (and added a test) and it now parses and prints correctly without that method. So it should be safe to remove.
This is still broken. I originally filed an issue here: zxbodya/flowts#8 It seems to be looking at the first line of the template string and stripping that much indentation from all later lines. |
If a template expression is printed that's indented, it seems like indentation is added twice somewhere. This failing test illustrates the bug.
Output
The text was updated successfully, but these errors were encountered: