Skip to content

Commit 888ef25

Browse files
committed
feat(parser,codegen): handle long surrogate in string literal
closes #3526
1 parent 1c32047 commit 888ef25

File tree

16 files changed

+362
-132
lines changed

16 files changed

+362
-132
lines changed

crates/oxc_ast/src/ast/literal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ pub struct StringLiteral<'a> {
8383
/// `None` when this ast node is not constructed from the parser.
8484
#[content_eq(skip)]
8585
pub raw: Option<Atom<'a>>,
86+
87+
/// The string value contains replacement character (U+FFFD).
88+
#[builder(default)]
89+
#[estree(skip)]
90+
pub lossy: bool,
8691
}
8792

8893
/// BigInt literal

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,11 @@ const _: () = {
295295
assert!(size_of::<Statement>() == 16);
296296
assert!(align_of::<Statement>() == 8);
297297

298-
assert!(size_of::<Directive>() == 64);
298+
assert!(size_of::<Directive>() == 72);
299299
assert!(align_of::<Directive>() == 8);
300300
assert!(offset_of!(Directive, span) == 0);
301301
assert!(offset_of!(Directive, expression) == 8);
302-
assert!(offset_of!(Directive, directive) == 48);
302+
assert!(offset_of!(Directive, directive) == 56);
303303

304304
assert!(size_of::<Hashbang>() == 24);
305305
assert!(align_of::<Hashbang>() == 8);
@@ -666,27 +666,27 @@ const _: () = {
666666
assert!(offset_of!(ImportExpression, options) == 24);
667667
assert!(offset_of!(ImportExpression, phase) == 56);
668668

669-
assert!(size_of::<ImportDeclaration>() == 104);
669+
assert!(size_of::<ImportDeclaration>() == 112);
670670
assert!(align_of::<ImportDeclaration>() == 8);
671671
assert!(offset_of!(ImportDeclaration, span) == 0);
672672
assert!(offset_of!(ImportDeclaration, specifiers) == 8);
673673
assert!(offset_of!(ImportDeclaration, source) == 40);
674-
assert!(offset_of!(ImportDeclaration, phase) == 80);
675-
assert!(offset_of!(ImportDeclaration, with_clause) == 88);
676-
assert!(offset_of!(ImportDeclaration, import_kind) == 96);
674+
assert!(offset_of!(ImportDeclaration, phase) == 88);
675+
assert!(offset_of!(ImportDeclaration, with_clause) == 96);
676+
assert!(offset_of!(ImportDeclaration, import_kind) == 104);
677677

678678
assert!(size_of::<ImportPhase>() == 1);
679679
assert!(align_of::<ImportPhase>() == 1);
680680

681681
assert!(size_of::<ImportDeclarationSpecifier>() == 16);
682682
assert!(align_of::<ImportDeclarationSpecifier>() == 8);
683683

684-
assert!(size_of::<ImportSpecifier>() == 96);
684+
assert!(size_of::<ImportSpecifier>() == 104);
685685
assert!(align_of::<ImportSpecifier>() == 8);
686686
assert!(offset_of!(ImportSpecifier, span) == 0);
687687
assert!(offset_of!(ImportSpecifier, imported) == 8);
688-
assert!(offset_of!(ImportSpecifier, local) == 56);
689-
assert!(offset_of!(ImportSpecifier, import_kind) == 88);
688+
assert!(offset_of!(ImportSpecifier, local) == 64);
689+
assert!(offset_of!(ImportSpecifier, import_kind) == 96);
690690

691691
assert!(size_of::<ImportDefaultSpecifier>() == 40);
692692
assert!(align_of::<ImportDefaultSpecifier>() == 8);
@@ -704,49 +704,49 @@ const _: () = {
704704
assert!(offset_of!(WithClause, attributes_keyword) == 8);
705705
assert!(offset_of!(WithClause, with_entries) == 32);
706706

707-
assert!(size_of::<ImportAttribute>() == 96);
707+
assert!(size_of::<ImportAttribute>() == 112);
708708
assert!(align_of::<ImportAttribute>() == 8);
709709
assert!(offset_of!(ImportAttribute, span) == 0);
710710
assert!(offset_of!(ImportAttribute, key) == 8);
711-
assert!(offset_of!(ImportAttribute, value) == 56);
711+
assert!(offset_of!(ImportAttribute, value) == 64);
712712

713-
assert!(size_of::<ImportAttributeKey>() == 48);
713+
assert!(size_of::<ImportAttributeKey>() == 56);
714714
assert!(align_of::<ImportAttributeKey>() == 8);
715715

716-
assert!(size_of::<ExportNamedDeclaration>() == 112);
716+
assert!(size_of::<ExportNamedDeclaration>() == 120);
717717
assert!(align_of::<ExportNamedDeclaration>() == 8);
718718
assert!(offset_of!(ExportNamedDeclaration, span) == 0);
719719
assert!(offset_of!(ExportNamedDeclaration, declaration) == 8);
720720
assert!(offset_of!(ExportNamedDeclaration, specifiers) == 24);
721721
assert!(offset_of!(ExportNamedDeclaration, source) == 56);
722-
assert!(offset_of!(ExportNamedDeclaration, export_kind) == 96);
723-
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 104);
722+
assert!(offset_of!(ExportNamedDeclaration, export_kind) == 104);
723+
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 112);
724724

725-
assert!(size_of::<ExportDefaultDeclaration>() == 72);
725+
assert!(size_of::<ExportDefaultDeclaration>() == 80);
726726
assert!(align_of::<ExportDefaultDeclaration>() == 8);
727727
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
728728
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
729-
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 56);
729+
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 64);
730730

