Add %%placeholders%% support to @babel/template #9648
Merged
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.
This is the last step to make #9364 usable in Babel. I'm sorry for opening this PR so late, but I hope to get it in v7.4.
In this PR I added a new option to
@babel/template
,syntacticPlaceholders: ?boolean
, which toggles between%%foo%%
placeholders (whentrue
) andFOO
placeholders. If it isn't specified, Babel tries to be "smart" to avoid breaking backward compat: if%%foo%%
is usedsyntacticPlaceholders
defaults totrue
, otherwise tofalse
.0e58e25 commit shows how some templates we used could be simplified by using this new placeholders syntax (we can't actually do it yet because we are importing
template
from@babel/core
which could be an older version).NOTE: Since I wanted to keep this PR as small as possible to make it easier to review, I didn't migrate
template.ast
to internally use the new syntax. It is an implementation detail, so it will be possible to change it in a patch release.