Skip to content

fix(parser): respect unicode escape in isUnparsedContextual - #18443

Merged
JLHwung merged 2 commits into
babel:mainfrom
JLHwung:fix-parser-unparsed-contextual-escape
Oct 31, 2026
Merged

JLHwung merged 2 commits into
babel:mainfrom
JLHwung:fix-parser-unparsed-contextual-escape

Conversation

@JLHwung

@JLHwung JLHwung commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Babel accepts invalid JS async function\u{61} f() {}
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

In this PR we fix an issue reported by the Claude Fable: The isUnparsedContextual missed \ escape when doing ad-hoc lookahead, and therefore it incorrectly considers \ as the end of an identifier name, although \u can continue.

We also fixed a regression introduced in #17354: Currently throws a confusing error for export type from\u{61} = number;: "Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled" as the parser simply takes from without checking the boundaries when expecting the flow/typescript plugin.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser 7.x: needs backport labels Oct 29, 2026
@babel-bot

babel-bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62862

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 6eef881

@JLHwung
JLHwung force-pushed the fix-parser-unparsed-contextual-escape branch from f4745af to 783be78 Compare October 29, 2026 14:47
`isUnparsedContextual` matched a name in the raw input when the next
character was not an IdentifierPart, but a backslash starts a `\u`
escape that continues the same IdentifierName: `function\u{61}` is the
identifier `functiona`, not the keyword `function`, and `using\u{61}` is
`usinga`. So `async function\u{61} f(){}` was parsed as an async function
declaration and `for (using of\u{61} = x;;);` was rejected although it is
a `using` declaration binding `ofa`.

Assisted-by: Claude Fable 5.1 <[email protected]>
@JLHwung
JLHwung force-pushed the fix-parser-unparsed-contextual-escape branch from 64d2e1f to 6eef881 Compare October 31, 2026 17:47
@JLHwung
JLHwung added this pull request to the merge queue Oct 31, 2026
Merged via the queue into babel:main with commit 1149eae Oct 31, 2026
59 of 60 checks passed
@JLHwung
JLHwung deleted the fix-parser-unparsed-contextual-escape branch October 31, 2026 18:13
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18483.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants