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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve mustache whitespace stripping information in AST and printer #951

Merged
merged 1 commit into from Jul 4, 2019

Conversation

CvX
Copy link
Contributor

@CvX CvX commented Jun 29, 2019

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

Copy link
Member

@rwjblue rwjblue left a 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鈥檇 be completely fine to land (once green)...

@CvX CvX force-pushed the save-mustache-strip-options branch from 34ec15a to 3dc8912 Compare June 29, 2019 21:25
@CvX
Copy link
Contributor Author

CvX commented Jun 29, 2019

It鈥檚 the Edge tests that are randomly failing: https://travis-ci.org/glimmerjs/glimmer-vm/builds

I鈥檝e rebased and force-pushed to trigger Travis. Gotta spin the wheel. 馃槈

@CvX CvX marked this pull request as ready for review June 29, 2019 21:48
@rwjblue
Copy link
Member

rwjblue commented Jul 3, 2019

@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~}}';
Copy link
Member

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...

Copy link
Member

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...

Copy link
Contributor Author

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.

Copy link
Member

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).

@rwjblue rwjblue merged commit 7137fca into glimmerjs:master Jul 4, 2019
@rwjblue rwjblue changed the title Preserve mustache whitespace stripping information Preserve mustache whitespace stripping information in AST and printer Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support whitespace control (~)
2 participants