-
Notifications
You must be signed in to change notification settings - Fork 192
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
Preserve mustache whitespace stripping information in AST and printer #951
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like great progress! I think it’d be completely fine to land (once green)...
34ec15a
to
3dc8912
Compare
It’s the Edge tests that are randomly failing: https://travis-ci.org/glimmerjs/glimmer-vm/builds I’ve rebased and force-pushed to trigger Travis. Gotta spin the wheel. 😉 |
@wycats / @chancancode - Any objections to the AST changes made here? In practical terms, this is quite important to any codemod situations (e.g. prettier, ember-template-recast, angle-bracket-codemod, etc)... |
|
||
test('block whitespace control is preserved', function(assert) { | ||
let before = '\n{{~#foo-bar~}} {{~else if x~}} {{~else~}} {{~/foo-bar~}} '; | ||
let after = '{{~#foo-bar~}}{{~else if x~}}{{~else~}}{{~/foo-bar~}}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why is the newline removed? We want to ensure that it isn't removed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind working through this in a follow up? I'd like to merge now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue The newline is removed by handlebars.js parser:
handlebars/compiler/base.js#L22-L23
handlebars/compiler/whitespace-control.js#L30-L35
We could add a preserveWhitespace
option that would allow to return the AST with all whitespace information left intact.
Currently the only WhitespaceControl
option is ignoreStandalone
, which we use in the codemod
mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, that seems good to me. In the meantime, I think we can work around by adding back the whitespace that is stripped (at least in "codemod" mode).
Fixes https://github.com/rajasegar/ember-angle-brackets-codemod/issues/46 (a part of the prettier quest: jgwhite/prettier#1)
This PR most likely requires some work (e.g. not sure how I feel about those
{ open: true, close: false }
all over the place), so all feedback is welcome! 🙂cc: @GavinJoyce @rwjblue @jgwhite