Repository navigation
fix(parser): reject module export names containing a lone surrogate - #26953
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
…26953) A module export name that is not well-formed Unicode is an [early error](https://tc39.es/ecma262/#sec-module-semantics-static-semantics-early-errors) (`ModuleExportName : StringLiteral` is a Syntax Error if `IsStringWellFormedUnicode` of its value is false), and the parser reported it, but it still built the node and returned the recovered AST. Every consumer of `ModuleExportName::name` therefore had to tolerate an export name that cannot exist in a valid module. Acorn rejects the input outright, and Babel does the same unless error recovery is enabled. Make the error fatal, so no AST carries an ill-formed export name. Consumers can treat the name as well-formed by construction. This is preparation for the JSStr stack (#26242), where `ModuleExportName::name` keeps returning UTF-8 text and currently needs a fallback for exactly this case; with this change the fallback becomes dead and is removed there. ## Example ```js export { x as "\uD800" }; ``` Before, the error was reported and parsing continued with a recovered AST. After, the same diagnostic is reported and parsing stops: ``` x An export name cannot include a unicode lone surrogate ``` The test262 negative test `early-export-ill-formed-string.js` still fails to parse; it now reports only its first error instead of three, and a duplicate-export diagnostic that printed the surrogate as marker text disappears with it. Verified with four new misc fixtures covering the export, re-export, namespace re-export, and import forms, the parser, semantic, codegen, and lexer conformance runs, and the parser, semantic, and linter test suites. Implemented with AI assistance.
e25a1d5 to
01ff33e
Compare
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
### 🚀 Features - 02331c8 str: Add `JSStr`, `JSChar` and `JSStrBuilder` types (#26435) (Dunqing) - 52ae63f regular_expression: Support buffer boundary assertions (#27048) (Boshen) - 3255b89 transform-react: Add `reportDiagnostics` option to expose recoverable React Compiler diagnostics (#26624) (Jack) - f585cb4 napi: Add threadless WASI builds (#26898) (Boshen) ### 🐛 Bug Fixes - c380c85 minifier: Preserve iife with directives (#27060) (Armano) - c55b35d str: Correct clippy reason (#27013) (overlookmotel) - 8fbddb1 formatter/jsdoc: More alignment with original plugin (#27039) (leaysgur) - 5186328 parser: Handle HTML comment values (#22933) (Boshen) - 01ff33e parser: Reject module export names containing a lone surrogate (#26953) (Dunqing) - d79ad19 codegen: Remove redundant dollar escapes in minified templates (#26924) (camc314) ### ⚡ Performance - 0afbf85 minifier: Fold logical expressions in place (#26768) (Armano) - 3471f29 minifier: Avoid creation of empty block when folding try finally (#26971) (Armano) - 3893d64 minifier: Update boolean context expressions in place (#26823) (Armano) - de8af47 minifier: Take return argument directly when converting arrow fn (#26830) (Armano) - fc37ba0 minifier: Reduce allocations when minimizing assignments (#26609) (Armano) - dce64f6 minifier: Use ident hashes for catch var and arguments (#26907) (Armano) - 57610b3 minifier: Use ident hashes in label comparison (#26887) (Armano) ### 📚 Documentation - dfa6cf9 str: Reformat and simplify comments (#27011) (overlookmotel) - d775315 parser: Document AST property order (#27038) (Boshen) - cd80e3f ast: Correct `JSXExpressionContainer` example (#26975) (camc314) - 8cb05e3 ast: Simplify `JSXAttribute` value description (#26974) (camc314) - fda7fbb ast: Correct `TSNumberKeyword` example (#26973) (camc314) - e63c439 ast: Clarify `RegExpFlags::V` flag features (#26972) (camc314) - 278288e ast: Correct `JSXText` example (#26970) (camc314) - e9ff529 ast: Correct `TSIntrinsicKeyword` example (#26967) (camc314) - c643ce4 ast: Fix `TSTupleType` example syntax (#26966) (camc314) - 895b1a7 ast: Correct `TSPropertySignature` usage example (#26964) (camc314) - 8d8cc7c ast: Correct `Class` abstract example values (#26963) (camc314) - f7ef2e2 ast: Use valid variance example for `TSTypeParameter` (#26962) (camc314) - 145fcdb ast: Attach `pure` comment to `NewExpression` field (#26961) (camc314) - 06dfd9f ast: Clarify `TSNonNullExpression` docs (#26960) (camc314) - d5f92b5 ast: Add docs for TSNonNullExpression (#26910) (camchenry) - 4a76723 ast: Add docs for TSNamespaceExportDeclaration (#26909) (camchenry) - de41927 ast: Add docs for `TSInstantiationExpression` (#26908) (camchenry)
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
oxc-project/oxc#26953 Oxc now treats module export names containing a Unicode lone surrogate as a fatal parse error. Parsing stops after the first diagnostic instead of returning a recovered AST that triggers additional semantic errors. The test262 module-code snapshot removes two repeated lone-surrogate diagnostics and the downstream duplicate-export diagnostic for early-export-ill-formed-string.js. The remaining single parse error is the expected ECMAScript early error. First-Bad-Oxc-Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 Oxc-Revision: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9
## Summary - Upgrade Oxc Rust dependencies to the published 0.152.0 crates. - Upgrade `@oxc-project/runtime`, `@oxc-project/types`, `oxc-parser`, and `oxc-transform` JavaScript packages to 0.152.0. ## Root causes ### oxc-project/oxc#26953 oxc-project/oxc#26953 Oxc now treats a lone surrogate in a module export name as a fatal parse error. Rolldown's test262 module-code snapshot accordingly retains the one expected early error and removes two duplicate parse diagnostics plus a downstream duplicate-export diagnostic that depended on recovery after the fatal error. Commit: 01ff33e9c834a04eda027a9f5716a3dbf0f389b9 ### oxc-project/oxc#22933 oxc-project/oxc#22933 Oxc distinguishes HTML opening and closing comments in `CommentKind`. Rolldown handles the new variants as line comments when generating sourcemap references, preserving the existing `//` reference form. No snapshot changes were needed. Commit: 51863287632df2ab85cafc16c9d66015c5d5a754 ### oxc-project/oxc#27078 oxc-project/oxc#27078 Oxc moved to `oxc_sourcemap` 9, so Rolldown must use the same version to avoid incompatible `SourceMap` types. Source maps now serialize the standard `ignoreList` field; Rolldown still accepts legacy `x_google_ignoreList` input and preserves the plugin/MagicString compatibility surface. The native and WASI binding declarations were regenerated for v9's NAPI sourcemap type and field changes. The allocation snapshot did not change. Commit: efc646a59041b183bb8b13c728bc824f07f33b85 Closes #11004

A module export name that is not well-formed Unicode is an early error (
ModuleExportName : StringLiteralis a Syntax Error ifIsStringWellFormedUnicodeof its value is false), and the parser reported it, but it still built the node and returned the recovered AST. Every consumer ofModuleExportName::nametherefore had to tolerate an export name that cannot exist in a valid module. Acorn rejects the input outright, and Babel does the same unless error recovery is enabled.Make the error fatal, so no AST carries an ill-formed export name. Consumers can treat the name as well-formed by construction. This is preparation for the JSStr stack (#26242), where
ModuleExportName::namekeeps returning UTF-8 text and currently needs a fallback for exactly this case; with this change the fallback becomes dead and is removed there.Example
Before, the error was reported and parsing continued with a recovered AST. After, the same diagnostic is reported and parsing stops:
The test262 negative test
early-export-ill-formed-string.jsstill fails to parse; it now reports only its first error instead of three, and a duplicate-export diagnostic that printed the surrogate as marker text disappears with it. Verified with four new misc fixtures covering the export, re-export, namespace re-export, and import forms, the parser, semantic, codegen, and lexer conformance runs, and the parser, semantic, and linter test suites.Implemented with AI assistance.