Repository navigation
refactor(ast)!: migrate string literals and templates to JSStr - #26548
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
|
e54d697 to
28e02f7
Compare
28e02f7 to
cf4b7d7
Compare
297b495 to
194cd64
Compare
194cd64 to
6610acd
Compare
cf4b7d7 to
c64ceeb
Compare
6610acd to
782e863
Compare
eda8341 to
5cd7f34
Compare
StringLiteral::value and TemplateElementValue from Str to JSStr
There was a problem hiding this comment.
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().
|
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. |
leaysgur
left a comment
There was a problem hiding this comment.
Reviewed formatter related files and 👍🏻 (Sorry for conflicts...!)
overlookmotel
left a comment
There was a problem hiding this comment.
Excellent! I have a few small follow-ups. Will put up PRs once I've reviewed the next 2 and got this merged.
|
Restacked the whole stack on latest main to hopefully fix the failing security CI job, so can get this merged. |
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.

JavaScript strings can contain lone surrogates, which Rust's
strcannot hold. String literal values and template cooked values stored them in a private U+FFFD escape encoding behind alone_surrogatesflag that every consumer had to check.This migrates
StringLiteral::valueandTemplateElementValue::cookedtoJSStr, which keeps the exact UTF-16 value through parsing, AST consumers, codegen and ESTree/raw transfer. Code that needs Rust text callsJSStr::as_str(), which returnsNonefor 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::valueisJSStr<'a>, andTemplateElementValue::cookedisOption<JSStr<'a>>.lone_surrogatesfields, the*_with_lone_surrogatesbuilder methods,oxc_parser::Token::lone_surrogates, andimpl Display for StringLiteral.ImportAttributeKey::as_arena_stris renamed toas_js_str.TSEnumMemberName::static_name,TemplateLiteral::single_quasiandModuleRunnerTransform::transformreturnJSStr.oxc_estree::LoneSurrogatesStringwraps an iterator of code points.ModuleExportName::namepanics on a string name with a lone surrogate, which only a built AST can contain.Part of #26242.
Implemented with AI assistance.