Skip to content

refactor(ast)!: migrate string literals and templates to JSStr - #26548

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/jsstr-migration
Oct 14, 2026
Merged

graphite-app[bot] merged 1 commit into
mainfrom
codex/jsstr-migration

Conversation

@Dunqing

@Dunqing Dunqing commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

JavaScript strings can contain lone surrogates, which Rust's str cannot hold. String literal values and template cooked values stored them in a private U+FFFD escape encoding behind a lone_surrogates flag that every consumer had to check.

This migrates StringLiteral::value and TemplateElementValue::cooked to JSStr, which keeps the exact UTF-16 value through parsing, AST consumers, codegen and ESTree/raw transfer. Code that needs Rust text calls JSStr::as_str(), which returns None for a value with a lone surrogate. Surrogate halves written as separate escapes or concatenated from separate parts are joined. Enum members whose name or value contains a lone surrogate keep their string kind, so lowering no longer emits a reverse mapping for a string alias that could overwrite another member.

Some lint and declaration checks skip lone-surrogate names until #26677, #27095, #26716 and #26717.

Breaking changes

  • StringLiteral::value is JSStr<'a>, and TemplateElementValue::cooked is Option<JSStr<'a>>.
  • Removed: the lone_surrogates fields, the *_with_lone_surrogates builder methods, oxc_parser::Token::lone_surrogates, and impl Display for StringLiteral.
  • ImportAttributeKey::as_arena_str is renamed to as_js_str. TSEnumMemberName::static_name, TemplateLiteral::single_quasi and ModuleRunnerTransform::transform return JSStr.
  • oxc_estree::LoneSurrogatesString wraps an iterator of code points.
  • ModuleExportName::name panics on a string name with a lone surrogate, which only a built AST can contain.

Part of #26242.

Implemented with AI assistance.

Dunqing commented Sep 11, 2026 •

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@github-actions github-actions Bot added A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details A-parser Area - JS/TS parsing and syntax errors, oxc_parser A-semantic Area - Scopes, symbols, references and semantic errors, oxc_semantic A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-minifier Area - Minification, compression and name mangling, oxc_minifier / oxc_mangler A-ast Area - AST definitions and visitors, oxc_ast / oxc_ast_visit A-transformer Area - JS/TS transforms and downleveling, oxc_transformer A-codegen Area - JS/TS code printing and source maps, oxc_codegen A-isolated-declarations Area - TypeScript declaration (.d.ts) generation, oxc_isolated_declarations A-ast-tools Area - AST code generation tooling, tasks/ast_tools A-formatter Area - Formatter (oxfmt). Add F-* labels for details L-js-plugins Linter > JS plugins (ESLint-compatible plugin API) A-react-compiler Area - React Compiler transforms and lint rules, oxc_react_compiler A-ecmascript Area - ECMAScript spec operations, oxc_ecmascript labels Sep 11, 2026
@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 87 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing codex/jsstr-migration (d8fcdb4) with main (82ecc43)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@github-actions github-actions Bot added the A-regular-expression Area - Regular expression parsing and validation, oxc_regular_expression label Sep 14, 2026
@Dunqing
Dunqing force-pushed the codex/jsstr-migration branch from e54d697 to 28e02f7 Compare September 14, 2026 09:09
@Dunqing
Dunqing changed the base branch from codex/jsstr-core to graphite-base/26548 September 14, 2026 09:09
@Dunqing
Dunqing changed the base branch from graphite-base/26548 to codex/jsstr-static-name September 14, 2026 09:09
@Dunqing
Dunqing force-pushed the codex/jsstr-migration branch from 28e02f7 to cf4b7d7 Compare September 14, 2026 09:32
@Dunqing
Dunqing force-pushed the codex/jsstr-static-name branch from 297b495 to 194cd64 Compare September 14, 2026 09:32
@Dunqing
Dunqing changed the base branch from codex/jsstr-static-name to graphite-base/26548 September 15, 2026 02:09
@Dunqing
Dunqing force-pushed the graphite-base/26548 branch from 194cd64 to 6610acd Compare September 15, 2026 02:10
@Dunqing
Dunqing force-pushed the codex/jsstr-migration branch from cf4b7d7 to c64ceeb Compare September 15, 2026 02:10
@Dunqing
Dunqing changed the base branch from graphite-base/26548 to codex/jsstr-core September 15, 2026 02:10
@Dunqing
Dunqing force-pushed the codex/jsstr-migration branch from eda8341 to 5cd7f34 Compare September 15, 2026 05:12

