-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add parser support for placeholders #9364
Add parser support for placeholders #9364
Conversation
export type Placeholder<N: PlaceholderTypes> = NodeBase & { | ||
type: "Placeholder", | ||
id: Identifier, | ||
expectedNode: N, |
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.
What do you prefer?
expectedNode
expectedType
expected
original
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10276/ |
I just wanted to ask once again why we aren't using {% %} (I'm totally OK with %% if {% can't be done!), I just know that {%%} gets used for a lot of templating systems and it would be cool to allow it to fit naturally into those. In particular I am currently considering gitbook.io, where it would be nice to be able to use the same templating syntax in both the markdown itself as well as the codeblocks. Again though, I'm open to a different thing just wanted to raise this. |
It is mainly because of https://github.com/keithamus/proposal-object-freeze-seal-syntax. Currently it uses If no one thinkgs that that proposal could use If the "open-close" tokens pair is better, maybe |
d2180c9
to
1abfbe2
Compare
@keithamus Do you think that the |
1abfbe2
to
aac75a2
Compare
Rebased and fixed #9364 (comment) |
@nicolo-ribaudo |
8e23611
to
3405274
Compare
3405274
to
18b465a
Compare
NOTE: Since %%FOO%% is parsed as an Expression, the following arrow functions are not valid: %%FOO%% => {}; async %%FOO%% => {}; The heads must be parenthesized: (%%FOO%%) => {}; async (%%FOO%%) => {}; Also, placeholders must be parenthesized when used inside decorators: Invalid: Valid: @%%DECO%% @(%%DECO%%) class X {} class X {}
c379076
to
4c6418f
Compare
Rebased on top of the scope tracking PR. The only changes are in the last two commits |
Co-Authored-By: nicolo-ribaudo <nicolo.ribaudo@gmail.com>
Off Topic: I changed the threshold to 30KB as the threshold is the total of changes for all assets together, so I calculated as 10KB per bundle + 5KB per minified bundle. |
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 (when `true`) and `FOO` placeholders. If it isn't specified, Babel tries to be "smart" to avoid breaking backward compat: if `%%foo%%` is used `syntacticPlaceholders` defaults to `true`, otherwise to `false`. 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.
I added support for
%%foo%%
style placeholders to@babel/parser
throught theplaceholders
plugin.Part of this PR, which is a small refactor of import/export parsing, is split up at #9326 since it can be reviewd by its own.
For now I only allowed the
Placeholder :: %% Identifier %%
syntax, it could be expanded later.@babel/types
,@babel/generator
and@babel/template
support will come in separate PRs.cc @tolmasky