diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8fa57368b670..928cdc6bada3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -354,6 +354,11 @@ jobs: run: | ./scripts/github/run-cargo-hack.sh ${{ matrix.settings.crate }} + - name: Check unknown variant with transforms + if: matrix.settings.crate == 'swc_ecma_transforms' + run: | + env RUSTFLAGS="--cfg swc_ast_unknown" cargo check -p ${{ matrix.settings.crate }} --features typescript,react,proposal,optimization,module,compat + node-test: name: Test node bindings - ${{ matrix.os }} if: >- diff --git a/crates/ast_node/src/lib.rs b/crates/ast_node/src/lib.rs index bc58300dc4ea..ade3332a9eba 100644 --- a/crates/ast_node/src/lib.rs +++ b/crates/ast_node/src/lib.rs @@ -158,29 +158,34 @@ pub fn ast_node( let mut item = TokenStream::new(); match input.data { Data::Enum(..) => { - struct EnumArgs { - clone: bool, - } - impl parse::Parse for EnumArgs { - fn parse(i: parse::ParseStream<'_>) -> syn::Result { - let name: Ident = i.parse()?; - if name != "no_clone" { - return Err(i.error("unknown attribute")); - } - Ok(EnumArgs { clone: false }) + use syn::parse::Parser; + + let attrs = >::parse_terminated + .parse(args) + .expect("failed to parse #[ast_node]"); + + let mut has_no_clone = false; + let mut has_no_unknown = false; + for attr in &attrs { + if attr == "no_clone" { + has_no_clone = true; + } else if attr == "no_unknown" { + has_no_unknown = true; + } else { + panic!("unknown attribute: {attr:?}") } } - let args = if args.is_empty() { - EnumArgs { clone: true } - } else { - parse(args).expect("failed to parse args of #[ast_node]") - }; - let clone = if args.clone { + let clone = if !has_no_clone { Some(quote!(#[derive(Clone)])) } else { None }; + let non_exhaustive = if !has_no_unknown { + Some(quote!(#[cfg_attr(swc_ast_unknown, non_exhaustive)])) + } else { + None + }; item.extend(quote!( #[allow(clippy::derive_partial_eq_without_eq)] @@ -198,6 +203,7 @@ pub fn ast_node( ::swc_common::DeserializeEnum, )] #clone + #non_exhaustive #[cfg_attr( feature = "rkyv-impl", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) diff --git a/crates/jsdoc/src/ast.rs b/crates/jsdoc/src/ast.rs index 8b98f083ccc4..7ac521b58773 100644 --- a/crates/jsdoc/src/ast.rs +++ b/crates/jsdoc/src/ast.rs @@ -30,7 +30,6 @@ pub struct TagItem { } #[ast_node] -#[non_exhaustive] pub enum Tag { #[tag("Yield")] Yield(YieldTag), diff --git a/crates/swc_bundler/Cargo.toml b/crates/swc_bundler/Cargo.toml index f2a5377ae1ee..40a436372323 100644 --- a/crates/swc_bundler/Cargo.toml +++ b/crates/swc_bundler/Cargo.toml @@ -18,6 +18,9 @@ version = "32.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] concurrent = ["swc_common/concurrent", "dashmap", "rayon", "indexmap/rayon"] diff --git a/crates/swc_bundler/src/bundler/chunk/cjs.rs b/crates/swc_bundler/src/bundler/chunk/cjs.rs index 4d6e1c6fc2c6..8b7db90b3886 100644 --- a/crates/swc_bundler/src/bundler/chunk/cjs.rs +++ b/crates/swc_bundler/src/bundler/chunk/cjs.rs @@ -140,6 +140,8 @@ fn wrap_module( unreachable!("module item found but is_es6 is false: {:?}", i) } ModuleItem::Stmt(s) => s, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .collect(), ..Default::default() @@ -318,6 +320,8 @@ where .into(); return; } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_bundler/src/bundler/chunk/computed_key.rs b/crates/swc_bundler/src/bundler/chunk/computed_key.rs index bef0b974fd4b..677043d014f0 100644 --- a/crates/swc_bundler/src/bundler/chunk/computed_key.rs +++ b/crates/swc_bundler/src/bundler/chunk/computed_key.rs @@ -73,6 +73,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if ctx.transitive_remap.get(&exported.ctxt).is_some() { let specifier = ExportSpecifier::Named(ExportNamedSpecifier { @@ -230,6 +232,8 @@ impl Fold for ExportToReturn { let decl = match item { ModuleItem::ModuleDecl(decl) => decl, ModuleItem::Stmt(_) => return item, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let stmt = match decl { @@ -287,6 +291,8 @@ impl Fold for ExportToReturn { ) } DefaultDecl::TsInterfaceDecl(_) => None, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, ModuleDecl::ExportDefaultExpr(_) => None, ModuleDecl::ExportAll(export) => return export.into(), @@ -308,6 +314,8 @@ impl Fold for ExportToReturn { Some(ModuleExportName::Str(..)) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + Some(_) => panic!("unable to access unknown nodes"), None => { if let ModuleExportName::Ident(orig) = &named.orig { self.export_id(orig.clone()); @@ -316,6 +324,8 @@ impl Fold for ExportToReturn { } } }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -332,6 +342,8 @@ impl Fold for ExportToReturn { ModuleDecl::TsImportEquals(_) => None, ModuleDecl::TsExportAssignment(_) => None, ModuleDecl::TsNamespaceExport(_) => None, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(stmt) = stmt { diff --git a/crates/swc_bundler/src/bundler/chunk/merge.rs b/crates/swc_bundler/src/bundler/chunk/merge.rs index 7fae8feaae94..4263aafef3ee 100644 --- a/crates/swc_bundler/src/bundler/chunk/merge.rs +++ b/crates/swc_bundler/src/bundler/chunk/merge.rs @@ -264,6 +264,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let id: Id = exported.into(); @@ -286,9 +288,13 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -380,11 +386,15 @@ where Expr::Call(CallExpr { callee, .. }) => match callee { Callee::Super(_) | Callee::Import(_) => continue, Callee::Expr(v) => v, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, Expr::Await(AwaitExpr { arg, .. }) => match &mut **arg { Expr::Call(CallExpr { callee, .. }) => match callee { Callee::Super(_) | Callee::Import(_) => continue, Callee::Expr(v) => v, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => continue, }, @@ -518,6 +528,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; // Default is not exported via `export *` if &*exported.sym == "default" { @@ -613,6 +625,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; new.push( imported @@ -665,6 +679,8 @@ where ); } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -754,6 +770,8 @@ where } } DefaultDecl::TsInterfaceDecl(_) => continue, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } // Create `export { local_default as default }` @@ -926,6 +944,8 @@ where | Decl::TsEnum(_) | Decl::TsModule(_) | Decl::Using(..) => continue, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; tracing::trace!( @@ -1023,6 +1043,8 @@ where "module string names unimplemented" ) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } ExportSpecifier::Default(s) => { @@ -1069,6 +1091,8 @@ where definite: Default::default(), }); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1101,6 +1125,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let orig_ident = match orig { ModuleExportName::Ident(ident) => ident, @@ -1202,6 +1228,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -1262,6 +1290,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; vars.push(( module_id, @@ -1317,6 +1347,8 @@ where continue; } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_bundler/src/bundler/export.rs b/crates/swc_bundler/src/bundler/export.rs index 234e6d6e419b..8d224dc7360c 100644 --- a/crates/swc_bundler/src/bundler/export.rs +++ b/crates/swc_bundler/src/bundler/export.rs @@ -229,6 +229,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } ExportSpecifier::Default(d) => { @@ -243,6 +245,8 @@ where ModuleExportName::Str(..) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some((_, export_ctxt)) = ctxt { orig.ctxt = export_ctxt; @@ -255,6 +259,8 @@ where Some(ModuleExportName::Str(..)) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + Some(_) => panic!("unable to access unknown nodes"), None => { let mut exported: Ident = orig.clone(); exported.ctxt = self.export_ctxt; @@ -280,6 +286,8 @@ where } } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_bundler/src/bundler/finalize.rs b/crates/swc_bundler/src/bundler/finalize.rs index 8a5fcd9170c9..59aef6b95fac 100644 --- a/crates/swc_bundler/src/bundler/finalize.rs +++ b/crates/swc_bundler/src/bundler/finalize.rs @@ -164,6 +164,8 @@ where let decl = match item { ModuleItem::ModuleDecl(v) => v, ModuleItem::Stmt(stmt) => return Some(stmt), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match decl { @@ -224,6 +226,8 @@ where ModuleExportName::Str(..) => unimplemented!( "module string names unimplemented" ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; props.push(PropOrSpread::Prop(Box::new( Prop::KeyValue(KeyValueProp { @@ -235,18 +239,24 @@ where Some(ModuleExportName::Str(..)) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + Some(_) => panic!("unable to access unknown nodes"), None => { let orig = match s.orig { ModuleExportName::Ident(ident) => ident, ModuleExportName::Str(..) => unimplemented!( "module string names unimplemented" ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; props.push(PropOrSpread::Prop(Box::new( Prop::Shorthand(orig), ))); } }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -303,6 +313,8 @@ where ) } DefaultDecl::TsInterfaceDecl(_) => None, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, ModuleDecl::ExportDefaultExpr(export) => { let default_var = private_ident!("default"); @@ -328,6 +340,9 @@ where } ModuleDecl::ExportAll(_) => None, + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } }) .collect(), diff --git a/crates/swc_bundler/src/bundler/import/mod.rs b/crates/swc_bundler/src/bundler/import/mod.rs index 7260fd34cf01..8c79601ab0d3 100644 --- a/crates/swc_bundler/src/bundler/import/mod.rs +++ b/crates/swc_bundler/src/bundler/import/mod.rs @@ -368,6 +368,8 @@ where let orig = match &s.orig { ModuleExportName::Ident(ident) => ident, ModuleExportName::Str(..) => unimplemented!("module string names unimplemented"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; self.add_forced_ns_for(orig.to_id()); @@ -378,6 +380,8 @@ where exported.ctxt = self.module_ctxt; } Some(ModuleExportName::Str(..)) => unimplemented!("module string names unimplemented"), + #[cfg(swc_ast_unknown)] + Some(_) => panic!("unable to access unknown nodes"), None => { let exported = Ident::new(orig.sym.clone(), orig.span, self.module_ctxt); s.exported = Some(ModuleExportName::Ident(exported)); @@ -438,6 +442,8 @@ where Some(ModuleExportName::Str(..)) => { unimplemented!("module string names unimplemented") } + #[cfg(swc_ast_unknown)] + Some(_) => panic!("unable to access unknown nodes"), None => { let mut imported: Ident = n.local.clone(); imported.ctxt = export_ctxt; @@ -451,6 +457,8 @@ where ImportSpecifier::Namespace(n) => { self.imported_idents.insert(n.local.to_id(), export_ctxt); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_bundler/src/bundler/keywords.rs b/crates/swc_bundler/src/bundler/keywords.rs index 53112c77f4f3..f5bcf0b2a956 100644 --- a/crates/swc_bundler/src/bundler/keywords.rs +++ b/crates/swc_bundler/src/bundler/keywords.rs @@ -61,6 +61,8 @@ impl VisitMut for KeywordRenamer { let orig = match &n.orig { ModuleExportName::Ident(ident) => ident, ModuleExportName::Str(..) => unimplemented!("module string names unimplemented"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(renamed) = self.renamed(orig) { n.orig = ModuleExportName::Ident(renamed); diff --git a/crates/swc_bundler/src/bundler/load.rs b/crates/swc_bundler/src/bundler/load.rs index 23f9362ade00..4d5bc47b26c1 100644 --- a/crates/swc_bundler/src/bundler/load.rs +++ b/crates/swc_bundler/src/bundler/load.rs @@ -373,6 +373,8 @@ where all: forced_ns.contains(&src.src.value), }); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -438,6 +440,8 @@ impl Visit for Es6ModuleDetector { } } Callee::Super(_) | Callee::Import(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -480,6 +484,8 @@ impl Visit for Es6ModuleDetector { ModuleDecl::TsImportEquals(_) => {} ModuleDecl::TsExportAssignment(_) => {} ModuleDecl::TsNamespaceExport(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_bundler/src/inline.rs b/crates/swc_bundler/src/inline.rs index 6545db636344..1d8c6496225e 100644 --- a/crates/swc_bundler/src/inline.rs +++ b/crates/swc_bundler/src/inline.rs @@ -141,6 +141,8 @@ impl VisitMut for Inliner { e.expr.visit_mut_with(self); } PropName::BigInt(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_bundler/src/modules/sort/stmt.rs b/crates/swc_bundler/src/modules/sort/stmt.rs index 719c01f80cca..f3b7366ab667 100644 --- a/crates/swc_bundler/src/modules/sort/stmt.rs +++ b/crates/swc_bundler/src/modules/sort/stmt.rs @@ -422,6 +422,8 @@ impl Visit for FieldInitFinder { } } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } e.visit_children_with(self); @@ -568,6 +570,8 @@ impl Visit for RequirementCalculator { let orig = match &n.orig { ModuleExportName::Ident(ident) => ident, ModuleExportName::Str(..) => unimplemented!("module string names unimplemented"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; self.insert(orig.clone().into()); } diff --git a/crates/swc_css_ast/src/at_rule.rs b/crates/swc_css_ast/src/at_rule.rs index 062c200b41b0..cb530c76cf41 100644 --- a/crates/swc_css_ast/src/at_rule.rs +++ b/crates/swc_css_ast/src/at_rule.rs @@ -18,7 +18,7 @@ pub struct AtRule { pub block: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AtRuleName { #[tag("DashedIdent")] @@ -46,7 +46,7 @@ impl PartialEq for AtRuleName { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AtRulePrelude { #[tag("ListOfComponentValues")] @@ -99,7 +99,7 @@ pub struct ScopeRange { pub scope_end: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ColorProfileName { #[tag("DashedIdent")] @@ -122,7 +122,7 @@ pub struct FontFeatureValuesPrelude { pub font_family: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum DocumentPreludeMatchingFunction { #[tag("Url")] @@ -131,7 +131,7 @@ pub enum DocumentPreludeMatchingFunction { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum KeyframesName { #[tag("CustomIdent")] @@ -170,7 +170,7 @@ pub struct KeyframeBlock { pub block: SimpleBlock, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum KeyframeSelector { #[tag("Ident")] @@ -188,7 +188,7 @@ pub struct ImportPrelude { pub import_conditions: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ImportHref { #[tag("Url")] @@ -197,7 +197,7 @@ pub enum ImportHref { Str(Str), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ImportLayerName { #[tag("Ident")] @@ -222,7 +222,7 @@ pub struct NamespacePrelude { pub uri: Box, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum NamespacePreludeUri { #[tag("Url")] @@ -269,14 +269,14 @@ impl EqIgnoreSpan for MediaQuery { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaType { #[tag("Ident")] Ident(Ident), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaConditionType { #[tag("MediaCondition")] @@ -300,7 +300,7 @@ pub struct MediaConditionWithoutOr { pub conditions: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaConditionAllType { #[tag("MediaNot")] @@ -316,7 +316,7 @@ pub enum MediaConditionAllType { MediaInParens(MediaInParens), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaConditionWithoutOrType { #[tag("MediaNot")] @@ -371,7 +371,7 @@ impl EqIgnoreSpan for MediaOr { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaInParens { #[tag("MediaCondition")] @@ -384,7 +384,7 @@ pub enum MediaInParens { GeneralEnclosed(GeneralEnclosed), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaFeature { #[tag("MediaFeaturePlain")] @@ -400,7 +400,7 @@ pub enum MediaFeature { RangeInterval(MediaFeatureRangeInterval), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaFeatureName { #[tag("Ident")] @@ -410,7 +410,7 @@ pub enum MediaFeatureName { ExtensionName(ExtensionName), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaFeatureValue { #[tag("Number")] @@ -502,7 +502,7 @@ pub struct SupportsCondition { pub conditions: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SupportsConditionType { #[tag("SupportsNot")] @@ -560,7 +560,7 @@ impl EqIgnoreSpan for SupportsOr { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SupportsInParens { #[tag("SupportsCondition")] @@ -573,7 +573,7 @@ pub enum SupportsInParens { GeneralEnclosed(GeneralEnclosed), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SupportsFeature { #[tag("Declaration")] @@ -582,7 +582,7 @@ pub enum SupportsFeature { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum GeneralEnclosed { #[tag("Function")] @@ -620,7 +620,7 @@ pub struct PageSelectorPseudo { pub value: Ident, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum LayerPrelude { #[tag("LayerName")] @@ -651,7 +651,7 @@ pub struct ContainerCondition { pub query: ContainerQuery, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ContainerName { #[tag("CustomIdent")] @@ -665,7 +665,7 @@ pub struct ContainerQuery { pub queries: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ContainerQueryType { #[tag("ContainerQueryNot")] @@ -723,7 +723,7 @@ impl EqIgnoreSpan for ContainerQueryOr { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum QueryInParens { #[tag("ContainerQuery")] @@ -740,7 +740,7 @@ pub enum QueryInParens { GeneralEnclosed(GeneralEnclosed), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SizeFeature { #[tag("SizeFeaturePlain")] @@ -822,7 +822,7 @@ pub struct SizeFeatureRangeInterval { pub right: Box, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SizeFeatureValue { #[tag("Number")] @@ -841,7 +841,7 @@ pub enum SizeFeatureValue { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SizeFeatureName { #[tag("Ident")] @@ -893,7 +893,7 @@ impl Take for CustomMediaQuery { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CustomMediaQueryMediaType { #[tag("Ident")] diff --git a/crates/swc_css_ast/src/base.rs b/crates/swc_css_ast/src/base.rs index a877d72ed109..4638cf78a60a 100644 --- a/crates/swc_css_ast/src/base.rs +++ b/crates/swc_css_ast/src/base.rs @@ -16,7 +16,7 @@ pub struct Stylesheet { pub rules: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Rule { #[tag("QualifiedRule")] @@ -53,7 +53,7 @@ impl Take for QualifiedRule { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum QualifiedRulePrelude { #[tag("SelectorList")] @@ -70,7 +70,7 @@ impl Take for QualifiedRulePrelude { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum StyleBlock { #[tag("AtRule")] @@ -101,7 +101,7 @@ impl Take for SimpleBlock { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum FunctionName { #[tag("Ident")] @@ -162,7 +162,7 @@ pub struct ListOfComponentValues { pub children: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ComponentValue { // No grammar @@ -284,7 +284,7 @@ impl From for ComponentValue { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum DeclarationOrAtRule { #[tag("Declaration")] @@ -306,7 +306,7 @@ pub struct Declaration { pub important: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum DeclarationName { #[tag("Ident")] diff --git a/crates/swc_css_ast/src/selector.rs b/crates/swc_css_ast/src/selector.rs index 4854ac390c29..de5555b51e42 100644 --- a/crates/swc_css_ast/src/selector.rs +++ b/crates/swc_css_ast/src/selector.rs @@ -28,7 +28,7 @@ pub struct ForgivingSelectorList { pub children: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ForgivingComplexSelector { #[tag("ComplexSelector")] @@ -58,7 +58,7 @@ pub struct ForgivingRelativeSelectorList { pub children: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ForgivingRelativeSelector { #[tag("RelativeSelector")] @@ -83,7 +83,7 @@ impl Take for ComplexSelector { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ComplexSelectorChildren { #[tag("CompoundSelector")] @@ -153,7 +153,7 @@ pub struct NestingSelector { pub span: Span, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum TypeSelector { #[tag("TagNameSelector")] @@ -183,7 +183,7 @@ pub struct NamespacePrefix { pub namespace: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Namespace { #[tag("NamedNamespace")] @@ -213,7 +213,7 @@ pub struct WqName { pub value: Ident, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SubclassSelector { #[tag("IdSelector")] @@ -297,7 +297,7 @@ pub struct AttributeSelectorMatcher { pub value: AttributeSelectorMatcherValue, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AttributeSelectorValue { #[tag("String")] @@ -322,7 +322,7 @@ pub struct PseudoClassSelector { pub children: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum PseudoClassSelectorChildren { #[tag("TokenAndSpan")] @@ -362,7 +362,7 @@ pub enum PseudoClassSelectorChildren { CompoundSelector(CompoundSelector), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AnPlusB { #[tag("Ident")] @@ -389,7 +389,7 @@ pub struct PseudoElementSelector { pub children: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum PseudoElementSelectorChildren { #[tag("TokenAndSpan")] diff --git a/crates/swc_css_ast/src/value.rs b/crates/swc_css_ast/src/value.rs index 5bde31084d6b..dbd8faa64c4d 100644 --- a/crates/swc_css_ast/src/value.rs +++ b/crates/swc_css_ast/src/value.rs @@ -141,7 +141,7 @@ pub struct Delimiter { // TODO small AST improve for `CurrentColorOrSystemColor` and // `NamedColorOrTransparent` -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Color { #[tag("AbsoluteColorBase")] @@ -153,7 +153,7 @@ pub enum Color { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AbsoluteColorBase { #[tag("HexColor")] @@ -175,7 +175,7 @@ pub struct HexColor { pub raw: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AlphaValue { #[tag("Number")] @@ -184,7 +184,7 @@ pub enum AlphaValue { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Hue { #[tag("Number")] @@ -193,7 +193,7 @@ pub enum Hue { Angle(Angle), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CmykComponent { #[tag("Number")] @@ -204,7 +204,7 @@ pub enum CmykComponent { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Dimension { #[tag("Length")] @@ -292,7 +292,7 @@ pub struct Percentage { pub value: Number, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum LengthPercentage { #[tag("Length")] @@ -301,7 +301,7 @@ pub enum LengthPercentage { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum FrequencyPercentage { #[tag("Frequency")] @@ -310,7 +310,7 @@ pub enum FrequencyPercentage { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AnglePercentage { #[tag("Angle")] @@ -319,7 +319,7 @@ pub enum AnglePercentage { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum TimePercentage { #[tag("Time")] @@ -420,7 +420,7 @@ pub struct Url { pub modifiers: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum UrlValue { #[tag("Str")] @@ -438,7 +438,7 @@ pub struct UrlValueRaw { pub raw: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum UrlModifier { #[tag("Ident")] @@ -472,7 +472,7 @@ pub struct CalcSum { pub expressions: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CalcProductOrOperator { #[tag("CalcProduct")] @@ -518,7 +518,7 @@ pub enum CalcOperatorType { Div, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CalcValueOrOperator { #[tag("CalcValue")] @@ -527,7 +527,7 @@ pub enum CalcValueOrOperator { Operator(CalcOperator), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CalcValue { #[tag("Number")] @@ -544,7 +544,7 @@ pub enum CalcValue { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum FamilyName { #[tag("Str")] diff --git a/crates/swc_ecma_ast/Cargo.toml b/crates/swc_ecma_ast/Cargo.toml index 48c1dfe7a3b0..91b5ea374398 100644 --- a/crates/swc_ecma_ast/Cargo.toml +++ b/crates/swc_ecma_ast/Cargo.toml @@ -15,6 +15,9 @@ version = "15.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] __rkyv = [] default = [] @@ -34,7 +37,6 @@ shrink-to-fit = [ "swc_common/shrink-to-fit", ] - [dependencies] arbitrary = { workspace = true, features = ["derive"], optional = true } bitflags = { workspace = true } diff --git a/crates/swc_ecma_ast/src/class.rs b/crates/swc_ecma_ast/src/class.rs index b14aa3ed870b..86daf8b68230 100644 --- a/crates/swc_ecma_ast/src/class.rs +++ b/crates/swc_ecma_ast/src/class.rs @@ -271,6 +271,7 @@ pub struct Decorator { #[cfg_attr(feature = "rkyv-impl", repr(u32))] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum MethodKind { #[default] #[cfg_attr(feature = "serde-impl", serde(rename = "method"))] diff --git a/crates/swc_ecma_ast/src/decl.rs b/crates/swc_ecma_ast/src/decl.rs index 69fdaf7d589b..40282c8cec7d 100644 --- a/crates/swc_ecma_ast/src/decl.rs +++ b/crates/swc_ecma_ast/src/decl.rs @@ -179,6 +179,7 @@ impl Take for VarDecl { #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum VarDeclKind { /// `var` #[default] diff --git a/crates/swc_ecma_ast/src/expr.rs b/crates/swc_ecma_ast/src/expr.rs index af7d6c2f5b05..e87bcdc188a4 100644 --- a/crates/swc_ecma_ast/src/expr.rs +++ b/crates/swc_ecma_ast/src/expr.rs @@ -1116,6 +1116,7 @@ pub struct MetaPropExpr { #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum MetaPropKind { /// `new.target` NewTarget, diff --git a/crates/swc_ecma_ast/src/module_decl.rs b/crates/swc_ecma_ast/src/module_decl.rs index f3ec54af99dd..a8a03e4499a4 100644 --- a/crates/swc_ecma_ast/src/module_decl.rs +++ b/crates/swc_ecma_ast/src/module_decl.rs @@ -146,6 +146,7 @@ pub struct ImportDecl { #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum ImportPhase { #[default] #[cfg_attr(feature = "serde-impl", serde(rename = "evaluation"))] diff --git a/crates/swc_ecma_ast/src/operators.rs b/crates/swc_ecma_ast/src/operators.rs index 89160a819240..eb1c7bad272d 100644 --- a/crates/swc_ecma_ast/src/operators.rs +++ b/crates/swc_ecma_ast/src/operators.rs @@ -10,6 +10,7 @@ use swc_common::EqIgnoreSpan; )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum BinaryOp { /// `==` #[default] @@ -123,6 +124,7 @@ impl BinaryOp { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum AssignOp { /// `=` #[default] @@ -200,6 +202,7 @@ impl AssignOp { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum UpdateOp { /// `++` #[default] @@ -217,6 +220,7 @@ pub enum UpdateOp { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum UnaryOp { /// `-` Minus, diff --git a/crates/swc_ecma_ast/src/typescript.rs b/crates/swc_ecma_ast/src/typescript.rs index 0fb25f40c096..fc983b812ac8 100644 --- a/crates/swc_ecma_ast/src/typescript.rs +++ b/crates/swc_ecma_ast/src/typescript.rs @@ -410,6 +410,7 @@ pub struct TsKeywordType { #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum TsKeywordTypeKind { #[cfg_attr(feature = "serde-impl", serde(rename = "any"))] TsAnyKeyword, @@ -729,6 +730,7 @@ pub struct TsTypeOperator { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum TsTypeOperatorOp { /// `keyof` KeyOf, @@ -759,6 +761,7 @@ pub struct TsIndexedAccessType { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum TruePlusMinus { True, Plus, @@ -1162,6 +1165,7 @@ pub struct TsSatisfiesExpr { #[cfg_attr(feature = "rkyv-impl", repr(u32))] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum Accessibility { #[cfg_attr(feature = "serde-impl", serde(rename = "public"))] Public, diff --git a/crates/swc_ecma_codegen/Cargo.toml b/crates/swc_ecma_codegen/Cargo.toml index f5ba510e83c2..54e68fbed5bb 100644 --- a/crates/swc_ecma_codegen/Cargo.toml +++ b/crates/swc_ecma_codegen/Cargo.toml @@ -13,6 +13,9 @@ version = "17.0.2" # This does not enable serde for ast nodes. serde-impl = ["swc_ecma_ast/serde"] +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [lib] bench = false diff --git a/crates/swc_ecma_codegen/src/class.rs b/crates/swc_ecma_codegen/src/class.rs index 58607f1529d2..6547c3a01105 100644 --- a/crates/swc_ecma_codegen/src/class.rs +++ b/crates/swc_ecma_codegen/src/class.rs @@ -2,6 +2,8 @@ use swc_common::{SourceMapper, Spanned}; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; use crate::{ text_writer::WriteJs, util::StartsWithAlphaNum, Emitter, ListFormat, Result, SourceMapperExt, }; @@ -146,6 +148,8 @@ impl MacroNode for ClassMember { ClassMember::Empty(ref n) => emit!(n), ClassMember::StaticBlock(ref n) => emit!(n), ClassMember::AutoAccessor(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -207,6 +211,8 @@ impl MacroNode for Key { match self { Key::Private(n) => emit!(n), Key::Public(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -248,6 +254,8 @@ impl MacroNode for PrivateMethod { emit!(self.key); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } emitter.emit_fn_trailing(&self.function)?; @@ -286,6 +294,8 @@ impl MacroNode for ClassMethod { } MethodKind::Getter => true, MethodKind::Setter => true, + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), }; if starts_with_alpha_num { @@ -339,6 +349,8 @@ impl MacroNode for ClassMethod { emit!(self.key); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } if self.is_optional { @@ -563,6 +575,8 @@ where Accessibility::Public => keyword!(self, "public"), Accessibility::Protected => keyword!(self, "protected"), Accessibility::Private => keyword!(self, "private"), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } space!(self); } diff --git a/crates/swc_ecma_codegen/src/decl.rs b/crates/swc_ecma_codegen/src/decl.rs index f88406756206..e30fa8471df3 100644 --- a/crates/swc_ecma_codegen/src/decl.rs +++ b/crates/swc_ecma_codegen/src/decl.rs @@ -4,6 +4,8 @@ use swc_ecma_codegen_macros::node_impl; use super::{Emitter, Result}; use crate::text_writer::WriteJs; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; impl Emitter<'_, W, S> where @@ -98,6 +100,8 @@ impl MacroNode for Decl { Decl::TsInterface(n) => emit!(n), Decl::TsModule(n) => emit!(n), Decl::TsTypeAlias(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/jsx.rs b/crates/swc_ecma_codegen/src/jsx.rs index 420dd443bf9e..9e9bf76c38ea 100644 --- a/crates/swc_ecma_codegen/src/jsx.rs +++ b/crates/swc_ecma_codegen/src/jsx.rs @@ -4,6 +4,8 @@ use swc_ecma_codegen_macros::node_impl; use super::Emitter; use crate::text_writer::WriteJs; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; impl Emitter<'_, W, S> where @@ -63,6 +65,8 @@ impl MacroNode for JSXElementName { JSXElementName::Ident(ref n) => emit!(n), JSXElementName::JSXMemberExpr(ref n) => emit!(n), JSXElementName::JSXNamespacedName(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -89,6 +93,8 @@ impl MacroNode for JSXAttrValue { JSXAttrValue::JSXExprContainer(ref n) => emit!(n), JSXAttrValue::JSXElement(ref n) => emit!(n), JSXAttrValue::JSXFragment(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -100,6 +106,8 @@ impl MacroNode for JSXAttrName { match *self { JSXAttrName::Ident(ref n) => emit!(n), JSXAttrName::JSXNamespacedName(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -115,6 +123,8 @@ impl MacroNode for JSXAttrOrSpread { emit!(n); punct!(emitter, "}"); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -129,6 +139,8 @@ impl MacroNode for JSXElementChild { JSXElementChild::JSXFragment(ref n) => emit!(n), JSXElementChild::JSXSpreadChild(ref n) => emit!(n), JSXElementChild::JSXText(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -162,6 +174,8 @@ impl MacroNode for JSXExpr { match *self { JSXExpr::Expr(ref n) => emit!(n), JSXExpr::JSXEmptyExpr(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -250,6 +264,8 @@ impl MacroNode for JSXObject { match *self { JSXObject::Ident(ref n) => emit!(n), JSXObject::JSXMemberExpr(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 3e599c0706f0..aae7558fd7b8 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -794,6 +794,8 @@ where Callee::Super(callee) => span_has_leading_comment(cmt, callee.span), Callee::Import(callee) => span_has_leading_comment(cmt, callee.span), Callee::Expr(callee) => self.has_leading_comment(callee), + #[cfg(swc_ast_unknown)] + _ => false, }; if has_leading { @@ -847,7 +849,11 @@ where AssignTargetPat::Array(a) => span_has_leading_comment(cmt, a.span), AssignTargetPat::Object(o) => span_has_leading_comment(cmt, o.span), AssignTargetPat::Invalid(..) => false, + #[cfg(swc_ast_unknown)] + _ => false, }, + #[cfg(swc_ast_unknown)] + _ => false, }; if has_leading { @@ -866,6 +872,8 @@ where return true; } } + #[cfg(swc_ast_unknown)] + _ => (), }, _ => {} @@ -1409,6 +1417,8 @@ impl MacroNode for Program { match self { Program::Module(m) => emit!(m), Program::Script(s) => emit!(s), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), // TODO: reenable once experimental_metadata breaking change is merged // _ => unreachable!(), } @@ -1480,6 +1490,8 @@ impl MacroNode for ModuleItem { match self { ModuleItem::Stmt(stmt) => emit!(stmt), ModuleItem::ModuleDecl(decl) => emit!(decl), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } emitter.emit_trailing_comments_of_pos(self.span().hi, true, true)?; @@ -1500,6 +1512,8 @@ impl MacroNode for Callee { } Callee::Super(n) => emit!(n), Callee::Import(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -1581,6 +1595,8 @@ impl MacroNode for Expr { Expr::TsSatisfies(n) => { emit!(n) } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } if emitter.comments.is_some() { @@ -1613,6 +1629,8 @@ impl MacroNode for OptChainExpr { MemberProp::Computed(computed) => emit!(computed), MemberProp::Ident(i) => emit!(i), MemberProp::PrivateName(p) => emit!(p), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } } OptChainBase::Call(e) => { @@ -1631,6 +1649,8 @@ impl MacroNode for OptChainExpr { )?; punct!(emitter, ")"); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -1735,6 +1755,8 @@ impl MacroNode for MemberExpr { punct!(emitter, "."); emit!(private); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } srcmap!(emitter, self, false); @@ -1761,6 +1783,8 @@ impl MacroNode for SuperPropExpr { punct!(emitter, "."); emit!(i); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -1836,6 +1860,9 @@ impl MacroNode for MetaPropExpr { MetaPropKind::ImportMeta => keyword!(emitter, "import.meta"), MetaPropKind::NewTarget => keyword!(emitter, "new.target"), + + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -2002,6 +2029,8 @@ impl MacroNode for BlockStmtOrExpr { emit!(expr); emitter.wr.decrease_indent()?; } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -2132,6 +2161,8 @@ impl MacroNode for UnaryExpr { punct!(emitter, self.op.as_str()); false } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), }; if should_emit_whitespace_before_operand(self) { @@ -2327,3 +2358,11 @@ impl MacroNode for IdentName { Ok(()) } } + +#[cfg(swc_ast_unknown)] +fn unknown_error() -> io::Error { + io::Error::new( + io::ErrorKind::Unsupported, + "emit unknown variant is not supported", + ) +} diff --git a/crates/swc_ecma_codegen/src/lit.rs b/crates/swc_ecma_codegen/src/lit.rs index 1ebe6497faf6..9f9f5d81b974 100644 --- a/crates/swc_ecma_codegen/src/lit.rs +++ b/crates/swc_ecma_codegen/src/lit.rs @@ -6,6 +6,8 @@ use swc_common::{Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; use crate::{text_writer::WriteJs, CowStr, Emitter, SourceMapperExt}; #[node_impl] @@ -34,6 +36,8 @@ impl MacroNode for Lit { emitter.wr.write_str(&n.flags)?; } Lit::JSXText(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/module_decls.rs b/crates/swc_ecma_codegen/src/module_decls.rs index 5fc63e4d71e6..49ce14bffaae 100644 --- a/crates/swc_ecma_codegen/src/module_decls.rs +++ b/crates/swc_ecma_codegen/src/module_decls.rs @@ -2,6 +2,8 @@ use swc_common::Spanned; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; use crate::{util::StartsWithAlphaNum, ListFormat}; #[node_impl] @@ -19,6 +21,8 @@ impl MacroNode for ModuleDecl { ModuleDecl::TsExportAssignment(ref n) => emit!(n), ModuleDecl::TsImportEquals(ref n) => emit!(n), ModuleDecl::TsNamespaceExport(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } emitter.emit_trailing_comments_of_pos(self.span().hi, true, true)?; @@ -101,6 +105,8 @@ impl MacroNode for ExportDefaultDecl { DefaultDecl::Class(ref n) => emit!(n), DefaultDecl::Fn(ref n) => emit!(n), DefaultDecl::TsInterfaceDecl(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -131,6 +137,8 @@ impl MacroNode for ImportDecl { space!(emitter); keyword!(emitter, "defer"); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } let starts_with_ident = !self.specifiers.is_empty() @@ -171,6 +179,8 @@ impl MacroNode for ImportDecl { space!(emitter); emit!(ns.local); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } } @@ -254,6 +264,8 @@ impl MacroNode for ExportSpecifier { } ExportSpecifier::Namespace(ref node) => emit!(node), ExportSpecifier::Named(ref node) => emit!(node), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/object.rs b/crates/swc_ecma_codegen/src/object.rs index c329826a5cec..9e6200eae0a3 100644 --- a/crates/swc_ecma_codegen/src/object.rs +++ b/crates/swc_ecma_codegen/src/object.rs @@ -2,6 +2,8 @@ use swc_common::{Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; use crate::{is_empty_comments, ListFormat}; #[node_impl] @@ -50,6 +52,8 @@ impl MacroNode for Prop { Prop::Getter(ref n) => emit!(n), Prop::Setter(ref n) => emit!(n), Prop::Method(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -227,6 +231,8 @@ impl MacroNode for PropName { PropName::Num(ref n) => emit!(n), PropName::BigInt(ref n) => emit!(n), PropName::Computed(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/pat.rs b/crates/swc_ecma_codegen/src/pat.rs index 5e2165e1c9b1..2c5bc283b188 100644 --- a/crates/swc_ecma_codegen/src/pat.rs +++ b/crates/swc_ecma_codegen/src/pat.rs @@ -2,6 +2,9 @@ use swc_common::Spanned; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; + #[node_impl] impl MacroNode for Param { fn emit(&mut self, emitter: &mut Macro) -> Result { @@ -30,6 +33,8 @@ impl MacroNode for Pat { Pat::Object(ref n) => emit!(n), Pat::Rest(ref n) => emit!(n), Pat::Invalid(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } if emitter.comments.is_some() { @@ -64,6 +69,8 @@ impl MacroNode for PropOrSpread { match self { PropOrSpread::Prop(ref n) => emit!(n), PropOrSpread::Spread(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -94,6 +101,8 @@ impl MacroNode for AssignTarget { match self { AssignTarget::Simple(ref n) => emit!(n), AssignTarget::Pat(ref n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -115,6 +124,8 @@ impl MacroNode for SimpleAssignTarget { SimpleAssignTarget::TsSatisfies(n) => emit!(n), SimpleAssignTarget::TsTypeAssertion(n) => emit!(n), SimpleAssignTarget::TsInstantiation(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -128,6 +139,8 @@ impl MacroNode for AssignTargetPat { AssignTargetPat::Array(n) => emit!(n), AssignTargetPat::Object(n) => emit!(n), AssignTargetPat::Invalid(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -225,6 +238,8 @@ impl MacroNode for ObjectPatProp { ObjectPatProp::KeyValue(ref node) => emit!(node), ObjectPatProp::Assign(ref node) => emit!(node), ObjectPatProp::Rest(ref node) => emit!(node), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -277,6 +292,8 @@ impl MacroNode for ForHead { ForHead::Pat(n) => emit!(n), ForHead::VarDecl(n) => emit!(n), ForHead::UsingDecl(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/stmt.rs b/crates/swc_ecma_codegen/src/stmt.rs index 9f28b5f1fb7d..189f45dfa8db 100644 --- a/crates/swc_ecma_codegen/src/stmt.rs +++ b/crates/swc_ecma_codegen/src/stmt.rs @@ -2,6 +2,8 @@ use swc_common::Spanned; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; use crate::util::{EndsWithAlphaNum, StartsWithAlphaNum}; #[node_impl] @@ -38,6 +40,8 @@ impl MacroNode for Stmt { semi!(emitter); } Stmt::Decl(ref e) => emit!(e), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } if emitter.comments.is_some() { emitter.emit_trailing_comments_of_pos(self.span().hi(), true, true)?; @@ -582,6 +586,8 @@ impl MacroNode for ModuleExportName { match self { ModuleExportName::Ident(ident) => emit!(ident), ModuleExportName::Str(s) => emit!(s), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -594,6 +600,8 @@ impl MacroNode for VarDeclOrExpr { match self { VarDeclOrExpr::Expr(node) => emit!(node), VarDeclOrExpr::VarDecl(node) => emit!(node), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/typescript.rs b/crates/swc_ecma_codegen/src/typescript.rs index 39757b7f87e4..bc7cbb59be61 100644 --- a/crates/swc_ecma_codegen/src/typescript.rs +++ b/crates/swc_ecma_codegen/src/typescript.rs @@ -2,12 +2,17 @@ use swc_common::Spanned; use swc_ecma_ast::*; use swc_ecma_codegen_macros::node_impl; +#[cfg(swc_ast_unknown)] +use crate::unknown_error; + #[node_impl] impl MacroNode for ParamOrTsParamProp { fn emit(&mut self, emitter: &mut Macro) -> Result { match self { ParamOrTsParamProp::Param(n) => emit!(n), ParamOrTsParamProp::TsParamProp(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) @@ -170,6 +175,8 @@ impl MacroNode for TsEntityName { emit!(n); } TsEntityName::Ident(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -228,6 +235,8 @@ impl MacroNode for TsEnumMemberId { match self { TsEnumMemberId::Ident(n) => emit!(n), TsEnumMemberId::Str(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -280,6 +289,8 @@ impl MacroNode for TsFnOrConstructorType { match self { TsFnOrConstructorType::TsFnType(n) => emit!(n), TsFnOrConstructorType::TsConstructorType(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -293,6 +304,8 @@ impl MacroNode for TsFnParam { TsFnParam::Array(n) => emit!(n), TsFnParam::Rest(n) => emit!(n), TsFnParam::Object(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -485,6 +498,8 @@ impl MacroNode for TsKeywordType { TsKeywordTypeKind::TsNullKeyword => keyword!(emitter, self.span, "null"), TsKeywordTypeKind::TsNeverKeyword => keyword!(emitter, self.span, "never"), TsKeywordTypeKind::TsIntrinsicKeyword => keyword!(emitter, self.span, "intrinsic"), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -499,6 +514,8 @@ impl MacroNode for TsLit { TsLit::Str(n) => emit!(n), TsLit::Bool(n) => emit!(n), TsLit::Tpl(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -562,6 +579,8 @@ impl MacroNode for TsMappedType { keyword!(emitter, "readonly"); space!(emitter); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), }, } @@ -606,6 +625,8 @@ impl MacroNode for TsMappedType { punct!(emitter, "-"); punct!(emitter, "?"); } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), }, } @@ -689,6 +710,8 @@ impl MacroNode for TsModuleDecl { // deprecate the module keyword in this context TsModuleName::Ident(_) => keyword!(emitter, "namespace"), TsModuleName::Str(_) => keyword!(emitter, "module"), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } space!(emitter); emit!(self.id); @@ -713,6 +736,8 @@ impl MacroNode for TsModuleName { match self { TsModuleName::Ident(n) => emit!(n), TsModuleName::Str(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -726,6 +751,8 @@ impl MacroNode for TsModuleRef { match self { TsModuleRef::TsEntityName(n) => emit!(n), TsModuleRef::TsExternalModuleRef(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -741,6 +768,8 @@ impl MacroNode for TsNamespaceBody { match self { TsNamespaceBody::TsModuleBlock(n) => emit!(n), TsNamespaceBody::TsNamespaceDecl(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } emitter.wr.decrease_indent()?; punct!(emitter, "}"); @@ -816,6 +845,8 @@ impl MacroNode for TsParamProp { Accessibility::Public => keyword!(emitter, "public"), Accessibility::Protected => keyword!(emitter, "protected"), Accessibility::Private => keyword!(emitter, "private"), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } space!(emitter); } @@ -843,6 +874,8 @@ impl MacroNode for TsParamPropParam { match self { TsParamPropParam::Ident(n) => emit!(n), TsParamPropParam::Assign(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -932,6 +965,8 @@ impl MacroNode for TsThisTypeOrIdent { match self { TsThisTypeOrIdent::TsThisType(n) => emit!(n), TsThisTypeOrIdent::Ident(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -993,6 +1028,8 @@ impl MacroNode for TsType { TsType::TsLitType(n) => emit!(n), TsType::TsTypePredicate(n) => emit!(n), TsType::TsImportType(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -1130,6 +1167,8 @@ impl MacroNode for TsTypeElement { TsTypeElement::TsSetterSignature(n) => { emit!(n) } + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } formatting_semi!(emitter); Ok(()) @@ -1209,6 +1248,8 @@ impl MacroNode for TsTypeOperator { TsTypeOperatorOp::KeyOf => keyword!(emitter, "keyof"), TsTypeOperatorOp::Unique => keyword!(emitter, "unique"), TsTypeOperatorOp::ReadOnly => keyword!(emitter, "readonly"), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } space!(emitter); emit!(self.type_ann); @@ -1323,6 +1364,8 @@ impl MacroNode for TsTypeQueryExpr { match self { TsTypeQueryExpr::TsEntityName(n) => emit!(n), TsTypeQueryExpr::Import(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } @@ -1350,6 +1393,8 @@ impl MacroNode for TsUnionOrIntersectionType { match self { TsUnionOrIntersectionType::TsUnionType(n) => emit!(n), TsUnionOrIntersectionType::TsIntersectionType(n) => emit!(n), + #[cfg(swc_ast_unknown)] + _ => return Err(unknown_error()), } Ok(()) } diff --git a/crates/swc_ecma_codegen/src/util.rs b/crates/swc_ecma_codegen/src/util.rs index 9ee6ad134f3b..7c742f67c03f 100644 --- a/crates/swc_ecma_codegen/src/util.rs +++ b/crates/swc_ecma_codegen/src/util.rs @@ -10,6 +10,8 @@ impl EndsWithAlphaNum for ForHead { ForHead::VarDecl(n) => n.ends_with_alpha_num(), ForHead::Pat(n) => n.ends_with_alpha_num(), ForHead::UsingDecl(n) => n.ends_with_alpha_num(), + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -72,6 +74,8 @@ impl EndsWithAlphaNum for Expr { Expr::OptChain(n) => match n.base.as_ref() { OptChainBase::Member(base) => !base.prop.is_computed(), OptChainBase::Call(_) => false, + #[cfg(swc_ast_unknown)] + _ => false, }, Expr::Bin(n) => n.right.ends_with_alpha_num(), @@ -99,6 +103,8 @@ macro_rules! alpha_num_enum { $( Self::$name(ref n) => n.starts_with_alpha_num(), )* + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -162,6 +168,8 @@ impl StartsWithAlphaNum for PropName { match self { PropName::Str(_) | PropName::Computed(_) => false, PropName::Ident(_) | PropName::Num(_) | PropName::BigInt(_) => true, + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -246,6 +254,8 @@ impl StartsWithAlphaNum for Expr { Expr::OptChain(e) => e.starts_with_alpha_num(), Expr::Invalid(..) => true, + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -255,6 +265,8 @@ impl StartsWithAlphaNum for OptChainExpr { match &*self.base { OptChainBase::Member(base) => base.obj.starts_with_alpha_num(), OptChainBase::Call(base) => base.callee.starts_with_alpha_num(), + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -267,6 +279,8 @@ impl StartsWithAlphaNum for Pat { Pat::Object(..) | Pat::Array(..) | Pat::Rest(..) => false, Pat::Expr(ref expr) => expr.starts_with_alpha_num(), Pat::Invalid(..) => true, + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -308,6 +322,8 @@ impl StartsWithAlphaNum for Callee { match *self { Callee::Super(_) | Callee::Import(_) => true, Callee::Expr(ref e) => e.starts_with_alpha_num(), + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -332,6 +348,8 @@ impl StartsWithAlphaNum for Stmt { | Stmt::ForOf(..) | Stmt::If(..) => true, Stmt::Block(..) | Stmt::Empty(..) => false, + #[cfg(swc_ast_unknown)] + _ => false, } } } @@ -347,6 +365,8 @@ impl StartsWithAlphaNum for Decl { | Decl::TsModule(..) | Decl::TsTypeAlias(..) | Decl::Using(..) => true, + #[cfg(swc_ast_unknown)] + _ => false, } } } diff --git a/crates/swc_ecma_compat_common/src/macros.rs b/crates/swc_ecma_compat_common/src/macros.rs index 2bf89c9a602a..749968c62e41 100644 --- a/crates/swc_ecma_compat_common/src/macros.rs +++ b/crates/swc_ecma_compat_common/src/macros.rs @@ -44,6 +44,7 @@ macro_rules! impl_visit_mut_fn { })], ..Default::default() }, + _ => panic!("unable to access unknown nodes"), }, ); diff --git a/crates/swc_ecma_compat_es2015/Cargo.toml b/crates/swc_ecma_compat_es2015/Cargo.toml index ff0d4072cf19..1f2dd41d58d7 100644 --- a/crates/swc_ecma_compat_es2015/Cargo.toml +++ b/crates/swc_ecma_compat_es2015/Cargo.toml @@ -12,6 +12,9 @@ version = "29.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] arrayvec = { workspace = true } indexmap = { workspace = true } diff --git a/crates/swc_ecma_compat_es2015/src/arrow.rs b/crates/swc_ecma_compat_es2015/src/arrow.rs index 208d46738632..a5bcfd1c5d70 100644 --- a/crates/swc_ecma_compat_es2015/src/arrow.rs +++ b/crates/swc_ecma_compat_es2015/src/arrow.rs @@ -158,6 +158,8 @@ impl VisitMut for Arrow { })], ..Default::default() }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }), ..Default::default() } diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index e6b35370283f..d0410f961543 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -700,6 +700,8 @@ impl VisitMut for FlowHelper<'_> { self.check(id); } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } n.visit_mut_children_with(self); diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs index 12f7b0e124d8..7b5357c6145e 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/vars.rs @@ -252,6 +252,8 @@ impl VisitMut for BlockScopedVars { BlockStmtOrExpr::Expr(b) => { b.visit_mut_with(v); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } }); } diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs index f61a92c14876..677f7c821b02 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs @@ -520,6 +520,9 @@ impl Classes { | ClassMember::StaticBlock(..) | ClassMember::AutoAccessor(..) => {} ClassMember::Empty(..) => {} + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -632,6 +635,8 @@ impl Classes { } .into(), PropName::Computed(c) => c.expr, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, })) } @@ -657,6 +662,8 @@ impl Classes { .into(), }), PropName::Computed(c) => MemberProp::Computed(c), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -832,6 +839,8 @@ impl Classes { data.set = None; data.method = Some(value) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_compat_es2015/src/classes/prop_name.rs b/crates/swc_ecma_compat_es2015/src/classes/prop_name.rs index 4373cbeb2674..f5d11838a0d9 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/prop_name.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/prop_name.rs @@ -18,6 +18,8 @@ impl From<&PropName> for HashKey { PropName::Num(Number { value, .. }) => HashKey::Str(value.to_string().into()), PropName::BigInt(BigInt { value, .. }) => HashKey::Str(value.to_string().into()), PropName::Computed(expr) => HashKey::Computed(expr.span()), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -36,6 +38,8 @@ pub fn is_pure_prop_name(p: &PropName) -> bool { Expr::Tpl(tpl) => tpl.exprs.is_empty(), _ => false, }, + #[cfg(swc_ast_unknown)] + _ => false, } } diff --git a/crates/swc_ecma_compat_es2015/src/computed_props.rs b/crates/swc_ecma_compat_es2015/src/computed_props.rs index e63e5c9dc3d6..b621892ed940 100644 --- a/crates/swc_ecma_compat_es2015/src/computed_props.rs +++ b/crates/swc_ecma_compat_es2015/src/computed_props.rs @@ -249,8 +249,12 @@ impl VisitMut for ComputedProps { } .into(), ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, PropOrSpread::Spread(..) => unimplemented!("computed spread property"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if !self.c.loose && props_cnt == 1 { @@ -425,6 +429,8 @@ fn prop_name_to_expr(p: PropName, loose: bool) -> (Expr, bool) { PropName::Num(n) => (Lit::Num(n).into(), true), PropName::BigInt(b) => (Lit::BigInt(b).into(), true), PropName::Computed(c) => (*c.expr, true), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_compat_es2015/src/destructuring.rs b/crates/swc_ecma_compat_es2015/src/destructuring.rs index 1200f292a2b3..0f2e7b26cfda 100644 --- a/crates/swc_ecma_compat_es2015/src/destructuring.rs +++ b/crates/swc_ecma_compat_es2015/src/destructuring.rs @@ -124,6 +124,9 @@ macro_rules! impl_for_for_stmt { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; for_stmt.left = left; @@ -420,6 +423,8 @@ impl AssignFolder { "Object rest pattern should be removed by es2018::object_rest_spread \ pass" ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -520,6 +525,8 @@ impl Destructuring { } Pat::Rest(..) | Pat::Expr(..) => params.push(param), Pat::Invalid(..) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1004,6 +1011,8 @@ impl VisitMut for AssignFolder { "object rest pattern should be removed by \ es2018::object_rest_spread pass" ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1018,6 +1027,8 @@ impl VisitMut for AssignFolder { } AssignTargetPat::Invalid(..) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } }; } @@ -1295,6 +1306,8 @@ fn can_be_null(e: &Expr) -> bool { | Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => can_be_null(expr), Expr::Invalid(..) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_compat_es2015/src/for_of.rs b/crates/swc_ecma_compat_es2015/src/for_of.rs index f4eca94ea553..203569fbfb48 100644 --- a/crates/swc_ecma_compat_es2015/src/for_of.rs +++ b/crates/swc_ecma_compat_es2015/src/for_of.rs @@ -185,6 +185,9 @@ impl ForOf { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } let stmt = ForStmt { @@ -286,6 +289,9 @@ impl ForOf { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } // !(_step = _iterator()).done; @@ -377,6 +383,8 @@ impl ForOf { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, ); diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index 924cbba6383c..56171a8a1d04 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -623,6 +623,8 @@ impl VisitMut for Generator { expr: prop.into(), }); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } // [source] } @@ -735,6 +737,8 @@ impl VisitMut for Generator { props.push(CompiledProp::Prop(p)); } }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } props @@ -1271,6 +1275,8 @@ impl Generator { right: p.function.into(), } .into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, CompiledProp::Accessor(getter, setter) => { let key = getter @@ -1704,6 +1710,8 @@ impl Generator { .into(), ); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1830,6 +1838,9 @@ impl Generator { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; self.emit_assignment( variable.try_into().unwrap(), diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index 85b4fea6d3f1..09e3fa4f4f6f 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -150,6 +150,8 @@ impl VisitMut for SuperReplacer { } } Prop::Shorthand(_) | Prop::Assign(_) => (), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -200,6 +202,8 @@ impl SuperReplacer { .into(), SuperProp::Computed(ComputedPropName { expr, .. }) => expr, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -287,6 +291,8 @@ impl SuperReplacer { let op = match op { op!("++") => op!("+="), op!("--") => op!("-="), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; *n = self.super_to_set_call(*super_token, true, prop, op, 1.0.into(), *prefix); } @@ -396,6 +402,8 @@ impl SuperReplacer { let computed = match prop { SuperProp::Ident(_) => false, SuperProp::Computed(_) => true, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let mut prop = self.normalize_computed_expr(prop); match op { diff --git a/crates/swc_ecma_compat_es2015/src/parameters.rs b/crates/swc_ecma_compat_es2015/src/parameters.rs index d781c1d14ef9..f57d92ff3e18 100644 --- a/crates/swc_ecma_compat_es2015/src/parameters.rs +++ b/crates/swc_ecma_compat_es2015/src/parameters.rs @@ -650,6 +650,8 @@ impl VisitMut for Params { })], ..Default::default() }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; self.visit_mut_fn_like(&mut params, &mut body, false); diff --git a/crates/swc_ecma_compat_es2016/Cargo.toml b/crates/swc_ecma_compat_es2016/Cargo.toml index 5ad6dde071e2..3d793ebcc56e 100644 --- a/crates/swc_ecma_compat_es2016/Cargo.toml +++ b/crates/swc_ecma_compat_es2016/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] swc_common = { version = "14.0.4", path = "../swc_common" } swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast" } diff --git a/crates/swc_ecma_compat_es2017/Cargo.toml b/crates/swc_ecma_compat_es2017/Cargo.toml index 72feccef36c3..f38b2dc75b0b 100644 --- a/crates/swc_ecma_compat_es2017/Cargo.toml +++ b/crates/swc_ecma_compat_es2017/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] serde = { workspace = true, features = ["derive"] } tracing = { workspace = true } diff --git a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs index 078954baa35e..6cc0cfdbfd43 100644 --- a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs +++ b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs @@ -207,6 +207,8 @@ impl VisitMut for AsyncToGenerator { .into()], ..Default::default() }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let expr = make_fn_ref(&fn_state, vec![], body); @@ -571,6 +573,9 @@ fn handle_await_for(stmt: &mut Stmt, is_async_generator: bool) { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } for_loop_body.extend(orig_body); diff --git a/crates/swc_ecma_compat_es2018/Cargo.toml b/crates/swc_ecma_compat_es2018/Cargo.toml index 58e67aea7c20..f1b017d4d8e1 100644 --- a/crates/swc_ecma_compat_es2018/Cargo.toml +++ b/crates/swc_ecma_compat_es2018/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] serde = { workspace = true, features = ["derive"] } tracing = { workspace = true } diff --git a/crates/swc_ecma_compat_es2018/src/object_rest.rs b/crates/swc_ecma_compat_es2018/src/object_rest.rs index ca43ed2ddf82..e1f900820168 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest.rs @@ -109,6 +109,9 @@ macro_rules! impl_for_for_stmt { ForHead::UsingDecl(..) => { unreachable!("using declaration must be removed by previous pass") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; for_stmt.left = left; @@ -779,6 +782,8 @@ impl ObjectRest { }), ) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let value = Box::new( @@ -965,6 +970,8 @@ fn excluded_props(props: &[ObjectPatProp]) -> Vec> { }) .as_arg(), PropName::Computed(c) => c.expr.clone().as_arg(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, ObjectPatProp::Assign(AssignPatProp { key, .. }) => Lit::Str(Str { span: key.span, @@ -973,6 +980,8 @@ fn excluded_props(props: &[ObjectPatProp]) -> Vec> { }) .as_arg(), ObjectPatProp::Rest(..) => unreachable!("invalid syntax (multiple rest element)"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .map(Some) .collect() diff --git a/crates/swc_ecma_compat_es2018/src/object_spread.rs b/crates/swc_ecma_compat_es2018/src/object_spread.rs index 5c9403b1952e..65ea9a644288 100644 --- a/crates/swc_ecma_compat_es2018/src/object_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_spread.rs @@ -82,6 +82,8 @@ impl VisitMut for ObjectSpread { buf.push(expr.as_arg()); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_compat_es2019/Cargo.toml b/crates/swc_ecma_compat_es2019/Cargo.toml index f12e59986021..8b970d5aeba1 100644 --- a/crates/swc_ecma_compat_es2019/Cargo.toml +++ b/crates/swc_ecma_compat_es2019/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] tracing = { workspace = true } swc_common = { version = "14.0.4", path = "../swc_common" } diff --git a/crates/swc_ecma_compat_es2020/Cargo.toml b/crates/swc_ecma_compat_es2020/Cargo.toml index e7f260a5b3e8..2da905567e9c 100644 --- a/crates/swc_ecma_compat_es2020/Cargo.toml +++ b/crates/swc_ecma_compat_es2020/Cargo.toml @@ -12,6 +12,9 @@ version = "28.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] serde = { workspace = true, features = ["derive"] } tracing = { workspace = true } diff --git a/crates/swc_ecma_compat_es2021/Cargo.toml b/crates/swc_ecma_compat_es2021/Cargo.toml index cfef9baf72fd..f7a010f284f1 100644 --- a/crates/swc_ecma_compat_es2021/Cargo.toml +++ b/crates/swc_ecma_compat_es2021/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] tracing = { workspace = true } diff --git a/crates/swc_ecma_compat_es2022/Cargo.toml b/crates/swc_ecma_compat_es2022/Cargo.toml index d35e5a0d3b32..357f086bbce0 100644 --- a/crates/swc_ecma_compat_es2022/Cargo.toml +++ b/crates/swc_ecma_compat_es2022/Cargo.toml @@ -12,6 +12,9 @@ version = "28.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] rustc-hash = { workspace = true } tracing = { workspace = true } diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index 25eec4cd9a9d..4ba106ce8af3 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -448,6 +448,8 @@ impl ClassProperties { MethodKind::Getter => kind.has_getter = true, MethodKind::Setter => kind.has_setter = true, MethodKind::Method => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } else { @@ -524,6 +526,9 @@ impl ClassProperties { | ClassMember::AutoAccessor(_) | ClassMember::PrivateProp(_) | ClassMember::StaticBlock(_) => true, + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); for member in class.body { @@ -791,6 +796,8 @@ impl ClassProperties { method.key.name.clone() } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, method.span, SyntaxContext::empty().apply_mark(self.private.cur_mark()), @@ -879,6 +886,8 @@ impl ClassProperties { None } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(extra) = extra_collect { @@ -937,6 +946,9 @@ impl ClassProperties { ClassMember::AutoAccessor(..) => { unreachable!("auto_accessor pass should remove this") } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs b/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs index 510464e6333b..240081e795f6 100644 --- a/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs +++ b/crates/swc_ecma_compat_es2022/src/optional_chaining_impl.rs @@ -217,6 +217,9 @@ impl OptionalChaining { Gathering::Call(c.take().into()) }); } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } match *next { diff --git a/crates/swc_ecma_compat_es3/Cargo.toml b/crates/swc_ecma_compat_es3/Cargo.toml index 70f31b8d2c00..1d03143120d7 100644 --- a/crates/swc_ecma_compat_es3/Cargo.toml +++ b/crates/swc_ecma_compat_es3/Cargo.toml @@ -12,6 +12,9 @@ version = "22.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] tracing = { workspace = true } diff --git a/crates/swc_ecma_compiler/Cargo.toml b/crates/swc_ecma_compiler/Cargo.toml index 2843790ce1f2..3f549fb6739f 100644 --- a/crates/swc_ecma_compiler/Cargo.toml +++ b/crates/swc_ecma_compiler/Cargo.toml @@ -9,6 +9,9 @@ name = "swc_ecma_compiler" repository = { workspace = true } version = "5.0.0" +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] bitflags = { workspace = true } rustc-hash = { workspace = true } diff --git a/crates/swc_ecma_compiler/src/es2020/export_namespace_from.rs b/crates/swc_ecma_compiler/src/es2020/export_namespace_from.rs index 06f08b04b02e..ea6ed58a8f7d 100644 --- a/crates/swc_ecma_compiler/src/es2020/export_namespace_from.rs +++ b/crates/swc_ecma_compiler/src/es2020/export_namespace_from.rs @@ -62,6 +62,8 @@ impl<'a> CompilerImpl<'a> { ExportSpecifier::Default(..) | ExportSpecifier::Named(..) => { origin_specifiers.push(s); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -115,5 +117,7 @@ fn normalize_name(module_export_name: &ModuleExportName) -> &Atom { match module_export_name { ModuleExportName::Ident(Ident { sym: name, .. }) | ModuleExportName::Str(Str { value: name, .. }) => name, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_lexer/Cargo.toml b/crates/swc_ecma_lexer/Cargo.toml index 5f59a2d9d79f..cfdb164df604 100644 --- a/crates/swc_ecma_lexer/Cargo.toml +++ b/crates/swc_ecma_lexer/Cargo.toml @@ -16,6 +16,9 @@ version = "23.0.2" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] # Used for debugging debug = ["tracing-spans"] diff --git a/crates/swc_ecma_lexer/src/common/parser/class_and_fn.rs b/crates/swc_ecma_lexer/src/common/parser/class_and_fn.rs index be2f52dfe7cc..7e4db577a09b 100644 --- a/crates/swc_ecma_lexer/src/common/parser/class_and_fn.rs +++ b/crates/swc_ecma_lexer/src/common/parser/class_and_fn.rs @@ -582,6 +582,8 @@ where } .into()) } + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } @@ -817,6 +819,8 @@ fn make_property<'a, P: Parser<'a>>( } .into() } + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }) }) } diff --git a/crates/swc_ecma_lexer/src/common/parser/expr.rs b/crates/swc_ecma_lexer/src/common/parser/expr.rs index 8a74f6fb7899..e26512d5ce74 100644 --- a/crates/swc_ecma_lexer/src/common/parser/expr.rs +++ b/crates/swc_ecma_lexer/src/common/parser/expr.rs @@ -586,6 +586,8 @@ fn parse_subscript<'a, P: Parser<'a>>( ) } Callee::Expr(expr) => expr, + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }; return Ok(( TsNonNullExpr { @@ -808,6 +810,8 @@ fn parse_subscript<'a, P: Parser<'a>>( expr } } + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }), true, )); @@ -853,6 +857,8 @@ fn parse_subscript<'a, P: Parser<'a>>( .into(), true, )), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } else { Ok(( @@ -944,6 +950,8 @@ fn parse_subscript<'a, P: Parser<'a>>( ) } MemberProp::Computed(..) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } } @@ -972,6 +980,8 @@ fn parse_subscript<'a, P: Parser<'a>>( expr } } + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }), true, )); @@ -1013,6 +1023,8 @@ fn parse_subscript<'a, P: Parser<'a>>( Callee::Import(..) => { syntax_error!(p, p.input().cur_span(), SyntaxError::InvalidImport); } + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } @@ -1962,6 +1974,8 @@ fn parse_args_or_pats_inner<'a, P: Parser<'a>>( // creating `Invalid`, we don't have to emit a new // error. } + #[cfg(swc_ast_unknown)] + _ => (), } if p.input_mut().eat(&P::Token::EQUAL) { diff --git a/crates/swc_ecma_lexer/src/common/parser/expr_ext.rs b/crates/swc_ecma_lexer/src/common/parser/expr_ext.rs index 40b3c9c5e09b..aa5e2bd14756 100644 --- a/crates/swc_ecma_lexer/src/common/parser/expr_ext.rs +++ b/crates/swc_ecma_lexer/src/common/parser/expr_ext.rs @@ -74,6 +74,9 @@ pub trait ExprExt { Expr::TsConstAssertion(..) => false, Expr::Invalid(..) => false, + + #[cfg(swc_ast_unknown)] + _ => false, } } } diff --git a/crates/swc_ecma_lexer/src/common/parser/jsx.rs b/crates/swc_ecma_lexer/src/common/parser/jsx.rs index ac01484a1abf..248207d90b7b 100644 --- a/crates/swc_ecma_lexer/src/common/parser/jsx.rs +++ b/crates/swc_ecma_lexer/src/common/parser/jsx.rs @@ -101,6 +101,8 @@ fn parse_jsx_element_name<'a, P: Parser<'a>>(p: &mut P) -> PResult JSXElementName::Ident(i.into()), JSXAttrName::JSXNamespacedName(i) => JSXElementName::JSXNamespacedName(i), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }; while p.input_mut().eat(&P::Token::DOT) { let prop = parse_jsx_ident(p).map(IdentName::from)?; @@ -149,6 +151,8 @@ pub fn jsx_expr_container_to_jsx_attr_value<'a, P: Parser<'a>>( syntax_error!(p, p.span(start), SyntaxError::EmptyJSXAttr) } JSXExpr::Expr(..) => Ok(node.into()), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } diff --git a/crates/swc_ecma_lexer/src/common/parser/module_item.rs b/crates/swc_ecma_lexer/src/common/parser/module_item.rs index 8437bbceffea..cd94241a5c5d 100644 --- a/crates/swc_ecma_lexer/src/common/parser/module_item.rs +++ b/crates/swc_ecma_lexer/src/common/parser/module_item.rs @@ -331,6 +331,9 @@ fn parse_import_specifier<'a, P: Parser<'a>>( ) } } + + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } @@ -685,6 +688,8 @@ fn parse_export<'a, P: Parser<'a>>( let export_name = match &namespace.name { ModuleExportName::Ident(i) => i.sym.clone(), ModuleExportName::Str(s) => s.value.clone(), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }; p.emit_err(namespace.span, SyntaxError::ExportExpectFrom(export_name)); } @@ -697,6 +702,8 @@ fn parse_export<'a, P: Parser<'a>>( } _ => {} }, + #[cfg(swc_ast_unknown)] + _ => (), } } diff --git a/crates/swc_ecma_lexer/src/common/parser/pat.rs b/crates/swc_ecma_lexer/src/common/parser/pat.rs index c99ee929d652..66d97a3538c4 100644 --- a/crates/swc_ecma_lexer/src/common/parser/pat.rs +++ b/crates/swc_ecma_lexer/src/common/parser/pat.rs @@ -51,11 +51,15 @@ fn pat_is_valid_argument_in_strict<'a>(p: &mut impl Parser<'a>, pat: &Pat) { p.emit_strict_mode_err(key.span, SyntaxError::EvalAndArgumentsInStrict) } } + #[cfg(swc_ast_unknown)] + _ => (), } } } Pat::Assign(a) => pat_is_valid_argument_in_strict(p, &a.left), Pat::Invalid(_) | Pat::Expr(_) => (), + #[cfg(swc_ast_unknown)] + _ => (), } } @@ -175,6 +179,8 @@ fn reparse_expr_as_pat_inner<'a>( Box::new(reparse_expr_as_pat(p, pat_ty, left.into())?) } AssignTarget::Pat(pat) => pat.into(), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }, right, } @@ -250,6 +256,9 @@ fn reparse_expr_as_pat_inner<'a>( type_ann: None, })) } + + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } }) .collect::>()?, diff --git a/crates/swc_ecma_lexer/src/common/parser/stmt.rs b/crates/swc_ecma_lexer/src/common/parser/stmt.rs index ba4bcad6ad68..1e92f9858b32 100644 --- a/crates/swc_ecma_lexer/src/common/parser/stmt.rs +++ b/crates/swc_ecma_lexer/src/common/parser/stmt.rs @@ -783,6 +783,8 @@ fn parse_catch_param<'a, P: Parser<'a>>(p: &mut P) -> PResult> { Pat::Assign(..) => {} Pat::Invalid(_) => {} Pat::Expr(_) => {} + #[cfg(swc_ast_unknown)] + _ => {} } } expect!(p, &P::Token::RPAREN); diff --git a/crates/swc_ecma_lexer/src/common/parser/typescript.rs b/crates/swc_ecma_lexer/src/common/parser/typescript.rs index 98cc59d4f64b..6ca9d4bd5656 100644 --- a/crates/swc_ecma_lexer/src/common/parser/typescript.rs +++ b/crates/swc_ecma_lexer/src/common/parser/typescript.rs @@ -1770,6 +1770,8 @@ fn parse_ts_type_operator<'a, P: Parser<'a>>( TsTypeOperatorOp::Unique => expect!(p, &P::Token::UNIQUE), TsTypeOperatorOp::KeyOf => expect!(p, &P::Token::KEYOF), TsTypeOperatorOp::ReadOnly => expect!(p, &P::Token::READONLY), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } let type_ann = parse_ts_type_operator_or_higher(p)?; diff --git a/crates/swc_ecma_lexer/src/common/parser/util.rs b/crates/swc_ecma_lexer/src/common/parser/util.rs index 66a98e871c72..ea2a02856f74 100644 --- a/crates/swc_ecma_lexer/src/common/parser/util.rs +++ b/crates/swc_ecma_lexer/src/common/parser/util.rs @@ -59,6 +59,8 @@ pub fn get_qualified_jsx_name(name: &JSXElementName) -> Atom { member.prop.sym ) .into(), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } match *name { @@ -69,6 +71,8 @@ pub fn get_qualified_jsx_name(name: &JSXElementName) -> Atom { JSXElementName::JSXMemberExpr(JSXMemberExpr { ref obj, ref prop, .. }) => format!("{}.{}", get_qualified_obj_name(obj), prop.sym).into(), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } } @@ -83,6 +87,8 @@ pub fn make_decl_declare(mut decl: Decl) -> Decl { Decl::TsEnum(ref mut e) => e.declare = true, Decl::TsModule(ref mut m) => m.declare = true, Decl::Using(..) => unreachable!("Using is not a valid declaration for `declare` keyword"), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), } decl } diff --git a/crates/swc_ecma_lexer/src/parser/mod.rs b/crates/swc_ecma_lexer/src/parser/mod.rs index a8eafa497232..51481a5f1eab 100644 --- a/crates/swc_ecma_lexer/src/parser/mod.rs +++ b/crates/swc_ecma_lexer/src/parser/mod.rs @@ -251,6 +251,8 @@ impl> Parser { above" ), ModuleItem::Stmt(stmt) => stmt, + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }) .collect(); Program::Script(Script { diff --git a/crates/swc_ecma_lints/Cargo.toml b/crates/swc_ecma_lints/Cargo.toml index 49fc253fc28b..57793e717f63 100644 --- a/crates/swc_ecma_lints/Cargo.toml +++ b/crates/swc_ecma_lints/Cargo.toml @@ -12,6 +12,9 @@ version = "22.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] auto_impl = { workspace = true } dashmap = { workspace = true } @@ -42,7 +45,6 @@ testing = { version = "15.0.0", path = "../testing" } [features] non_critical_lints = [] - [[bench]] harness = false name = "all" diff --git a/crates/swc_ecma_lints/src/rules/critical_rules.rs b/crates/swc_ecma_lints/src/rules/critical_rules.rs index 5abea66d21f6..5f3430551a91 100644 --- a/crates/swc_ecma_lints/src/rules/critical_rules.rs +++ b/crates/swc_ecma_lints/src/rules/critical_rules.rs @@ -628,6 +628,8 @@ impl Visit for CriticalRules { let orig = match &s.orig { ModuleExportName::Ident(ident) => ident, ModuleExportName::Str(..) => return, + #[cfg(swc_ast_unknown)] + _ => return, }; self.add_export(exported.as_ref().unwrap_or(&orig)); } @@ -636,6 +638,8 @@ impl Visit for CriticalRules { match &s.name { ModuleExportName::Ident(name) => self.add_export(name), ModuleExportName::Str(..) => {} + #[cfg(swc_ast_unknown)] + _ => (), }; } @@ -689,6 +693,8 @@ impl Visit for ConstCollector<'_> { | ImportSpecifier::Namespace(ImportStarAsSpecifier { local, .. }) => { self.import_binding.insert(local.to_id(), local.span); } + #[cfg(swc_ast_unknown)] + _ => (), } } diff --git a/crates/swc_ecma_lints/src/rules/mod.rs b/crates/swc_ecma_lints/src/rules/mod.rs index 8ecf067f6aef..e1292d106f0a 100644 --- a/crates/swc_ecma_lints/src/rules/mod.rs +++ b/crates/swc_ecma_lints/src/rules/mod.rs @@ -231,6 +231,8 @@ where match program { Program::Module(m) => self.0.lint_module(m), Program::Script(s) => self.0.lint_script(s), + #[cfg(swc_ast_unknown)] + _ => (), } } } diff --git a/crates/swc_ecma_minifier/Cargo.toml b/crates/swc_ecma_minifier/Cargo.toml index 9975e090d897..62bb32338472 100644 --- a/crates/swc_ecma_minifier/Cargo.toml +++ b/crates/swc_ecma_minifier/Cargo.toml @@ -16,6 +16,9 @@ version = "33.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] # This enables global concurrent mode concurrent = [ diff --git a/crates/swc_ecma_minifier/src/compress/optimize/evaluate.rs b/crates/swc_ecma_minifier/src/compress/optimize/evaluate.rs index 0e98eaf0d6ff..6764c6245219 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/evaluate.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/evaluate.rs @@ -380,6 +380,8 @@ impl Optimizer<'_> { }, _ => return, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs index 661d38e40081..3ae5cac8fcca 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs @@ -35,6 +35,8 @@ impl Optimizer<'_> { let callee = match &mut expr.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Expr::Fn(..) = callee { @@ -66,6 +68,8 @@ impl Optimizer<'_> { let callee = match &mut test_call.callee { Callee::Super(_) | Callee::Import(_) => return false, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match callee { @@ -153,6 +157,8 @@ impl Optimizer<'_> { let callee = match &mut e.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(scope) = find_scope(self.data, callee) { @@ -328,6 +334,8 @@ impl Optimizer<'_> { let callee = match &mut e.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match find_body(callee) { @@ -441,6 +449,8 @@ impl Optimizer<'_> { let callee = match &call.callee { Callee::Super(_) | Callee::Import(_) => return false, Callee::Expr(e) => &**e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if self.ctx.bit_ctx.contains(BitCtx::DontInvokeIife) { @@ -560,6 +570,8 @@ impl Optimizer<'_> { let callee = match &mut call.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match callee { @@ -627,6 +639,8 @@ impl Optimizer<'_> { *e = *Expr::from_exprs(exprs); e.visit_mut_with(self); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } Expr::Fn(f) => { @@ -691,6 +705,8 @@ impl Optimizer<'_> { let callee = match &mut call.callee { Callee::Super(_) | Callee::Import(_) => return None, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match callee { @@ -709,6 +725,8 @@ impl Optimizer<'_> { call.span, ) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } Expr::Fn(f) => { @@ -1311,6 +1329,8 @@ impl Optimizer<'_> { } _ => return false, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1360,6 +1380,8 @@ fn find_body(callee: &mut Expr) -> Option> { Expr::Arrow(e) => match &mut *e.body { BlockStmtOrExpr::BlockStmt(b) => Some(Either::Left(b)), BlockStmtOrExpr::Expr(b) => Some(Either::Right(&mut **b)), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, Expr::Fn(e) => Some(Either::Left(e.function.body.as_mut().unwrap())), _ => None, @@ -1453,6 +1475,8 @@ impl Visit for DeclVisitor { Decl::Var(var_decl) => var_decl.decls.len(), Decl::Using(using_decl) => using_decl.decls.len(), Decl::TsInterface(_) | Decl::TsTypeAlias(_) | Decl::TsEnum(_) | Decl::TsModule(_) => 0, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs index 710a70a5be5a..6273a5e28c9c 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs @@ -978,6 +978,8 @@ fn is_arrow_simple_enough_for_copy(e: &ArrowExpr) -> Option { match &*e.body { BlockStmtOrExpr::BlockStmt(s) => is_block_stmt_of_fn_simple_enough_for_copy(s), BlockStmtOrExpr::Expr(e) => is_arrow_body_simple_enough_for_copy(e), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/loops.rs b/crates/swc_ecma_minifier/src/compress/optimize/loops.rs index c11009082176..4ec242fa0da4 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/loops.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/loops.rs @@ -34,6 +34,8 @@ impl Optimizer<'_> { expr, } .into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } })); self.prepend_stmts.extend(f.test.take().map(|expr| { @@ -94,6 +96,8 @@ impl Optimizer<'_> { expr, } .into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } })); self.prepend_stmts.push( diff --git a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs index 4b703a403763..ea52199abfa4 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs @@ -802,6 +802,8 @@ impl Optimizer<'_> { Expr::Arrow(f) => match &*f.body { BlockStmtOrExpr::BlockStmt(body) => body.stmts.is_empty(), BlockStmtOrExpr::Expr(_) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => false, } && args.is_empty() => @@ -1078,6 +1080,8 @@ impl Optimizer<'_> { ); } PropName::BigInt(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } exprs.extend(self.ignore_return_value(&mut value).map(Box::new)); @@ -1094,6 +1098,8 @@ impl Optimizer<'_> { ); } PropName::BigInt(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, Prop::Assign(mut prop) => { @@ -1103,7 +1109,11 @@ impl Optimizer<'_> { } Prop::Shorthand(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1513,6 +1523,8 @@ impl VisitMut for Optimizer<'_> { ..Default::default() })); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1602,6 +1614,8 @@ impl VisitMut for Optimizer<'_> { self.drop_else_token(&mut n.stmts); } BlockStmtOrExpr::Expr(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1610,6 +1624,8 @@ impl VisitMut for Optimizer<'_> { let is_this_undefined = match &e.callee { Callee::Super(_) | Callee::Import(_) => false, Callee::Expr(e) => e.is_ident(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; { let ctx = self @@ -1622,6 +1638,8 @@ impl VisitMut for Optimizer<'_> { || match &e.callee { Callee::Super(_) | Callee::Import(_) => false, Callee::Expr(callee) => is_callee_this_aware(callee), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, ) .with(BitCtx::IsLhsOfAssign, false) @@ -1762,6 +1780,8 @@ impl VisitMut for Optimizer<'_> { self.drop_unused_params(&mut f.function.params); } DefaultDecl::TsInterfaceDecl(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } n.visit_mut_children_with(self); diff --git a/crates/swc_ecma_minifier/src/compress/optimize/props.rs b/crates/swc_ecma_minifier/src/compress/optimize/props.rs index 67e635a13d65..d8a354d2e9cc 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/props.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/props.rs @@ -82,6 +82,8 @@ impl Optimizer<'_> { let prop = match prop { PropOrSpread::Spread(_) => return None, PropOrSpread::Prop(prop) => prop, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match &**prop { @@ -141,6 +143,8 @@ impl Optimizer<'_> { let prop = match prop { PropOrSpread::Spread(_) => unreachable!(), PropOrSpread::Prop(prop) => prop, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let value = match &mut **prop { @@ -244,6 +248,8 @@ fn is_expr_fine_for_hoist_props(value: &Expr) -> bool { Prop::KeyValue(p) => is_expr_fine_for_hoist_props(&p.value), _ => false, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }), _ => false, @@ -292,7 +298,11 @@ impl Optimizer<'_> { Prop::Getter(p) => prop_name_eq(&p.key, &key.sym), Prop::Setter(p) => prop_name_eq(&p.key, &key.sym), Prop::Method(p) => prop_name_eq(&p.key, &key.sym), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .count() != 1; @@ -322,7 +332,11 @@ impl Optimizer<'_> { Prop::Getter(p) => p.key.is_computed(), Prop::Setter(p) => p.key.is_computed(), Prop::Method(p) => p.key.is_computed(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) { log_abort!("Property accesses should not be inlined to preserve side effects"); return; @@ -348,7 +362,11 @@ impl Optimizer<'_> { Prop::Getter(_) => {} Prop::Setter(_) => {} Prop::Method(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs index 83a2ab135615..07eb4dffd03d 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs @@ -1015,6 +1015,8 @@ impl Optimizer<'_> { return false; } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1022,6 +1024,8 @@ impl Optimizer<'_> { } Pat::Assign(..) => false, Pat::Expr(e) => self.is_skippable_for_seq(a, e), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1304,6 +1308,8 @@ impl Optimizer<'_> { return false; } }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1419,6 +1425,8 @@ impl Optimizer<'_> { false } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, Expr::Invalid(_) => true, @@ -1434,6 +1442,9 @@ impl Optimizer<'_> { | Expr::TsAs(_) | Expr::TsInstantiation(_) | Expr::TsSatisfies(_) => false, + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1968,6 +1979,8 @@ impl Optimizer<'_> { Prop::Getter(prop) => prop.key.as_mut_computed(), Prop::Setter(prop) => prop.key.as_mut_computed(), Prop::Method(prop) => prop.key.as_mut_computed(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(computed) = computed { @@ -2013,6 +2026,8 @@ impl Optimizer<'_> { _ => {} } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_minifier/src/compress/optimize/unused.rs b/crates/swc_ecma_minifier/src/compress/optimize/unused.rs index 3e4de5a3f7cd..0f4fb1eec544 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/unused.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/unused.rs @@ -302,7 +302,11 @@ impl Optimizer<'_> { Prop::Setter(_) => true, Prop::Method(_) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); } @@ -448,6 +452,8 @@ impl Optimizer<'_> { } } ObjectPatProp::Rest(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } true @@ -604,6 +610,9 @@ impl Optimizer<'_> { Decl::TsInterface(_) | Decl::TsTypeAlias(_) | Decl::TsEnum(_) | Decl::TsModule(_) => { // Nothing to do. We might change this to unreachable!() } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -894,7 +903,11 @@ impl Optimizer<'_> { Prop::Getter(p) => p.key.is_computed(), Prop::Setter(p) => p.key.is_computed(), Prop::Method(p) => p.key.is_computed(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) { return None; } @@ -921,6 +934,8 @@ impl Optimizer<'_> { let prop = match prop { PropOrSpread::Spread(_) => return None, PropOrSpread::Prop(prop) => prop, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match &**prop { @@ -1016,6 +1031,8 @@ impl Optimizer<'_> { PropName::Num(..) => true, PropName::Computed(..) => true, PropName::BigInt(..) => true, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let len = obj.props.len(); @@ -1032,7 +1049,11 @@ impl Optimizer<'_> { Prop::Getter(p) => should_preserve(&p.key), Prop::Setter(p) => should_preserve(&p.key), Prop::Method(p) => should_preserve(&p.key), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); if obj.props.len() != len { diff --git a/crates/swc_ecma_minifier/src/compress/optimize/util.rs b/crates/swc_ecma_minifier/src/compress/optimize/util.rs index 7d2d1f0d3614..fc231fc13dc7 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/util.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/util.rs @@ -805,11 +805,15 @@ pub fn get_ids_of_pat(pat: &Pat) -> Vec { ids.push(assign_pat_prop.key.to_id()) } ObjectPatProp::Rest(rest_pat) => append(&rest_pat.arg, ids), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } Pat::Assign(assign_pat) => append(&assign_pat.left, ids), Pat::Invalid(_) | Pat::Expr(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_minifier/src/compress/pure/arrows.rs b/crates/swc_ecma_minifier/src/compress/pure/arrows.rs index 5b6f22b2e79d..de43003d1feb 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/arrows.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/arrows.rs @@ -56,6 +56,8 @@ impl Pure<'_> { } } BlockStmtOrExpr::Expr(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs b/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs index afb961fe2203..b046b84b8eea 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs @@ -210,6 +210,8 @@ impl Pure<'_> { let callee = match &mut call.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Expr::Member(MemberExpr { @@ -367,6 +369,8 @@ impl Pure<'_> { let callee = match &mut call.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(e) => &mut **e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Expr::Member(MemberExpr { @@ -443,6 +447,8 @@ impl Pure<'_> { } } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -734,6 +740,8 @@ impl Pure<'_> { *e = *Expr::undefined(*span); } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -840,6 +848,8 @@ impl Pure<'_> { }, _ => return, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let new_val = match &*method { diff --git a/crates/swc_ecma_minifier/src/compress/pure/member_expr.rs b/crates/swc_ecma_minifier/src/compress/pure/member_expr.rs index 365ea5843632..85fe377e6eb1 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/member_expr.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/member_expr.rs @@ -216,6 +216,9 @@ fn does_key_exist(key: &str, props: &Vec) -> Option { return Some(true); } } + + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => { diff --git a/crates/swc_ecma_minifier/src/compress/pure/misc.rs b/crates/swc_ecma_minifier/src/compress/pure/misc.rs index e6df994f8148..19d67023fcd8 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/misc.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/misc.rs @@ -188,6 +188,8 @@ impl Pure<'_> { BinaryOp::NullishCoalescing => { op!("??=") } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; e.op = op; @@ -278,6 +280,8 @@ impl Pure<'_> { } _ => false, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -458,6 +462,8 @@ impl Pure<'_> { let callee = match &mut call.callee { Callee::Super(_) | Callee::Import(_) => return, Callee::Expr(callee) => &mut **callee, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let separator = if call.args.is_empty() { @@ -2029,6 +2035,8 @@ impl Pure<'_> { _ => {} }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -2143,6 +2151,8 @@ impl Pure<'_> { return; } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => {} } @@ -2290,6 +2300,8 @@ impl Pure<'_> { Prop::Getter(..) | Prop::Setter(..) => false, _ => true, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) { let mut exprs = collect_exprs_from_object(object); exprs.push(prop.expr.take()); diff --git a/crates/swc_ecma_minifier/src/compress/pure/mod.rs b/crates/swc_ecma_minifier/src/compress/pure/mod.rs index a7cf4ebd8703..7f043c39e884 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/mod.rs @@ -259,6 +259,8 @@ impl VisitMut for Pure<'_> { match body { BlockStmtOrExpr::BlockStmt(b) => self.optimize_fn_stmts(&mut b.stmts), BlockStmtOrExpr::Expr(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } self.optimize_arrow_body(body); diff --git a/crates/swc_ecma_minifier/src/compress/pure/unsafes.rs b/crates/swc_ecma_minifier/src/compress/pure/unsafes.rs index ccdf412c2102..1e16acb90217 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/unsafes.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/unsafes.rs @@ -16,6 +16,8 @@ impl Pure<'_> { Expr::Ident(Ident { sym, .. }) if &**sym == "Symbol" => {} _ => return, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } e.args diff --git a/crates/swc_ecma_minifier/src/program_data.rs b/crates/swc_ecma_minifier/src/program_data.rs index fe64a935de58..724c12838653 100644 --- a/crates/swc_ecma_minifier/src/program_data.rs +++ b/crates/swc_ecma_minifier/src/program_data.rs @@ -695,6 +695,8 @@ impl ProgramData { self.simple_assign_target_contains_unresolved(left) } AssignTarget::Pat(_) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) || self.contains_unresolved(right) } Expr::Cond(CondExpr { @@ -770,6 +772,8 @@ impl ProgramData { false } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -808,6 +812,8 @@ impl ProgramData { | SimpleAssignTarget::TsTypeAssertion(..) | SimpleAssignTarget::TsInstantiation(..) => false, SimpleAssignTarget::Invalid(..) => true, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_minifier/src/util/mod.rs b/crates/swc_ecma_minifier/src/util/mod.rs index fa88ae849a90..363697add5cf 100644 --- a/crates/swc_ecma_minifier/src/util/mod.rs +++ b/crates/swc_ecma_minifier/src/util/mod.rs @@ -66,6 +66,8 @@ impl ModuleItemExt for ModuleItem { match self { ModuleItem::ModuleDecl(v) => Ok(v), ModuleItem::Stmt(v) => Err(v), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -73,6 +75,8 @@ impl ModuleItemExt for ModuleItem { match self { ModuleItem::ModuleDecl(v) => Ok(v), ModuleItem::Stmt(v) => Err(v), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -84,6 +88,8 @@ impl ModuleItemExt for ModuleItem { match self { ModuleItem::ModuleDecl(v) => Ok(v), ModuleItem::Stmt(v) => Err(v), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_minifier/src/util/size.rs b/crates/swc_ecma_minifier/src/util/size.rs index 8bd68491c181..e34cb21659ff 100644 --- a/crates/swc_ecma_minifier/src/util/size.rs +++ b/crates/swc_ecma_minifier/src/util/size.rs @@ -18,6 +18,8 @@ impl Size for Lit { Lit::BigInt(i) => i.value.size(), Lit::Regex(r) => r.exp.len(), Lit::JSXText(s) => s.value.len(), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -30,6 +32,8 @@ impl Size for UnaryOp { TypeOf => 7, Void => 5, Delete => 7, + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -50,6 +54,8 @@ impl Size for BinaryOp { In => 4, InstanceOf => 12, + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -169,6 +175,8 @@ impl SizeWithCtxt for Expr { p + a + 2 + e.size(unresolved) } + #[cfg(swc_ast_unknown)] + _ => TODO, }, Expr::Fn(_) => TODO, Expr::Class(_) => TODO, @@ -176,6 +184,8 @@ impl SizeWithCtxt for Expr { Expr::MetaProp(m) => match m.kind { MetaPropKind::NewTarget => 10, MetaPropKind::ImportMeta => 11, + #[cfg(swc_ast_unknown)] + _ => TODO, }, Expr::PrivateName(p) => p.size(), Expr::OptChain(p) => match &*p.base { @@ -183,6 +193,8 @@ impl SizeWithCtxt for Expr { OptChainBase::Call(c) => { 1 + c.callee.size(unresolved) + c.args.size(unresolved) + 2 } + #[cfg(swc_ast_unknown)] + _ => TODO, }, Expr::Paren(p) => 2 + p.expr.size(unresolved), @@ -199,6 +211,8 @@ impl SizeWithCtxt for Expr { Expr::TsAs(_) => TODO, Expr::TsInstantiation(_) => TODO, Expr::TsSatisfies(_) => TODO, + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -219,6 +233,8 @@ impl SizeWithCtxt for Callee { Callee::Super(_) => 5, Callee::Import(_) => 6, Callee::Expr(e) => e.size(unresolved), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -243,6 +259,8 @@ impl SizeWithCtxt for MemberProp { MemberProp::Ident(id) => 1 + id.sym.len(), MemberProp::PrivateName(priv_name) => 1 + priv_name.size(), MemberProp::Computed(c) => 2 + c.expr.size(unresolved), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -252,6 +270,8 @@ impl SizeWithCtxt for SuperProp { match self { SuperProp::Ident(id) => 1 + id.sym.len(), SuperProp::Computed(c) => 2 + c.expr.size(unresolved), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -266,6 +286,8 @@ impl SizeWithCtxt for Pat { Pat::Assign(a) => a.left.size(unresolved) + 1 + a.right.size(unresolved), Pat::Invalid(_) => 0, Pat::Expr(e) => e.size(unresolved), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -275,6 +297,8 @@ impl SizeWithCtxt for AssignTarget { match self { AssignTarget::Simple(e) => e.size(unresolved), AssignTarget::Pat(p) => p.size(unresolved), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -297,6 +321,8 @@ impl SizeWithCtxt for SimpleAssignTarget { OptChainBase::Call(c) => { 1 + c.callee.size(unresolved) + c.args.size(unresolved) + 2 } + #[cfg(swc_ast_unknown)] + _ => TODO, }, SimpleAssignTarget::TsAs(_) | SimpleAssignTarget::TsSatisfies(_) @@ -304,6 +330,8 @@ impl SizeWithCtxt for SimpleAssignTarget { | SimpleAssignTarget::TsTypeAssertion(_) | SimpleAssignTarget::TsInstantiation(_) | SimpleAssignTarget::Invalid(_) => TODO, + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -314,6 +342,8 @@ impl SizeWithCtxt for AssignTargetPat { AssignTargetPat::Array(a) => 2 + a.elems.size(unresolved), AssignTargetPat::Object(o) => 2 + o.props.size(unresolved), AssignTargetPat::Invalid(_) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -326,6 +356,8 @@ impl SizeWithCtxt for PropName { PropName::Num(n) => n.value.size(), PropName::Computed(c) => 2 + c.expr.size(unresolved), PropName::BigInt(n) => n.value.size(), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -338,6 +370,8 @@ impl SizeWithCtxt for ObjectPatProp { a.key.sym.len() + a.value.as_ref().map_or(0, |v| v.size(unresolved) + 1) } ObjectPatProp::Rest(r) => 3 + r.arg.size(unresolved), + #[cfg(swc_ast_unknown)] + _ => TODO, } } } @@ -356,7 +390,11 @@ impl SizeWithCtxt for PropOrSpread { Prop::Getter(_) => TODO, Prop::Setter(_) => TODO, Prop::Method(_) => TODO, + #[cfg(swc_ast_unknown)] + _ => TODO, }, + #[cfg(swc_ast_unknown)] + _ => TODO, } } } diff --git a/crates/swc_ecma_parser/Cargo.toml b/crates/swc_ecma_parser/Cargo.toml index 31806ab5898d..41413bad83f8 100644 --- a/crates/swc_ecma_parser/Cargo.toml +++ b/crates/swc_ecma_parser/Cargo.toml @@ -16,6 +16,9 @@ version = "24.0.2" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] # Used for debugging debug = ["tracing-spans"] diff --git a/crates/swc_ecma_parser/src/parser/jsx/mod.rs b/crates/swc_ecma_parser/src/parser/jsx/mod.rs index a8faa76a8fe5..a9248fa435ff 100644 --- a/crates/swc_ecma_parser/src/parser/jsx/mod.rs +++ b/crates/swc_ecma_parser/src/parser/jsx/mod.rs @@ -82,6 +82,8 @@ impl Parser { let mut node = match self.parse_jsx_tag_name()? { JSXAttrName::Ident(i) => JSXElementName::Ident(i.into()), JSXAttrName::JSXNamespacedName(i) => JSXElementName::JSXNamespacedName(i), + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }; while self.input_mut().eat(&Token::Dot) { self.input_mut().scan_jsx_identifier(); diff --git a/crates/swc_ecma_parser/src/parser/mod.rs b/crates/swc_ecma_parser/src/parser/mod.rs index 8d0ae6b29893..576799159269 100644 --- a/crates/swc_ecma_parser/src/parser/mod.rs +++ b/crates/swc_ecma_parser/src/parser/mod.rs @@ -295,6 +295,8 @@ impl Parser { .map(|item| match item { ModuleItem::ModuleDecl(_) => unreachable!("Module is handled above"), ModuleItem::Stmt(stmt) => stmt, + #[cfg(swc_ast_unknown)] + _ => unreachable!(), }) .collect(); Program::Script(Script { diff --git a/crates/swc_ecma_quote/Cargo.toml b/crates/swc_ecma_quote/Cargo.toml index 11755d2839b7..3645ea16e077 100644 --- a/crates/swc_ecma_quote/Cargo.toml +++ b/crates/swc_ecma_quote/Cargo.toml @@ -11,6 +11,9 @@ version = "24.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] swc_common = { version = "14.0.4", path = "../swc_common" } swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast" } diff --git a/crates/swc_ecma_quote_macros/Cargo.toml b/crates/swc_ecma_quote_macros/Cargo.toml index 8816fce0f77f..390336b1ad24 100644 --- a/crates/swc_ecma_quote_macros/Cargo.toml +++ b/crates/swc_ecma_quote_macros/Cargo.toml @@ -12,6 +12,9 @@ version = "24.0.0" bench = false proc-macro = true +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] anyhow = { workspace = true } proc-macro2 = { workspace = true } diff --git a/crates/swc_ecma_quote_macros/src/ast/enums.rs b/crates/swc_ecma_quote_macros/src/ast/enums.rs index a04ce8421802..e2d5ff48b97f 100644 --- a/crates/swc_ecma_quote_macros/src/ast/enums.rs +++ b/crates/swc_ecma_quote_macros/src/ast/enums.rs @@ -11,6 +11,8 @@ macro_rules! impl_simple_enum { swc_core::ecma::ast::$E::$v ), )* + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_quote_macros/src/ast/mod.rs b/crates/swc_ecma_quote_macros/src/ast/mod.rs index 08d68bdd0a37..28d5b162388d 100644 --- a/crates/swc_ecma_quote_macros/src/ast/mod.rs +++ b/crates/swc_ecma_quote_macros/src/ast/mod.rs @@ -25,6 +25,8 @@ macro_rules! impl_enum_body { ) }, )* + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } }; } diff --git a/crates/swc_ecma_regexp_ast/src/lib.rs b/crates/swc_ecma_regexp_ast/src/lib.rs index df083f2936d9..42c2cef25497 100644 --- a/crates/swc_ecma_regexp_ast/src/lib.rs +++ b/crates/swc_ecma_regexp_ast/src/lib.rs @@ -30,7 +30,7 @@ pub struct Alternative { } /// Single unit of [`Alternative`], containing various kinds. -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, EqIgnoreSpan, Is)] pub enum Term { // Assertion @@ -219,7 +219,7 @@ pub enum CharacterClassContentsKind { Subtraction = 2, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, EqIgnoreSpan, Is)] pub enum CharacterClassContents { #[tag("CharacterClassRange")] diff --git a/crates/swc_ecma_transforms/Cargo.toml b/crates/swc_ecma_transforms/Cargo.toml index 4dd3ba64f557..af5c834557af 100644 --- a/crates/swc_ecma_transforms/Cargo.toml +++ b/crates/swc_ecma_transforms/Cargo.toml @@ -16,6 +16,9 @@ version = "34.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] compat = ["swc_ecma_transforms_compat"] concurrent = [ diff --git a/crates/swc_ecma_transforms_base/Cargo.toml b/crates/swc_ecma_transforms_base/Cargo.toml index 3e268e2bfd88..fa397ab82767 100644 --- a/crates/swc_ecma_transforms_base/Cargo.toml +++ b/crates/swc_ecma_transforms_base/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] concurrent = ["concurrent-renamer", "par-iter", "swc_ecma_utils/concurrent"] concurrent-renamer = ["par-iter"] diff --git a/crates/swc_ecma_transforms_base/src/ext.rs b/crates/swc_ecma_transforms_base/src/ext.rs index ac705ef8c156..549e1df636d9 100644 --- a/crates/swc_ecma_transforms_base/src/ext.rs +++ b/crates/swc_ecma_transforms_base/src/ext.rs @@ -27,6 +27,8 @@ impl AsOptExpr for Callee { match self { Callee::Super(_) | Callee::Import(_) => None, Callee::Expr(e) => Some(e), + #[cfg(swc_ast_unknown)] + _ => None, } } @@ -34,6 +36,8 @@ impl AsOptExpr for Callee { match self { Callee::Super(_) | Callee::Import(_) => None, Callee::Expr(e) => Some(e), + #[cfg(swc_ast_unknown)] + _ => None, } } } diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs index 8418785ced4f..ce428bb4b757 100644 --- a/crates/swc_ecma_transforms_base/src/fixer.rs +++ b/crates/swc_ecma_transforms_base/src/fixer.rs @@ -156,6 +156,8 @@ impl VisitMut for Fixer<'_> { let lhs_expr = match &mut expr.left { AssignTarget::Simple(e) => Some(e), AssignTarget::Pat(..) => None, + #[cfg(swc_ast_unknown)] + _ => None, }; if let Some(e) = lhs_expr @@ -203,6 +205,8 @@ impl VisitMut for Fixer<'_> { })); } } + #[cfg(swc_ast_unknown)] + _ => (), } } diff --git a/crates/swc_ecma_transforms_base/src/rename/analyer_and_collector.rs b/crates/swc_ecma_transforms_base/src/rename/analyer_and_collector.rs index f45075fac9d3..cf04f4c24bfa 100644 --- a/crates/swc_ecma_transforms_base/src/rename/analyer_and_collector.rs +++ b/crates/swc_ecma_transforms_base/src/rename/analyer_and_collector.rs @@ -100,6 +100,8 @@ impl Visit for AnalyzerAndCollector { match node.body.as_ref() { BlockStmtOrExpr::BlockStmt(n) => n.visit_children_with(self), BlockStmtOrExpr::Expr(n) => n.visit_with(self), + #[cfg(swc_ast_unknown)] + _ => (), } self.analyzer.is_pat_decl = old_analyzer_is_pat_decl; @@ -229,6 +231,8 @@ impl Visit for AnalyzerAndCollector { f.visit_with(self); } DefaultDecl::TsInterfaceDecl(_) => {} + #[cfg(swc_ast_unknown)] + _ => {} } } diff --git a/crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs b/crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs index dc42882d8bf2..904f1c0b34b9 100644 --- a/crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/analyzer/mod.rs @@ -167,6 +167,8 @@ impl Analyzer { self.add_usage(orig.to_id()); } ModuleExportName::Str(..) => {} + #[cfg(swc_ast_unknown)] + _ => {} }; } diff --git a/crates/swc_ecma_transforms_base/src/rename/mod.rs b/crates/swc_ecma_transforms_base/src/rename/mod.rs index 87fb3e4ece4c..e5618c1af68f 100644 --- a/crates/swc_ecma_transforms_base/src/rename/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/mod.rs @@ -382,6 +382,8 @@ where DefaultDecl::TsInterfaceDecl(n) => { n.visit_mut_children_with(self); } + #[cfg(swc_ast_unknown)] + _ => (), } } diff --git a/crates/swc_ecma_transforms_base/src/rename/ops.rs b/crates/swc_ecma_transforms_base/src/rename/ops.rs index ddecc6e71407..0c0e535b3118 100644 --- a/crates/swc_ecma_transforms_base/src/rename/ops.rs +++ b/crates/swc_ecma_transforms_base/src/rename/ops.rs @@ -168,6 +168,8 @@ where } } ModuleExportName::Str(_) => {} + #[cfg(swc_ast_unknown)] + _ => {} } s.exported = Some(exported); diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 06067f8c9f61..cc82f5a18aab 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -563,6 +563,8 @@ impl VisitMut for Resolver<'_> { child.strict_mode = old_strict_mode; } BlockStmtOrExpr::Expr(e) => e.visit_mut_with(child), + #[cfg(swc_ast_unknown)] + _ => (), } e.return_type.visit_mut_with(child); @@ -710,6 +712,8 @@ impl VisitMut for Resolver<'_> { ParamOrTsParamProp::Param(p) => { p.decorators.visit_mut_with(self); } + #[cfg(swc_ast_unknown)] + _ => (), } } @@ -723,6 +727,8 @@ impl VisitMut for Resolver<'_> { .filter(|p| match p { ParamOrTsParamProp::TsParamProp(_) => false, ParamOrTsParamProp::Param(p) => !p.pat.is_rest(), + #[cfg(swc_ast_unknown)] + _ => false, }) .flat_map(find_pat_ids::<_, Id>); @@ -787,6 +793,8 @@ impl VisitMut for Resolver<'_> { self.try_resolving_as_type(orig); } ModuleExportName::Str(_) => {} + #[cfg(swc_ast_unknown)] + _ => {} } } } @@ -1018,6 +1026,8 @@ impl VisitMut for Resolver<'_> { | ImportSpecifier::Namespace(..) | ImportSpecifier::Default(..) => s.visit_mut_children_with(self), ImportSpecifier::Named(s) => s.local.visit_mut_with(self), + #[cfg(swc_ast_unknown)] + _ => (), } self.ident_type = old; @@ -1253,6 +1263,8 @@ impl VisitMut for Resolver<'_> { let member_names = decl.members.iter().filter_map(|m| match &m.id { TsEnumMemberId::Ident(id) => Some((id.sym.clone(), DeclKind::Lexical)), TsEnumMemberId::Str(_) => None, + #[cfg(swc_ast_unknown)] + _ => None, }); child.current.declared_symbols.extend(member_names); @@ -1384,6 +1396,8 @@ impl VisitMut for Resolver<'_> { self.modify(i, DeclKind::Lexical); } TsModuleName::Str(_) => {} + #[cfg(swc_ast_unknown)] + _ => {} } self.with_child(ScopeKind::Block, |child| { diff --git a/crates/swc_ecma_transforms_base/src/scope.rs b/crates/swc_ecma_transforms_base/src/scope.rs index 0e8ea17fe0a0..d15e2a2d8910 100644 --- a/crates/swc_ecma_transforms_base/src/scope.rs +++ b/crates/swc_ecma_transforms_base/src/scope.rs @@ -29,6 +29,8 @@ impl From for DeclKind { match kind { VarDeclKind::Const | VarDeclKind::Let => Self::Lexical, VarDeclKind::Var => Self::Var, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_transforms_classes/Cargo.toml b/crates/swc_ecma_transforms_classes/Cargo.toml index 66bd7cbf4ef5..e4b60f401b8c 100644 --- a/crates/swc_ecma_transforms_classes/Cargo.toml +++ b/crates/swc_ecma_transforms_classes/Cargo.toml @@ -11,6 +11,9 @@ version = "27.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] swc_common = { version = "14.0.4", path = "../swc_common" } swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast" } diff --git a/crates/swc_ecma_transforms_classes/src/super_field.rs b/crates/swc_ecma_transforms_classes/src/super_field.rs index 5023f9a74e7f..0551f2933b69 100644 --- a/crates/swc_ecma_transforms_classes/src/super_field.rs +++ b/crates/swc_ecma_transforms_classes/src/super_field.rs @@ -323,6 +323,8 @@ impl SuperFieldAccessFolder<'_> { prop: match prop { SuperProp::Ident(i) => MemberProp::Ident(i), SuperProp::Computed(c) => MemberProp::Computed(c), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, } .into() @@ -369,6 +371,8 @@ impl SuperFieldAccessFolder<'_> { prop: match prop { SuperProp::Ident(i) => MemberProp::Ident(i), SuperProp::Computed(c) => MemberProp::Computed(c), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, }; @@ -496,5 +500,7 @@ fn prop_arg(prop: SuperProp) -> Expr { }) .into(), SuperProp::Computed(c) => *c.expr, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_transforms_compat/Cargo.toml b/crates/swc_ecma_transforms_compat/Cargo.toml index 9531a21b20fa..951cf3d1f8bb 100644 --- a/crates/swc_ecma_transforms_compat/Cargo.toml +++ b/crates/swc_ecma_transforms_compat/Cargo.toml @@ -12,6 +12,9 @@ version = "30.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] concurrent = [ "swc_ecma_transforms_base/concurrent", diff --git a/crates/swc_ecma_transforms_module/Cargo.toml b/crates/swc_ecma_transforms_module/Cargo.toml index d6dc9382ef84..00b5777b4144 100644 --- a/crates/swc_ecma_transforms_module/Cargo.toml +++ b/crates/swc_ecma_transforms_module/Cargo.toml @@ -12,6 +12,9 @@ version = "30.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [dependencies] Inflector = { workspace = true } anyhow = { workspace = true } diff --git a/crates/swc_ecma_transforms_module/src/amd.rs b/crates/swc_ecma_transforms_module/src/amd.rs index d1a4de75b58f..018b0a5f8e76 100644 --- a/crates/swc_ecma_transforms_module/src/amd.rs +++ b/crates/swc_ecma_transforms_module/src/amd.rs @@ -298,6 +298,8 @@ where _ => return, }, MemberProp::PrivateName(..) => return, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; self.found_import_meta = true; @@ -324,6 +326,8 @@ where } } MemberProp::PrivateName(..) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } // module.uri.split("/").pop() @@ -348,6 +352,8 @@ where } } MemberProp::PrivateName(..) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } *n = n.take().as_call(n.span(), vec![quote_str!(".").as_arg()]); diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index b244605e2c67..5ae4ab524f74 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -219,6 +219,8 @@ impl VisitMut for Cjs { _ => return, }, MemberProp::PrivateName(..) => return, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match p { diff --git a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs index e52f6202d87b..54cc9c87ae35 100644 --- a/crates/swc_ecma_transforms_module/src/module_decl_strip.rs +++ b/crates/swc_ecma_transforms_module/src/module_decl_strip.rs @@ -79,6 +79,8 @@ impl VisitMut for ModuleDeclStrip { list.extend(fn_expr.as_fn_decl().map(From::from)) } DefaultDecl::TsInterfaceDecl(_) => continue, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, ModuleDecl::ExportDefaultExpr(..) => { list.extend(self.export_default.take().map(From::from)) @@ -87,8 +89,12 @@ impl VisitMut for ModuleDeclStrip { ModuleDecl::TsImportEquals(..) => continue, ModuleDecl::TsExportAssignment(..) => continue, ModuleDecl::TsNamespaceExport(..) => continue, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } @@ -180,6 +186,8 @@ impl VisitMut for ModuleDeclStrip { ModuleExportName::Str(_) => { unreachable!(r#"`export {{ "foo" }}` without src is invalid"#) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(exported) = exported { @@ -190,6 +198,8 @@ impl VisitMut for ModuleDeclStrip { ModuleExportName::Str(Str { span, value, .. }) => { (value, (span, Default::default())) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; (export_name, ExportItem::new(export_name_span, orig)) @@ -200,6 +210,8 @@ impl VisitMut for ModuleDeclStrip { ) } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), })) } } @@ -242,6 +254,8 @@ impl VisitMut for ModuleDeclStrip { ); } DefaultDecl::TsInterfaceDecl(_) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -427,6 +441,8 @@ impl From for LinkSpecifier { let imported = imported.map(|e| match e { ModuleExportName::Ident(Ident { sym, .. }) => sym, ModuleExportName::Str(Str { value, .. }) => value, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); Self::ImportNamed { @@ -471,6 +487,8 @@ impl From for LinkSpecifier { | ModuleExportName::Str(Str { span, value: sym, .. }) => (sym, (span, SyntaxContext::empty().apply_mark(Mark::new()))), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let exported = exported.map(|exported| match exported { @@ -478,6 +496,8 @@ impl From for LinkSpecifier { | ModuleExportName::Str(Str { span, value: sym, .. }) => (sym, (span, SyntaxContext::empty().apply_mark(Mark::new()))), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); match (&*orig.0, orig.1) { diff --git a/crates/swc_ecma_transforms_module/src/system_js.rs b/crates/swc_ecma_transforms_module/src/system_js.rs index 1b4972b2c8ed..043defe2b8e0 100644 --- a/crates/swc_ecma_transforms_module/src/system_js.rs +++ b/crates/swc_ecma_transforms_module/src/system_js.rs @@ -142,6 +142,8 @@ impl SystemJs { _ => assign_expr.into(), } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -705,6 +707,8 @@ impl Fold for SystemJs { .into_stmt(), ); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -765,6 +769,8 @@ impl Fold for SystemJs { export_values .push(quote_ident!(source_alias.clone()).into()); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } self.add_module_item_meta(ModuleItemMeta { @@ -950,6 +956,8 @@ impl Fold for SystemJs { }, _ => execute_stmts.push(stmt), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1129,6 +1137,8 @@ fn get_module_export_name(module_export_name: &ModuleExportName) -> Id { match &module_export_name { ModuleExportName::Ident(ident) => ident.to_id(), ModuleExportName::Str(s) => (s.value.clone(), SyntaxContext::empty()), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1137,6 +1147,8 @@ fn get_module_export_expr(module_export_name: &ModuleExportName) -> Expr { match &module_export_name { ModuleExportName::Ident(ident) => ident.clone().into(), ModuleExportName::Str(s) => Lit::Str(quote_str!(s.value.clone())).into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1148,5 +1160,7 @@ fn get_module_export_member_prop(module_export_name: &ModuleExportName) -> Membe span: s.span, expr: Lit::Str(quote_str!(s.value.clone())).into(), }), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_transforms_optimization/Cargo.toml b/crates/swc_ecma_transforms_optimization/Cargo.toml index 781adf2ea37d..bcecbeefd388 100644 --- a/crates/swc_ecma_transforms_optimization/Cargo.toml +++ b/crates/swc_ecma_transforms_optimization/Cargo.toml @@ -13,6 +13,9 @@ version = "29.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] concurrent = ["swc_common/concurrent", "swc_ecma_transforms_base/concurrent"] debug = [] diff --git a/crates/swc_ecma_transforms_optimization/src/const_modules.rs b/crates/swc_ecma_transforms_optimization/src/const_modules.rs index 6cdc454856a5..07ddbe040fdb 100644 --- a/crates/swc_ecma_transforms_optimization/src/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/src/const_modules.rs @@ -109,6 +109,8 @@ impl VisitMut for ConstModules { .map(|m| match m { ModuleExportName::Ident(id) => &id.sym, ModuleExportName::Str(s) => &s.value, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .unwrap_or(&s.local.sym); let value = entry.get(imported).cloned().unwrap_or_else(|| { @@ -136,6 +138,8 @@ impl VisitMut for ConstModules { }); self.scope.imported.insert(imported.clone(), value); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } @@ -181,6 +185,8 @@ impl VisitMut for ConstModules { _ => return, }, MemberProp::PrivateName(..) => return, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let value = self diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs index cfbd5697bf85..42163d610c9f 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs @@ -1615,6 +1615,8 @@ fn ignore_result(e: Box, drop_str_lit: bool, ctx: ExprCtx) -> Option panic!("unable to access unknown nodes"), }); if props.is_empty() { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs index a9b2a97486c8..ab2f663559d2 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs @@ -48,6 +48,8 @@ impl VisitMut for ConstPropagation<'_> { let id = match &n.orig { ModuleExportName::Ident(ident) => ident.to_id(), ModuleExportName::Str(..) => return, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(expr) = self.scope.find_var(&id) { if let Expr::Ident(v) = &**expr { @@ -68,8 +70,12 @@ impl VisitMut for ConstPropagation<'_> { } } ModuleExportName::Str(..) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, Some(ModuleExportName::Str(..)) => {} + #[cfg(swc_ast_unknown)] + Some(_) => panic!("unable to access unknown nodes"), None => {} } } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index 1315ef7f7ca3..19384b044f54 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -859,6 +859,8 @@ impl VisitMut for TreeShaker { | ClassMember::Empty(_) | ClassMember::Constructor(_) | ClassMember::PrivateMethod(_) => true, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) { debug!("Dropping class `{}` as it's not used", c.ident); @@ -928,6 +930,8 @@ impl VisitMut for TreeShaker { Prop::KeyValue(p) => p.value.is_ident(), _ => false, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) { self.changed = true; debug!("Dropping a wrapped esm"); @@ -947,6 +951,8 @@ impl VisitMut for TreeShaker { if match &a.left { AssignTarget::Simple(l) => l.is_invalid(), AssignTarget::Pat(l) => l.is_invalid(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } { *n = *a.right.take(); } @@ -971,6 +977,8 @@ impl VisitMut for TreeShaker { ForHead::Pat(v) => { v.visit_mut_with(self); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -987,6 +995,8 @@ impl VisitMut for TreeShaker { ImportSpecifier::Named(l) => &l.local, ImportSpecifier::Default(l) => &l.local, ImportSpecifier::Namespace(l) => &l.local, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if self.can_drop_binding(local.to_id(), false) { @@ -1190,6 +1200,8 @@ impl VisitMut for TreeShaker { VarDeclOrExpr::Expr(v) => { v.visit_mut_with(self); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs index fff50a77de56..eeaf05163d78 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs @@ -163,6 +163,8 @@ impl VisitMut for SimplifyExpr { } } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } self.in_callee = false; @@ -330,6 +332,8 @@ impl VisitMut for SimplifyExpr { &**p, Prop::Shorthand(_) | Prop::KeyValue(_) | Prop::Method(_) ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) { ps.push(PropOrSpread::Spread(SpreadElement { dot3_token, @@ -632,6 +636,8 @@ fn get_key_value(key: &str, props: &mut Vec) -> Option> let prop = match prop { PropOrSpread::Prop(x) => &mut **x, PropOrSpread::Spread(_) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match prop { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs index d1692ab94cca..917cc754ee3c 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs @@ -138,6 +138,8 @@ impl VisitMut for Inlining<'_> { AssignTarget::Pat(p) => { p.visit_mut_with(self); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_transforms_proposal/Cargo.toml b/crates/swc_ecma_transforms_proposal/Cargo.toml index cd7e1fe76f43..e401470accd8 100644 --- a/crates/swc_ecma_transforms_proposal/Cargo.toml +++ b/crates/swc_ecma_transforms_proposal/Cargo.toml @@ -12,6 +12,9 @@ version = "27.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] default = [] multi-module = [] diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs index ef8339da53fb..e0424e8242b9 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs @@ -925,12 +925,16 @@ impl VisitMut for DecoratorPass { MethodKind::Method => 7, MethodKind::Setter => 9, MethodKind::Getter => 8, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } else { match p.kind { MethodKind::Method => 2, MethodKind::Setter => 4, MethodKind::Getter => 3, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } .as_arg(), @@ -1014,6 +1018,8 @@ impl VisitMut for DecoratorPass { ..Default::default() }); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -1068,6 +1074,8 @@ impl VisitMut for DecoratorPass { .into(), } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, value: if accessor.decorators.is_empty() { accessor.value @@ -1170,6 +1178,8 @@ impl VisitMut for DecoratorPass { Some(private_ident!(format!("_set_{}", field_name_like))), ), Key::Public(_) => Default::default(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let initialize_init = { @@ -1287,6 +1297,8 @@ impl VisitMut for DecoratorPass { Some(name.as_arg()), ] } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, } .as_arg() @@ -1374,6 +1386,8 @@ impl VisitMut for DecoratorPass { new.push(ClassMember::Method(getter)); new.push(ClassMember::Method(setter)); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } continue; @@ -1448,6 +1462,8 @@ impl VisitMut for DecoratorPass { (false, MethodKind::Setter) => 4, (true, MethodKind::Getter) => 8, (false, MethodKind::Getter) => 3, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } .as_arg(), ), @@ -1630,6 +1646,8 @@ impl VisitMut for DecoratorPass { .position(|module_item| match module_item { ModuleItem::Stmt(stmt) => !is_maybe_branch_directive(stmt), ModuleItem::ModuleDecl(_) => true, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .unwrap_or(0); insert_builder.push_front( diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs index f70cc2050475..c4c948f02b60 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs @@ -39,6 +39,8 @@ impl VisitMut for ParamMetadata { decorators.push(new_dec); } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -170,6 +172,8 @@ impl VisitMut for Metadata<'_> { let ann = match &p.param { TsParamPropParam::Ident(i) => i.type_ann.as_deref(), TsParamPropParam::Assign(a) => get_type_ann_of_pat(&a.left), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; Some(serialize_type(self.class_name, ann).as_arg()) } @@ -177,6 +181,8 @@ impl VisitMut for Metadata<'_> { serialize_type(self.class_name, get_type_ann_of_pat(&p.pat)) .as_arg(), ), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .collect(), } @@ -208,6 +214,8 @@ impl VisitMut for Metadata<'_> { get_type_ann_of_pat(&m.function.params[0].pat), ) .as_arg(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; let dec = self.create_metadata_design_decorator("design:type", type_arg); @@ -542,6 +550,8 @@ fn serialize_type(class_name: Option<&Ident>, param: Option<&TsTypeAnn>) -> Expr TsUnionOrIntersectionType::TsIntersectionType(ty) => { serialize_type_list(class_name, &ty.types) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, TsType::TsConditionalType(ty) => { @@ -575,6 +585,8 @@ fn ts_entity_to_member_expr(type_name: &TsEntityName) -> Expr { .into() } TsEntityName::Ident(i) => i.clone().with_pos(BytePos::DUMMY, BytePos::DUMMY).into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -587,6 +599,8 @@ fn get_type_ann_of_pat(p: &Pat) -> Option<&TsTypeAnn> { Pat::Assign(p) => get_type_ann_of_pat(&p.left), Pat::Invalid(_) => None, Pat::Expr(_) => None, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs index 895dcfcb1566..6f200a351de7 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs @@ -366,6 +366,8 @@ impl Decorators { MethodKind::Method => "method", MethodKind::Getter => "get", MethodKind::Setter => "set", + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } )))), }, diff --git a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs index 489b42da9055..ab92b841e89b 100644 --- a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs +++ b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs @@ -71,6 +71,8 @@ impl VisitMut for ExportDefaultFrom { export_specifiers.push(s); } } + #[cfg(swc_ast_unknown)] + _ => (), } } diff --git a/crates/swc_ecma_transforms_react/Cargo.toml b/crates/swc_ecma_transforms_react/Cargo.toml index 86917f539a08..38155cf94932 100644 --- a/crates/swc_ecma_transforms_react/Cargo.toml +++ b/crates/swc_ecma_transforms_react/Cargo.toml @@ -12,6 +12,9 @@ version = "30.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] concurrent = ["swc_common/concurrent"] default = ["serde-impl"] diff --git a/crates/swc_ecma_transforms_react/src/display_name/mod.rs b/crates/swc_ecma_transforms_react/src/display_name/mod.rs index e631ae335e73..02c18625ee97 100644 --- a/crates/swc_ecma_transforms_react/src/display_name/mod.rs +++ b/crates/swc_ecma_transforms_react/src/display_name/mod.rs @@ -85,20 +85,22 @@ impl VisitMut for DisplayName { prop.visit_mut_children_with(self); if let Prop::KeyValue(KeyValueProp { key, value }) = prop { - value.visit_mut_with(&mut Folder { - name: Some(match key { - PropName::Ident(ref i) => Lit::Str(Str { - span: i.span, - raw: None, - value: i.sym.clone(), - }) - .into(), - PropName::Str(ref s) => Lit::Str(s.clone()).into(), - PropName::Num(ref n) => Lit::Num(n.clone()).into(), - PropName::BigInt(ref b) => Lit::BigInt(b.clone()).into(), - PropName::Computed(ref c) => c.expr.clone(), - }), - }); + let name = match key { + PropName::Ident(ref i) => Lit::Str(Str { + span: i.span, + raw: None, + value: i.sym.clone(), + }) + .into(), + PropName::Str(ref s) => Lit::Str(s.clone()).into(), + PropName::Num(ref n) => Lit::Num(n.clone()).into(), + PropName::BigInt(ref b) => Lit::BigInt(b.clone()).into(), + PropName::Computed(ref c) => c.expr.clone(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), + }; + + value.visit_mut_with(&mut Folder { name: Some(name) }); } } @@ -148,6 +150,8 @@ fn is_create_class_call(call: &CallExpr) -> bool { let callee = match &call.callee { Callee::Super(_) | Callee::Import(_) => return false, Callee::Expr(callee) => &**callee, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; match callee { @@ -198,8 +202,12 @@ fn is_key_display_name(prop: &PropOrSpread) -> bool { PropName::Num(..) => false, PropName::BigInt(..) => false, PropName::Computed(..) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, Prop::Assign(..) => unreachable!("invalid syntax"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => false, // TODO(kdy1): maybe.. handle spread diff --git a/crates/swc_ecma_transforms_react/src/jsx/mod.rs b/crates/swc_ecma_transforms_react/src/jsx/mod.rs index b54cfffad945..cff10525a483 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/mod.rs @@ -798,6 +798,8 @@ where Prop::KeyValue(KeyValueProp { key, value }), ))); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } JSXAttrOrSpread::SpreadElement(attr) => match *attr.expr { @@ -808,6 +810,8 @@ where props_obj.props.push(PropOrSpread::Spread(attr)); } }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -964,6 +968,8 @@ where spread: Some(span), expr, }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) } @@ -989,6 +995,8 @@ where _ => props.push(PropOrSpread::Spread(spread)), } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1026,6 +1034,8 @@ where span: _, expr: JSXExpr::JSXEmptyExpr(_), }) => unreachable!("attr_to_prop(JSXEmptyExpr)"), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .unwrap_or_else(|| { Lit::Bool(Bool { @@ -1337,6 +1347,8 @@ where prop: MemberProp::Ident(e.prop), } .into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) .into() } @@ -1347,6 +1359,8 @@ where } .into() } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -1375,6 +1389,8 @@ fn to_prop_name(n: JSXAttrName) -> PropName { value: value.into(), }) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1495,9 +1511,13 @@ fn jsx_attr_value_to_expr(v: JSXAttrValue) -> Option> { JSXAttrValue::JSXExprContainer(e) => match e.expr { JSXExpr::JSXEmptyExpr(_) => None?, JSXExpr::Expr(e) => e, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, JSXAttrValue::JSXElement(e) => e.into(), JSXAttrValue::JSXFragment(f) => f.into(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }) } diff --git a/crates/swc_ecma_transforms_react/src/jsx/static_check.rs b/crates/swc_ecma_transforms_react/src/jsx/static_check.rs index a1f6221f361a..889ecf67372e 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/static_check.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/static_check.rs @@ -13,6 +13,8 @@ pub(super) fn should_use_create_element(attrs: &[JSXAttrOrSpread]) -> bool { JSXAttrOrSpread::JSXAttr(attr) => match &attr.name { JSXAttrName::Ident(i) => i.sym == "key", JSXAttrName::JSXNamespacedName(_) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => false, } diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs index 98fc33b81143..723cfb75328f 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs @@ -54,6 +54,8 @@ where Some(ModuleExportName::Ident(imported)) => imported.sym.clone(), Some(ModuleExportName::Str(..)) => named.local.sym.clone(), None => named.local.sym.clone(), + #[cfg(swc_ast_unknown)] + Some(_) => continue, }; self.imports.insert(named.local.to_id(), (src, imported)); } @@ -64,6 +66,8 @@ where ImportSpecifier::Namespace(ns) => { self.imports.insert(ns.local.to_id(), (src, atom!("*"))); } + #[cfg(swc_ast_unknown)] + _ => (), } } } diff --git a/crates/swc_ecma_transforms_react/src/refresh/hook.rs b/crates/swc_ecma_transforms_react/src/refresh/hook.rs index b88c89a18b53..4b4a45232e6b 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/hook.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/hook.rs @@ -368,6 +368,8 @@ fn collect_hooks_arrow(body: &mut BlockStmtOrExpr, cm: &SourceMap) -> Option None, } } diff --git a/crates/swc_ecma_transforms_typescript/Cargo.toml b/crates/swc_ecma_transforms_typescript/Cargo.toml index e3d9f337b097..b4d2bdc47047 100644 --- a/crates/swc_ecma_transforms_typescript/Cargo.toml +++ b/crates/swc_ecma_transforms_typescript/Cargo.toml @@ -12,6 +12,9 @@ version = "30.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] concurrent = ["swc_common/concurrent"] diff --git a/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs b/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs index 8912667ca27c..a2ad8165d93c 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_import_export.rs @@ -139,6 +139,8 @@ fn get_module_ident(ts_entity_name: &TsEntityName) -> &Ident { get_module_ident(&ts_qualified_name.left) } TsEntityName::Ident(ident) => ident, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -240,6 +242,8 @@ impl Visit for DeclareCollect { self.id_type.insert(namespace.local.to_id()); } } + #[cfg(swc_ast_unknown)] + _ => (), }); } @@ -341,6 +345,8 @@ impl VisitMut for StripImportExport { self.usage_info.has_usage(&id) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); self.import_not_used_as_values == ImportsNotUsedAsValues::Preserve @@ -368,6 +374,8 @@ impl VisitMut for StripImportExport { ExportSpecifier::Named(ExportNamedSpecifier { is_type_only, .. }) => { !is_type_only } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); !specifiers.is_empty() diff --git a/crates/swc_ecma_transforms_typescript/src/strip_type.rs b/crates/swc_ecma_transforms_typescript/src/strip_type.rs index c0b099278e2e..c7439b481045 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip_type.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip_type.rs @@ -292,6 +292,8 @@ impl IsConcrete for TsNamespaceBody { ts_module_block.body.iter().any(|item| item.is_concrete()) } Self::TsNamespaceDecl(ts_namespace_decl) => ts_namespace_decl.body.is_concrete(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -301,6 +303,8 @@ impl IsConcrete for ModuleItem { match self { Self::ModuleDecl(module_decl) => module_decl.is_concrete(), Self::Stmt(stmt) => stmt.is_concrete(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -317,6 +321,8 @@ impl IsConcrete for ModuleDecl { Self::TsImportEquals(ts_import_equals) => !ts_import_equals.is_type_only, Self::TsExportAssignment(..) => true, Self::TsNamespaceExport(..) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -328,6 +334,8 @@ impl IsConcrete for Decl { Self::Fn(r#fn) => r#fn.function.body.is_some(), Self::Class(..) | Self::Var(..) | Self::Using(..) | Self::TsEnum(..) => true, Self::TsModule(ts_module) => ts_module.is_concrete(), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -338,6 +346,8 @@ impl IsConcrete for DefaultDecl { Self::Class(_) => true, Self::Fn(r#fn) => r#fn.function.body.is_some(), Self::TsInterfaceDecl(..) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -367,6 +377,8 @@ impl IsDeclare for Decl { Decl::TsInterface(_) | Decl::TsTypeAlias(_) => true, Decl::TsEnum(ts_enum) => ts_enum.declare, Decl::TsModule(ts_module) => ts_module.declare || ts_module.global, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index 50f0df8ae21d..630c017be143 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -331,6 +331,8 @@ impl VisitMut for Transform { id, ) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; self.in_class_prop.push(id); @@ -344,6 +346,8 @@ impl VisitMut for Transform { .into(); } ParamOrTsParamProp::Param(..) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); node.params.visit_mut_children_with(self); @@ -863,6 +867,8 @@ impl Transform { return Self::transform_ts_module_block(id, ts_module_block); } TsNamespaceBody::TsNamespaceDecl(ts_namespace_decl) => ts_namespace_decl, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; debug_assert!(!declare); @@ -1017,6 +1023,8 @@ impl Transform { .emit(); }); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } item => { @@ -1187,6 +1195,8 @@ impl Transform { } .into() } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } @@ -1328,6 +1338,8 @@ impl Transform { } } } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(..)) => { @@ -1540,5 +1552,7 @@ fn get_member_key(prop: &MemberProp) -> Option { _ => None, }, MemberProp::PrivateName(_) => None, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index 685f8c36acf3..4cfc340ee715 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -130,6 +130,8 @@ impl EsModuleDecl for ModuleDecl { ModuleDecl::TsImportEquals(..) | ModuleDecl::TsExportAssignment(..) | ModuleDecl::TsNamespaceExport(..) => false, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } } diff --git a/crates/swc_ecma_usage_analyzer/Cargo.toml b/crates/swc_ecma_usage_analyzer/Cargo.toml index 646ead7ae336..f9f726234e63 100644 --- a/crates/swc_ecma_usage_analyzer/Cargo.toml +++ b/crates/swc_ecma_usage_analyzer/Cargo.toml @@ -16,6 +16,9 @@ version = "22.0.1" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] # This enables global concurrent mode concurrent = ["swc_common/concurrent", "indexmap/rayon"] diff --git a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs index ded8e1479ed0..b63e7a6cb90a 100644 --- a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs +++ b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs @@ -255,6 +255,8 @@ where BlockStmtOrExpr::Expr(body) => { body.visit_with(child); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } }) } @@ -297,12 +299,16 @@ where ); self.mark_mutation_if_member(e.as_member()) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if n.op == op!("=") { let left = match &n.left { AssignTarget::Simple(left) => left.leftmost().map(Ident::to_id), AssignTarget::Pat(..) => None, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; if let Some(left) = left { @@ -712,6 +718,8 @@ where v.mark_used_as_ref(); } ModuleExportName::Str(..) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }; } @@ -1562,7 +1570,11 @@ fn for_each_id_ref_in_expr(e: &Expr, op: &mut impl FnMut(&Ident)) { Prop::Method(p) => { for_each_id_ref_in_fn(&p.function, op); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); } _ => {} @@ -1580,6 +1592,8 @@ fn for_each_id_ref_in_class(c: &Class, op: &mut impl FnMut(&Ident)) { ParamOrTsParamProp::Param(p) => { for_each_id_ref_in_pat(&p.pat, op); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); } @@ -1618,6 +1632,8 @@ fn for_each_id_ref_in_class(c: &Class, op: &mut impl FnMut(&Ident)) { ClassMember::Empty(..) | ClassMember::StaticBlock(..) | ClassMember::TsIndexSignature(..) => {} + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); } fn for_each_id_ref_in_prop_name(p: &PropName, op: &mut impl FnMut(&Ident)) { @@ -1655,6 +1671,8 @@ fn for_each_id_ref_in_pat(p: &Pat, op: &mut impl FnMut(&Ident)) { ObjectPatProp::Rest(p) => { for_each_id_ref_in_pat(&p.arg, op); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }); } Pat::Assign(p) => { @@ -1665,6 +1683,8 @@ fn for_each_id_ref_in_pat(p: &Pat, op: &mut impl FnMut(&Ident)) { Pat::Expr(p) => { for_each_id_ref_in_expr(p, op); } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } diff --git a/crates/swc_ecma_utils/Cargo.toml b/crates/swc_ecma_utils/Cargo.toml index 0913c4e66f8b..eaf8ad824d81 100644 --- a/crates/swc_ecma_utils/Cargo.toml +++ b/crates/swc_ecma_utils/Cargo.toml @@ -15,6 +15,9 @@ version = "21.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] # Process in parallel. concurrent = ["swc_common/concurrent", "par-core/parallel"] diff --git a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs index 06157f436ad2..75f863052f27 100644 --- a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs +++ b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs @@ -393,6 +393,8 @@ impl VisitMut for FnEnvHoister { e.visit_mut_children_with(self); return; } + #[cfg(swc_ast_unknown)] + _ => return, }; if !self.super_disabled { if let SimpleAssignTarget::SuperProp(super_prop) = &mut *expr { @@ -463,6 +465,8 @@ impl VisitMut for FnEnvHoister { } .into(); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -508,6 +512,8 @@ impl VisitMut for FnEnvHoister { *e = call.call_fn(*span, new_args); } + #[cfg(swc_ast_unknown)] + _ => (), } }; } @@ -559,6 +565,8 @@ impl VisitMut for FnEnvHoister { .into() }; } + #[cfg(swc_ast_unknown)] + _ => (), }, _ => e.visit_mut_children_with(self), } diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index 2771b746eb82..b9b5808ded42 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -237,6 +237,8 @@ impl StmtOrModuleItem for ModuleItem { match self { ModuleItem::ModuleDecl(v) => Err(v), ModuleItem::Stmt(v) => Ok(v), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -245,6 +247,8 @@ impl StmtOrModuleItem for ModuleItem { match self { ModuleItem::ModuleDecl(v) => Err(v), ModuleItem::Stmt(v) => Ok(v), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -253,6 +257,8 @@ impl StmtOrModuleItem for ModuleItem { match self { ModuleItem::ModuleDecl(v) => Err(v), ModuleItem::Stmt(v) => Ok(v), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1199,6 +1205,8 @@ impl Visit for LiteralVisitor { } PropName::BigInt(_) => self.is_lit = false, PropName::Computed(..) => self.is_lit = false, + #[cfg(swc_ast_unknown)] + _ => (), } } @@ -1260,6 +1268,8 @@ pub fn is_simple_pure_member_expr(m: &MemberExpr, pure_getters: bool) -> bool { MemberProp::Computed(c) => { is_simple_pure_expr(&c.expr, pure_getters) && is_simple_pure_expr(&m.obj, pure_getters) } + #[cfg(swc_ast_unknown)] + _ => false, } } @@ -1423,6 +1433,8 @@ pub fn prop_name_to_expr(p: PropName) -> Expr { PropName::Num(n) => Lit::Num(n).into(), PropName::BigInt(b) => Lit::BigInt(b).into(), PropName::Computed(c) => *c.expr, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } /// Similar to `prop_name_to_expr`, but used for value position. @@ -1440,6 +1452,8 @@ pub fn prop_name_to_expr_value(p: PropName) -> Expr { PropName::Num(n) => Lit::Num(n).into(), PropName::BigInt(b) => Lit::BigInt(b).into(), PropName::Computed(c) => *c.expr, + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1459,6 +1473,8 @@ pub fn prop_name_to_member_prop(prop_name: PropName) -> MemberProp { span: DUMMY_SP, expr: b.into(), }), + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), } } @@ -1930,11 +1946,15 @@ impl ExprCtx { Prop::Assign(..) => { unreachable!("assign property in object literal is not a valid syntax") } + #[cfg(swc_ast_unknown)] + _ => true, }, PropOrSpread::Spread(SpreadElement { .. }) => { has_spread = true; true } + #[cfg(swc_ast_unknown)] + _ => true, }); if has_spread { @@ -1962,6 +1982,8 @@ impl ExprCtx { "assign property in object literal is not a valid syntax" ) } + #[cfg(swc_ast_unknown)] + _ => panic!("unable to access unknown nodes"), }, _ => unreachable!(), }) @@ -2007,6 +2029,8 @@ impl ExprCtx { Expr::OptChain(..) => to.push(Box::new(expr)), Expr::Invalid(..) => unreachable!(), + #[cfg(swc_ast_unknown)] + _ => to.push(Box::new(expr)), } } } @@ -2021,6 +2045,8 @@ pub fn prop_name_eq(p: &PropName, key: &str) -> bool { Expr::Lit(Lit::Str(Str { value, .. })) => *value == *key, _ => false, }, + #[cfg(swc_ast_unknown)] + _ => false, } } @@ -2364,6 +2390,8 @@ impl VisitMut for IdentRenamer<'_> { } } ModuleExportName::Str(_) => {} + #[cfg(swc_ast_unknown)] + _ => {} } } @@ -2515,6 +2543,8 @@ where JSXElementName::Ident(ident) => ident.into(), JSXElementName::JSXMemberExpr(expr) => Box::new(expr).into(), JSXElementName::JSXNamespacedName(..) => unimplemented!(), + #[cfg(swc_ast_unknown)] + _ => return, } } } @@ -2949,6 +2979,8 @@ fn cast_to_bool(expr: &Expr, ctx: ExprCtx) -> (Purity, BoolValue) { Lit::Null(..) => false, Lit::Regex(..) => true, Lit::JSXText(..) => unreachable!("as_bool() for JSXText"), + #[cfg(swc_ast_unknown)] + _ => return (Pure, Unknown), }), ); } @@ -3506,6 +3538,8 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool { }) => true, _ => false, }, + #[cfg(swc_ast_unknown)] + _ => true, }; if obj.props.iter().any(can_have_side_effect) { return true; @@ -3517,6 +3551,8 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool { match prop { MemberProp::Computed(c) => c.expr.may_have_side_effects(ctx), MemberProp::Ident(_) | MemberProp::PrivateName(_) => false, + #[cfg(swc_ast_unknown)] + _ => true, } } @@ -3590,9 +3626,13 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool { _ => false, }, Prop::Assign(_) => true, + #[cfg(swc_ast_unknown)] + _ => true, }, // may trigger getter PropOrSpread::Spread(_) => true, + #[cfg(swc_ast_unknown)] + _ => true, }), Expr::JSXMember(..) @@ -3608,6 +3648,8 @@ fn may_have_side_effects(expr: &Expr, ctx: ExprCtx) -> bool { | Expr::TsSatisfies(TsSatisfiesExpr { ref expr, .. }) => expr.may_have_side_effects(ctx), Expr::Invalid(..) => true, + #[cfg(swc_ast_unknown)] + _ => true, } } diff --git a/crates/swc_ecma_visit/Cargo.toml b/crates/swc_ecma_visit/Cargo.toml index f0757fc8d814..566b5223a8ab 100644 --- a/crates/swc_ecma_visit/Cargo.toml +++ b/crates/swc_ecma_visit/Cargo.toml @@ -15,6 +15,9 @@ version = "15.0.0" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] debug = [] default = [] diff --git a/crates/swc_ecma_visit/src/generated.rs b/crates/swc_ecma_visit/src/generated.rs index ff620835aaa6..dc14a1fe5604 100644 --- a/crates/swc_ecma_visit/src/generated.rs +++ b/crates/swc_ecma_visit/src/generated.rs @@ -9745,6 +9745,8 @@ impl VisitWith for Accessibility { Accessibility::Public => {} Accessibility::Protected => {} Accessibility::Private => {} + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -9888,6 +9890,8 @@ impl VisitWith for AssignOp { AssignOp::AndAssign => {} AssignOp::OrAssign => {} AssignOp::NullishAssign => {} + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -9971,6 +9975,8 @@ impl VisitWith for AssignTarget { AssignTarget::Pat { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -9991,6 +9997,8 @@ impl VisitWith for AssignTargetPat { AssignTargetPat::Invalid { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10140,6 +10148,8 @@ impl VisitWith for BinaryOp { BinaryOp::InstanceOf => {} BinaryOp::Exp => {} BinaryOp::NullishCoalescing => {} + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10198,6 +10208,8 @@ impl VisitWith for BlockStmtOrExpr { BlockStmtOrExpr::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10289,6 +10301,8 @@ impl VisitWith for Callee { Callee::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10441,6 +10455,8 @@ impl VisitWith for ClassMember { ClassMember::AutoAccessor { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10682,6 +10698,8 @@ impl VisitWith for Decl { Decl::TsModule { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10721,6 +10739,8 @@ impl VisitWith for DefaultDecl { DefaultDecl::TsInterfaceDecl { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -10925,6 +10945,8 @@ impl VisitWith for ExportSpecifier { ExportSpecifier::Named { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11050,6 +11072,8 @@ impl VisitWith for Expr { Expr::Invalid { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11150,6 +11174,8 @@ impl VisitWith for ForHead { ForHead::Pat { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11509,6 +11535,8 @@ impl VisitWith for ImportPhase { ImportPhase::Evaluation => {} ImportPhase::Source => {} ImportPhase::Defer => {} + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11529,6 +11557,8 @@ impl VisitWith for ImportSpecifier { ImportSpecifier::Namespace { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11641,6 +11671,8 @@ impl VisitWith for JSXAttrName { JSXAttrName::JSXNamespacedName { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11658,6 +11690,8 @@ impl VisitWith for JSXAttrOrSpread { JSXAttrOrSpread::SpreadElement { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11681,6 +11715,8 @@ impl VisitWith for JSXAttrValue { JSXAttrValue::JSXFragment { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11772,6 +11808,8 @@ impl VisitWith for JSXElementChild { JSXElementChild::JSXFragment { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11792,6 +11830,8 @@ impl VisitWith for JSXElementName { JSXElementName::JSXNamespacedName { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11825,6 +11865,8 @@ impl VisitWith for JSXExpr { JSXExpr::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -11935,6 +11977,8 @@ impl VisitWith for JSXObject { JSXObject::Ident { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12042,6 +12086,8 @@ impl VisitWith for Key { Key::Public { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12134,6 +12180,8 @@ impl VisitWith for Lit { Lit::JSXText { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12176,6 +12224,8 @@ impl VisitWith for MemberProp { MemberProp::Computed { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12208,6 +12258,8 @@ impl VisitWith for MetaPropKind { match self { MetaPropKind::NewTarget => {} MetaPropKind::ImportMeta => {} + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12222,6 +12274,8 @@ impl VisitWith for MethodKind { MethodKind::Method => {} MethodKind::Getter => {} MethodKind::Setter => {} + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12305,6 +12359,8 @@ impl VisitWith for ModuleDecl { ModuleDecl::TsNamespaceExport { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12322,6 +12378,8 @@ impl VisitWith for ModuleExportName { ModuleExportName::Str { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12339,6 +12397,8 @@ impl VisitWith for ModuleItem { ModuleItem::Stmt { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12507,6 +12567,8 @@ impl VisitWith for ObjectPatProp { ObjectPatProp::Rest { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12560,6 +12622,8 @@ impl VisitWith for OptChainBase { OptChainBase::Call { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12626,6 +12690,8 @@ impl VisitWith for ParamOrTsParamProp { ParamOrTsParamProp::Param { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12677,6 +12743,8 @@ impl VisitWith for Pat { Pat::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(swc_ast_unknown)] + _ => (), } } } @@ -12798,6 +12866,8 @@ impl VisitWith for Program { Program::Script { 0: _field_0 } => {