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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure codemod mode ignores whitespace control. #983

Merged
merged 1 commit into from Oct 28, 2019

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Oct 28, 2019

handlebars.parse automatically applies whitespace control to the AST before it is returned. For example, parsing the following template (feel free to review the AST on ASTExplorer):

 {{#foo}}
   {{~bar~}} {{baz~}}
 {{/foo}}

Using Handlebars.parse, the AST returned would have truncated the following whitespace:

  • The whitespace prior to the {{#foo}}
  • The newline following {{#foo}}
  • The leading whitespace before {{~bar~}}
  • The whitespace between {{~bar~}} and {{baz~}}
  • The newline after {{baz~}}
  • The whitespace prior to the {{/foo}}

The inline parseWithoutProcessing method can be removed when we update to a version of handlebars that includes handlebars-lang/handlebars.js#1584 (likely to be 4.5.0).

`handlebars.parse` automatically applies whitespace control to the AST
before it is returned. For example, parsing the following template
([feel free to review the AST on
ASTExplorer](https://astexplorer.net/#/gist/f850c5457b808756107c0bc5ad226989/b0366df64be5c01b5f9eadd93e795b3b9d65d2c7)):

```hbs
 {{#foo}}
   {{~bar~}} {{baz~}}
 {{/foo}}
```

Using `Handlebars.parse`, the AST returned would have truncated the following whitespace:

* The whitespace prior to the `{{#foo}}`
* The newline following `{{#foo}}`
* The leading whitespace before `{{~bar~}}`
* The whitespace between `{{~bar~}}` and `{{baz~}}`
* The newline after `{{baz~}}`
* The whitespace prior to the `{{/foo}}`

A future version of `handlebars` (likely 4.5.0) will have a new method named
`parseWithoutProcessing`. When we update to that version we can remove
the custom workaround here.
@rwjblue
Copy link
Member Author

rwjblue commented Oct 28, 2019

Labeling this as "breaking" since the impact to tooling currently using codemod mode is that they have to remove work arounds for the previously stripped whitespace.

let parseOptions = options.parseOptions || {};

if (mode === 'codemod') {
parseOptions.ignoreStandalone = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - ignoreStandalone is not used in parseWithoutProcessing mode so no need to preserve passing it here.

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.

None yet

1 participant