handlebars: Support escaping a mustache with a backslash #8634
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In handlebars, it is possible to escape a mustache with a backslash. See handelbars documentation here.
This PR propose to add the support for this feature.
This would close #8633
Initial report: jgwhite#1 (comment)
Details
This PR would introduce a new file:
src/language-handlebars/preprocess.js
. It is present to make an adjustement to the AST produced by Glimmer parser.Indeed, given that template:
Glimmer parser will produce two nodes for the template body:
node.chars === "a non-escaped mustache: \\\\"
(note the backslash escaping here, so it is actually"a non-escaped mustache: \\"
, which means that a backslash has been swallowed){{helper}}
In order to correctly print the input, we need to adjust the TextNode to
node.chars === "a non-escaped mustache: \\\\\\"
(or"a non-escaped mustache: \\\"
without the backslash escaping), namely we have to add a backslash that is removed by Glimmer parser. This is the third commit purpose. If you'd like you could checkout the second commit's CI report. It highlights the need for the third commit (the preprocess file).Checklist
docs/
directory)changelog_unreleased/*/pr-XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