Repository navigation
fix(generator): escape of binding of a using declaration in for-of head - #18430
nicolo-ribaudo merged 2 commits into
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62912 |
|
commit: |
Merging this PR will degrade performance by 39.04%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression with the CodSpeed MCP and your agent. Comparing |
|
For this |
Indeed, and I think the preserveFormat mode is exactly for such purpose. I will check if we can preserve the escape format of different |
| this.word(this.tokenMap ? lastRawIdentResult : node.name); | ||
| let name = this.tokenMap ? lastRawIdentResult : node.name; | ||
| if (name === "of" && this.tokenContext & TokenContext.usingForOfBinding) { | ||
| name = "\\u006ff"; |
There was a problem hiding this comment.
Very nit-picky, but I'd prefer if we escaped the f instead of the o. I feel like if it at least starts with a normal identifier character it will be more obvious that this is just a "normal" identifier.
7fa7fe6 to
db43d50
Compare
…head
`for (using \u{6f}f of y);` was printed as `for (using of of y);`, which
does not parse: the token pair `using of` is excluded by lookahead at the
start of a for-of head so that `for (using of x)` keeps meaning "iterate
with the identifier `using`", so the binding `of` must be spelled with a
Unicode escape (the escape is not retained in the AST). Parentheses are
not an option because a binding identifier cannot be parenthesized.
Set a `TokenContext.usingForOfBinding` flag while printing the binding of
a `using` declaration that is the left of a ForOfStatement, and make the
Identifier printer emit `of` for a binding named `of` in that context.
`await using`, `for (using of = 1;;)` and `using of = 1;` are unaffected.
Assisted-by: Claude Fable 5.1
db43d50 to
c21e875
Compare
|
(merging this as it's a low-risk one and I want to see the test262 cache in action) |
|
Backported to 7.x in #18500. |
for (using \u006ff of y);, closes #15117.In this PR we fix an issue reported by Claude Fable:
for (using \u{6f}f of y);was printed asfor (using of of y);, which does not parse. Here we set aTokenContext.usingForOfBindingflag when printing the for-of head, and let the Identifier printer emit an escapedoffor a binding namedofin that context. Cases likeawait using,for (using of = 1;;)andusing of = 1;are not affected.Assisted-by: Claude Fable 5.1
/cc @fisker I updated the PR description to close #15117: I think the contextual identifier case should be fixed in generators rather than the parser: Even if we can add the
.rawdata to the AST, it risks out-of-sync information when the AST is modified: because the identifier buildert.identifiernow has to check the surrounding context to decide if it should escape theofor not. The generator fix ensures that ultimately, no matter how the AST is manipulated, as long as the AST is still valid, the output JS code is always valid.