diff --git a/Cargo.lock b/Cargo.lock index 039dbd8..7fba7bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,18 +7,17 @@ name = "Inflector" version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -dependencies = [ - "lazy_static", - "regex", -] [[package]] -name = "aho-corasick" -version = "1.1.3" +name = "ahash" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "memchr", + "cfg-if", + "once_cell", + "version_check", + "zerocopy", ] [[package]] @@ -36,7 +35,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn", + "syn 2.0.72", ] [[package]] @@ -163,7 +162,7 @@ checksum = "32016f1242eb82af5474752d00fd8ebcd9004bd69b462b1c91de833972d08ed4" dependencies = [ "proc-macro2", "swc_macros_common", - "syn", + "syn 2.0.72", ] [[package]] @@ -177,6 +176,10 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] name = "hstr" @@ -217,7 +220,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -226,24 +229,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -327,7 +318,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -373,6 +364,26 @@ dependencies = [ "cc", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quote" version = "1.0.36" @@ -403,35 +414,6 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -[[package]] -name = "regex" -version = "1.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - [[package]] name = "rustc-hash" version = "1.1.0" @@ -491,7 +473,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -590,7 +572,20 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn", + "syn 2.0.72", +] + +[[package]] +name = "swc_allocator" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc8bd3075d1c6964010333fae9ddcd91ad422a4f8eb8b3206a9b2b6afb4209e" +dependencies = [ + "bumpalo", + "hashbrown", + "ptr_meta", + "rustc-hash", + "triomphe", ] [[package]] @@ -607,9 +602,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.34.4" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9087befec6b63911f9d2f239e4f91c9b21589c169b86ed2d616944d23cf4a243" +checksum = "1802b1642488aec58597dc55ea88992c165660d6e44e9838d4d93f7b78ab95f3" dependencies = [ "ast_node", "better_scoped_tls", @@ -623,6 +618,7 @@ dependencies = [ "serde", "siphasher", "sourcemap", + "swc_allocator", "swc_atoms", "swc_eq_ignore_macros", "swc_visit", @@ -633,9 +629,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.115.1" +version = "0.117.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be1306930c235435a892104c00c2b5e16231043c085d5a10bd3e7537b15659b" +checksum = "a5da2f0310e8cd84b8c803095e75b2cbca872c71fc7f7404d4c9c8117d894960" dependencies = [ "bitflags", "is-macro", @@ -650,9 +646,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.146.12" +version = "0.148.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e0c2e85f12c63b85c805e923079b04d1fb3e25edd069d638eed5f2098de74" +checksum = "a8204235f635274dba4adc30c47ac896fd126ddfc53b27210676722423cbb2e7" dependencies = [ "either", "new_debug_unreachable", @@ -678,7 +674,7 @@ checksum = "63db0adcff29d220c3d151c5b25c0eabe7e32dd936212b84cdaa1392e3130497" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -689,30 +685,27 @@ checksum = "f486687bfb7b5c560868f69ed2d458b880cebc9babebcb67e49f31b55c5bf847" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] name = "swc_visit" -version = "0.5.14" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043d11fe683dcb934583ead49405c0896a5af5face522e4682c16971ef7871b9" +checksum = "2e194d14f94121fd08b823d3379eedb3ce455785d9e0c3d2742c59377e283207" dependencies = [ "either", - "swc_visit_macros", ] [[package]] -name = "swc_visit_macros" -version = "0.5.13" +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92807d840959f39c60ce8a774a3f83e8193c658068e6d270dbe0a05e40e90b41" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "Inflector", "proc-macro2", "quote", - "swc_macros_common", - "syn", + "unicode-ident", ] [[package]] @@ -772,7 +765,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -808,9 +801,9 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-id-start" -version = "1.0.4" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02aebfa694eccbbbffdd92922c7de136b9fe764396d2f10e21bce1681477cfc1" +checksum = "bc3882f69607a2ac8cc4de3ee7993d8f68bb06f2974271195065b3bd07f2edea" [[package]] name = "unicode-ident" @@ -892,3 +885,23 @@ name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] diff --git a/generation/generate/helpers.ts b/generation/generate/helpers.ts index de32a1e..96697d3 100644 --- a/generation/generate/helpers.ts +++ b/generation/generate/helpers.ts @@ -37,7 +37,7 @@ export function writeType(writer: Writer, analysisResult: AnalysisResult, type: } function writeReference(type: TypeReferenceDefinition) { - const path = type.path.join("::").replace(/^swc_ecma_ast::/, ""); + const path = type.path.join("::").replace(/^swc_ecma_ast::/, "").replace("swc_common::syntax_pos::hygiene::SyntaxContext", "swc_common::SyntaxContext"); if ( type.path[0] === "swc_ecma_ast" && (analysisResult.astEnums.some(e => e.name === type.name) || analysisResult.astStructs.some(s => s.name === type.name)) @@ -77,6 +77,10 @@ export function getIsReferenceType(analysisResult: AnalysisResult, type: TypeDef return getIsReferenceType(analysisResult, type.genericArgs[0]); } + if (type.name === "SyntaxContext") { + return false; + } + const isSwcPlainEnumType = type != null && type.kind === "Reference" && analysisResult.plainEnums.some(e => e.name === type.name); if (isSwcPlainEnumType) { return false; diff --git a/rs-lib/Cargo.toml b/rs-lib/Cargo.toml index 0725e8b..1b339ef 100644 --- a/rs-lib/Cargo.toml +++ b/rs-lib/Cargo.toml @@ -20,9 +20,9 @@ bumpalo = { version = "3.16.0", optional = true, features = ["collections", "all num-bigint = "0.4" rustc-hash = "1.1.0" swc_atoms = "0.6.7" -swc_common = "0.34.4" -swc_ecma_ast = "0.115.1" -swc_ecma_parser = "0.146.12" +swc_common = "0.36.2" +swc_ecma_ast = "0.117.4" +swc_ecma_parser = "0.148.1" text_lines = "0.6.0" [dev-dependencies] diff --git a/rs-lib/src/common/pos.rs b/rs-lib/src/common/pos.rs index 2a15f48..cd4f1d5 100644 --- a/rs-lib/src/common/pos.rs +++ b/rs-lib/src/common/pos.rs @@ -240,7 +240,7 @@ impl + Clone + Copy> SourceRanged for SourceRange { #[allow(clippy::from_over_into)] impl Into for SourceRange { fn into(self) -> Span { - Span::new(self.start.as_byte_pos(), self.end.as_byte_pos(), Default::default()) + Span::new(self.start.as_byte_pos(), self.end.as_byte_pos()) } } diff --git a/rs-lib/src/test_helpers.rs b/rs-lib/src/test_helpers.rs index f12c1b7..839f979 100644 --- a/rs-lib/src/test_helpers.rs +++ b/rs-lib/src/test_helpers.rs @@ -20,7 +20,7 @@ pub fn get_swc_module(file_path: &Path, file_text: &str) -> (Module, Vec Ident<'a> { pub fn to_id(&self) -> Id { (self.sym().clone(), self.ctxt()) } - - pub fn ctxt(&self) -> SyntaxContext { - self.inner.span.ctxt - } } impl<'a> BindingIdent<'a> { diff --git a/rs-lib/src/view/generated.rs b/rs-lib/src/view/generated.rs index 0bf9ccd..a85903c 100644 --- a/rs-lib/src/view/generated.rs +++ b/rs-lib/src/view/generated.rs @@ -127,6 +127,7 @@ pub enum Node<'a> { Function(&'a Function<'a>), GetterProp(&'a GetterProp<'a>), Ident(&'a Ident<'a>), + IdentName(&'a IdentName<'a>), IfStmt(&'a IfStmt<'a>), Import(&'a Import<'a>), ImportDecl(&'a ImportDecl<'a>), @@ -320,6 +321,7 @@ impl<'a> SourceRanged for Node<'a> { Node::Function(node) => node.start(), Node::GetterProp(node) => node.start(), Node::Ident(node) => node.start(), + Node::IdentName(node) => node.start(), Node::IfStmt(node) => node.start(), Node::Import(node) => node.start(), Node::ImportDecl(node) => node.start(), @@ -494,6 +496,7 @@ impl<'a> SourceRanged for Node<'a> { Node::Function(node) => node.end(), Node::GetterProp(node) => node.end(), Node::Ident(node) => node.end(), + Node::IdentName(node) => node.end(), Node::IfStmt(node) => node.end(), Node::Import(node) => node.end(), Node::ImportDecl(node) => node.end(), @@ -671,6 +674,7 @@ impl<'a> NodeTrait<'a> for Node<'a> { Node::Function(node) => NodeTrait::parent(*node), Node::GetterProp(node) => NodeTrait::parent(*node), Node::Ident(node) => NodeTrait::parent(*node), + Node::IdentName(node) => NodeTrait::parent(*node), Node::IfStmt(node) => NodeTrait::parent(*node), Node::Import(node) => NodeTrait::parent(*node), Node::ImportDecl(node) => NodeTrait::parent(*node), @@ -846,6 +850,7 @@ impl<'a> NodeTrait<'a> for Node<'a> { Node::Function(node) => node.children(), Node::GetterProp(node) => node.children(), Node::Ident(node) => node.children(), + Node::IdentName(node) => node.children(), Node::IfStmt(node) => node.children(), Node::Import(node) => node.children(), Node::ImportDecl(node) => node.children(), @@ -1021,6 +1026,7 @@ impl<'a> NodeTrait<'a> for Node<'a> { Node::Function(node) => node.as_node(), Node::GetterProp(node) => node.as_node(), Node::Ident(node) => node.as_node(), + Node::IdentName(node) => node.as_node(), Node::IfStmt(node) => node.as_node(), Node::Import(node) => node.as_node(), Node::ImportDecl(node) => node.as_node(), @@ -1196,6 +1202,7 @@ impl<'a> NodeTrait<'a> for Node<'a> { Node::Function(_) => NodeKind::Function, Node::GetterProp(_) => NodeKind::GetterProp, Node::Ident(_) => NodeKind::Ident, + Node::IdentName(_) => NodeKind::IdentName, Node::IfStmt(_) => NodeKind::IfStmt, Node::Import(_) => NodeKind::Import, Node::ImportDecl(_) => NodeKind::ImportDecl, @@ -1372,6 +1379,7 @@ pub enum NodeKind { Function, GetterProp, Ident, + IdentName, IfStmt, Import, ImportDecl, @@ -1547,6 +1555,7 @@ impl std::fmt::Display for NodeKind { NodeKind::Function => "Function", NodeKind::GetterProp => "GetterProp", NodeKind::Ident => "Ident", + NodeKind::IdentName => "IdentName", NodeKind::IfStmt => "IfStmt", NodeKind::Import => "Import", NodeKind::ImportDecl => "ImportDecl", @@ -3433,7 +3442,7 @@ fn set_parent_for_import_specifier<'a>(node: &ImportSpecifier<'a>, parent: Node< #[derive(Copy, Clone)] pub enum JSXAttrName<'a> { - Ident(&'a Ident<'a>), + Ident(&'a IdentName<'a>), JSXNamespacedName(&'a JSXNamespacedName<'a>), } @@ -3498,7 +3507,7 @@ impl<'a> NodeTrait<'a> for JSXAttrName<'a> { fn kind(&self) -> NodeKind { match self { - JSXAttrName::Ident(_) => NodeKind::Ident, + JSXAttrName::Ident(_) => NodeKind::IdentName, JSXAttrName::JSXNamespacedName(_) => NodeKind::JSXNamespacedName, } } @@ -3524,14 +3533,14 @@ impl<'a> From> for Node<'a> { fn get_view_for_jsxattr_name<'a>(inner: &'a swc_ast::JSXAttrName, bump: &'a Bump) -> JSXAttrName<'a> { match inner { - swc_ast::JSXAttrName::Ident(value) => JSXAttrName::Ident(get_view_for_ident(value, bump)), + swc_ast::JSXAttrName::Ident(value) => JSXAttrName::Ident(get_view_for_ident_name(value, bump)), swc_ast::JSXAttrName::JSXNamespacedName(value) => JSXAttrName::JSXNamespacedName(get_view_for_jsxnamespaced_name(value, bump)), } } fn set_parent_for_jsxattr_name<'a>(node: &JSXAttrName<'a>, parent: Node<'a>) { match node { - JSXAttrName::Ident(value) => set_parent_for_ident(value, parent), + JSXAttrName::Ident(value) => set_parent_for_ident_name(value, parent), JSXAttrName::JSXNamespacedName(value) => set_parent_for_jsxnamespaced_name(value, parent), } } @@ -4492,7 +4501,7 @@ fn set_parent_for_lit<'a>(node: &Lit<'a>, parent: Node<'a>) { #[derive(Copy, Clone)] pub enum MemberProp<'a> { - Ident(&'a Ident<'a>), + Ident(&'a IdentName<'a>), PrivateName(&'a PrivateName<'a>), Computed(&'a ComputedPropName<'a>), } @@ -4563,7 +4572,7 @@ impl<'a> NodeTrait<'a> for MemberProp<'a> { fn kind(&self) -> NodeKind { match self { - MemberProp::Ident(_) => NodeKind::Ident, + MemberProp::Ident(_) => NodeKind::IdentName, MemberProp::PrivateName(_) => NodeKind::PrivateName, MemberProp::Computed(_) => NodeKind::ComputedPropName, } @@ -4592,7 +4601,7 @@ impl<'a> From> for Node<'a> { fn get_view_for_member_prop<'a>(inner: &'a swc_ast::MemberProp, bump: &'a Bump) -> MemberProp<'a> { match inner { - swc_ast::MemberProp::Ident(value) => MemberProp::Ident(get_view_for_ident(value, bump)), + swc_ast::MemberProp::Ident(value) => MemberProp::Ident(get_view_for_ident_name(value, bump)), swc_ast::MemberProp::PrivateName(value) => MemberProp::PrivateName(get_view_for_private_name(value, bump)), swc_ast::MemberProp::Computed(value) => MemberProp::Computed(get_view_for_computed_prop_name(value, bump)), } @@ -4600,7 +4609,7 @@ fn get_view_for_member_prop<'a>(inner: &'a swc_ast::MemberProp, bump: &'a Bump) fn set_parent_for_member_prop<'a>(node: &MemberProp<'a>, parent: Node<'a>) { match node { - MemberProp::Ident(value) => set_parent_for_ident(value, parent), + MemberProp::Ident(value) => set_parent_for_ident_name(value, parent), MemberProp::PrivateName(value) => set_parent_for_private_name(value, parent), MemberProp::Computed(value) => set_parent_for_computed_prop_name(value, parent), } @@ -5633,7 +5642,7 @@ fn set_parent_for_prop<'a>(node: &Prop<'a>, parent: Node<'a>) { #[derive(Copy, Clone)] pub enum PropName<'a> { - Ident(&'a Ident<'a>), + Ident(&'a IdentName<'a>), /// String literal. Str(&'a Str<'a>), /// Numeric literal. @@ -5718,7 +5727,7 @@ impl<'a> NodeTrait<'a> for PropName<'a> { fn kind(&self) -> NodeKind { match self { - PropName::Ident(_) => NodeKind::Ident, + PropName::Ident(_) => NodeKind::IdentName, PropName::Str(_) => NodeKind::Str, PropName::Num(_) => NodeKind::Number, PropName::Computed(_) => NodeKind::ComputedPropName, @@ -5753,7 +5762,7 @@ impl<'a> From> for Node<'a> { fn get_view_for_prop_name<'a>(inner: &'a swc_ast::PropName, bump: &'a Bump) -> PropName<'a> { match inner { - swc_ast::PropName::Ident(value) => PropName::Ident(get_view_for_ident(value, bump)), + swc_ast::PropName::Ident(value) => PropName::Ident(get_view_for_ident_name(value, bump)), swc_ast::PropName::Str(value) => PropName::Str(get_view_for_str(value, bump)), swc_ast::PropName::Num(value) => PropName::Num(get_view_for_number(value, bump)), swc_ast::PropName::Computed(value) => PropName::Computed(get_view_for_computed_prop_name(value, bump)), @@ -5763,7 +5772,7 @@ fn get_view_for_prop_name<'a>(inner: &'a swc_ast::PropName, bump: &'a Bump) -> P fn set_parent_for_prop_name<'a>(node: &PropName<'a>, parent: Node<'a>) { match node { - PropName::Ident(value) => set_parent_for_ident(value, parent), + PropName::Ident(value) => set_parent_for_ident_name(value, parent), PropName::Str(value) => set_parent_for_str(value, parent), PropName::Num(value) => set_parent_for_number(value, parent), PropName::Computed(value) => set_parent_for_computed_prop_name(value, parent), @@ -6372,7 +6381,7 @@ fn set_parent_for_stmt<'a>(node: &Stmt<'a>, parent: Node<'a>) { #[derive(Copy, Clone)] pub enum SuperProp<'a> { - Ident(&'a Ident<'a>), + Ident(&'a IdentName<'a>), Computed(&'a ComputedPropName<'a>), } @@ -6437,7 +6446,7 @@ impl<'a> NodeTrait<'a> for SuperProp<'a> { fn kind(&self) -> NodeKind { match self { - SuperProp::Ident(_) => NodeKind::Ident, + SuperProp::Ident(_) => NodeKind::IdentName, SuperProp::Computed(_) => NodeKind::ComputedPropName, } } @@ -6463,14 +6472,14 @@ impl<'a> From> for Node<'a> { fn get_view_for_super_prop<'a>(inner: &'a swc_ast::SuperProp, bump: &'a Bump) -> SuperProp<'a> { match inner { - swc_ast::SuperProp::Ident(value) => SuperProp::Ident(get_view_for_ident(value, bump)), + swc_ast::SuperProp::Ident(value) => SuperProp::Ident(get_view_for_ident_name(value, bump)), swc_ast::SuperProp::Computed(value) => SuperProp::Computed(get_view_for_computed_prop_name(value, bump)), } } fn set_parent_for_super_prop<'a>(node: &SuperProp<'a>, parent: Node<'a>) { match node { - SuperProp::Ident(value) => set_parent_for_ident(value, parent), + SuperProp::Ident(value) => set_parent_for_ident_name(value, parent), SuperProp::Computed(value) => set_parent_for_computed_prop_name(value, parent), } } @@ -8561,6 +8570,10 @@ impl<'a> ArrowExpr<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + pub fn is_async(&self) -> bool { self.inner.is_async } @@ -9481,6 +9494,10 @@ impl<'a> BlockStmt<'a> { pub fn parent(&self) -> Node<'a> { self.parent.get().unwrap() } + + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } } impl<'a> SourceRanged for BlockStmt<'a> { @@ -9735,6 +9752,10 @@ impl<'a> CallExpr<'a> { pub fn parent(&self) -> Node<'a> { self.parent.get().unwrap() } + + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } } impl<'a> SourceRanged for CallExpr<'a> { @@ -9930,6 +9951,10 @@ impl<'a> Class<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + pub fn is_abstract(&self) -> bool { self.inner.is_abstract } @@ -10652,6 +10677,10 @@ impl<'a> Constructor<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + pub fn accessibility(&self) -> Option { self.inner.accessibility } @@ -11382,6 +11411,25 @@ fn set_parent_for_export_default_decl<'a>(node: &ExportDefaultDecl<'a>, parent: node.parent.set(parent); } +/// Default exports other than **direct** function expression or class +/// expression. +/// +/// +/// # Note +/// +/// ```ts +/// export default function Foo() { +/// } +/// ``` +/// +/// is [`ExportDefaultDecl`] and it's hoisted. +/// +/// ```ts +/// export default (function Foo() { +/// }) +/// ``` +/// +/// is [`ExportDefaultExpr`] and it's not hoisted. #[derive(Clone)] pub struct ExportDefaultExpr<'a> { parent: ParentOnceCell>, @@ -12358,6 +12406,10 @@ impl<'a> Function<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + /// if it's a generator. pub fn is_generator(&self) -> bool { self.inner.is_generator @@ -12636,6 +12688,10 @@ impl<'a> Ident<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + pub fn sym(&self) -> &swc_atoms::Atom { &self.inner.sym } @@ -12706,6 +12762,82 @@ fn set_parent_for_ident<'a>(node: &Ident<'a>, parent: Node<'a>) { node.parent.set(parent); } +#[derive(Clone)] +pub struct IdentName<'a> { + parent: ParentOnceCell>, + pub inner: &'a swc_ast::IdentName, +} + +impl<'a> IdentName<'a> { + pub fn parent(&self) -> Node<'a> { + self.parent.get().unwrap() + } + + pub fn sym(&self) -> &swc_atoms::Atom { + &self.inner.sym + } +} + +impl<'a> SourceRanged for IdentName<'a> { + fn start(&self) -> SourcePos { + SourcePos::unsafely_from_byte_pos(self.inner.span().lo) + } + fn end(&self) -> SourcePos { + SourcePos::unsafely_from_byte_pos(self.inner.span().hi) + } +} + +impl<'a> From<&IdentName<'a>> for Node<'a> { + fn from(node: &IdentName<'a>) -> Node<'a> { + let node = unsafe { mem::transmute::<&IdentName<'a>, &'a IdentName<'a>>(node) }; + Node::IdentName(node) + } +} + +impl<'a> NodeTrait<'a> for IdentName<'a> { + fn parent(&self) -> Option> { + Some(self.parent.get().unwrap().clone()) + } + + fn children(&self) -> Vec> { + Vec::with_capacity(0) + } + + fn as_node(&self) -> Node<'a> { + self.into() + } + + fn kind(&self) -> NodeKind { + NodeKind::IdentName + } +} + +impl<'a> CastableNode<'a> for IdentName<'a> { + fn to(node: &Node<'a>) -> Option<&'a Self> { + if let Node::IdentName(node) = node { + Some(node) + } else { + None + } + } + + fn kind() -> NodeKind { + NodeKind::IdentName + } +} + +fn get_view_for_ident_name<'a>(inner: &'a swc_ast::IdentName, bump: &'a Bump) -> &'a IdentName<'a> { + let node = bump.alloc(IdentName { + inner, + parent: Default::default(), + }); + node +} + +fn set_parent_for_ident_name<'a>(node: &IdentName<'a>, parent: Node<'a>) { + node.parent.set(parent); +} + #[derive(Clone)] pub struct IfStmt<'a> { parent: ParentOnceCell>, @@ -13889,7 +14021,7 @@ pub struct JSXMemberExpr<'a> { parent: ParentOnceCell>, pub inner: &'a swc_ast::JSXMemberExpr, pub obj: JSXObject<'a>, - pub prop: &'a Ident<'a>, + pub prop: &'a IdentName<'a>, } impl<'a> JSXMemberExpr<'a> { @@ -13954,11 +14086,11 @@ fn get_view_for_jsxmember_expr<'a>(inner: &'a swc_ast::JSXMemberExpr, bump: &'a inner, parent: Default::default(), obj: get_view_for_jsxobject(&inner.obj, bump), - prop: get_view_for_ident(&inner.prop, bump), + prop: get_view_for_ident_name(&inner.prop, bump), }); let parent: Node<'a> = (&*node).into(); set_parent_for_jsxobject(&node.obj, parent); - set_parent_for_ident(&node.prop, parent); + set_parent_for_ident_name(&node.prop, parent); node } @@ -13971,8 +14103,8 @@ fn set_parent_for_jsxmember_expr<'a>(node: &JSXMemberExpr<'a>, parent: Node<'a>) pub struct JSXNamespacedName<'a> { parent: ParentOnceCell>, pub inner: &'a swc_ast::JSXNamespacedName, - pub ns: &'a Ident<'a>, - pub name: &'a Ident<'a>, + pub ns: &'a IdentName<'a>, + pub name: &'a IdentName<'a>, } impl<'a> JSXNamespacedName<'a> { @@ -14036,12 +14168,12 @@ fn get_view_for_jsxnamespaced_name<'a>(inner: &'a swc_ast::JSXNamespacedName, bu let node = bump.alloc(JSXNamespacedName { inner, parent: Default::default(), - ns: get_view_for_ident(&inner.ns, bump), - name: get_view_for_ident(&inner.name, bump), + ns: get_view_for_ident_name(&inner.ns, bump), + name: get_view_for_ident_name(&inner.name, bump), }); let parent: Node<'a> = (&*node).into(); - set_parent_for_ident(&node.ns, parent); - set_parent_for_ident(&node.name, parent); + set_parent_for_ident_name(&node.ns, parent); + set_parent_for_ident_name(&node.name, parent); node } @@ -15075,6 +15207,10 @@ impl<'a> NewExpr<'a> { pub fn parent(&self) -> Node<'a> { self.parent.get().unwrap() } + + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } } impl<'a> SourceRanged for NewExpr<'a> { @@ -15527,6 +15663,10 @@ impl<'a> OptCall<'a> { pub fn parent(&self) -> &'a OptChainExpr<'a> { self.parent.get().unwrap() } + + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } } impl<'a> SourceRanged for OptCall<'a> { @@ -15970,13 +16110,16 @@ fn set_parent_for_private_method<'a>(node: &PrivateMethod<'a>, parent: Node<'a>) pub struct PrivateName<'a> { parent: ParentOnceCell>, pub inner: &'a swc_ast::PrivateName, - pub id: &'a Ident<'a>, } impl<'a> PrivateName<'a> { pub fn parent(&self) -> Node<'a> { self.parent.get().unwrap() } + + pub fn name(&self) -> &swc_atoms::Atom { + &self.inner.name + } } impl<'a> SourceRanged for PrivateName<'a> { @@ -16001,9 +16144,7 @@ impl<'a> NodeTrait<'a> for PrivateName<'a> { } fn children(&self) -> Vec> { - let mut children = Vec::with_capacity(1); - children.push(self.id.into()); - children + Vec::with_capacity(0) } fn as_node(&self) -> Node<'a> { @@ -16033,10 +16174,7 @@ fn get_view_for_private_name<'a>(inner: &'a swc_ast::PrivateName, bump: &'a Bump let node = bump.alloc(PrivateName { inner, parent: Default::default(), - id: get_view_for_ident(&inner.id, bump), }); - let parent: Node<'a> = (&*node).into(); - set_parent_for_ident(&node.id, parent); node } @@ -16059,6 +16197,10 @@ impl<'a> PrivateProp<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + pub fn is_static(&self) -> bool { self.inner.is_static } @@ -17296,6 +17438,10 @@ impl<'a> TaggedTpl<'a> { pub fn parent(&self) -> Node<'a> { self.parent.get().unwrap() } + + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } } impl<'a> SourceRanged for TaggedTpl<'a> { @@ -21037,7 +21183,7 @@ pub struct TsQualifiedName<'a> { parent: ParentOnceCell>, pub inner: &'a swc_ast::TsQualifiedName, pub left: TsEntityName<'a>, - pub right: &'a Ident<'a>, + pub right: &'a IdentName<'a>, } impl<'a> TsQualifiedName<'a> { @@ -21102,11 +21248,11 @@ fn get_view_for_ts_qualified_name<'a>(inner: &'a swc_ast::TsQualifiedName, bump: inner, parent: Default::default(), left: get_view_for_ts_entity_name(&inner.left, bump), - right: get_view_for_ident(&inner.right, bump), + right: get_view_for_ident_name(&inner.right, bump), }); let parent: Node<'a> = (&*node).into(); set_parent_for_ts_entity_name(&node.left, parent); - set_parent_for_ident(&node.right, parent); + set_parent_for_ident_name(&node.right, parent); node } @@ -23011,6 +23157,10 @@ impl<'a> VarDecl<'a> { self.parent.get().unwrap() } + pub fn ctxt(&self) -> swc_common::SyntaxContext { + self.inner.ctxt + } + pub fn decl_kind(&self) -> VarDeclKind { self.inner.kind }