731-
assert!(size_of::<ExportAllDeclaration>() == 112);
731+
assert!(size_of::<ExportAllDeclaration>() == 128);
732732
assert!(align_of::<ExportAllDeclaration>() == 8);
733733
assert!(offset_of!(ExportAllDeclaration, span) == 0);
734734
assert!(offset_of!(ExportAllDeclaration, exported) == 8);
735-
assert!(offset_of!(ExportAllDeclaration, source) == 56);
736-
assert!(offset_of!(ExportAllDeclaration, with_clause) == 96);
737-
assert!(offset_of!(ExportAllDeclaration, export_kind) == 104);
735+
assert!(offset_of!(ExportAllDeclaration, source) == 64);
736+
assert!(offset_of!(ExportAllDeclaration, with_clause) == 112);
737+
assert!(offset_of!(ExportAllDeclaration, export_kind) == 120);
738738

739-
assert!(size_of::<ExportSpecifier>() == 112);
739+
assert!(size_of::<ExportSpecifier>() == 128);
740740
assert!(align_of::<ExportSpecifier>() == 8);
741741
assert!(offset_of!(ExportSpecifier, span) == 0);
742742
assert!(offset_of!(ExportSpecifier, local) == 8);
743-
assert!(offset_of!(ExportSpecifier, exported) == 56);
744-
assert!(offset_of!(ExportSpecifier, export_kind) == 104);
743+
assert!(offset_of!(ExportSpecifier, exported) == 64);
744+
assert!(offset_of!(ExportSpecifier, export_kind) == 120);
745745

746746
assert!(size_of::<ExportDefaultDeclarationKind>() == 16);
747747
assert!(align_of::<ExportDefaultDeclarationKind>() == 8);
748748

749-
assert!(size_of::<ModuleExportName>() == 48);
749+
assert!(size_of::<ModuleExportName>() == 56);
750750
assert!(align_of::<ModuleExportName>() == 8);
751751

