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
Permit %%placeholder%% in left-hand-side of a let declaration #12725
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/39237/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c54793b:
|
There are a few different ways to implement this. I didn't like the idea of overriding So my choice was between adding adding a very narrow hook method that the plugin could override, or just adding ad-hoc code directly in the parser itself. I went with the ad-hoc code because it's very straightforward and compact, and that seems worth the downside of having placeholder code that lives outside the placeholder plugin. |
I'd like to add some explicit test cases for |
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.
I would really prefer to keep this code in placeholders.js
, even if we would then have to duplicate this.isContextual("let")
.
This isn't an hot code path (usually the placeholders plugin is not enabled), and even when perf matters the isContextual
function is not expensive.
Btw, thanks for also adding tests for the let %%LHS%%;
case!
eeb9955
to
ff82582
Compare
Just to be clear, I have only added tests for I had also written tests for |
Sorry I was tired 🙃 |
5b5994a
to
35efc3a
Compare
I'm rather baffled by my new failure test ( |
I think it could be because GitHub runs CI not on your branch, but on the result of merging your branch in |
9d6f705
to
c54793b
Compare
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.
Thanks!
This change adds support for template syntactic placeholders in the left-hand-side of a
let
declaration (e.g.let %%lhs%% = 7
).This already works for
var
andconst
, but wasn't working forlet
because the special handling needed to disambiguate let-as-keyword vs let-as-identifier didn't know to treat a following placeholder as though it were a variable.