From abd411af1056c60af944b47b47afd913f5845727 Mon Sep 17 00:00:00 2001 From: quininer Date: Mon, 22 Sep 2025 17:18:45 +0800 Subject: [PATCH 01/16] make non_exhaustive --- crates/ast_node/src/lib.rs | 38 +++++++++++--------- crates/swc_css_ast/src/at_rule.rs | 58 +++++++++++++++--------------- crates/swc_css_ast/src/base.rs | 14 ++++---- crates/swc_css_ast/src/selector.rs | 20 +++++------ crates/swc_css_ast/src/value.rs | 32 ++++++++--------- crates/swc_ecma_ast/Cargo.toml | 2 +- crates/swc_ecma_lexer/Cargo.toml | 1 + crates/swc_ecma_parser/Cargo.toml | 1 + 8 files changed, 87 insertions(+), 79 deletions(-) diff --git a/crates/ast_node/src/lib.rs b/crates/ast_node/src/lib.rs index bc58300dc4ea..ce4e6c3d81e0 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(feature = "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/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..d7a8d4d25aed 100644 --- a/crates/swc_ecma_ast/Cargo.toml +++ b/crates/swc_ecma_ast/Cargo.toml @@ -33,7 +33,7 @@ shrink-to-fit = [ "swc_atoms/shrink-to-fit", "swc_common/shrink-to-fit", ] - +unknown = [] [dependencies] arbitrary = { workspace = true, features = ["derive"], optional = true } diff --git a/crates/swc_ecma_lexer/Cargo.toml b/crates/swc_ecma_lexer/Cargo.toml index 5f59a2d9d79f..bc13b9002baf 100644 --- a/crates/swc_ecma_lexer/Cargo.toml +++ b/crates/swc_ecma_lexer/Cargo.toml @@ -23,6 +23,7 @@ default = ["typescript", "stacker"] tracing-spans = [] typescript = [] verify = ["swc_ecma_visit"] +unknown = ["swc_ecma_ast/unknown"] [dependencies] arrayvec = { workspace = true } diff --git a/crates/swc_ecma_parser/Cargo.toml b/crates/swc_ecma_parser/Cargo.toml index 679c6c19b4c3..410217e29f9e 100644 --- a/crates/swc_ecma_parser/Cargo.toml +++ b/crates/swc_ecma_parser/Cargo.toml @@ -24,6 +24,7 @@ tracing-spans = [] typescript = [] unstable = [] verify = ["swc_ecma_visit", "swc_ecma_lexer/verify"] +unknown = ["swc_ecma_ast/unknown"] [dependencies] either = { workspace = true } From fa1f606a69f2b7c016dcd114ced4fb4dafaefa88 Mon Sep 17 00:00:00 2001 From: quininer Date: Mon, 22 Sep 2025 17:18:45 +0800 Subject: [PATCH 02/16] fix ecma parser --- .../src/common/parser/class_and_fn.rs | 6 +++++- crates/swc_ecma_lexer/src/common/parser/expr.rs | 14 ++++++++++++++ .../swc_ecma_lexer/src/common/parser/expr_ext.rs | 3 +++ crates/swc_ecma_lexer/src/common/parser/jsx.rs | 4 ++++ .../src/common/parser/module_item.rs | 7 +++++++ crates/swc_ecma_lexer/src/common/parser/pat.rs | 9 +++++++++ crates/swc_ecma_lexer/src/common/parser/stmt.rs | 2 ++ crates/swc_ecma_lexer/src/common/parser/util.rs | 6 ++++++ crates/swc_ecma_lexer/src/parser/mod.rs | 2 ++ crates/swc_ecma_parser/Cargo.toml | 2 +- crates/swc_ecma_parser/src/parser/jsx/mod.rs | 2 ++ crates/swc_ecma_parser/src/parser/mod.rs | 2 ++ 12 files changed, 57 insertions(+), 2 deletions(-) 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..02bd6b3f6a0e 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 @@ -581,7 +581,9 @@ where kind, } .into()) - } + }, + #[cfg(feature = "unknown")] + _ => unreachable!() } } @@ -817,6 +819,8 @@ fn make_property<'a, P: Parser<'a>>( } .into() } + #[cfg(feature = "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..6aca26931911 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(feature = "unknown")] + _ => unreachable!() }; return Ok(( TsNonNullExpr { @@ -808,6 +810,8 @@ fn parse_subscript<'a, P: Parser<'a>>( expr } } + #[cfg(feature = "unknown")] + _ => unreachable!() }), true, )); @@ -853,6 +857,8 @@ fn parse_subscript<'a, P: Parser<'a>>( .into(), true, )), + #[cfg(feature = "unknown")] + _ => unreachable!() } } else { Ok(( @@ -944,6 +950,8 @@ fn parse_subscript<'a, P: Parser<'a>>( ) } MemberProp::Computed(..) => unreachable!(), + #[cfg(feature = "unknown")] + _ => unreachable!() } } } @@ -972,6 +980,8 @@ fn parse_subscript<'a, P: Parser<'a>>( expr } } + #[cfg(feature = "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(feature = "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(feature = "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..f873b89fabef 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(feature = "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..b544326cc342 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(feature = "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(feature = "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..107f8e6a3716 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(feature = "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(feature = "unknown")] + _ => unreachable!() }; p.emit_err(namespace.span, SyntaxError::ExportExpectFrom(export_name)); } @@ -697,6 +702,8 @@ fn parse_export<'a, P: Parser<'a>>( } _ => {} }, + #[cfg(feature = "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..e96d1acbb633 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(feature = "unknown")] + _ => () } } } Pat::Assign(a) => pat_is_valid_argument_in_strict(p, &a.left), Pat::Invalid(_) | Pat::Expr(_) => (), + #[cfg(feature = "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(feature = "unknown")] + _ => unreachable!() }, right, } @@ -250,6 +256,9 @@ fn reparse_expr_as_pat_inner<'a>( type_ann: None, })) } + + #[cfg(feature = "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..e0c740f1f2d9 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(feature = "unknown")] + _ => {} } } expect!(p, &P::Token::RPAREN); diff --git a/crates/swc_ecma_lexer/src/common/parser/util.rs b/crates/swc_ecma_lexer/src/common/parser/util.rs index 66a98e871c72..3b0a07c7db41 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(feature = "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(feature = "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(feature = "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..2b6918e759dc 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(feature = "unknown")] + _ => unreachable!() }) .collect(); Program::Script(Script { diff --git a/crates/swc_ecma_parser/Cargo.toml b/crates/swc_ecma_parser/Cargo.toml index 410217e29f9e..faae4dea0a79 100644 --- a/crates/swc_ecma_parser/Cargo.toml +++ b/crates/swc_ecma_parser/Cargo.toml @@ -24,7 +24,7 @@ tracing-spans = [] typescript = [] unstable = [] verify = ["swc_ecma_visit", "swc_ecma_lexer/verify"] -unknown = ["swc_ecma_ast/unknown"] +unknown = ["swc_ecma_ast/unknown", "swc_ecma_lexer/unknown"] [dependencies] either = { workspace = true } diff --git a/crates/swc_ecma_parser/src/parser/jsx/mod.rs b/crates/swc_ecma_parser/src/parser/jsx/mod.rs index a8faa76a8fe5..4853103c62d4 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(feature = "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..19ae848eccd4 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(feature = "unknown")] + _ => unreachable!() }) .collect(); Program::Script(Script { From bc2856381608987f8dcea1dbf58e18d8e6a1eb14 Mon Sep 17 00:00:00 2001 From: quininer Date: Wed, 24 Sep 2025 16:50:12 +0800 Subject: [PATCH 03/16] fix ecma_codegen --- crates/swc_ecma_codegen/Cargo.toml | 1 + crates/swc_ecma_codegen/src/class.rs | 7 +++++ crates/swc_ecma_codegen/src/decl.rs | 5 +++ crates/swc_ecma_codegen/src/jsx.rs | 17 ++++++++++ crates/swc_ecma_codegen/src/lib.rs | 34 ++++++++++++++++++++ crates/swc_ecma_codegen/src/lit.rs | 5 +++ crates/swc_ecma_codegen/src/module_decls.rs | 11 +++++++ crates/swc_ecma_codegen/src/object.rs | 7 +++++ crates/swc_ecma_codegen/src/pat.rs | 17 ++++++++++ crates/swc_ecma_codegen/src/stmt.rs | 9 ++++++ crates/swc_ecma_codegen/src/typescript.rs | 35 +++++++++++++++++++++ crates/swc_ecma_codegen/src/util.rs | 20 ++++++++++++ 12 files changed, 168 insertions(+) diff --git a/crates/swc_ecma_codegen/Cargo.toml b/crates/swc_ecma_codegen/Cargo.toml index 970538c4aa7b..8889abb32e56 100644 --- a/crates/swc_ecma_codegen/Cargo.toml +++ b/crates/swc_ecma_codegen/Cargo.toml @@ -12,6 +12,7 @@ version = "17.0.2" [features] # This does not enable serde for ast nodes. serde-impl = ["swc_ecma_ast/serde"] +unknown = ["swc_ecma_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..23385bb0025f 100644 --- a/crates/swc_ecma_codegen/src/class.rs +++ b/crates/swc_ecma_codegen/src/class.rs @@ -6,6 +6,9 @@ use crate::{ text_writer::WriteJs, util::StartsWithAlphaNum, Emitter, ListFormat, Result, SourceMapperExt, }; +#[cfg(feature = "unknown")] +use crate::unknown_error; + impl Emitter<'_, W, S> where W: WriteJs, @@ -146,6 +149,8 @@ impl MacroNode for ClassMember { ClassMember::Empty(ref n) => emit!(n), ClassMember::StaticBlock(ref n) => emit!(n), ClassMember::AutoAccessor(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -207,6 +212,8 @@ impl MacroNode for Key { match self { Key::Private(n) => emit!(n), Key::Public(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) diff --git a/crates/swc_ecma_codegen/src/decl.rs b/crates/swc_ecma_codegen/src/decl.rs index f88406756206..b4b7c13d0156 100644 --- a/crates/swc_ecma_codegen/src/decl.rs +++ b/crates/swc_ecma_codegen/src/decl.rs @@ -5,6 +5,9 @@ use swc_ecma_codegen_macros::node_impl; use super::{Emitter, Result}; use crate::text_writer::WriteJs; +#[cfg(feature = "unknown")] +use crate::unknown_error; + impl Emitter<'_, W, S> where W: WriteJs, @@ -98,6 +101,8 @@ impl MacroNode for Decl { Decl::TsInterface(n) => emit!(n), Decl::TsModule(n) => emit!(n), Decl::TsTypeAlias(n) => emit!(n), + #[cfg(feature = "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..b3694a28ce7b 100644 --- a/crates/swc_ecma_codegen/src/jsx.rs +++ b/crates/swc_ecma_codegen/src/jsx.rs @@ -5,6 +5,9 @@ use swc_ecma_codegen_macros::node_impl; use super::Emitter; use crate::text_writer::WriteJs; +#[cfg(feature = "unknown")] +use crate::unknown_error; + impl Emitter<'_, W, S> where W: WriteJs, @@ -63,6 +66,8 @@ impl MacroNode for JSXElementName { JSXElementName::Ident(ref n) => emit!(n), JSXElementName::JSXMemberExpr(ref n) => emit!(n), JSXElementName::JSXNamespacedName(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -89,6 +94,8 @@ impl MacroNode for JSXAttrValue { JSXAttrValue::JSXExprContainer(ref n) => emit!(n), JSXAttrValue::JSXElement(ref n) => emit!(n), JSXAttrValue::JSXFragment(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -100,6 +107,8 @@ impl MacroNode for JSXAttrName { match *self { JSXAttrName::Ident(ref n) => emit!(n), JSXAttrName::JSXNamespacedName(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -115,6 +124,8 @@ impl MacroNode for JSXAttrOrSpread { emit!(n); punct!(emitter, "}"); } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -129,6 +140,8 @@ impl MacroNode for JSXElementChild { JSXElementChild::JSXFragment(ref n) => emit!(n), JSXElementChild::JSXSpreadChild(ref n) => emit!(n), JSXElementChild::JSXText(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -162,6 +175,8 @@ impl MacroNode for JSXExpr { match *self { JSXExpr::Expr(ref n) => emit!(n), JSXExpr::JSXEmptyExpr(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -250,6 +265,8 @@ impl MacroNode for JSXObject { match *self { JSXObject::Ident(ref n) => emit!(n), JSXObject::JSXMemberExpr(ref n) => emit!(n), + #[cfg(feature = "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..6869dad98b67 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(feature = "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(feature = "unknown")] + _ => false, }, + #[cfg(feature = "unknown")] + _ => false, }; if has_leading { @@ -866,6 +872,8 @@ where return true; } } + #[cfg(feature = "unknown")] + _ => (), }, _ => {} @@ -1409,6 +1417,8 @@ impl MacroNode for Program { match self { Program::Module(m) => emit!(m), Program::Script(s) => emit!(s), + #[cfg(feature = "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(feature = "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(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -1581,6 +1595,8 @@ impl MacroNode for Expr { Expr::TsSatisfies(n) => { emit!(n) } + #[cfg(feature = "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(feature = "unknown")] + _ => return Err(unknown_error()), } } OptChainBase::Call(e) => { @@ -1631,6 +1649,8 @@ impl MacroNode for OptChainExpr { )?; punct!(emitter, ")"); } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -1735,6 +1755,8 @@ impl MacroNode for MemberExpr { punct!(emitter, "."); emit!(private); } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } srcmap!(emitter, self, false); @@ -1761,6 +1783,8 @@ impl MacroNode for SuperPropExpr { punct!(emitter, "."); emit!(i); } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -2002,6 +2026,8 @@ impl MacroNode for BlockStmtOrExpr { emit!(expr); emitter.wr.decrease_indent()?; } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -2327,3 +2353,11 @@ impl MacroNode for IdentName { Ok(()) } } + +#[cfg(feature = "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..0ef2d63526be 100644 --- a/crates/swc_ecma_codegen/src/lit.rs +++ b/crates/swc_ecma_codegen/src/lit.rs @@ -8,6 +8,9 @@ use swc_ecma_codegen_macros::node_impl; use crate::{text_writer::WriteJs, CowStr, Emitter, SourceMapperExt}; +#[cfg(feature = "unknown")] +use crate::unknown_error; + #[node_impl] impl MacroNode for Lit { fn emit(&mut self, emitter: &mut Macro) -> Result { @@ -34,6 +37,8 @@ impl MacroNode for Lit { emitter.wr.write_str(&n.flags)?; } Lit::JSXText(ref n) => emit!(n), + #[cfg(feature = "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..dc7430d6b907 100644 --- a/crates/swc_ecma_codegen/src/module_decls.rs +++ b/crates/swc_ecma_codegen/src/module_decls.rs @@ -4,6 +4,9 @@ use swc_ecma_codegen_macros::node_impl; use crate::{util::StartsWithAlphaNum, ListFormat}; +#[cfg(feature = "unknown")] +use crate::unknown_error; + #[node_impl] impl MacroNode for ModuleDecl { fn emit(&mut self, emitter: &mut Macro) -> Result { @@ -19,6 +22,8 @@ impl MacroNode for ModuleDecl { ModuleDecl::TsExportAssignment(ref n) => emit!(n), ModuleDecl::TsImportEquals(ref n) => emit!(n), ModuleDecl::TsNamespaceExport(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } emitter.emit_trailing_comments_of_pos(self.span().hi, true, true)?; @@ -101,6 +106,8 @@ impl MacroNode for ExportDefaultDecl { DefaultDecl::Class(ref n) => emit!(n), DefaultDecl::Fn(ref n) => emit!(n), DefaultDecl::TsInterfaceDecl(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -171,6 +178,8 @@ impl MacroNode for ImportDecl { space!(emitter); emit!(ns.local); } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } } @@ -254,6 +263,8 @@ impl MacroNode for ExportSpecifier { } ExportSpecifier::Namespace(ref node) => emit!(node), ExportSpecifier::Named(ref node) => emit!(node), + #[cfg(feature = "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..7b8172cbaac0 100644 --- a/crates/swc_ecma_codegen/src/object.rs +++ b/crates/swc_ecma_codegen/src/object.rs @@ -4,6 +4,9 @@ use swc_ecma_codegen_macros::node_impl; use crate::{is_empty_comments, ListFormat}; +#[cfg(feature = "unknown")] +use crate::unknown_error; + #[node_impl] impl MacroNode for ObjectLit { fn emit(&mut self, emitter: &mut Macro) -> Result { @@ -50,6 +53,8 @@ impl MacroNode for Prop { Prop::Getter(ref n) => emit!(n), Prop::Setter(ref n) => emit!(n), Prop::Method(ref n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -227,6 +232,8 @@ impl MacroNode for PropName { PropName::Num(ref n) => emit!(n), PropName::BigInt(ref n) => emit!(n), PropName::Computed(ref n) => emit!(n), + #[cfg(feature = "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..91da23c3fe99 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(feature = "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(feature = "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(feature = "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(feature = "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(feature = "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(feature = "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(feature = "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(feature = "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..32e0c2e00585 100644 --- a/crates/swc_ecma_codegen/src/stmt.rs +++ b/crates/swc_ecma_codegen/src/stmt.rs @@ -4,6 +4,9 @@ use swc_ecma_codegen_macros::node_impl; use crate::util::{EndsWithAlphaNum, StartsWithAlphaNum}; +#[cfg(feature = "unknown")] +use crate::unknown_error; + #[node_impl] impl MacroNode for Stmt { fn emit(&mut self, emitter: &mut Macro) -> Result { @@ -38,6 +41,8 @@ impl MacroNode for Stmt { semi!(emitter); } Stmt::Decl(ref e) => emit!(e), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } if emitter.comments.is_some() { emitter.emit_trailing_comments_of_pos(self.span().hi(), true, true)?; @@ -582,6 +587,8 @@ impl MacroNode for ModuleExportName { match self { ModuleExportName::Ident(ident) => emit!(ident), ModuleExportName::Str(s) => emit!(s), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -594,6 +601,8 @@ impl MacroNode for VarDeclOrExpr { match self { VarDeclOrExpr::Expr(node) => emit!(node), VarDeclOrExpr::VarDecl(node) => emit!(node), + #[cfg(feature = "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..35cd52397fb5 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(feature = "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(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) @@ -170,6 +175,8 @@ impl MacroNode for TsEntityName { emit!(n); } TsEntityName::Ident(n) => emit!(n), + #[cfg(feature = "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(feature = "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(feature = "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(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -499,6 +512,8 @@ impl MacroNode for TsLit { TsLit::Str(n) => emit!(n), TsLit::Bool(n) => emit!(n), TsLit::Tpl(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -689,6 +704,8 @@ impl MacroNode for TsModuleDecl { // deprecate the module keyword in this context TsModuleName::Ident(_) => keyword!(emitter, "namespace"), TsModuleName::Str(_) => keyword!(emitter, "module"), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } space!(emitter); emit!(self.id); @@ -713,6 +730,8 @@ impl MacroNode for TsModuleName { match self { TsModuleName::Ident(n) => emit!(n), TsModuleName::Str(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -726,6 +745,8 @@ impl MacroNode for TsModuleRef { match self { TsModuleRef::TsEntityName(n) => emit!(n), TsModuleRef::TsExternalModuleRef(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -741,6 +762,8 @@ impl MacroNode for TsNamespaceBody { match self { TsNamespaceBody::TsModuleBlock(n) => emit!(n), TsNamespaceBody::TsNamespaceDecl(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } emitter.wr.decrease_indent()?; punct!(emitter, "}"); @@ -843,6 +866,8 @@ impl MacroNode for TsParamPropParam { match self { TsParamPropParam::Ident(n) => emit!(n), TsParamPropParam::Assign(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -932,6 +957,8 @@ impl MacroNode for TsThisTypeOrIdent { match self { TsThisTypeOrIdent::TsThisType(n) => emit!(n), TsThisTypeOrIdent::Ident(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -993,6 +1020,8 @@ impl MacroNode for TsType { TsType::TsLitType(n) => emit!(n), TsType::TsTypePredicate(n) => emit!(n), TsType::TsImportType(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -1130,6 +1159,8 @@ impl MacroNode for TsTypeElement { TsTypeElement::TsSetterSignature(n) => { emit!(n) } + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } formatting_semi!(emitter); Ok(()) @@ -1323,6 +1354,8 @@ impl MacroNode for TsTypeQueryExpr { match self { TsTypeQueryExpr::TsEntityName(n) => emit!(n), TsTypeQueryExpr::Import(n) => emit!(n), + #[cfg(feature = "unknown")] + _ => return Err(unknown_error()), } Ok(()) } @@ -1350,6 +1383,8 @@ impl MacroNode for TsUnionOrIntersectionType { match self { TsUnionOrIntersectionType::TsUnionType(n) => emit!(n), TsUnionOrIntersectionType::TsIntersectionType(n) => emit!(n), + #[cfg(feature = "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..73d8a66595f1 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(feature = "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(feature = "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(feature = "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(feature = "unknown")] + _ => false, } } } @@ -246,6 +254,8 @@ impl StartsWithAlphaNum for Expr { Expr::OptChain(e) => e.starts_with_alpha_num(), Expr::Invalid(..) => true, + #[cfg(feature = "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(feature = "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(feature = "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(feature = "unknown")] + _ => false, } } } @@ -332,6 +348,8 @@ impl StartsWithAlphaNum for Stmt { | Stmt::ForOf(..) | Stmt::If(..) => true, Stmt::Block(..) | Stmt::Empty(..) => false, + #[cfg(feature = "unknown")] + _ => false, } } } @@ -347,6 +365,8 @@ impl StartsWithAlphaNum for Decl { | Decl::TsModule(..) | Decl::TsTypeAlias(..) | Decl::Using(..) => true, + #[cfg(feature = "unknown")] + _ => false, } } } From 85b8b3631350b75be3d55408bc8f4346ff9e8837 Mon Sep 17 00:00:00 2001 From: quininer Date: Wed, 24 Sep 2025 19:55:13 +0800 Subject: [PATCH 04/16] fix ecma_visit --- crates/swc_css_visit/src/generated.rs | 4 +- crates/swc_ecma_ast/src/class.rs | 1 + crates/swc_ecma_ast/src/decl.rs | 1 + crates/swc_ecma_ast/src/expr.rs | 1 + crates/swc_ecma_ast/src/module_decl.rs | 1 + crates/swc_ecma_ast/src/operators.rs | 4 + crates/swc_ecma_ast/src/typescript.rs | 4 + crates/swc_ecma_visit/Cargo.toml | 1 + crates/swc_ecma_visit/src/generated.rs | 744 ++++++++++++++++++ tools/generate-code/src/generators/visitor.rs | 22 +- tools/generate-code/src/main.rs | 10 +- 11 files changed, 783 insertions(+), 10 deletions(-) diff --git a/crates/swc_css_visit/src/generated.rs b/crates/swc_css_visit/src/generated.rs index a7973ca8edba..7334bdd9907b 100644 --- a/crates/swc_css_visit/src/generated.rs +++ b/crates/swc_css_visit/src/generated.rs @@ -84590,7 +84590,9 @@ impl FoldWith for Token { let raw = { >::fold_with(raw, visitor) }; Token::BadUrl { raw } } - Token::Delim { value } => Token::Delim { value }, + Token::Delim { value } => { + Token::Delim { value } + } Token::Number { value, raw, diff --git a/crates/swc_ecma_ast/src/class.rs b/crates/swc_ecma_ast/src/class.rs index b14aa3ed870b..6cb1c90a3de1 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(feature = "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..2457f651c244 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(feature = "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..dc4692803753 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(feature = "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..d1986a0455b4 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(feature = "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..e6f888066efb 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(feature = "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(feature = "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(feature = "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(feature = "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..d2a00622fb56 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(feature = "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(feature = "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(feature = "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(feature = "unknown", non_exhaustive)] pub enum Accessibility { #[cfg_attr(feature = "serde-impl", serde(rename = "public"))] Public, diff --git a/crates/swc_ecma_visit/Cargo.toml b/crates/swc_ecma_visit/Cargo.toml index f0757fc8d814..d6c1689795c7 100644 --- a/crates/swc_ecma_visit/Cargo.toml +++ b/crates/swc_ecma_visit/Cargo.toml @@ -20,6 +20,7 @@ debug = [] default = [] path = [] serde-impl = ["serde"] +unknown = ["swc_ecma_ast/unknown"] [dependencies] new_debug_unreachable = { workspace = true } diff --git a/crates/swc_ecma_visit/src/generated.rs b/crates/swc_ecma_visit/src/generated.rs index ff620835aaa6..65cc272764be 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(feature = "unknown")] + _ => (), } } } @@ -9888,6 +9890,8 @@ impl VisitWith for AssignOp { AssignOp::AndAssign => {} AssignOp::OrAssign => {} AssignOp::NullishAssign => {} + #[cfg(feature = "unknown")] + _ => (), } } } @@ -9971,6 +9975,8 @@ impl VisitWith for AssignTarget { AssignTarget::Pat { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -9991,6 +9997,8 @@ impl VisitWith for AssignTargetPat { AssignTargetPat::Invalid { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10140,6 +10148,8 @@ impl VisitWith for BinaryOp { BinaryOp::InstanceOf => {} BinaryOp::Exp => {} BinaryOp::NullishCoalescing => {} + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10198,6 +10208,8 @@ impl VisitWith for BlockStmtOrExpr { BlockStmtOrExpr::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10289,6 +10301,8 @@ impl VisitWith for Callee { Callee::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10441,6 +10455,8 @@ impl VisitWith for ClassMember { ClassMember::AutoAccessor { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10682,6 +10698,8 @@ impl VisitWith for Decl { Decl::TsModule { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10721,6 +10739,8 @@ impl VisitWith for DefaultDecl { DefaultDecl::TsInterfaceDecl { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -10925,6 +10945,8 @@ impl VisitWith for ExportSpecifier { ExportSpecifier::Named { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11050,6 +11072,8 @@ impl VisitWith for Expr { Expr::Invalid { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11150,6 +11174,8 @@ impl VisitWith for ForHead { ForHead::Pat { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11509,6 +11535,8 @@ impl VisitWith for ImportPhase { ImportPhase::Evaluation => {} ImportPhase::Source => {} ImportPhase::Defer => {} + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11529,6 +11557,8 @@ impl VisitWith for ImportSpecifier { ImportSpecifier::Namespace { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11641,6 +11671,8 @@ impl VisitWith for JSXAttrName { JSXAttrName::JSXNamespacedName { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11658,6 +11690,8 @@ impl VisitWith for JSXAttrOrSpread { JSXAttrOrSpread::SpreadElement { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11681,6 +11715,8 @@ impl VisitWith for JSXAttrValue { JSXAttrValue::JSXFragment { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11772,6 +11808,8 @@ impl VisitWith for JSXElementChild { JSXElementChild::JSXFragment { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11792,6 +11830,8 @@ impl VisitWith for JSXElementName { JSXElementName::JSXNamespacedName { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11825,6 +11865,8 @@ impl VisitWith for JSXExpr { JSXExpr::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -11935,6 +11977,8 @@ impl VisitWith for JSXObject { JSXObject::Ident { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12042,6 +12086,8 @@ impl VisitWith for Key { Key::Public { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12134,6 +12180,8 @@ impl VisitWith for Lit { Lit::JSXText { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12176,6 +12224,8 @@ impl VisitWith for MemberProp { MemberProp::Computed { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12208,6 +12258,8 @@ impl VisitWith for MetaPropKind { match self { MetaPropKind::NewTarget => {} MetaPropKind::ImportMeta => {} + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12222,6 +12274,8 @@ impl VisitWith for MethodKind { MethodKind::Method => {} MethodKind::Getter => {} MethodKind::Setter => {} + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12305,6 +12359,8 @@ impl VisitWith for ModuleDecl { ModuleDecl::TsNamespaceExport { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12322,6 +12378,8 @@ impl VisitWith for ModuleExportName { ModuleExportName::Str { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12339,6 +12397,8 @@ impl VisitWith for ModuleItem { ModuleItem::Stmt { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12507,6 +12567,8 @@ impl VisitWith for ObjectPatProp { ObjectPatProp::Rest { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12560,6 +12622,8 @@ impl VisitWith for OptChainBase { OptChainBase::Call { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12626,6 +12690,8 @@ impl VisitWith for ParamOrTsParamProp { ParamOrTsParamProp::Param { 0: _field_0 } => { >::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12677,6 +12743,8 @@ impl VisitWith for Pat { Pat::Expr { 0: _field_0 } => { as VisitWith>::visit_with(_field_0, visitor); } + #[cfg(feature = "unknown")] + _ => (), } } } @@ -12798,6 +12866,8 @@ impl VisitWith for Program { Program::Script { 0: _field_0 } => {