diff --git a/crates/oxc_ast/src/ast/literal.rs b/crates/oxc_ast/src/ast/literal.rs index 97b95bc35b006..00d1f3f9b5a56 100644 --- a/crates/oxc_ast/src/ast/literal.rs +++ b/crates/oxc_ast/src/ast/literal.rs @@ -65,7 +65,7 @@ pub struct NumericLiteral<'a> { #[ast(visit)] #[derive(Debug, Clone)] #[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash, ESTree)] -#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral, add_ts = "raw?: undefined")] +#[estree(type = "Literal", via = crate::serialize::ESTreeLiteral)] pub struct StringLiteral<'a> { /// Node location in source code pub span: Span, @@ -73,6 +73,11 @@ pub struct StringLiteral<'a> { /// /// Any escape sequences in the raw code are unescaped. pub value: Atom<'a>, + + /// The raw string as it appears in source code. + /// + /// `None` when this ast node is not constructed from the parser. + pub raw: Option>, } /// BigInt literal diff --git a/crates/oxc_ast/src/generated/assert_layouts.rs b/crates/oxc_ast/src/generated/assert_layouts.rs index ea28fc20f9c61..43930945773f9 100644 --- a/crates/oxc_ast/src/generated/assert_layouts.rs +++ b/crates/oxc_ast/src/generated/assert_layouts.rs @@ -25,10 +25,11 @@ const _: () = { assert!(offset_of!(NumericLiteral, raw) == 16usize); assert!(offset_of!(NumericLiteral, base) == 32usize); - assert!(size_of::() == 24usize); + assert!(size_of::() == 40usize); assert!(align_of::() == 8usize); assert!(offset_of!(StringLiteral, span) == 0usize); assert!(offset_of!(StringLiteral, value) == 8usize); + assert!(offset_of!(StringLiteral, raw) == 24usize); assert!(size_of::() == 32usize); assert!(align_of::() == 8usize); @@ -334,11 +335,11 @@ const _: () = { assert!(size_of::() == 16usize); assert!(align_of::() == 8usize); - assert!(size_of::() == 48usize); + assert!(size_of::() == 64usize); assert!(align_of::() == 8usize); assert!(offset_of!(Directive, span) == 0usize); assert!(offset_of!(Directive, expression) == 8usize); - assert!(offset_of!(Directive, directive) == 32usize); + assert!(offset_of!(Directive, directive) == 48usize); assert!(size_of::() == 24usize); assert!(align_of::() == 8usize); @@ -702,23 +703,23 @@ const _: () = { assert!(offset_of!(ImportExpression, source) == 8usize); assert!(offset_of!(ImportExpression, arguments) == 24usize); - assert!(size_of::() == 80usize); + assert!(size_of::() == 96usize); assert!(align_of::() == 8usize); assert!(offset_of!(ImportDeclaration, span) == 0usize); assert!(offset_of!(ImportDeclaration, specifiers) == 8usize); assert!(offset_of!(ImportDeclaration, source) == 40usize); - assert!(offset_of!(ImportDeclaration, with_clause) == 64usize); - assert!(offset_of!(ImportDeclaration, import_kind) == 72usize); + assert!(offset_of!(ImportDeclaration, with_clause) == 80usize); + assert!(offset_of!(ImportDeclaration, import_kind) == 88usize); assert!(size_of::() == 16usize); assert!(align_of::() == 8usize); - assert!(size_of::() == 88usize); + assert!(size_of::() == 96usize); assert!(align_of::() == 8usize); assert!(offset_of!(ImportSpecifier, span) == 0usize); assert!(offset_of!(ImportSpecifier, imported) == 8usize); - assert!(offset_of!(ImportSpecifier, local) == 48usize); - assert!(offset_of!(ImportSpecifier, import_kind) == 80usize); + assert!(offset_of!(ImportSpecifier, local) == 56usize); + assert!(offset_of!(ImportSpecifier, import_kind) == 88usize); assert!(size_of::() == 40usize); assert!(align_of::() == 8usize); @@ -736,49 +737,49 @@ const _: () = { assert!(offset_of!(WithClause, attributes_keyword) == 8usize); assert!(offset_of!(WithClause, with_entries) == 32usize); - assert!(size_of::() == 64usize); + assert!(size_of::() == 96usize); assert!(align_of::() == 8usize); assert!(offset_of!(ImportAttribute, span) == 0usize); assert!(offset_of!(ImportAttribute, key) == 8usize); - assert!(offset_of!(ImportAttribute, value) == 40usize); + assert!(offset_of!(ImportAttribute, value) == 56usize); - assert!(size_of::() == 32usize); + assert!(size_of::() == 48usize); assert!(align_of::() == 8usize); - assert!(size_of::() == 96usize); + assert!(size_of::() == 112usize); assert!(align_of::() == 8usize); assert!(offset_of!(ExportNamedDeclaration, span) == 0usize); assert!(offset_of!(ExportNamedDeclaration, declaration) == 8usize); assert!(offset_of!(ExportNamedDeclaration, specifiers) == 24usize); assert!(offset_of!(ExportNamedDeclaration, source) == 56usize); - assert!(offset_of!(ExportNamedDeclaration, export_kind) == 80usize); - assert!(offset_of!(ExportNamedDeclaration, with_clause) == 88usize); + assert!(offset_of!(ExportNamedDeclaration, export_kind) == 96usize); + assert!(offset_of!(ExportNamedDeclaration, with_clause) == 104usize); - assert!(size_of::() == 64usize); + assert!(size_of::() == 72usize); assert!(align_of::() == 8usize); assert!(offset_of!(ExportDefaultDeclaration, span) == 0usize); assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8usize); assert!(offset_of!(ExportDefaultDeclaration, exported) == 24usize); - assert!(size_of::() == 88usize); + assert!(size_of::() == 112usize); assert!(align_of::() == 8usize); assert!(offset_of!(ExportAllDeclaration, span) == 0usize); assert!(offset_of!(ExportAllDeclaration, exported) == 8usize); - assert!(offset_of!(ExportAllDeclaration, source) == 48usize); - assert!(offset_of!(ExportAllDeclaration, with_clause) == 72usize); - assert!(offset_of!(ExportAllDeclaration, export_kind) == 80usize); + assert!(offset_of!(ExportAllDeclaration, source) == 56usize); + assert!(offset_of!(ExportAllDeclaration, with_clause) == 96usize); + assert!(offset_of!(ExportAllDeclaration, export_kind) == 104usize); - assert!(size_of::() == 96usize); + assert!(size_of::() == 112usize); assert!(align_of::() == 8usize); assert!(offset_of!(ExportSpecifier, span) == 0usize); assert!(offset_of!(ExportSpecifier, local) == 8usize); - assert!(offset_of!(ExportSpecifier, exported) == 48usize); - assert!(offset_of!(ExportSpecifier, export_kind) == 88usize); + assert!(offset_of!(ExportSpecifier, exported) == 56usize); + assert!(offset_of!(ExportSpecifier, export_kind) == 104usize); assert!(size_of::() == 16usize); assert!(align_of::() == 8usize); - assert!(size_of::() == 40usize); + assert!(size_of::() == 48usize); assert!(align_of::() == 8usize); assert!(size_of::() == 24usize); @@ -1088,19 +1089,19 @@ const _: () = { assert!(size_of::() == 16usize); assert!(align_of::() == 8usize); - assert!(size_of::() == 72usize); + assert!(size_of::() == 80usize); assert!(align_of::() == 8usize); assert!(offset_of!(TSModuleDeclaration, span) == 0usize); assert!(offset_of!(TSModuleDeclaration, id) == 8usize); - assert!(offset_of!(TSModuleDeclaration, body) == 48usize); - assert!(offset_of!(TSModuleDeclaration, kind) == 64usize); - assert!(offset_of!(TSModuleDeclaration, declare) == 65usize); - assert!(offset_of!(TSModuleDeclaration, scope_id) == 68usize); + assert!(offset_of!(TSModuleDeclaration, body) == 56usize); + assert!(offset_of!(TSModuleDeclaration, kind) == 72usize); + assert!(offset_of!(TSModuleDeclaration, declare) == 73usize); + assert!(offset_of!(TSModuleDeclaration, scope_id) == 76usize); assert!(size_of::() == 1usize); assert!(align_of::() == 1usize); - assert!(size_of::() == 40usize); + assert!(size_of::() == 48usize); assert!(align_of::() == 8usize); assert!(size_of::() == 16usize); @@ -1146,13 +1147,13 @@ const _: () = { assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8usize); assert!(offset_of!(TSImportAttributes, elements) == 32usize); - assert!(size_of::() == 56usize); + assert!(size_of::() == 72usize); assert!(align_of::() == 8usize); assert!(offset_of!(TSImportAttribute, span) == 0usize); assert!(offset_of!(TSImportAttribute, name) == 8usize); - assert!(offset_of!(TSImportAttribute, value) == 40usize); + assert!(offset_of!(TSImportAttribute, value) == 56usize); - assert!(size_of::() == 32usize); + assert!(size_of::() == 48usize); assert!(align_of::() == 8usize); assert!(size_of::() == 40usize); @@ -1218,7 +1219,7 @@ const _: () = { assert!(size_of::() == 16usize); assert!(align_of::() == 8usize); - assert!(size_of::() == 32usize); + assert!(size_of::() == 48usize); assert!(align_of::() == 8usize); assert!(offset_of!(TSExternalModuleReference, span) == 0usize); assert!(offset_of!(TSExternalModuleReference, expression) == 8usize); @@ -1581,10 +1582,11 @@ const _: () = { assert!(offset_of!(NumericLiteral, raw) == 16usize); assert!(offset_of!(NumericLiteral, base) == 24usize); - assert!(size_of::() == 16usize); + assert!(size_of::() == 24usize); assert!(align_of::() == 4usize); assert!(offset_of!(StringLiteral, span) == 0usize); assert!(offset_of!(StringLiteral, value) == 8usize); + assert!(offset_of!(StringLiteral, raw) == 16usize); assert!(size_of::() == 20usize); assert!(align_of::() == 4usize); @@ -1890,11 +1892,11 @@ const _: () = { assert!(size_of::() == 8usize); assert!(align_of::() == 4usize); - assert!(size_of::() == 32usize); + assert!(size_of::() == 40usize); assert!(align_of::() == 4usize); assert!(offset_of!(Directive, span) == 0usize); assert!(offset_of!(Directive, expression) == 8usize); - assert!(offset_of!(Directive, directive) == 24usize); + assert!(offset_of!(Directive, directive) == 32usize); assert!(size_of::() == 16usize); assert!(align_of::() == 4usize); @@ -2258,23 +2260,23 @@ const _: () = { assert!(offset_of!(ImportExpression, source) == 8usize); assert!(offset_of!(ImportExpression, arguments) == 16usize); - assert!(size_of::() == 48usize); + assert!(size_of::() == 56usize); assert!(align_of::() == 4usize); assert!(offset_of!(ImportDeclaration, span) == 0usize); assert!(offset_of!(ImportDeclaration, specifiers) == 8usize); assert!(offset_of!(ImportDeclaration, source) == 24usize); - assert!(offset_of!(ImportDeclaration, with_clause) == 40usize); - assert!(offset_of!(ImportDeclaration, import_kind) == 44usize); + assert!(offset_of!(ImportDeclaration, with_clause) == 48usize); + assert!(offset_of!(ImportDeclaration, import_kind) == 52usize); assert!(size_of::() == 8usize); assert!(align_of::() == 4usize); - assert!(size_of::() == 56usize); + assert!(size_of::() == 60usize); assert!(align_of::() == 4usize); assert!(offset_of!(ImportSpecifier, span) == 0usize); assert!(offset_of!(ImportSpecifier, imported) == 8usize); - assert!(offset_of!(ImportSpecifier, local) == 32usize); - assert!(offset_of!(ImportSpecifier, import_kind) == 52usize); + assert!(offset_of!(ImportSpecifier, local) == 36usize); + assert!(offset_of!(ImportSpecifier, import_kind) == 56usize); assert!(size_of::() == 28usize); assert!(align_of::() == 4usize); @@ -2292,49 +2294,49 @@ const _: () = { assert!(offset_of!(WithClause, attributes_keyword) == 8usize); assert!(offset_of!(WithClause, with_entries) == 24usize); - assert!(size_of::() == 44usize); + assert!(size_of::() == 60usize); assert!(align_of::() == 4usize); assert!(offset_of!(ImportAttribute, span) == 0usize); assert!(offset_of!(ImportAttribute, key) == 8usize); - assert!(offset_of!(ImportAttribute, value) == 28usize); + assert!(offset_of!(ImportAttribute, value) == 36usize); - assert!(size_of::() == 20usize); + assert!(size_of::() == 28usize); assert!(align_of::() == 4usize); - assert!(size_of::() == 56usize); + assert!(size_of::() == 64usize); assert!(align_of::() == 4usize); assert!(offset_of!(ExportNamedDeclaration, span) == 0usize); assert!(offset_of!(ExportNamedDeclaration, declaration) == 8usize); assert!(offset_of!(ExportNamedDeclaration, specifiers) == 16usize); assert!(offset_of!(ExportNamedDeclaration, source) == 32usize); - assert!(offset_of!(ExportNamedDeclaration, export_kind) == 48usize); - assert!(offset_of!(ExportNamedDeclaration, with_clause) == 52usize); + assert!(offset_of!(ExportNamedDeclaration, export_kind) == 56usize); + assert!(offset_of!(ExportNamedDeclaration, with_clause) == 60usize); - assert!(size_of::() == 40usize); + assert!(size_of::() == 44usize); assert!(align_of::() == 4usize); assert!(offset_of!(ExportDefaultDeclaration, span) == 0usize); assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8usize); assert!(offset_of!(ExportDefaultDeclaration, exported) == 16usize); - assert!(size_of::() == 56usize); + assert!(size_of::() == 68usize); assert!(align_of::() == 4usize); assert!(offset_of!(ExportAllDeclaration, span) == 0usize); assert!(offset_of!(ExportAllDeclaration, exported) == 8usize); - assert!(offset_of!(ExportAllDeclaration, source) == 32usize); - assert!(offset_of!(ExportAllDeclaration, with_clause) == 48usize); - assert!(offset_of!(ExportAllDeclaration, export_kind) == 52usize); + assert!(offset_of!(ExportAllDeclaration, source) == 36usize); + assert!(offset_of!(ExportAllDeclaration, with_clause) == 60usize); + assert!(offset_of!(ExportAllDeclaration, export_kind) == 64usize); - assert!(size_of::() == 60usize); + assert!(size_of::() == 68usize); assert!(align_of::() == 4usize); assert!(offset_of!(ExportSpecifier, span) == 0usize); assert!(offset_of!(ExportSpecifier, local) == 8usize); - assert!(offset_of!(ExportSpecifier, exported) == 32usize); - assert!(offset_of!(ExportSpecifier, export_kind) == 56usize); + assert!(offset_of!(ExportSpecifier, exported) == 36usize); + assert!(offset_of!(ExportSpecifier, export_kind) == 64usize); assert!(size_of::() == 8usize); assert!(align_of::() == 4usize); - assert!(size_of::() == 24usize); + assert!(size_of::() == 28usize); assert!(align_of::() == 4usize); assert!(size_of::() == 20usize); @@ -2644,19 +2646,19 @@ const _: () = { assert!(size_of::() == 12usize); assert!(align_of::() == 4usize); - assert!(size_of::() == 48usize); + assert!(size_of::() == 52usize); assert!(align_of::() == 4usize); assert!(offset_of!(TSModuleDeclaration, span) == 0usize); assert!(offset_of!(TSModuleDeclaration, id) == 8usize); - assert!(offset_of!(TSModuleDeclaration, body) == 32usize); - assert!(offset_of!(TSModuleDeclaration, kind) == 40usize); - assert!(offset_of!(TSModuleDeclaration, declare) == 41usize); - assert!(offset_of!(TSModuleDeclaration, scope_id) == 44usize); + assert!(offset_of!(TSModuleDeclaration, body) == 36usize); + assert!(offset_of!(TSModuleDeclaration, kind) == 44usize); + assert!(offset_of!(TSModuleDeclaration, declare) == 45usize); + assert!(offset_of!(TSModuleDeclaration, scope_id) == 48usize); assert!(size_of::() == 1usize); assert!(align_of::() == 1usize); - assert!(size_of::() == 24usize); + assert!(size_of::() == 28usize); assert!(align_of::() == 4usize); assert!(size_of::() == 8usize); @@ -2702,13 +2704,13 @@ const _: () = { assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8usize); assert!(offset_of!(TSImportAttributes, elements) == 24usize); - assert!(size_of::() == 36usize); + assert!(size_of::() == 44usize); assert!(align_of::() == 4usize); assert!(offset_of!(TSImportAttribute, span) == 0usize); assert!(offset_of!(TSImportAttribute, name) == 8usize); - assert!(offset_of!(TSImportAttribute, value) == 28usize); + assert!(offset_of!(TSImportAttribute, value) == 36usize); - assert!(size_of::() == 20usize); + assert!(size_of::() == 28usize); assert!(align_of::() == 4usize); assert!(size_of::() == 24usize); @@ -2774,7 +2776,7 @@ const _: () = { assert!(size_of::() == 8usize); assert!(align_of::() == 4usize); - assert!(size_of::() == 24usize); + assert!(size_of::() == 32usize); assert!(align_of::() == 4usize); assert!(offset_of!(TSExternalModuleReference, span) == 0usize); assert!(offset_of!(TSExternalModuleReference, expression) == 8usize); diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 193e190787496..639d54a9d82f6 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -123,12 +123,13 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] - pub fn string_literal(self, span: Span, value: A) -> StringLiteral<'a> + pub fn string_literal(self, span: Span, value: A, raw: Option>) -> StringLiteral<'a> where A: IntoIn<'a, Atom<'a>>, { - StringLiteral { span, value: value.into_in(self.allocator) } + StringLiteral { span, value: value.into_in(self.allocator), raw } } /// Build a [`StringLiteral`], and store it in the memory arena. @@ -138,12 +139,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] - pub fn alloc_string_literal(self, span: Span, value: A) -> Box<'a, StringLiteral<'a>> + pub fn alloc_string_literal( + self, + span: Span, + value: A, + raw: Option>, + ) -> Box<'a, StringLiteral<'a>> where A: IntoIn<'a, Atom<'a>>, { - Box::new_in(self.string_literal(span, value), self.allocator) + Box::new_in(self.string_literal(span, value, raw), self.allocator) } /// Build a [`BigIntLiteral`]. @@ -468,12 +475,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] - pub fn expression_string_literal(self, span: Span, value: A) -> Expression<'a> + pub fn expression_string_literal( + self, + span: Span, + value: A, + raw: Option>, + ) -> Expression<'a> where A: IntoIn<'a, Atom<'a>>, { - Expression::StringLiteral(self.alloc(self.string_literal(span, value))) + Expression::StringLiteral(self.alloc(self.string_literal(span, value, raw))) } /// Build an [`Expression::TemplateLiteral`] @@ -7182,16 +7195,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] pub fn import_attribute_key_string_literal( self, span: Span, value: A, + raw: Option>, ) -> ImportAttributeKey<'a> where A: IntoIn<'a, Atom<'a>>, { - ImportAttributeKey::StringLiteral(self.string_literal(span, value)) + ImportAttributeKey::StringLiteral(self.string_literal(span, value, raw)) } /// Build an [`ExportNamedDeclaration`]. @@ -7569,12 +7584,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] - pub fn module_export_name_string_literal(self, span: Span, value: A) -> ModuleExportName<'a> + pub fn module_export_name_string_literal( + self, + span: Span, + value: A, + raw: Option>, + ) -> ModuleExportName<'a> where A: IntoIn<'a, Atom<'a>>, { - ModuleExportName::StringLiteral(self.string_literal(span, value)) + ModuleExportName::StringLiteral(self.string_literal(span, value, raw)) } /// Build a [`TSThisParameter`]. @@ -7783,12 +7804,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] - pub fn ts_enum_member_name_string_literal(self, span: Span, value: A) -> TSEnumMemberName<'a> + pub fn ts_enum_member_name_string_literal( + self, + span: Span, + value: A, + raw: Option>, + ) -> TSEnumMemberName<'a> where A: IntoIn<'a, Atom<'a>>, { - TSEnumMemberName::String(self.alloc(self.string_literal(span, value))) + TSEnumMemberName::String(self.alloc(self.string_literal(span, value, raw))) } /// Build a [`TSTypeAnnotation`]. @@ -7946,12 +7973,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] - pub fn ts_literal_string_literal(self, span: Span, value: A) -> TSLiteral<'a> + pub fn ts_literal_string_literal( + self, + span: Span, + value: A, + raw: Option>, + ) -> TSLiteral<'a> where A: IntoIn<'a, Atom<'a>>, { - TSLiteral::StringLiteral(self.alloc(self.string_literal(span, value))) + TSLiteral::StringLiteral(self.alloc(self.string_literal(span, value, raw))) } /// Build a [`TSLiteral::TemplateLiteral`] @@ -10996,16 +11029,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] pub fn ts_module_declaration_name_string_literal( self, span: Span, value: A, + raw: Option>, ) -> TSModuleDeclarationName<'a> where A: IntoIn<'a, Atom<'a>>, { - TSModuleDeclarationName::StringLiteral(self.string_literal(span, value)) + TSModuleDeclarationName::StringLiteral(self.string_literal(span, value, raw)) } /// Build a [`TSModuleDeclarationBody::TSModuleDeclaration`] @@ -11394,16 +11429,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] pub fn ts_import_attribute_name_string_literal( self, span: Span, value: A, + raw: Option>, ) -> TSImportAttributeName<'a> where A: IntoIn<'a, Atom<'a>>, { - TSImportAttributeName::StringLiteral(self.string_literal(span, value)) + TSImportAttributeName::StringLiteral(self.string_literal(span, value, raw)) } /// Build a [`TSFunctionType`]. @@ -12788,16 +12825,18 @@ impl<'a> AstBuilder<'a> { /// ## Parameters /// - span: Node location in source code /// - value: The value of the string. + /// - raw: The raw string as it appears in source code. #[inline] pub fn jsx_attribute_value_string_literal( self, span: Span, value: A, + raw: Option>, ) -> JSXAttributeValue<'a> where A: IntoIn<'a, Atom<'a>>, { - JSXAttributeValue::StringLiteral(self.alloc(self.string_literal(span, value))) + JSXAttributeValue::StringLiteral(self.alloc(self.string_literal(span, value, raw))) } /// Build a [`JSXAttributeValue::ExpressionContainer`] diff --git a/crates/oxc_ast/src/generated/derive_clone_in.rs b/crates/oxc_ast/src/generated/derive_clone_in.rs index a1278e1fd6bd2..193871da4b8e2 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -50,6 +50,7 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for StringLiteral<'old_alloc> { StringLiteral { span: CloneIn::clone_in(&self.span, allocator), value: CloneIn::clone_in(&self.value, allocator), + raw: CloneIn::clone_in(&self.raw, allocator), } } } diff --git a/crates/oxc_ast/src/generated/derive_content_eq.rs b/crates/oxc_ast/src/generated/derive_content_eq.rs index e86fa1d9fb798..4cffc6708063a 100644 --- a/crates/oxc_ast/src/generated/derive_content_eq.rs +++ b/crates/oxc_ast/src/generated/derive_content_eq.rs @@ -38,6 +38,7 @@ impl<'a> ContentEq for NumericLiteral<'a> { impl<'a> ContentEq for StringLiteral<'a> { fn content_eq(&self, other: &Self) -> bool { ContentEq::content_eq(&self.value, &other.value) + && ContentEq::content_eq(&self.raw, &other.raw) } } diff --git a/crates/oxc_ast/src/generated/derive_content_hash.rs b/crates/oxc_ast/src/generated/derive_content_hash.rs index b3ad44c59f97e..0cb53022c60cf 100644 --- a/crates/oxc_ast/src/generated/derive_content_hash.rs +++ b/crates/oxc_ast/src/generated/derive_content_hash.rs @@ -26,6 +26,7 @@ impl ContentHash for BooleanLiteral { impl<'a> ContentHash for StringLiteral<'a> { fn content_hash(&self, state: &mut H) { ContentHash::content_hash(&self.value, state); + ContentHash::content_hash(&self.raw, state); } } diff --git a/crates/oxc_ecmascript/src/array_join.rs b/crates/oxc_ecmascript/src/array_join.rs index a518c9b106621..90035877e07ff 100644 --- a/crates/oxc_ecmascript/src/array_join.rs +++ b/crates/oxc_ecmascript/src/array_join.rs @@ -37,7 +37,7 @@ mod tests { NumberBase::Decimal, )))); elements.push(ArrayExpressionElement::StringLiteral( - ast.alloc(ast.string_literal(SPAN, "foo")), + ast.alloc(ast.string_literal(SPAN, "foo", None)), )); elements.push(ArrayExpressionElement::BooleanLiteral( ast.alloc(ast.boolean_literal(SPAN, true)), diff --git a/crates/oxc_isolated_declarations/src/enum.rs b/crates/oxc_isolated_declarations/src/enum.rs index c43588fd25e30..70ef76b02354b 100644 --- a/crates/oxc_isolated_declarations/src/enum.rs +++ b/crates/oxc_isolated_declarations/src/enum.rs @@ -77,7 +77,7 @@ impl<'a> IsolatedDeclarations<'a> { expr } } - ConstantValue::String(v) => self.ast.expression_string_literal(SPAN, v), + ConstantValue::String(v) => self.ast.expression_string_literal(SPAN, v, None), }), ); diff --git a/crates/oxc_isolated_declarations/src/literal.rs b/crates/oxc_isolated_declarations/src/literal.rs index b36109eb8971c..d7d66f7603cc3 100644 --- a/crates/oxc_isolated_declarations/src/literal.rs +++ b/crates/oxc_isolated_declarations/src/literal.rs @@ -13,6 +13,7 @@ impl<'a> IsolatedDeclarations<'a> { self.ast.alloc(self.ast.string_literal( lit.span, if let Some(cooked) = &item.value.cooked { cooked } else { &item.value.raw }, + None, )) }) } else { diff --git a/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs b/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs index 4a8b044b0a74f..9a433e29556a9 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs @@ -50,14 +50,18 @@ impl PeepholeReplaceKnownMethods { "toLowerCase" => Some(ctx.ast.expression_string_literal( call_expr.span, string_lit.value.cow_to_lowercase(), + None, )), "toUpperCase" => Some(ctx.ast.expression_string_literal( call_expr.span, string_lit.value.cow_to_uppercase(), + None, + )), + "trim" => Some(ctx.ast.expression_string_literal( + call_expr.span, + string_lit.value.trim(), + None, )), - "trim" => Some( - ctx.ast.expression_string_literal(call_expr.span, string_lit.value.trim()), - ), _ => None, }, "indexOf" | "lastIndexOf" => Self::try_fold_string_index_of( @@ -167,6 +171,7 @@ impl PeepholeReplaceKnownMethods { return Some(ctx.ast.expression_string_literal( span, string_lit.value.as_str().substring(start_idx, end_idx), + None, )); } @@ -200,7 +205,7 @@ impl PeepholeReplaceKnownMethods { .char_at(char_at_index) .map_or(String::new(), |v| v.to_string()); - return Some(ctx.ast.expression_string_literal(span, result)); + return Some(ctx.ast.expression_string_literal(span, result, None)); } fn try_fold_string_char_code_at<'a>( @@ -265,7 +270,7 @@ impl PeepholeReplaceKnownMethods { _ => unreachable!(), }; - Some(ctx.ast.expression_string_literal(span, result)) + Some(ctx.ast.expression_string_literal(span, result, None)) } } diff --git a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs index dcd52b3eb3e57..a774af3c3d96e 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs @@ -118,7 +118,7 @@ impl<'a> Traverse<'a> for PeepholeSubstituteAlternateSyntax { } Expression::TemplateLiteral(_) => { if let Some(val) = expr.to_js_string() { - *expr = ctx.ast.expression_string_literal(expr.span(), val); + *expr = ctx.ast.expression_string_literal(expr.span(), val, None); self.changed = true; } } @@ -271,7 +271,7 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax { }; let argument = Expression::Identifier(ctx.alloc(id_ref)); let left = ctx.ast.expression_unary(SPAN, UnaryOperator::Typeof, argument); - let right = ctx.ast.expression_string_literal(SPAN, "u"); + let right = ctx.ast.expression_string_literal(SPAN, "u", None); let binary_expr = ctx.ast.binary_expression(expr.span, left, BinaryOperator::GreaterThan, right); *expr = binary_expr; @@ -521,7 +521,7 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax { Some(ctx.ast.expression_binary( call_expr.span, - ctx.ast.expression_string_literal(SPAN, ""), + ctx.ast.expression_string_literal(SPAN, "", None), BinaryOperator::Addition, ctx.ast.move_expression(arg), )) diff --git a/crates/oxc_minifier/src/node_util/mod.rs b/crates/oxc_minifier/src/node_util/mod.rs index 810e6f5ce5f4e..89a0f37afef54 100644 --- a/crates/oxc_minifier/src/node_util/mod.rs +++ b/crates/oxc_minifier/src/node_util/mod.rs @@ -40,7 +40,7 @@ impl<'a, 'b> Ctx<'a, 'b> { ConstantValue::BigInt(n) => { self.ast.expression_big_int_literal(span, n.to_string() + "n", BigintBase::Decimal) } - ConstantValue::String(s) => self.ast.expression_string_literal(span, s), + ConstantValue::String(s) => self.ast.expression_string_literal(span, s, None), ConstantValue::Boolean(b) => self.ast.expression_boolean_literal(span, b), ConstantValue::Undefined => self.ast.void_0(span), ConstantValue::Null => self.ast.expression_null_literal(span), diff --git a/crates/oxc_parser/src/cursor.rs b/crates/oxc_parser/src/cursor.rs index 1dbf3d85620a2..edd265295c695 100644 --- a/crates/oxc_parser/src/cursor.rs +++ b/crates/oxc_parser/src/cursor.rs @@ -49,7 +49,7 @@ impl<'a> ParserImpl<'a> { pub(crate) fn cur_src(&self) -> &'a str { let range = self.cur_token().span(); // SAFETY: - // range comes from the parser, which are ensured to meeting the criteria of `get_unchecked`. + // range comes from the lexer, which are ensured to meeting the criteria of `get_unchecked`. unsafe { self.source_text.get_unchecked(range.start as usize..range.end as usize) } } diff --git a/crates/oxc_parser/src/js/expression.rs b/crates/oxc_parser/src/js/expression.rs index 9ab6db9f5d0a5..713ceb1d9192c 100644 --- a/crates/oxc_parser/src/js/expression.rs +++ b/crates/oxc_parser/src/js/expression.rs @@ -398,7 +398,13 @@ impl<'a> ParserImpl<'a> { let value = self.cur_string(); let span = self.start_span(); self.bump_any(); - Ok(self.ast.string_literal(self.end_span(span), value)) + let span = self.end_span(span); + // SAFETY: + // range comes from the lexer, which are ensured to meeting the criteria of `get_unchecked`. + let raw = Atom::from(unsafe { + self.source_text.get_unchecked(span.start as usize..span.end as usize) + }); + Ok(self.ast.string_literal(self.end_span(span), value, Some(raw))) } /// Section [Array Expression](https://tc39.es/ecma262/#prod-ArrayLiteral) diff --git a/crates/oxc_parser/src/ts/statement.rs b/crates/oxc_parser/src/ts/statement.rs index b0649c48f5f19..ec19d6cfa2b72 100644 --- a/crates/oxc_parser/src/ts/statement.rs +++ b/crates/oxc_parser/src/ts/statement.rs @@ -72,6 +72,10 @@ impl<'a> ParserImpl<'a> { Ok(self.ast.ts_enum_member_name_string_literal( template.span, template.quasi().unwrap(), + Some(Atom::from( + Span::new(template.span.start + 1, template.span.end - 1) + .source_text(self.source_text), + )), )) } Expression::NumericLiteral(literal) => { diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index 46cfe3d7a6a4e..d8b181ede4555 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -1006,7 +1006,7 @@ impl<'a> ArrowFunctionConverter<'a> { if ctx.scopes().root_scope_id() == target_scope_id { let argument = Expression::Identifier(ctx.ast.alloc(reference)); let typeof_arguments = ctx.ast.expression_unary(SPAN, UnaryOperator::Typeof, argument); - let undefined_literal = ctx.ast.expression_string_literal(SPAN, "undefined"); + let undefined_literal = ctx.ast.expression_string_literal(SPAN, "undefined", None); let test = ctx.ast.expression_binary( SPAN, typeof_arguments, diff --git a/crates/oxc_transformer/src/common/module_imports.rs b/crates/oxc_transformer/src/common/module_imports.rs index 87a64a311d548..ab6221004907c 100644 --- a/crates/oxc_transformer/src/common/module_imports.rs +++ b/crates/oxc_transformer/src/common/module_imports.rs @@ -214,7 +214,7 @@ impl<'a> ModuleImportsStore<'a> { Statement::from(ctx.ast.module_declaration_import_declaration( SPAN, Some(specifiers), - ctx.ast.string_literal(SPAN, source), + ctx.ast.string_literal(SPAN, source, None), NONE, ImportOrExportKind::Value, )) @@ -234,7 +234,7 @@ impl<'a> ModuleImportsStore<'a> { ); let args = { - let arg = Argument::from(ctx.ast.expression_string_literal(SPAN, source)); + let arg = Argument::from(ctx.ast.expression_string_literal(SPAN, source, None)); ctx.ast.vec1(arg) }; let Some(Import::Default(local)) = names.into_iter().next() else { unreachable!() }; diff --git a/crates/oxc_transformer/src/es2016/exponentiation_operator.rs b/crates/oxc_transformer/src/es2016/exponentiation_operator.rs index f95d4a9a571a0..73fc8683a2333 100644 --- a/crates/oxc_transformer/src/es2016/exponentiation_operator.rs +++ b/crates/oxc_transformer/src/es2016/exponentiation_operator.rs @@ -246,7 +246,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { // ``` let prop_span = member_expr.property.span; let prop_name = member_expr.property.name.clone(); - let prop = ctx.ast.expression_string_literal(prop_span, prop_name.clone()); + let prop = ctx.ast.expression_string_literal(prop_span, prop_name.clone(), None); // Complete 2nd member expression // ``` @@ -264,7 +264,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> { AssignmentTarget::ComputedMemberExpression(ctx.ast.alloc_computed_member_expression( member_expr.span, ctx.ast.move_expression(&mut member_expr.object), - ctx.ast.expression_string_literal(prop_span, prop_name), + ctx.ast.expression_string_literal(prop_span, prop_name, None), false, )); diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread.rs b/crates/oxc_transformer/src/es2018/object_rest_spread.rs index 8bb3d5ec7a6a9..b425ad526a630 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread.rs @@ -326,7 +326,7 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> { match e { AssignmentTargetProperty::AssignmentTargetPropertyIdentifier(ident) => { let name = ident.binding.name.clone(); - let expr = ctx.ast.expression_string_literal(SPAN, name); + let expr = ctx.ast.expression_string_literal(SPAN, name, None); Some(ArrayExpressionElement::from(expr)) } AssignmentTargetProperty::AssignmentTargetPropertyProperty(p) => { @@ -968,14 +968,14 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> { // `let { a, ... rest }` PropertyKey::StaticIdentifier(ident) => { let name = ident.name.clone(); - let expr = ctx.ast.expression_string_literal(ident.span, name); + let expr = ctx.ast.expression_string_literal(ident.span, name, None); Some(ArrayExpressionElement::from(expr)) } // `let { 'a', ... rest }` // `let { ['a'], ... rest }` PropertyKey::StringLiteral(lit) => { let name = lit.value.clone(); - let expr = ctx.ast.expression_string_literal(lit.span, name.clone()); + let expr = ctx.ast.expression_string_literal(lit.span, name.clone(), None); Some(ArrayExpressionElement::from(expr)) } // `let { [`a`], ... rest }` @@ -993,7 +993,7 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> { if expr.is_literal() { let span = expr.span(); let s = expr.to_js_string().unwrap(); - let expr = ctx.ast.expression_string_literal(span, s); + let expr = ctx.ast.expression_string_literal(span, s, None); return Some(ArrayExpressionElement::from(expr)); } *all_primitives = false; diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index 2e744432c416f..076c66f0e36b3 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -557,7 +557,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { ) -> Expression<'a> { let key = match &mut prop.key { PropertyKey::StaticIdentifier(ident) => { - ctx.ast.expression_string_literal(ident.span, ident.name.clone()) + ctx.ast.expression_string_literal(ident.span, ident.name.clone(), None) } key @ match_expression!(PropertyKey) => { // TODO: This can also be a numeric key (non-computed). Maybe other key types? diff --git a/crates/oxc_transformer/src/jsx/display_name.rs b/crates/oxc_transformer/src/jsx/display_name.rs index 05b9c92c0374e..6b2ae8afe54ea 100644 --- a/crates/oxc_transformer/src/jsx/display_name.rs +++ b/crates/oxc_transformer/src/jsx/display_name.rs @@ -173,7 +173,7 @@ impl<'a, 'ctx> ReactDisplayName<'a, 'ctx> { SPAN, PropertyKind::Init, ctx.ast.property_key_identifier_name(SPAN, DISPLAY_NAME), - ctx.ast.expression_string_literal(SPAN, name), + ctx.ast.expression_string_literal(SPAN, name, None), false, false, false, diff --git a/crates/oxc_transformer/src/jsx/jsx_impl.rs b/crates/oxc_transformer/src/jsx/jsx_impl.rs index aa4fe96a03e2f..30ad791538660 100644 --- a/crates/oxc_transformer/src/jsx/jsx_impl.rs +++ b/crates/oxc_transformer/src/jsx/jsx_impl.rs @@ -736,7 +736,7 @@ impl<'a, 'ctx> JsxImpl<'a, 'ctx> { ) -> Expression<'a> { match name { JSXElementName::Identifier(ident) => { - ctx.ast.expression_string_literal(ident.span, ident.name.clone()) + ctx.ast.expression_string_literal(ident.span, ident.name.clone(), None) } JSXElementName::IdentifierReference(ident) => { Expression::Identifier(ctx.alloc(ident.as_ref().clone())) @@ -748,7 +748,7 @@ impl<'a, 'ctx> JsxImpl<'a, 'ctx> { if self.options.throw_if_namespace { self.ctx.error(diagnostics::namespace_does_not_support(namespaced.span)); } - ctx.ast.expression_string_literal(namespaced.span, namespaced.to_string()) + ctx.ast.expression_string_literal(namespaced.span, namespaced.to_string(), None) } JSXElementName::ThisExpression(expr) => ctx.ast.expression_this(expr.span), } @@ -830,7 +830,7 @@ impl<'a, 'ctx> JsxImpl<'a, 'ctx> { match value { Some(JSXAttributeValue::StringLiteral(s)) => { let jsx_text = Self::decode_entities(s.value.as_str()); - ctx.ast.expression_string_literal(s.span, jsx_text) + ctx.ast.expression_string_literal(s.span, jsx_text, None) } Some(JSXAttributeValue::Element(e)) => { self.transform_jsx(&JSXElementOrFragment::Element(e), ctx) @@ -883,21 +883,21 @@ impl<'a, 'ctx> JsxImpl<'a, 'ctx> { JSXAttributeName::Identifier(ident) => { let name = ident.name.clone(); if ident.name.contains('-') { - PropertyKey::from(ctx.ast.expression_string_literal(ident.span, name)) + PropertyKey::from(ctx.ast.expression_string_literal(ident.span, name, None)) } else { ctx.ast.property_key_identifier_name(ident.span, name) } } JSXAttributeName::NamespacedName(namespaced) => { let name = ctx.ast.atom(&namespaced.to_string()); - PropertyKey::from(ctx.ast.expression_string_literal(namespaced.span, name)) + PropertyKey::from(ctx.ast.expression_string_literal(namespaced.span, name, None)) } } } fn transform_jsx_text(text: &JSXText<'a>, ctx: &TraverseCtx<'a>) -> Option> { Self::fixup_whitespace_and_decode_entities(text.value.as_str()) - .map(|s| ctx.ast.expression_string_literal(text.span, s)) + .map(|s| ctx.ast.expression_string_literal(text.span, s, None)) } /// JSX trims whitespace at the end and beginning of lines, except that the diff --git a/crates/oxc_transformer/src/jsx/jsx_source.rs b/crates/oxc_transformer/src/jsx/jsx_source.rs index c0a1eae289f9b..40ad88eca6627 100644 --- a/crates/oxc_transformer/src/jsx/jsx_source.rs +++ b/crates/oxc_transformer/src/jsx/jsx_source.rs @@ -199,7 +199,8 @@ impl<'a, 'ctx> JsxSource<'a, 'ctx> { let filename_var = self.filename_var.as_ref()?; let id = filename_var.create_binding_pattern(ctx); - let init = ctx.ast.expression_string_literal(SPAN, self.ctx.source_path.to_string_lossy()); + let init = + ctx.ast.expression_string_literal(SPAN, self.ctx.source_path.to_string_lossy(), None); let decl = ctx.ast.variable_declarator(SPAN, VariableDeclarationKind::Var, id, Some(init), false); Some(decl) diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index a172ebc17f0c7..0180bce8e6e54 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -166,9 +166,11 @@ impl<'a, 'ctx> Traverse<'a> for ReactRefresh<'a, 'ctx> { let callee = self.refresh_reg.to_expression(ctx); let arguments = ctx.ast.vec_from_array([ Argument::from(binding.create_read_expression(ctx)), - Argument::from( - ctx.ast.expression_string_literal(SPAN, ctx.ast.atom(&persistent_id)), - ), + Argument::from(ctx.ast.expression_string_literal( + SPAN, + ctx.ast.atom(&persistent_id), + None, + )), ]); new_statements.push(ctx.ast.statement_expression( SPAN, @@ -536,7 +538,11 @@ impl<'a, 'ctx> ReactRefresh<'a, 'ctx> { let force_reset = custom_hooks_in_scope.len() != callee_len; let mut arguments = ctx.ast.vec(); - arguments.push(Argument::from(ctx.ast.expression_string_literal(SPAN, ctx.ast.atom(&key)))); + arguments.push(Argument::from(ctx.ast.expression_string_literal( + SPAN, + ctx.ast.atom(&key), + None, + ))); if force_reset || !custom_hooks_in_scope.is_empty() { arguments.push(Argument::from(ctx.ast.expression_boolean_literal(SPAN, force_reset))); diff --git a/crates/oxc_transformer/src/plugins/inject_global_variables.rs b/crates/oxc_transformer/src/plugins/inject_global_variables.rs index d45e07ab015cf..c5ce8a83f4659 100644 --- a/crates/oxc_transformer/src/plugins/inject_global_variables.rs +++ b/crates/oxc_transformer/src/plugins/inject_global_variables.rs @@ -198,7 +198,7 @@ impl<'a> InjectGlobalVariables<'a> { fn inject_imports(&self, injects: &[InjectImport], program: &mut Program<'a>) { let imports = injects.iter().map(|inject| { let specifiers = Some(self.ast.vec1(self.inject_import_to_specifier(inject))); - let source = self.ast.string_literal(SPAN, inject.source.as_str()); + let source = self.ast.string_literal(SPAN, inject.source.as_str(), None); let kind = ImportOrExportKind::Value; let import_decl = self .ast diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 14097852ffa48..7bdf29ad04fb9 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -184,8 +184,8 @@ impl<'a, 'ctx> Traverse<'a> for RegExp<'a, 'ctx> { }; let arguments = ctx.ast.vec_from_array([ - Argument::from(ctx.ast.expression_string_literal(SPAN, pattern_source)), - Argument::from(ctx.ast.expression_string_literal(SPAN, flags.to_string())), + Argument::from(ctx.ast.expression_string_literal(SPAN, pattern_source, None)), + Argument::from(ctx.ast.expression_string_literal(SPAN, flags.to_string(), None)), ]); *expr = ctx.ast.expression_new(regexp.span, callee, arguments, NONE); diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index b503f9ff32704..472cd1579f221 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -234,7 +234,7 @@ impl<'a> TypeScriptEnum<'a> { } ConstantValue::String(str) => { prev_constant_value = None; - ast.expression_string_literal(SPAN, str) + ast.expression_string_literal(SPAN, str, None) } } } @@ -255,7 +255,7 @@ impl<'a> TypeScriptEnum<'a> { } else if let Some(prev_member_name) = prev_member_name { let self_ref = { let obj = param_binding.create_read_expression(ctx); - let expr = ctx.ast.expression_string_literal(SPAN, prev_member_name); + let expr = ctx.ast.expression_string_literal(SPAN, prev_member_name, None); ast.member_expression_computed(SPAN, obj, expr, false).into() }; @@ -271,7 +271,7 @@ impl<'a> TypeScriptEnum<'a> { // Foo["x"] = init let member_expr = { let obj = param_binding.create_read_expression(ctx); - let expr = ast.expression_string_literal(SPAN, member_name); + let expr = ast.expression_string_literal(SPAN, member_name, None); ast.member_expression_computed(SPAN, obj, expr, false) }; @@ -286,7 +286,7 @@ impl<'a> TypeScriptEnum<'a> { ast.member_expression_computed(SPAN, obj, expr, false) }; let left = SimpleAssignmentTarget::from(member_expr); - let right = ast.expression_string_literal(SPAN, member_name); + let right = ast.expression_string_literal(SPAN, member_name, None); expr = ast.expression_assignment(SPAN, AssignmentOperator::Assign, left.into(), right); } diff --git a/crates/oxc_transformer/src/typescript/module.rs b/crates/oxc_transformer/src/typescript/module.rs index 0c7b650e8312b..4280921e6b8ca 100644 --- a/crates/oxc_transformer/src/typescript/module.rs +++ b/crates/oxc_transformer/src/typescript/module.rs @@ -23,7 +23,7 @@ impl<'a, 'ctx> Traverse<'a> for TypeScriptModule<'a, 'ctx> { if self.ctx.module.is_commonjs() { let has_use_strict = program.directives.iter().any(Directive::is_use_strict); if !has_use_strict { - let use_strict = ctx.ast.string_literal(SPAN, "use strict"); + let use_strict = ctx.ast.string_literal(SPAN, "use strict", None); program.directives.insert(0, ctx.ast.directive(SPAN, use_strict, "use strict")); } } diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index 8e911599d8d8b..0cbdcc5eef497 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -22,7 +22,7 @@ export interface NumericLiteral extends Span { export interface StringLiteral extends Span { type: 'Literal'; value: string; - raw?: undefined; + raw: string | null; } export interface BigIntLiteral extends Span {