752752
assert!(size_of::<V8IntrinsicExpression>() == 64);
@@ -771,11 +771,12 @@ const _: () = {
771771
assert!(offset_of!(NumericLiteral, raw) == 16);
772772
assert!(offset_of!(NumericLiteral, base) == 32);
773773

774-
assert!(size_of::<StringLiteral>() == 40);
774+
assert!(size_of::<StringLiteral>() == 48);
775775
assert!(align_of::<StringLiteral>() == 8);
776776
assert!(offset_of!(StringLiteral, span) == 0);
777777
assert!(offset_of!(StringLiteral, value) == 8);
778778
assert!(offset_of!(StringLiteral, raw) == 24);
779+
assert!(offset_of!(StringLiteral, lossy) == 40);
779780

780781
assert!(size_of::<BigIntLiteral>() == 32);
781782
assert!(align_of::<BigIntLiteral>() == 8);
@@ -1211,19 +1212,19 @@ const _: () = {
12111212
assert!(size_of::<TSTypePredicateName>() == 16);
12121213
assert!(align_of::<TSTypePredicateName>() == 8);
12131214

1214-
assert!(size_of::<TSModuleDeclaration>() == 80);
1215+
assert!(size_of::<TSModuleDeclaration>() == 88);
12151216
assert!(align_of::<TSModuleDeclaration>() == 8);
12161217
assert!(offset_of!(TSModuleDeclaration, span) == 0);
12171218
assert!(offset_of!(TSModuleDeclaration, id) == 8);
1218-
assert!(offset_of!(TSModuleDeclaration, body) == 56);
1219-
assert!(offset_of!(TSModuleDeclaration, kind) == 72);
1220-
assert!(offset_of!(TSModuleDeclaration, declare) == 73);
1221-
assert!(offset_of!(TSModuleDeclaration, scope_id) == 76);
1219+
assert!(offset_of!(TSModuleDeclaration, body) == 64);
1220+
assert!(offset_of!(TSModuleDeclaration, kind) == 80);
1221+
assert!(offset_of!(TSModuleDeclaration, declare) == 81);
1222+
assert!(offset_of!(TSModuleDeclaration, scope_id) == 84);
12221223

12231224
assert!(size_of::<TSModuleDeclarationKind>() == 1);
12241225
assert!(align_of::<TSModuleDeclarationKind>() == 1);
12251226

1226-
assert!(size_of::<TSModuleDeclarationName>() == 48);
1227+
assert!(size_of::<TSModuleDeclarationName>() == 56);
12271228
assert!(align_of::<TSModuleDeclarationName>() == 8);
12281229

12291230
assert!(size_of::<TSModuleDeclarationBody>() == 16);
@@ -1327,7 +1328,7 @@ const _: () = {
13271328
assert!(size_of::<TSModuleReference>() == 16);
13281329
assert!(align_of::<TSModuleReference>() == 8);
13291330

1330-
assert!(size_of::<TSExternalModuleReference>() == 48);
1331+
assert!(size_of::<TSExternalModuleReference>() == 56);
13311332
assert!(align_of::<TSExternalModuleReference>() == 8);
13321333
assert!(offset_of!(TSExternalModuleReference, span) == 0);
13331334
assert!(offset_of!(TSExternalModuleReference, expression) == 8);
@@ -1685,11 +1686,11 @@ const _: () = {
16851686
assert!(size_of::<Statement>() == 8);
16861687
assert!(align_of::<Statement>() == 4);
16871688

1688-
assert!(size_of::<Directive>() == 40);
1689+
assert!(size_of::<Directive>() == 44);
16891690
assert!(align_of::<Directive>() == 4);
16901691
assert!(offset_of!(Directive, span) == 0);
16911692
assert!(offset_of!(Directive, expression) == 8);
1692-
assert!(offset_of!(Directive, directive) == 32);
1693+
assert!(offset_of!(Directive, directive) == 36);
16931694

16941695
assert!(size_of::<Hashbang>() == 16);
16951696
assert!(align_of::<Hashbang>() == 4);
@@ -2056,27 +2057,27 @@ const _: () = {
20562057
assert!(offset_of!(ImportExpression, options) == 16);
20572058
assert!(offset_of!(ImportExpression, phase) == 32);
20582059

2059-
assert!(size_of::<ImportDeclaration>() == 60);
2060+
assert!(size_of::<ImportDeclaration>() == 64);
20602061
assert!(align_of::<ImportDeclaration>() == 4);
20612062
assert!(offset_of!(ImportDeclaration, span) == 0);
20622063
assert!(offset_of!(ImportDeclaration, specifiers) == 8);
20632064
assert!(offset_of!(ImportDeclaration, source) == 24);
2064-
assert!(offset_of!(ImportDeclaration, phase) == 48);
2065-
assert!(offset_of!(ImportDeclaration, with_clause) == 52);
2066-
assert!(offset_of!(ImportDeclaration, import_kind) == 56);
2065+
assert!(offset_of!(ImportDeclaration, phase) == 52);
2066+
assert!(offset_of!(ImportDeclaration, with_clause) == 56);
2067+
assert!(offset_of!(ImportDeclaration, import_kind) == 60);
20672068

20682069
assert!(size_of::<ImportPhase>() == 1);
20692070
assert!(align_of::<ImportPhase>() == 1);
20702071

20712072
assert!(size_of::<ImportDeclarationSpecifier>() == 8);
20722073
assert!(align_of::<ImportDeclarationSpecifier>() == 4);
20732074

2074-
assert!(size_of::<ImportSpecifier>() == 60);
2075+
assert!(size_of::<ImportSpecifier>() == 64);
20752076
assert!(align_of::<ImportSpecifier>() == 4);
20762077
assert!(offset_of!(ImportSpecifier, span) == 0);
20772078
assert!(offset_of!(ImportSpecifier, imported) == 8);
2078-
assert!(offset_of!(ImportSpecifier, local) == 36);
2079-
assert!(offset_of!(ImportSpecifier, import_kind) == 56);
2079+
assert!(offset_of!(ImportSpecifier, local) == 40);
2080+
assert!(offset_of!(ImportSpecifier, import_kind) == 60);
20802081

20812082
assert!(size_of::<ImportDefaultSpecifier>() == 28);
20822083
assert!(align_of::<ImportDefaultSpecifier>() == 4);
@@ -2094,49 +2095,49 @@ const _: () = {
20942095
assert!(offset_of!(WithClause, attributes_keyword) == 8);
20952096
assert!(offset_of!(WithClause, with_entries) == 24);
20962097

2097-
assert!(size_of::<ImportAttribute>() == 60);
2098+
assert!(size_of::<ImportAttribute>() == 68);
20982099
assert!(align_of::<ImportAttribute>() == 4);
20992100
assert!(offset_of!(ImportAttribute, span) == 0);
21002101
assert!(offset_of!(ImportAttribute, key) == 8);
2101-
assert!(offset_of!(ImportAttribute, value) == 36);
2102+
assert!(offset_of!(ImportAttribute, value) == 40);
21022103

2103-
assert!(size_of::<ImportAttributeKey>() == 28);
2104+
assert!(size_of::<ImportAttributeKey>() == 32);
21042105
assert!(align_of::<ImportAttributeKey>() == 4);
21052106

2106-
assert!(size_of::<ExportNamedDeclaration>() == 64);
2107+
assert!(size_of::<ExportNamedDeclaration>() == 68);
21072108
assert!(align_of::<ExportNamedDeclaration>() == 4);
21082109
assert!(offset_of!(ExportNamedDeclaration, span) == 0);
21092110
assert!(offset_of!(ExportNamedDeclaration, declaration) == 8);
21102111
assert!(offset_of!(ExportNamedDeclaration, specifiers) == 16);
21112112
assert!(offset_of!(ExportNamedDeclaration, source) == 32);
2112-
assert!(offset_of!(ExportNamedDeclaration, export_kind) == 56);
2113-
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 60);
2113+
assert!(offset_of!(ExportNamedDeclaration, export_kind) == 60);
2114+
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 64);
21142115

2115-
assert!(size_of::<ExportDefaultDeclaration>() == 44);
2116+
assert!(size_of::<ExportDefaultDeclaration>() == 48);
21162117
assert!(align_of::<ExportDefaultDeclaration>() == 4);
21172118
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
21182119
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
2119-
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 36);
2120+
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 40);
21202121

2121-
assert!(size_of::<ExportAllDeclaration>() == 68);
2122+
assert!(size_of::<ExportAllDeclaration>() == 76);
21222123
assert!(align_of::<ExportAllDeclaration>() == 4);
21232124
assert!(offset_of!(ExportAllDeclaration, span) == 0);
21242125
assert!(offset_of!(ExportAllDeclaration, exported) == 8);
2125-
assert!(offset_of!(ExportAllDeclaration, source) == 36);
2126-
assert!(offset_of!(ExportAllDeclaration, with_clause) == 60);
2127-
assert!(offset_of!(ExportAllDeclaration, export_kind) == 64);
2126+
assert!(offset_of!(ExportAllDeclaration, source) == 40);
2127+
assert!(offset_of!(ExportAllDeclaration, with_clause) == 68);
2128+
assert!(offset_of!(ExportAllDeclaration, export_kind) == 72);
21282129

2129-
assert!(size_of::<ExportSpecifier>() == 68);
2130+
assert!(size_of::<ExportSpecifier>() == 76);
21302131
assert!(align_of::<ExportSpecifier>() == 4);
21312132
assert!(offset_of!(ExportSpecifier, span) == 0);
21322133
assert!(offset_of!(ExportSpecifier, local) == 8);
2133-
assert!(offset_of!(ExportSpecifier, exported) == 36);
2134-
assert!(offset_of!(ExportSpecifier, export_kind) == 64);
2134+
assert!(offset_of!(ExportSpecifier, exported) == 40);
2135+
assert!(offset_of!(ExportSpecifier, export_kind) == 72);
21352136

21362137
assert!(size_of::<ExportDefaultDeclarationKind>() == 8);
21372138
assert!(align_of::<ExportDefaultDeclarationKind>() == 4);
21382139

2139-
assert!(size_of::<ModuleExportName>() == 28);
2140+
assert!(size_of::<ModuleExportName>() == 32);
21402141
assert!(align_of::<ModuleExportName>() == 4);
21412142

21422143
assert!(size_of::<V8IntrinsicExpression>() == 40);
@@ -2161,11 +2162,12 @@ const _: () = {
21612162
assert!(offset_of!(NumericLiteral, raw) == 16);
21622163
assert!(offset_of!(NumericLiteral, base) == 24);
21632164

2164-
assert!(size_of::<StringLiteral>() == 24);
2165+
assert!(size_of::<StringLiteral>() == 28);
21652166
assert!(align_of::<StringLiteral>() == 4);
21662167
assert!(offset_of!(StringLiteral, span) == 0);
21672168
assert!(offset_of!(StringLiteral, value) == 8);
21682169
assert!(offset_of!(StringLiteral, raw) == 16);
2170+
assert!(offset_of!(StringLiteral, lossy) == 24);
21692171

21702172
assert!(size_of::<BigIntLiteral>() == 20);
21712173
assert!(align_of::<BigIntLiteral>() == 4);
@@ -2601,19 +2603,19 @@ const _: () = {
26012603
assert!(size_of::<TSTypePredicateName>() == 12);
26022604
assert!(align_of::<TSTypePredicateName>() == 4);
26032605

2604-
assert!(size_of::<TSModuleDeclaration>() == 52);
2606+
assert!(size_of::<TSModuleDeclaration>() == 56);
26052607
assert!(align_of::<TSModuleDeclaration>() == 4);
26062608
assert!(offset_of!(TSModuleDeclaration, span) == 0);
26072609
assert!(offset_of!(TSModuleDeclaration, id) == 8);
2608-
assert!(offset_of!(TSModuleDeclaration, body) == 36);
2609-
assert!(offset_of!(TSModuleDeclaration, kind) == 44);
2610-
assert!(offset_of!(TSModuleDeclaration, declare) == 45);
2611-
assert!(offset_of!(TSModuleDeclaration, scope_id) == 48);
2610+
assert!(offset_of!(TSModuleDeclaration, body) == 40);
2611+
assert!(offset_of!(TSModuleDeclaration, kind) == 48);
2612+
assert!(offset_of!(TSModuleDeclaration, declare) == 49);
2613+
assert!(offset_of!(TSModuleDeclaration, scope_id) == 52);
26122614

26132615
assert!(size_of::<TSModuleDeclarationKind>() == 1);
26142616
assert!(align_of::<TSModuleDeclarationKind>() == 1);
26152617

2616-
assert!(size_of::<TSModuleDeclarationName>() == 28);
2618+
assert!(size_of::<TSModuleDeclarationName>() == 32);
26172619
assert!(align_of::<TSModuleDeclarationName>() == 4);
26182620

26192621
assert!(size_of::<TSModuleDeclarationBody>() == 8);
@@ -2717,7 +2719,7 @@ const _: () = {
27172719
assert!(size_of::<TSModuleReference>() == 8);
27182720
assert!(align_of::<TSModuleReference>() == 4);
27192721

2720-
assert!(size_of::<TSExternalModuleReference>() == 32);
2722+
assert!(size_of::<TSExternalModuleReference>() == 36);
27212723
assert!(align_of::<TSExternalModuleReference>() == 4);
27222724
assert!(offset_of!(TSExternalModuleReference, span) == 0);
27232725
assert!(offset_of!(TSExternalModuleReference, expression) == 8);

0 commit comments

Comments
 (0)