@overlookmotel overlookmotel left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my god it's a biggie!

I've not reviewed it all - I only skimmed oxc_ecmascript, formatter, isolated declarations, linter, minifier, transformer. I did go through everything else properly.

A few comments below.

So is the plan to hold off merging this until all the follow-ups are complete? Obviously concern is that merge conflicts are inevitable if we leave this open for a long time. On other hand, if we merge to soon, it could cause breakage for users.

And by the looks of things there's a lot of follow-up changes to make - many many many places where currently exit / do the wrong thing if js_str.as_str().is_none().

Comment thread crates/oxc_ast/src/ast/jsx.rs Resolved
Comment thread crates/oxc_ast/src/ast_impl/js.rs Resolved
Comment thread crates/oxc_ast/src/ast_impl/js.rs Resolved
Comment thread crates/oxc_codegen/src/gen.rs Resolved
Comment thread crates/oxc_codegen/src/str.rs Resolved
Comment thread crates/oxc_str/src/js_str.rs Resolved
Comment thread crates/oxc_str/src/js_str.rs Resolved
Comment thread crates/oxc_parser/src/js/module.rs Resolved
@Dunqing

Dunqing commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review!

I'd like to merge the stack in a batch rather than hold this one back.

The remaining cases are tracked in #26242.

@camc314 camc314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@leaysgur leaysgur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed formatter related files and 👍🏻 (Sorry for conflicts...!)

@overlookmotel overlookmotel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! I have a few small follow-ups. Will put up PRs once I've reviewed the next 2 and got this merged.

@overlookmotel

Copy link
Copy Markdown
Member

Restacked the whole stack on latest main to hopefully fix the failing security CI job, so can get this merged.

@graphite-app

graphite-app Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge activity

JavaScript strings can contain lone surrogates, which Rust's `str` cannot hold. String literal values and template cooked values stored them in a private U+FFFD escape encoding behind a `lone_surrogates` flag that every consumer had to check.

This migrates `StringLiteral::value` and `TemplateElementValue::cooked` to `JSStr`, which keeps the exact UTF-16 value through parsing, AST consumers, codegen and ESTree/raw transfer. Code that needs Rust text calls `JSStr::as_str()`, which returns `None` for a value with a lone surrogate. Surrogate halves written as separate escapes or concatenated from separate parts are joined. Enum members whose name or value contains a lone surrogate keep their string kind, so lowering no longer emits a reverse mapping for a string alias that could overwrite another member.

Some lint and declaration checks skip lone-surrogate names until #26677, #27095, #26716 and #26717.

## Breaking changes

- `StringLiteral::value` is `JSStr<'a>`, and `TemplateElementValue::cooked` is `Option<JSStr<'a>>`.
- Removed: the `lone_surrogates` fields, the `*_with_lone_surrogates` builder methods, `oxc_parser::Token::lone_surrogates`, and `impl Display for StringLiteral`.
- `ImportAttributeKey::as_arena_str` is renamed to `as_js_str`. `TSEnumMemberName::static_name`, `TemplateLiteral::single_quasi` and `ModuleRunnerTransform::transform` return `JSStr`.
- `oxc_estree::LoneSurrogatesString` wraps an iterator of code points.
- `ModuleExportName::name` panics on a string name with a lone surrogate, which only a built AST can contain.

Part of #26242.

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

Labels

A-ast Area - AST definitions and visitors, oxc_ast / oxc_ast_visit A-ast-tools Area - AST code generation tooling, tasks/ast_tools A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-codegen Area - JS/TS code printing and source maps, oxc_codegen A-ecmascript Area - ECMAScript spec operations, oxc_ecmascript A-formatter Area - Formatter (oxfmt). Add F-* labels for details A-isolated-declarations Area - TypeScript declaration (.d.ts) generation, oxc_isolated_declarations A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details A-minifier Area - Minification, compression and name mangling, oxc_minifier / oxc_mangler A-parser Area - JS/TS parsing and syntax errors, oxc_parser A-react-compiler Area - React Compiler transforms and lint rules, oxc_react_compiler A-regular-expression Area - Regular expression parsing and validation, oxc_regular_expression A-semantic Area - Scopes, symbols, references and semantic errors, oxc_semantic A-transformer Area - JS/TS transforms and downleveling, oxc_transformer L-js-plugins Linter > JS plugins (ESLint-compatible plugin API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants