mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
1 parent
97af341cac
commit
b0e1c03284
29 files changed
+201
-129
No files matched your search
@@ -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<Atom<'a>>,
|
||||
}
|
||||
|
||||
/// BigInt literal
|
||||
|
||||
@@ -25,10 +25,11 @@ const _: () = {
|
||||
assert!(offset_of!(NumericLiteral, raw) == 16usize);
|
||||
assert!(offset_of!(NumericLiteral, base) == 32usize);
|
||||
|
||||
assert!(size_of::<StringLiteral>() == 24usize);
|
||||
assert!(size_of::<StringLiteral>() == 40usize);
|
||||
assert!(align_of::<StringLiteral>() == 8usize);
|
||||
assert!(offset_of!(StringLiteral, span) == 0usize);
|
||||
assert!(offset_of!(StringLiteral, value) == 8usize);
|
||||
assert!(offset_of!(StringLiteral, raw) == 24usize);
|
||||
|
||||
assert!(size_of::<BigIntLiteral>() == 32usize);
|
||||
assert!(align_of::<BigIntLiteral>() == 8usize);
|
||||
@@ -334,11 +335,11 @@ const _: () = {
|
||||
assert!(size_of::<Statement>() == 16usize);
|
||||
assert!(align_of::<Statement>() == 8usize);
|
||||
|
||||
assert!(size_of::<Directive>() == 48usize);
|
||||
assert!(size_of::<Directive>() == 64usize);
|
||||
assert!(align_of::<Directive>() == 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::<Hashbang>() == 24usize);
|
||||
assert!(align_of::<Hashbang>() == 8usize);
|
||||
@@ -702,23 +703,23 @@ const _: () = {
|
||||
assert!(offset_of!(ImportExpression, source) == 8usize);
|
||||
assert!(offset_of!(ImportExpression, arguments) == 24usize);
|
||||
|
||||
assert!(size_of::<ImportDeclaration>() == 80usize);
|
||||
assert!(size_of::<ImportDeclaration>() == 96usize);
|
||||
assert!(align_of::<ImportDeclaration>() == 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::<ImportDeclarationSpecifier>() == 16usize);
|
||||
assert!(align_of::<ImportDeclarationSpecifier>() == 8usize);
|
||||
|
||||
assert!(size_of::<ImportSpecifier>() == 88usize);
|
||||
assert!(size_of::<ImportSpecifier>() == 96usize);
|
||||
assert!(align_of::<ImportSpecifier>() == 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::<ImportDefaultSpecifier>() == 40usize);
|
||||
assert!(align_of::<ImportDefaultSpecifier>() == 8usize);
|
||||
@@ -736,49 +737,49 @@ const _: () = {
|
||||
assert!(offset_of!(WithClause, attributes_keyword) == 8usize);
|
||||
assert!(offset_of!(WithClause, with_entries) == 32usize);
|
||||
|
||||
assert!(size_of::<ImportAttribute>() == 64usize);
|
||||
assert!(size_of::<ImportAttribute>() == 96usize);
|
||||
assert!(align_of::<ImportAttribute>() == 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::<ImportAttributeKey>() == 32usize);
|
||||
assert!(size_of::<ImportAttributeKey>() == 48usize);
|
||||
assert!(align_of::<ImportAttributeKey>() == 8usize);
|
||||
|
||||
assert!(size_of::<ExportNamedDeclaration>() == 96usize);
|
||||
assert!(size_of::<ExportNamedDeclaration>() == 112usize);
|
||||
assert!(align_of::<ExportNamedDeclaration>() == 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::<ExportDefaultDeclaration>() == 64usize);
|
||||
assert!(size_of::<ExportDefaultDeclaration>() == 72usize);
|
||||
assert!(align_of::<ExportDefaultDeclaration>() == 8usize);
|
||||
assert!(offset_of!(ExportDefaultDeclaration, span) == 0usize);
|
||||
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8usize);
|
||||
assert!(offset_of!(ExportDefaultDeclaration, exported) == 24usize);
|
||||
|
||||
assert!(size_of::<ExportAllDeclaration>() == 88usize);
|
||||
assert!(size_of::<ExportAllDeclaration>() == 112usize);
|
||||
assert!(align_of::<ExportAllDeclaration>() == 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::<ExportSpecifier>() == 96usize);
|
||||
assert!(size_of::<ExportSpecifier>() == 112usize);
|
||||
assert!(align_of::<ExportSpecifier>() == 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::<ExportDefaultDeclarationKind>() == 16usize);
|
||||
assert!(align_of::<ExportDefaultDeclarationKind>() == 8usize);
|
||||
|
||||
assert!(size_of::<ModuleExportName>() == 40usize);
|
||||
assert!(size_of::<ModuleExportName>() == 48usize);
|
||||
assert!(align_of::<ModuleExportName>() == 8usize);
|
||||
|
||||
assert!(size_of::<TSThisParameter>() == 24usize);
|
||||
@@ -1088,19 +1089,19 @@ const _: () = {
|
||||
assert!(size_of::<TSTypePredicateName>() == 16usize);
|
||||
assert!(align_of::<TSTypePredicateName>() == 8usize);
|
||||
|
||||
assert!(size_of::<TSModuleDeclaration>() == 72usize);
|
||||
assert!(size_of::<TSModuleDeclaration>() == 80usize);
|
||||
assert!(align_of::<TSModuleDeclaration>() == 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::<TSModuleDeclarationKind>() == 1usize);
|
||||
assert!(align_of::<TSModuleDeclarationKind>() == 1usize);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationName>() == 40usize);
|
||||
assert!(size_of::<TSModuleDeclarationName>() == 48usize);
|
||||
assert!(align_of::<TSModuleDeclarationName>() == 8usize);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationBody>() == 16usize);
|
||||
@@ -1146,13 +1147,13 @@ const _: () = {
|
||||
assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8usize);
|
||||
assert!(offset_of!(TSImportAttributes, elements) == 32usize);
|
||||
|
||||
assert!(size_of::<TSImportAttribute>() == 56usize);
|
||||
assert!(size_of::<TSImportAttribute>() == 72usize);
|
||||
assert!(align_of::<TSImportAttribute>() == 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::<TSImportAttributeName>() == 32usize);
|
||||
assert!(size_of::<TSImportAttributeName>() == 48usize);
|
||||
assert!(align_of::<TSImportAttributeName>() == 8usize);
|
||||
|
||||
assert!(size_of::<TSFunctionType>() == 40usize);
|
||||
@@ -1218,7 +1219,7 @@ const _: () = {
|
||||
assert!(size_of::<TSModuleReference>() == 16usize);
|
||||
assert!(align_of::<TSModuleReference>() == 8usize);
|
||||
|
||||
assert!(size_of::<TSExternalModuleReference>() == 32usize);
|
||||
assert!(size_of::<TSExternalModuleReference>() == 48usize);
|
||||
assert!(align_of::<TSExternalModuleReference>() == 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::<StringLiteral>() == 16usize);
|
||||
assert!(size_of::<StringLiteral>() == 24usize);
|
||||
assert!(align_of::<StringLiteral>() == 4usize);
|
||||
assert!(offset_of!(StringLiteral, span) == 0usize);
|
||||
assert!(offset_of!(StringLiteral, value) == 8usize);
|
||||
assert!(offset_of!(StringLiteral, raw) == 16usize);
|
||||
|
||||
assert!(size_of::<BigIntLiteral>() == 20usize);
|
||||
assert!(align_of::<BigIntLiteral>() == 4usize);
|
||||
@@ -1890,11 +1892,11 @@ const _: () = {
|
||||
assert!(size_of::<Statement>() == 8usize);
|
||||
assert!(align_of::<Statement>() == 4usize);
|
||||
|
||||
assert!(size_of::<Directive>() == 32usize);
|
||||
assert!(size_of::<Directive>() == 40usize);
|
||||
assert!(align_of::<Directive>() == 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::<Hashbang>() == 16usize);
|
||||
assert!(align_of::<Hashbang>() == 4usize);
|
||||
@@ -2258,23 +2260,23 @@ const _: () = {
|
||||
assert!(offset_of!(ImportExpression, source) == 8usize);
|
||||
assert!(offset_of!(ImportExpression, arguments) == 16usize);
|
||||
|
||||
assert!(size_of::<ImportDeclaration>() == 48usize);
|
||||
assert!(size_of::<ImportDeclaration>() == 56usize);
|
||||
assert!(align_of::<ImportDeclaration>() == 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::<ImportDeclarationSpecifier>() == 8usize);
|
||||
assert!(align_of::<ImportDeclarationSpecifier>() == 4usize);
|
||||
|
||||
assert!(size_of::<ImportSpecifier>() == 56usize);
|
||||
assert!(size_of::<ImportSpecifier>() == 60usize);
|
||||
assert!(align_of::<ImportSpecifier>() == 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::<ImportDefaultSpecifier>() == 28usize);
|
||||
assert!(align_of::<ImportDefaultSpecifier>() == 4usize);
|
||||
@@ -2292,49 +2294,49 @@ const _: () = {
|
||||
assert!(offset_of!(WithClause, attributes_keyword) == 8usize);
|
||||
assert!(offset_of!(WithClause, with_entries) == 24usize);
|
||||
|
||||
assert!(size_of::<ImportAttribute>() == 44usize);
|
||||
assert!(size_of::<ImportAttribute>() == 60usize);
|
||||
assert!(align_of::<ImportAttribute>() == 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::<ImportAttributeKey>() == 20usize);
|
||||
assert!(size_of::<ImportAttributeKey>() == 28usize);
|
||||
assert!(align_of::<ImportAttributeKey>() == 4usize);
|
||||
|
||||
assert!(size_of::<ExportNamedDeclaration>() == 56usize);
|
||||
assert!(size_of::<ExportNamedDeclaration>() == 64usize);
|
||||
assert!(align_of::<ExportNamedDeclaration>() == 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::<ExportDefaultDeclaration>() == 40usize);
|
||||
assert!(size_of::<ExportDefaultDeclaration>() == 44usize);
|
||||
assert!(align_of::<ExportDefaultDeclaration>() == 4usize);
|
||||
assert!(offset_of!(ExportDefaultDeclaration, span) == 0usize);
|
||||
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8usize);
|
||||
assert!(offset_of!(ExportDefaultDeclaration, exported) == 16usize);
|
||||
|
||||
assert!(size_of::<ExportAllDeclaration>() == 56usize);
|
||||
assert!(size_of::<ExportAllDeclaration>() == 68usize);
|
||||
assert!(align_of::<ExportAllDeclaration>() == 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::<ExportSpecifier>() == 60usize);
|
||||
assert!(size_of::<ExportSpecifier>() == 68usize);
|
||||
assert!(align_of::<ExportSpecifier>() == 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::<ExportDefaultDeclarationKind>() == 8usize);
|
||||
assert!(align_of::<ExportDefaultDeclarationKind>() == 4usize);
|
||||
|
||||
assert!(size_of::<ModuleExportName>() == 24usize);
|
||||
assert!(size_of::<ModuleExportName>() == 28usize);
|
||||
assert!(align_of::<ModuleExportName>() == 4usize);
|
||||
|
||||
assert!(size_of::<TSThisParameter>() == 20usize);
|
||||
@@ -2644,19 +2646,19 @@ const _: () = {
|
||||
assert!(size_of::<TSTypePredicateName>() == 12usize);
|
||||
assert!(align_of::<TSTypePredicateName>() == 4usize);
|
||||
|
||||
assert!(size_of::<TSModuleDeclaration>() == 48usize);
|
||||
assert!(size_of::<TSModuleDeclaration>() == 52usize);
|
||||
assert!(align_of::<TSModuleDeclaration>() == 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::<TSModuleDeclarationKind>() == 1usize);
|
||||
assert!(align_of::<TSModuleDeclarationKind>() == 1usize);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationName>() == 24usize);
|
||||
assert!(size_of::<TSModuleDeclarationName>() == 28usize);
|
||||
assert!(align_of::<TSModuleDeclarationName>() == 4usize);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationBody>() == 8usize);
|
||||
@@ -2702,13 +2704,13 @@ const _: () = {
|
||||
assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8usize);
|
||||
assert!(offset_of!(TSImportAttributes, elements) == 24usize);
|
||||
|
||||
assert!(size_of::<TSImportAttribute>() == 36usize);
|
||||
assert!(size_of::<TSImportAttribute>() == 44usize);
|
||||
assert!(align_of::<TSImportAttribute>() == 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::<TSImportAttributeName>() == 20usize);
|
||||
assert!(size_of::<TSImportAttributeName>() == 28usize);
|
||||
assert!(align_of::<TSImportAttributeName>() == 4usize);
|
||||
|
||||
assert!(size_of::<TSFunctionType>() == 24usize);
|
||||
@@ -2774,7 +2776,7 @@ const _: () = {
|
||||
assert!(size_of::<TSModuleReference>() == 8usize);
|
||||
assert!(align_of::<TSModuleReference>() == 4usize);
|
||||
|
||||
assert!(size_of::<TSExternalModuleReference>() == 24usize);
|
||||
assert!(size_of::<TSExternalModuleReference>() == 32usize);
|
||||
assert!(align_of::<TSExternalModuleReference>() == 4usize);
|
||||
assert!(offset_of!(TSExternalModuleReference, span) == 0usize);
|
||||
assert!(offset_of!(TSExternalModuleReference, expression) == 8usize);
|
||||
|
||||
@@ -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<A>(self, span: Span, value: A) -> StringLiteral<'a>
|
||||
pub fn string_literal<A>(self, span: Span, value: A, raw: Option<Atom<'a>>) -> 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<A>(self, span: Span, value: A) -> Box<'a, StringLiteral<'a>>
|
||||
pub fn alloc_string_literal<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(self, span: Span, value: A) -> Expression<'a>
|
||||
pub fn expression_string_literal<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(self, span: Span, value: A) -> ModuleExportName<'a>
|
||||
pub fn module_export_name_string_literal<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(self, span: Span, value: A) -> TSEnumMemberName<'a>
|
||||
pub fn ts_enum_member_name_string_literal<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(self, span: Span, value: A) -> TSLiteral<'a>
|
||||
pub fn ts_literal_string_literal<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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<A>(
|
||||
self,
|
||||
span: Span,
|
||||
value: A,
|
||||
raw: Option<Atom<'a>>,
|
||||
) -> 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`]
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ impl ContentHash for BooleanLiteral {
|
||||
impl<'a> ContentHash for StringLiteral<'a> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.value, state);
|
||||
ContentHash::content_hash(&self.raw, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
))
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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!() };
|
||||
|
||||
@@ -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,
|
||||
));
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<Expression<'a>> {
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user