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/Cargo.lock b/Cargo.lock index d4e6c7a73654..7e4570703111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,7 +224,7 @@ version = "3.0.4" dependencies = [ "quote", "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -235,7 +235,7 @@ checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -257,7 +257,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -336,7 +336,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -504,7 +504,7 @@ checksum = "efb7846e0cb180355c2dec69e721edafa36919850f1a9f52ffba4ebc0393cb71" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -655,6 +655,11 @@ dependencies = [ "rustversion", ] +[[package]] +name = "cbor4ii" +version = "1.1.1" +source = "git+https://github.com/quininer/cbor4ii?branch=f%2Fderive#1084f6edc73a98b975533b81b6f570aca73550f2" + [[package]] name = "cc" version = "1.2.13" @@ -811,7 +816,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1426,7 +1431,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1448,7 +1453,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1539,7 +1544,7 @@ checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1581,7 +1586,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1601,7 +1606,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" dependencies = [ "derive_builder_core 0.20.0", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1612,7 +1617,7 @@ checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1632,7 +1637,7 @@ checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "unicode-xid", ] @@ -1684,7 +1689,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1800,7 +1805,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1911,7 +1916,7 @@ name = "from_variant" version = "2.0.2" dependencies = [ "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -1993,7 +1998,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -2036,7 +2041,7 @@ dependencies = [ "proc-macro2", "quote", "swc_config", - "syn 2.0.101", + "syn 2.0.106", "walkdir", ] @@ -2518,7 +2523,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -2663,7 +2668,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -2733,6 +2738,7 @@ dependencies = [ name = "jsdoc" version = "14.0.0" dependencies = [ + "cbor4ii", "dashmap 5.5.3", "nom 7.1.3", "serde", @@ -3100,7 +3106,7 @@ checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3168,7 +3174,7 @@ checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3204,7 +3210,7 @@ dependencies = [ "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3217,7 +3223,7 @@ dependencies = [ "proc-macro2", "quote", "semver", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3414,7 +3420,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3487,7 +3493,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3658,7 +3664,7 @@ dependencies = [ "phf_shared 0.11.3", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3696,7 +3702,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3844,7 +3850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3900,7 +3906,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3958,7 +3964,7 @@ checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -3992,7 +3998,7 @@ checksum = "938543690519c20c3a480d20a8efcc8e69abeb44093ab1df4e7c1f81f26c677a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4256,7 +4262,7 @@ checksum = "beb382a4d9f53bd5c0be86b10d8179c3f8a14c30bf774ff77096ed6581e35981" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4429,7 +4435,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4537,7 +4543,7 @@ checksum = "0ea936adf78b1f766949a4977b91d2f5595825bd6ec079aa9543ad2685fc4516" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4548,7 +4554,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4669,7 +4675,7 @@ checksum = "a5e9bca0d4a99ce6c7296fea5972a9327a5e70c062b73f38e11c7894cf7ec72c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4804,7 +4810,7 @@ checksum = "9cf483ea7e0e3a03d1b91687895814425149ad77facd3e2b6839dde26da98454" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4844,7 +4850,7 @@ dependencies = [ "quote", "serde", "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -4951,6 +4957,7 @@ version = "7.0.0" dependencies = [ "arbitrary", "bytecheck 0.8.1", + "cbor4ii", "hstr", "once_cell", "rancor", @@ -5032,6 +5039,7 @@ dependencies = [ "better_scoped_tls", "bytecheck 0.8.1", "bytes-str", + "cbor4ii", "either", "from_variant", "new_debug_unreachable", @@ -5108,7 +5116,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -5187,6 +5195,7 @@ name = "swc_css_ast" version = "14.0.0" dependencies = [ "bytecheck 0.8.1", + "cbor4ii", "is-macro", "rkyv", "serde", @@ -5218,7 +5227,7 @@ name = "swc_css_codegen_macros" version = "1.0.2" dependencies = [ "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -5357,6 +5366,7 @@ dependencies = [ "arbitrary", "bitflags 2.6.0", "bytecheck 0.8.1", + "cbor4ii", "is-macro", "num-bigint", "once_cell", @@ -5409,7 +5419,7 @@ version = "2.0.2" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -5800,7 +5810,7 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -5834,6 +5844,7 @@ name = "swc_ecma_regexp_ast" version = "0.3.0" dependencies = [ "bitflags 2.6.0", + "cbor4ii", "is-macro", "serde", "swc_atoms", @@ -5962,7 +5973,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6188,7 +6199,7 @@ version = "1.0.1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6263,6 +6274,7 @@ name = "swc_html_ast" version = "14.0.0" dependencies = [ "bytecheck 0.8.1", + "cbor4ii", "is-macro", "rkyv", "serde", @@ -6293,7 +6305,7 @@ name = "swc_html_codegen_macros" version = "1.0.1" dependencies = [ "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6372,7 +6384,7 @@ version = "1.0.1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6491,7 +6503,7 @@ version = "1.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6561,7 +6573,7 @@ name = "swc_trace_macro" version = "2.0.2" dependencies = [ "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6636,6 +6648,7 @@ dependencies = [ name = "swc_xml_ast" version = "14.0.0" dependencies = [ + "cbor4ii", "is-macro", "serde", "string_enum", @@ -6663,7 +6676,7 @@ name = "swc_xml_codegen_macros" version = "1.0.1" dependencies = [ "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6704,9 +6717,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.101" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -6727,7 +6740,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6883,7 +6896,7 @@ dependencies = [ "quote", "regex", "relative-path", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6924,7 +6937,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -6935,7 +6948,7 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -7060,7 +7073,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -7170,7 +7183,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -7638,7 +7651,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "wasm-bindgen-shared", ] @@ -7673,7 +7686,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -8227,7 +8240,7 @@ checksum = "342b0466f92b7217a4de9e114175fedee1907028567d2548bcd42f71a8b5b016" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -8357,7 +8370,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "witx", ] @@ -8369,7 +8382,7 @@ checksum = "f5872fbe512b73acd514e7ef5bd5aee0ff951a12c1fed0293e1f7992de30df9f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "wiggle-generate", ] @@ -8725,7 +8738,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "synstructure", ] @@ -8756,7 +8769,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -8767,7 +8780,7 @@ checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] [[package]] @@ -8787,7 +8800,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", "synstructure", ] @@ -8816,5 +8829,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.106", ] diff --git a/Cargo.toml b/Cargo.toml index d4c6e4baae49..46202df31e5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,6 +129,7 @@ resolver = "2" foldhash = "0.1" precomputed-map = "0.2" + cbor4ii = { git = "https://github.com/quininer/cbor4ii", branch = "f/derive" } [workspace.metadata.cargo-shear] # `serde` is used when #[ast_node] is expanded diff --git a/crates/ast_node/src/encoding/decode.rs b/crates/ast_node/src/encoding/decode.rs new file mode 100644 index 000000000000..f39c5f8cfa52 --- /dev/null +++ b/crates/ast_node/src/encoding/decode.rs @@ -0,0 +1,278 @@ +use syn::{spanned::Spanned, Data, DeriveInput}; + +use super::{is_unknown, is_with, EnumType}; + +pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl { + match data { + Data::Struct(data) => { + let is_named = data.fields.iter().any(|field| field.ident.is_some()); + let names = data + .fields + .iter() + .enumerate() + .map(|(idx, field)| match field.ident.as_ref() { + Some(name) => name.clone(), + None => { + let name = format!("unit{idx}"); + syn::Ident::new(&name, field.span()) + } + }) + .collect::>(); + + let fields = data.fields.iter() + .zip(names.iter()) + .map(|(field, field_name)| -> syn::Stmt { + let ty = &field.ty; + let value: syn::Expr = match is_with(&field.attrs) { + Some(with_type) => syn::parse_quote!(<#with_type<#ty> as cbor4ii::core::dec::Decode<'_>>::decode(reader)?.0), + None => syn::parse_quote!(<#ty as cbor4ii::core::dec::Decode<'_>>::decode(reader)?) + }; + + syn::parse_quote!{ + let #field_name = #value; + } + }); + let build_struct: syn::Expr = if is_named { + syn::parse_quote! { #ident { #(#names),* } } + } else { + syn::parse_quote! { #ident ( #(#names),* ) } + }; + + let count = data.fields.len(); + let head: Option = (count != 1).then(|| { + syn::parse_quote! { + let len = >::len(reader)?.unwrap(); + } + }); + let tail: Option = head.is_some().then(|| { + syn::parse_quote! { + // ignore unknown field + for _ in 0..(len - #count) { + cbor4ii::core::dec::IgnoredAny::decode(reader)?; + } + } + }); + + syn::parse_quote! { + impl<'de> cbor4ii::core::dec::Decode<'de> for #ident { + #[inline] + fn decode>(reader: &mut R) + -> Result> + { + #head; + let value = { + #(#fields)* + #build_struct + }; + #tail + Ok(value) + } + } + } + } + Data::Enum(data) => { + let enum_type = data.variants.iter().filter(|v| !is_unknown(&v.attrs)).fold( + None, + |mut sum, next| { + let ty = match &next.fields { + syn::Fields::Named(_) => EnumType::Struct, + syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => EnumType::One, + syn::Fields::Unit => EnumType::Unit, + syn::Fields::Unnamed(_) => { + panic!("more than 1 unnamed member field are not allowed") + } + }; + match (*sum.get_or_insert(ty), ty) { + (EnumType::Struct, EnumType::Struct) + | (EnumType::Struct, EnumType::Unit) + | (EnumType::Unit, EnumType::Unit) + | (EnumType::One, EnumType::One) => (), + (EnumType::Unit, EnumType::One) + | (EnumType::One, EnumType::Unit) + | (_, EnumType::Struct) => sum = Some(EnumType::Struct), + _ => panic!("enum member types must be consistent: {:?}", (sum, ty)), + } + sum + }, + ); + let enum_type = enum_type.expect("enum cannot be empty"); + let mut iter = data.variants.iter().peekable(); + + let unknown_arm: Option = iter.next_if(|variant| is_unknown(&variant.attrs)) + .map(|unknown| { + let name = &unknown.ident; + assert!( + unknown.discriminant.is_none(), + "unknown member is not allowed custom discriminant" + ); + assert!( + is_with(&unknown.attrs).is_none(), + "unknown member is not allowed with type" + ); + + match &unknown.fields { + syn::Fields::Unnamed(fields) => match fields.unnamed.len() { + 1 => { + assert_eq!(enum_type, EnumType::Unit); + syn::parse_quote! { + tag => #ident::#name(tag), + } + } + 2 => { + assert_eq!(enum_type, EnumType::One); + let val_ty = &fields.unnamed[1].ty; + syn::parse_quote! { + tag => { + let tag: u32 = tag.try_into().map_err(|_| cbor4ii::core::error::DecodeError::CastOverflow { + name: &"tag", + })?; + let val = <#val_ty as cbor4ii::core::dec::Decode<'_>>::decode(reader)?; + #ident::#name(tag, val) + }, + } + } + _ => panic!("unknown member must be a tag and a value"), + }, + _ => panic!("named enum unsupported"), + } + }); + + if matches!(enum_type, EnumType::Struct) { + assert!( + unknown_arm.is_none(), + "struct enum does not allow unknown variants" + ); + } + + let mut discriminant: u32 = 0; + let fields = iter + .map(|field| -> syn::Arm { + match field.discriminant.as_ref() { + Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(lit), .. }))) => { + discriminant = lit.base10_parse::().unwrap(); + }, + Some(_) => panic!("unsupported discriminant type"), + None => (), + }; + discriminant += 1; + let idx = discriminant as u64; + let name = &field.ident; + + assert!(!is_unknown(&field.attrs), "unknown member must be first"); + + match enum_type { + EnumType::Unit => { + assert!(is_with(&field.attrs).is_none(), "unit member is not allowed with type"); + syn::parse_quote!{ + #idx => #ident::#name, + } + }, + EnumType::One => { + let val_ty = &field.fields.iter().next().unwrap().ty; + let value: syn::Expr = match is_with(&field.attrs) { + Some(with_type) + => syn::parse_quote!(<#with_type<#val_ty> as cbor4ii::core::dec::Decode<'_>>::decode(reader)?.0), + None => syn::parse_quote!(<#val_ty as cbor4ii::core::dec::Decode<'_>>::decode(reader)?) + }; + + syn::parse_quote!{ + #idx => #ident::#name(#value), + } + }, + EnumType::Struct => { + let is_named = field.fields.iter().all(|field| field.ident.is_some()); + let names = field.fields.iter() + .enumerate() + .map(|(idx, field)| match field.ident.as_ref() { + Some(name) => name.clone(), + None => { + let name = format!("unit{idx}"); + syn::Ident::new(&name, field.span()) + } + }) + .collect::>(); + let count = field.fields.len(); + + let stmt = field.fields.iter() + .zip(names.iter()) + .map(|(field, field_name)| -> syn::Stmt { + let val_ty = &field.ty; + match is_with(&field.attrs) { + Some(with_type) => syn::parse_quote!{ + let #field_name = <#with_type<#val_ty> as cbor4ii::core::dec::Decode<'_>>::decode(reader)?.0; + }, + None => syn::parse_quote!{ + let #field_name = <#val_ty as cbor4ii::core::dec::Decode<'_>>::decode(reader)?; + } + } + }); + let build_struct: syn::Expr = if is_named { + syn::parse_quote! { #ident::#name { #(#names),* } } + } else { + syn::parse_quote! { #ident::#name ( #(#names),* ) } + }; + + syn::parse_quote!{ + #idx => { + let len = cbor4ii::core::types::Array::len(reader)?.unwrap(); + let value = { + #(#stmt)* + #build_struct + }; + + // ignore unknown field + for _ in 0..(len - #count) { + cbor4ii::core::dec::IgnoredAny::decode(reader)?; + } + + value + }, + } + } + } + }); + + let unknown_arm = match unknown_arm { + Some(arm) => arm, + None => { + syn::parse_quote! { + _ => { + let err = cbor4ii::core::error::DecodeError::Mismatch { + name: &stringify!(#ident), + found: 0 + }; + return Err(err); + } + } + } + }; + + let tag: syn::Stmt = if matches!(enum_type, EnumType::Unit) { + syn::parse_quote!{ + let tag = >::decode(reader)?; + } + } else { + syn::parse_quote!{ + let tag = >::tag(reader)?; + } + }; + + syn::parse_quote! { + impl<'de> cbor4ii::core::dec::Decode<'de> for #ident { + #[inline] + fn decode>(reader: &mut R) + -> Result> + { + #tag + let value = match tag { + #(#fields)* + #unknown_arm + }; + Ok(value) + } + } + } + } + Data::Union(_) => panic!("union unsupported"), + } +} diff --git a/crates/ast_node/src/encoding/encode.rs b/crates/ast_node/src/encoding/encode.rs new file mode 100644 index 000000000000..f8f8d6eb1944 --- /dev/null +++ b/crates/ast_node/src/encoding/encode.rs @@ -0,0 +1,237 @@ +use syn::{spanned::Spanned, Data, DeriveInput}; + +use super::{is_unknown, is_with, EnumType}; + +pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl { + match data { + Data::Struct(data) => { + let fields = data + .fields + .iter() + .enumerate() + .map(|(idx, field)| -> syn::Stmt { + let fieldpath: syn::ExprField = match field.ident.as_ref() { + Some(name) => syn::parse_quote!(self.#name), + None => { + let name = format!("{idx}"); + let name = syn::LitInt::new(&name, field.span()); + syn::parse_quote!(self.#name) + } + }; + + match is_with(&field.attrs) { + Some(with_type) => syn::parse_quote! { + cbor4ii::core::enc::Encode::encode(&#with_type(&#fieldpath), writer)?; + }, + None => syn::parse_quote! { + cbor4ii::core::enc::Encode::encode(&#fieldpath, writer)?; + }, + } + }); + let count = data.fields.len(); + let head: Option = (count != 1).then(|| { + syn::parse_quote! { + >::bounded(#count, writer)?; + } + }); + + syn::parse_quote! { + impl cbor4ii::core::enc::Encode for #ident { + #[inline] + fn encode(&self, writer: &mut W) + -> Result<(), cbor4ii::core::error::EncodeError> + { + #head + #(#fields)*; + Ok(()) + } + } + } + } + Data::Enum(data) => { + let enum_type = data.variants.iter().filter(|v| !is_unknown(&v.attrs)).fold( + None, + |mut sum, next| { + let ty = match &next.fields { + syn::Fields::Named(_) => EnumType::Struct, + syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => EnumType::One, + syn::Fields::Unit => EnumType::Unit, + syn::Fields::Unnamed(_) => { + panic!("more than 1 unnamed member field are not allowed") + } + }; + match (*sum.get_or_insert(ty), ty) { + (EnumType::Struct, EnumType::Struct) + | (EnumType::Struct, EnumType::Unit) + | (EnumType::Unit, EnumType::Unit) + | (EnumType::One, EnumType::One) => (), + (EnumType::Unit, EnumType::One) + | (EnumType::One, EnumType::Unit) + | (_, EnumType::Struct) => sum = Some(EnumType::Struct), + _ => panic!("enum member types must be consistent: {:?}", (sum, ty)), + } + sum + }, + ); + let enum_type = enum_type.expect("enum cannot be empty"); + let mut iter = data.variants.iter().peekable(); + + let unknown_arm: Option = iter.next_if(|variant| is_unknown(&variant.attrs)) + .map(|unknown| { + let name = &unknown.ident; + assert!( + unknown.discriminant.is_none(), + "unknown member is not allowed custom discriminant" + ); + assert!( + is_with(&unknown.attrs).is_none(), + "unknown member is not allowed with type" + ); + + match &unknown.fields { + syn::Fields::Unnamed(fields) => match fields.unnamed.len() { + 1 => { + assert_eq!(enum_type, EnumType::Unit); + syn::parse_quote! { + #ident::#name(tag) + => tag.encode(writer)?, + } + } + 2 => { + assert_eq!(enum_type, EnumType::One); + syn::parse_quote! { + #ident::#name(tag, value) + => cbor4ii::core::types::Tag((*tag).into(), &*value).encode(writer)?, + } + } + _ => panic!("unknown member must be a tag and a value"), + }, + _ => panic!("named enum unsupported"), + } + }); + + if matches!(enum_type, EnumType::Struct) { + assert!( + unknown_arm.is_none(), + "struct enum does not allow unknown variants" + ); + } + + let mut discriminant: u32 = 0; + let fields = iter.map(|field| -> syn::Arm { + match field.discriminant.as_ref() { + Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(lit), .. }))) => { + discriminant = lit.base10_parse::().unwrap(); + }, + Some(_) => panic!("unsupported discriminant type"), + None => (), + }; + discriminant += 1; + let idx = discriminant; + let name = &field.ident; + + assert!( + !is_unknown(&field.attrs), + "unknown member must be first: {:?}", + field.attrs.len() + ); + + match enum_type { + EnumType::Unit => { + assert!( + is_with(&field.attrs).is_none(), + "unit member is not allowed with type" + ); + + syn::parse_quote! { + #ident::#name => #idx.encode(writer)?, + } + }, + EnumType::One => { + let value: syn::Stmt = match is_with(&field.attrs) { + Some(ty) => syn::parse_quote! { + cbor4ii::core::enc::Encode::encode(&#ty(&*value), writer)?; + }, + None => syn::parse_quote! { + cbor4ii::core::enc::Encode::encode(&*value, writer)?; + }, + }; + + syn::parse_quote! { + #ident::#name(value) => { + cbor4ii::core::types::Tag(#idx.into(), cbor4ii::core::types::Nothing).encode(writer)?; + #value + }, + } + }, + EnumType::Struct => { + let is_named = field.fields.iter().all(|field| field.ident.is_some()); + let names = field.fields.iter() + .enumerate() + .map(|(idx, field)| match field.ident.as_ref() { + Some(name) => name.clone(), + None => { + let name = format!("unit{idx}"); + syn::Ident::new(&name, field.span()) + } + }) + .collect::>(); + let stmt = field.fields.iter() + .zip(names.iter()) + .map(|(field, field_name)| -> syn::Stmt { + match is_with(&field.attrs) { + Some(ty) => syn::parse_quote! { + cbor4ii::core::enc::Encode::encode(&#ty(&*#field_name), writer)?; + }, + None => syn::parse_quote! { + cbor4ii::core::enc::Encode::encode(&*#field_name, writer)?; + }, + } + }); + let head: syn::Expr = match field.fields.len() { + 0 | 1 => syn::parse_quote!{{ + cbor4ii::core::types::Tag(#idx.into(), cbor4ii::core::types::Nothing).encode(writer)?; + }}, + n => syn::parse_quote!{{ + cbor4ii::core::types::Tag(#idx.into(), cbor4ii::core::types::Nothing).encode(writer)?; + cbor4ii::core::types::Array::bounded(#n, writer)?; + }} + }; + + if is_named { + syn::parse_quote!{ + #ident::#name { #(#names),* } => { + #head; + #(#stmt)* + }, + } + } else { + syn::parse_quote!{ + #ident::#name ( #(#names),* ) => { + #head; + #(#stmt)* + }, + } + } + } + } + }); + + syn::parse_quote! { + impl cbor4ii::core::enc::Encode for #ident { + #[inline] + fn encode(&self, writer: &mut W) + -> Result<(), cbor4ii::core::error::EncodeError> + { + match self { + #(#fields)* + #unknown_arm + } + Ok(()) + } + } + } + } + Data::Union(_) => panic!("union unsupported"), + } +} diff --git a/crates/ast_node/src/encoding/mod.rs b/crates/ast_node/src/encoding/mod.rs new file mode 100644 index 000000000000..46e59e62e1ae --- /dev/null +++ b/crates/ast_node/src/encoding/mod.rs @@ -0,0 +1,45 @@ +pub(crate) mod decode; +pub(crate) mod encode; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum EnumType { + Unit, + One, + Struct, +} + +pub(crate) fn is_unknown(attrs: &[syn::Attribute]) -> bool { + attrs + .iter() + .filter(|attr| attr.path().is_ident("encoding")) + .any(|attr| { + let mut is_unknown = false; + attr.parse_nested_meta(|meta| { + is_unknown |= meta.path.is_ident("unknown"); + Ok(()) + }) + .unwrap(); + is_unknown + }) +} + +fn is_with(attrs: &[syn::Attribute]) -> Option { + attrs + .iter() + .filter(|attr| attr.path().is_ident("encoding")) + .find_map(|attr| { + let mut with_type = None; + attr.parse_nested_meta(|meta| { + if meta.path.is_ident("with") { + let val = meta.value()?; + let val: syn::LitStr = val.parse()?; + let val: syn::Path = val.parse()?; + with_type = Some(val); + } + + Ok(()) + }) + .ok()?; + with_type + }) +} diff --git a/crates/ast_node/src/enum_deserialize.rs b/crates/ast_node/src/enum_deserialize.rs index 0a1b0b275daa..2bbbee78aee7 100644 --- a/crates/ast_node/src/enum_deserialize.rs +++ b/crates/ast_node/src/enum_deserialize.rs @@ -36,6 +36,7 @@ pub fn expand( let tag_match_arms = data .variants .iter() + .filter(|v| !crate::encoding::is_unknown(&v.attrs)) .map(|variant| { let field_type = match variant.fields { Fields::Unnamed(ref fields) => { @@ -117,6 +118,10 @@ pub fn expand( let mut visit_bytes_arms = Vec::new(); for variant in &data.variants { + if crate::encoding::is_unknown(&variant.attrs) { + continue; + } + let tags = variant .attrs .iter() @@ -358,6 +363,7 @@ pub fn expand( let variants: Punctuated = { data.variants .iter() + .filter(|v| !crate::encoding::is_unknown(&v.attrs)) .cloned() .map(|variant| Variant { attrs: Default::default(), diff --git a/crates/ast_node/src/lib.rs b/crates/ast_node/src/lib.rs index bc58300dc4ea..351afe17e03c 100644 --- a/crates/ast_node/src/lib.rs +++ b/crates/ast_node/src/lib.rs @@ -8,6 +8,7 @@ use swc_macros_common::prelude::*; use syn::{visit_mut::VisitMut, *}; mod ast_node_macro; +mod encoding; mod enum_deserialize; mod spanned; @@ -23,7 +24,7 @@ pub fn derive_spanned(input: proc_macro::TokenStream) -> proc_macro::TokenStream } /// Derives `serde::Deserialize` which is aware of `tag` based deserialization. -#[proc_macro_derive(DeserializeEnum, attributes(tag))] +#[proc_macro_derive(DeserializeEnum, attributes(tag, encoding))] pub fn derive_deserialize_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input = parse::(input).expect("failed to parse input as DeriveInput"); @@ -32,6 +33,24 @@ pub fn derive_deserialize_enum(input: proc_macro::TokenStream) -> proc_macro::To print("derive(DeserializeEnum)", item.into_token_stream()) } +#[proc_macro_derive(Encode, attributes(encoding))] +pub fn derive_encode(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let input = + syn::parse::(input).expect("failed to parse input as DeriveInput"); + + let item = encoding::encode::expand(input); + print("derive(Encode)", item.into_token_stream()) +} + +#[proc_macro_derive(Decode, attributes(encoding))] +pub fn derive_decode(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let input = + syn::parse::(input).expect("failed to parse input as DeriveInput"); + + let item = encoding::decode::expand(input); + print("derive(Decode)", item.into_token_stream()) +} + /// Derives `serde::Serialize` and `serde::Deserialize`. /// /// # Struct attributes @@ -156,31 +175,65 @@ pub fn ast_node( // we should use call_site 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 }) + match &input.data { + Data::Enum(data) => { + 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 + }; + + let mut data = data.clone(); + if !has_no_unknown { + let unknown: syn::Variant = if data + .variants + .iter() + .all(|variant| variant.fields.is_empty()) + { + syn::parse_quote! { + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + #[from_variant(ignore)] + #[span(unknown)] + #[encoding(unknown)] + Unknown(u32) + } + } else { + syn::parse_quote! { + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + #[from_variant(ignore)] + #[span(unknown)] + #[encoding(unknown)] + Unknown(u32, swc_common::unknown::Unknown) + } + }; + + // insert unknown member + data.variants.insert(0, unknown); + input.data = Data::Enum(data); + } item.extend(quote!( #[allow(clippy::derive_partial_eq_without_eq)] @@ -198,6 +251,7 @@ pub fn ast_node( ::swc_common::DeserializeEnum, )] #clone + #non_exhaustive #[cfg_attr( feature = "rkyv-impl", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) @@ -223,6 +277,10 @@ pub fn ast_node( feature = "serde-impl", serde(untagged) )] + #[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) + )] #input )); } @@ -297,6 +355,10 @@ pub fn ast_node( serde(rename_all = "camelCase") )] #serde_rename + #[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) + )] #input )); diff --git a/crates/ast_node/src/spanned.rs b/crates/ast_node/src/spanned.rs index 2b11a0e1ced0..489b8be0d895 100644 --- a/crates/ast_node/src/spanned.rs +++ b/crates/ast_node/src/spanned.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] use swc_macros_common::prelude::*; -use syn::{parse::Parse, *}; +use syn::{parse::Parse, spanned::Spanned, *}; struct MyField { /// Name of the field. @@ -27,6 +27,21 @@ impl Parse for InputFieldAttr { } } +fn is_unknown(attrs: &[syn::Attribute]) -> bool { + attrs + .iter() + .filter(|attr| attr.path().is_ident("span")) + .any(|attr| { + let mut is_unknown = false; + attr.parse_nested_meta(|meta| { + is_unknown |= meta.path.is_ident("unknown"); + Ok(()) + }) + .unwrap(); + is_unknown + }) +} + impl MyField { fn from_field(f: &Field) -> Self { let mut lo = false; @@ -121,6 +136,12 @@ fn make_body_for_variant(v: &VariantBinder<'_>, bindings: Vec>) })) } + if is_unknown(v.attrs()) { + return Box::new(parse_quote_spanned! { v.data().span() => { + swc_common::DUMMY_SP + }}); + } + if bindings.is_empty() { panic!("#[derive(Spanned)] requires a field to get span from") } diff --git a/crates/from_variant/src/lib.rs b/crates/from_variant/src/lib.rs index 1f809dfedbf9..daa6c688befb 100644 --- a/crates/from_variant/src/lib.rs +++ b/crates/from_variant/src/lib.rs @@ -5,7 +5,7 @@ use syn::*; /// Derives [`From`] for all variants. This only supports an enum where every /// variant has a single field. -#[proc_macro_derive(FromVariant)] +#[proc_macro_derive(FromVariant, attributes(from_variant))] pub fn derive_from_variant(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input = parse::(input).expect("failed to parse input as DeriveInput"); @@ -19,6 +19,21 @@ pub fn derive_from_variant(input: proc_macro::TokenStream) -> proc_macro::TokenS print("derive(FromVariant)", item) } +fn is_ignored(attrs: &[syn::Attribute]) -> bool { + attrs + .iter() + .filter(|attr| attr.path().is_ident("from_variant")) + .any(|attr| { + let mut is_unknown = false; + attr.parse_nested_meta(|meta| { + is_unknown |= meta.path.is_ident("ignore"); + Ok(()) + }) + .unwrap(); + is_unknown + }) +} + fn derive( DeriveInput { generics, @@ -35,6 +50,10 @@ fn derive( let mut from_impls: Vec = Vec::new(); for v in variants { + if is_ignored(&v.attrs) { + continue; + } + let variant_name = v.ident; match v.fields { Fields::Unnamed(FieldsUnnamed { unnamed, .. }) => { diff --git a/crates/jsdoc/Cargo.toml b/crates/jsdoc/Cargo.toml index bda876f3c7db..b7e03b7e4454 100644 --- a/crates/jsdoc/Cargo.toml +++ b/crates/jsdoc/Cargo.toml @@ -14,10 +14,12 @@ bench = false [features] serde-impl = ["serde"] +encoding-impl = ["cbor4ii", "swc_atoms/encoding-impl", "swc_common/encoding-impl"] [dependencies] nom = { workspace = true } serde = { workspace = true, features = ["derive"], optional = true } +cbor4ii = { workspace = true, features = [ "use_std" ], optional = true } swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_common = { version = "14.0.4", path = "../swc_common" } diff --git a/crates/jsdoc/src/ast.rs b/crates/jsdoc/src/ast.rs index 8b98f083ccc4..d100c91ce109 100644 --- a/crates/jsdoc/src/ast.rs +++ b/crates/jsdoc/src/ast.rs @@ -29,8 +29,7 @@ pub struct TagItem { pub tag: Tag, } -#[ast_node] -#[non_exhaustive] +#[ast_node(no_unknown)] pub enum Tag { #[tag("Yield")] Yield(YieldTag), @@ -206,7 +205,15 @@ pub struct JSDocClassDescTag { #[ast_node] pub struct ConstTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, } @@ -256,7 +263,15 @@ pub struct AuthorTag { #[derive(Eq)] pub struct ClassTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, } @@ -270,6 +285,10 @@ pub struct PublicTag { #[derive(Eq)] pub struct PrivateTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, } @@ -277,6 +296,10 @@ pub struct PrivateTag { #[derive(Eq)] pub struct ProtectedTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, } @@ -297,6 +320,10 @@ pub struct PropertyTag { pub span: Span, pub name_path: NamePath, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, pub desc: Text, } @@ -305,8 +332,16 @@ pub struct PropertyTag { pub struct ParameterTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, #[cfg_attr(feature = "serde-impl", serde(rename = "typeExpression"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, pub desc: Text, @@ -322,6 +357,10 @@ pub struct EnumTag { #[ast_node] pub struct ReturnTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, pub description: Text, } @@ -341,6 +380,10 @@ pub struct TypeTag { #[ast_node] pub struct TemplateTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub constraint: Option, } @@ -348,14 +391,26 @@ pub struct TemplateTag { pub struct TypedefTag { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(rename = "full_name"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub full_name: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, #[cfg_attr(feature = "serde-impl", serde(rename = "typeExpression"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_expr: Option, } -#[ast_node] +#[ast_node(no_unknown)] pub enum Type { /// `*` #[tag("AllType")] @@ -552,6 +607,10 @@ pub struct FileTag { #[ast_node] pub struct FunctionTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, } @@ -587,6 +646,10 @@ pub struct InstanceTag { #[ast_node] pub struct InterfaceTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, } #[ast_node] @@ -629,6 +692,10 @@ pub struct MemberOfTag { #[ast_node] pub struct TypeDefTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, pub name_path: NamePath, } @@ -661,7 +728,15 @@ pub struct NameTag { #[ast_node] pub struct NamespaceTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, } @@ -673,6 +748,10 @@ pub struct OverrideTag { #[ast_node] pub struct PackageTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ty: Option, } @@ -738,6 +817,10 @@ pub struct VersionTag { #[ast_node] pub struct YieldTag { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option, pub description: Text, } diff --git a/crates/swc_atoms/Cargo.toml b/crates/swc_atoms/Cargo.toml index e66a468c564e..756753bc650a 100644 --- a/crates/swc_atoms/Cargo.toml +++ b/crates/swc_atoms/Cargo.toml @@ -14,6 +14,7 @@ bench = false [features] __rkyv = [] rkyv-impl = ["__rkyv", "rkyv", "bytecheck", "rancor"] +encoding-impl = ["cbor4ii"] shrink-to-fit = ["dep:shrink-to-fit"] [dependencies] @@ -25,5 +26,6 @@ rancor = { workspace = true, optional = true } rkyv = { workspace = true, optional = true } serde = { workspace = true } shrink-to-fit = { workspace = true, optional = true } +cbor4ii = { workspace = true, features = [ "use_std" ], optional = true } hstr = { version = "2.1.0", path = "../hstr" } diff --git a/crates/swc_atoms/src/lib.rs b/crates/swc_atoms/src/lib.rs index 07c584f10c8a..051bf76d65d5 100644 --- a/crates/swc_atoms/src/lib.rs +++ b/crates/swc_atoms/src/lib.rs @@ -34,6 +34,28 @@ mod fast; #[cfg_attr(feature = "rkyv-impl", repr(C))] pub struct Atom(hstr::Atom); +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for Atom { + #[inline] + fn encode( + &self, + writer: &mut W, + ) -> Result<(), cbor4ii::core::enc::Error> { + self.as_str().encode(writer) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de> cbor4ii::core::dec::Decode<'de> for Atom { + #[inline] + fn decode>( + reader: &mut R, + ) -> Result> { + let s = <&str>::decode(reader)?; + Ok(Atom::new(s)) + } +} + #[cfg(feature = "arbitrary")] #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))] impl<'a> arbitrary::Arbitrary<'a> for Atom { 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_common/Cargo.toml b/crates/swc_common/Cargo.toml index 4a6e31de6b26..0da7d8f3bf77 100644 --- a/crates/swc_common/Cargo.toml +++ b/crates/swc_common/Cargo.toml @@ -15,6 +15,9 @@ version = "14.0.4" [lib] bench = false +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] } + [features] __plugin = [] __plugin_mode = [] @@ -42,6 +45,7 @@ rkyv-impl = [ "bytecheck", "rancor", ] +encoding-impl = ["cbor4ii", "swc_atoms/encoding-impl"] shrink-to-fit = ["dep:shrink-to-fit", "swc_atoms/shrink-to-fit"] @@ -67,6 +71,7 @@ termcolor = { workspace = true, optional = true } tracing = { workspace = true } unicode-width = { workspace = true } url = { workspace = true } +cbor4ii = { workspace = true, features = [ "use_std" ], optional = true } ast_node = { version = "3.0.4", path = "../ast_node" } better_scoped_tls = { version = "1.0.1", path = "../better_scoped_tls" } @@ -75,7 +80,6 @@ swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_eq_ignore_macros = { version = "1.0.1", path = "../swc_eq_ignore_macros" } swc_visit = { version = "2.0.1", path = "../swc_visit" } - [dev-dependencies] par-iter = { workspace = true } serde_json = { workspace = true } diff --git a/crates/swc_common/src/lib.rs b/crates/swc_common/src/lib.rs index 8d09e8cc960d..bedc3a438677 100644 --- a/crates/swc_common/src/lib.rs +++ b/crates/swc_common/src/lib.rs @@ -32,7 +32,7 @@ use std::fmt::Debug; -pub use ast_node::{ast_node, ast_serde, DeserializeEnum, Spanned}; +pub use ast_node::{ast_node, ast_serde, Decode, DeserializeEnum, Encode, Spanned}; pub use from_variant::FromVariant; pub use swc_eq_ignore_macros::{EqIgnoreSpan, TypeEq}; @@ -69,6 +69,8 @@ pub mod serializer; pub mod source_map; pub mod sync; mod syntax_pos; +#[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] +pub mod unknown; pub mod util; #[cfg(all(not(debug_assertions), feature = "plugin-rt", feature = "plugin-mode"))] @@ -85,3 +87,9 @@ pub use self::syntax_pos::{ ArchivedBytePos, ArchivedCharPos, ArchivedFileName, ArchivedMultiSpan, ArchivedSourceFile, ArchivedSourceFileAndBytePos, ArchivedSpan, ArchivedSpanLinesError, ArchivedSpanSnippetError, }; + +#[cfg(swc_ast_unknown)] +#[track_caller] +pub fn unknown() -> ! { + panic!("unknown node") +} diff --git a/crates/swc_common/src/serializer.rs b/crates/swc_common/src/serializer.rs index 5449cfbd1abf..0b0140a75841 100644 --- a/crates/swc_common/src/serializer.rs +++ b/crates/swc_common/src/serializer.rs @@ -1,5 +1,5 @@ #![allow(deprecated)] -#![deprecated = "Not used by swc, and this will be removed with next breaking change"] + use serde::Deserialize; #[derive(Deserialize)] @@ -16,3 +16,62 @@ pub struct Type { #[serde(rename = "type")] pub ty: String, } + +#[cfg(feature = "encoding-impl")] +pub struct WithChar(pub T); + +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for WithChar<&char> { + fn encode( + &self, + writer: &mut W, + ) -> Result<(), cbor4ii::core::enc::Error> { + u32::from(*self.0).encode(writer) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de> cbor4ii::core::dec::Decode<'de> for WithChar { + fn decode>( + reader: &mut R, + ) -> Result> { + let n = u32::decode(reader)?; + let value = char::from_u32(n).ok_or_else(|| cbor4ii::core::dec::Error::Mismatch { + name: &"WithChar", + found: 0, + })?; + Ok(WithChar(value)) + } +} + +#[cfg(feature = "encoding-impl")] +pub struct ArrayOption(pub T); + +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for ArrayOption<&'_ Vec>> { + fn encode(&self, writer: &mut W) -> Result<(), cbor4ii::core::enc::Error> { + >::bounded(self.0.len(), writer)?; + for item in self.0.iter() { + cbor4ii::core::types::Maybe(item).encode(writer)?; + } + Ok(()) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de, T: cbor4ii::core::dec::Decode<'de>> cbor4ii::core::dec::Decode<'de> for ArrayOption>> { + fn decode>(reader: &mut R) -> Result> { + let len = >::len(reader)?; + let Some(len) = len else { + return Err(cbor4ii::core::error::DecodeError::RequireLength { + name: &"array-option", + found: len.map(cbor4ii::core::error::Len::new).unwrap_or(cbor4ii::core::error::Len::Indefinite), + }); + }; + let mut q = Vec::with_capacity(std::cmp::min(len, 128)); + for _ in 0..len { + q.push(>>::decode(reader)?.0); + } + Ok(ArrayOption(q)) + } +} diff --git a/crates/swc_common/src/syntax_pos.rs b/crates/swc_common/src/syntax_pos.rs index 3c1bbe5997e2..f1cb04b524cc 100644 --- a/crates/swc_common/src/syntax_pos.rs +++ b/crates/swc_common/src/syntax_pos.rs @@ -35,6 +35,10 @@ pub mod hygiene; )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(C))] +#[cfg_attr( + feature = "encoding-impl", + derive(::ast_node::Encode, ::ast_node::Decode) +)] #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] pub struct Span { #[serde(rename = "start")] @@ -1012,6 +1016,27 @@ pub trait SmallPos { #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] pub struct BytePos(#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))] pub u32); +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for BytePos { + #[inline] + fn encode( + &self, + writer: &mut W, + ) -> Result<(), cbor4ii::core::enc::Error> { + self.0.encode(writer) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de> cbor4ii::core::dec::Decode<'de> for BytePos { + #[inline] + fn decode>( + reader: &mut R, + ) -> Result> { + u32::decode(reader).map(BytePos) + } +} + impl BytePos { /// Dummy position. This is reserved for synthesized spans. pub const DUMMY: Self = BytePos(0); diff --git a/crates/swc_common/src/syntax_pos/hygiene.rs b/crates/swc_common/src/syntax_pos/hygiene.rs index 2de3cd470148..a76e589a5fc3 100644 --- a/crates/swc_common/src/syntax_pos/hygiene.rs +++ b/crates/swc_common/src/syntax_pos/hygiene.rs @@ -40,6 +40,27 @@ use crate::EqIgnoreSpan; #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] pub struct SyntaxContext(#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))] u32); +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for SyntaxContext { + #[inline] + fn encode( + &self, + writer: &mut W, + ) -> Result<(), cbor4ii::core::enc::Error> { + self.0.encode(writer) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de> cbor4ii::core::dec::Decode<'de> for SyntaxContext { + #[inline] + fn decode>( + reader: &mut R, + ) -> Result> { + u32::decode(reader).map(SyntaxContext) + } +} + #[cfg(feature = "arbitrary")] #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))] impl<'a> arbitrary::Arbitrary<'a> for SyntaxContext { diff --git a/crates/swc_common/src/unknown.rs b/crates/swc_common/src/unknown.rs new file mode 100644 index 000000000000..24b2d298eb01 --- /dev/null +++ b/crates/swc_common/src/unknown.rs @@ -0,0 +1,139 @@ +use cbor4ii::core::{dec, enc}; + +use crate::eq::EqIgnoreSpan; + +#[derive(Clone)] +pub struct Unknown(cbor4ii::core::BoxedRawValue); + +impl enc::Encode for Unknown { + fn encode(&self, writer: &mut W) -> Result<(), enc::Error> { + self.0.encode(writer) + } +} + +impl<'de> dec::Decode<'de> for Unknown { + fn decode>(reader: &mut R) -> Result> { + cbor4ii::core::BoxedRawValue::decode(reader).map(Unknown) + } +} + +impl PartialEq for Unknown { + fn eq(&self, other: &Self) -> bool { + self.0.as_bytes() == other.0.as_bytes() + } +} + +impl Eq for Unknown {} + +impl EqIgnoreSpan for Unknown { + fn eq_ignore_span(&self, other: &Self) -> bool { + self.0.as_bytes() == other.0.as_bytes() + } +} + +impl std::hash::Hash for Unknown { + fn hash(&self, state: &mut H) { + self.0.as_bytes().hash(state) + } +} + +#[cfg(feature = "rkyv-impl")] +#[derive(Debug)] +struct UnknownError; + +#[cfg(feature = "rkyv-impl")] +impl std::error::Error for UnknownError {} + +#[cfg(feature = "rkyv-impl")] +impl std::fmt::Display for UnknownError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "cannot access unknown type") + } +} + +#[cfg(feature = "rkyv-impl")] +impl rkyv::Archive for Unknown { + type Archived = std::marker::PhantomData; + type Resolver = (); + + fn resolve(&self, _resolver: Self::Resolver, _out: rkyv::Place) { + // + } +} + +/// NOT A PUBLIC API +#[cfg(feature = "rkyv-impl")] +impl rkyv::Serialize for Unknown +where + S: rancor::Fallible + rkyv::ser::Writer + ?Sized, + S::Error: rancor::Source, +{ + fn serialize(&self, _serializer: &mut S) -> Result { + Err(::new(UnknownError)) + } +} + +/// NOT A PUBLIC API +#[cfg(feature = "rkyv-impl")] +impl rkyv::Deserialize for std::marker::PhantomData +where + D: ?Sized + rancor::Fallible, + D::Error: rancor::Source, +{ + fn deserialize( + &self, + _deserializer: &mut D, + ) -> Result::Error> { + Err(::new(UnknownError)) + } +} + +impl std::fmt::Debug for Unknown { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Unknown") + } +} + +impl serde::Serialize for Unknown { + fn serialize(&self, _serializer: S) -> Result + where + S: serde::Serializer, + { + use serde::ser::Error; + + Err(S::Error::custom("cannot serialize unknown type")) + } +} + +impl<'de> serde::Deserialize<'de> for Unknown { + fn deserialize(_deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + use serde::de::Error; + + Err(D::Error::custom("cannot deserialize unknown type")) + } +} + +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for Unknown { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + use cbor4ii::core::{ Value, BoxedRawValue }; + + let mut list = Vec::new(); + for _ in 0..u.arbitrary_len::()? { + let n = u.int_in_range::(0..=102410241024)?; + list.push(Value::Integer(n.into())); + } + let value = Value::Array(list); + let value = BoxedRawValue::from_value(&value) + .map_err(|_| arbitrary::Error::IncorrectFormat)?; + Ok(Unknown(value)) + } +} + +#[cfg(feature = "shrink-to-fit")] +impl shrink_to_fit::ShrinkToFit for Unknown { + fn shrink_to_fit(&mut self) {} +} diff --git a/crates/swc_css_ast/Cargo.toml b/crates/swc_css_ast/Cargo.toml index 8391d1bed391..2d96eaedf339 100644 --- a/crates/swc_css_ast/Cargo.toml +++ b/crates/swc_css_ast/Cargo.toml @@ -22,6 +22,7 @@ rkyv-impl = [ "bytecheck", ] serde-impl = ["serde"] +encoding-impl = ["cbor4ii", "swc_atoms/encoding-impl", "swc_common/encoding-impl"] [dependencies] bytecheck = { workspace = true, optional = true } @@ -33,3 +34,4 @@ swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_common = { version = "14.0.4", path = "../swc_common" } rkyv = { workspace = true, optional = true } +cbor4ii = { workspace = true, features = [ "use_std" ], optional = true } diff --git a/crates/swc_css_ast/src/at_rule.rs b/crates/swc_css_ast/src/at_rule.rs index 062c200b41b0..b986304de805 100644 --- a/crates/swc_css_ast/src/at_rule.rs +++ b/crates/swc_css_ast/src/at_rule.rs @@ -14,11 +14,19 @@ use crate::{ pub struct AtRule { pub span: Span, pub name: AtRuleName, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub prelude: Option>, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub block: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AtRuleName { #[tag("DashedIdent")] @@ -46,7 +54,7 @@ impl PartialEq for AtRuleName { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AtRulePrelude { #[tag("ListOfComponentValues")] @@ -94,12 +102,20 @@ pub enum AtRulePrelude { pub struct ScopeRange { pub span: Span, /// https://drafts.csswg.org/css-cascade-6/#typedef-scope-start + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub scope_start: Option, /// https://drafts.csswg.org/css-cascade-6/#typedef-scope-end + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub scope_end: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ColorProfileName { #[tag("DashedIdent")] @@ -122,7 +138,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 +147,7 @@ pub enum DocumentPreludeMatchingFunction { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum KeyframesName { #[tag("CustomIdent")] @@ -170,7 +186,7 @@ pub struct KeyframeBlock { pub block: SimpleBlock, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum KeyframeSelector { #[tag("Ident")] @@ -184,11 +200,19 @@ pub enum KeyframeSelector { pub struct ImportPrelude { pub span: Span, pub href: Box, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub layer_name: Option>, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub import_conditions: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ImportHref { #[tag("Url")] @@ -197,7 +221,7 @@ pub enum ImportHref { Str(Str), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ImportLayerName { #[tag("Ident")] @@ -210,7 +234,15 @@ pub enum ImportLayerName { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct ImportConditions { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub supports: Option>, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub media: Option>, } @@ -218,11 +250,15 @@ pub struct ImportConditions { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct NamespacePrelude { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub prefix: Option, pub uri: Box, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum NamespacePreludeUri { #[tag("Url")] @@ -242,9 +278,25 @@ pub struct MediaQueryList { #[derive(Eq, Hash)] pub struct MediaQuery { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub modifier: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub media_type: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub condition: Option>, } @@ -269,14 +321,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 +352,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 +368,7 @@ pub enum MediaConditionAllType { MediaInParens(MediaInParens), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaConditionWithoutOrType { #[tag("MediaNot")] @@ -333,6 +385,10 @@ pub enum MediaConditionWithoutOrType { #[derive(Eq, Hash)] pub struct MediaNot { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub condition: MediaInParens, } @@ -347,6 +403,10 @@ impl EqIgnoreSpan for MediaNot { #[derive(Eq, Hash)] pub struct MediaAnd { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub condition: MediaInParens, } @@ -361,6 +421,10 @@ impl EqIgnoreSpan for MediaAnd { #[derive(Eq, Hash)] pub struct MediaOr { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub condition: MediaInParens, } @@ -371,7 +435,7 @@ impl EqIgnoreSpan for MediaOr { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaInParens { #[tag("MediaCondition")] @@ -384,7 +448,7 @@ pub enum MediaInParens { GeneralEnclosed(GeneralEnclosed), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaFeature { #[tag("MediaFeaturePlain")] @@ -400,7 +464,7 @@ pub enum MediaFeature { RangeInterval(MediaFeatureRangeInterval), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaFeatureName { #[tag("Ident")] @@ -410,7 +474,7 @@ pub enum MediaFeatureName { ExtensionName(ExtensionName), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum MediaFeatureValue { #[tag("Number")] @@ -451,6 +515,10 @@ pub struct MediaFeatureBoolean { )] #[cfg_attr(feature = "rkyv", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] //#[cfg_attr( // feature = "rkyv", // archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + @@ -502,7 +570,7 @@ pub struct SupportsCondition { pub conditions: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SupportsConditionType { #[tag("SupportsNot")] @@ -522,6 +590,10 @@ pub enum SupportsConditionType { #[derive(Eq, Hash)] pub struct SupportsNot { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub condition: Box, } @@ -536,6 +608,10 @@ impl EqIgnoreSpan for SupportsNot { #[derive(Eq, Hash)] pub struct SupportsAnd { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub condition: Box, } @@ -550,6 +626,10 @@ impl EqIgnoreSpan for SupportsAnd { #[derive(Eq, Hash)] pub struct SupportsOr { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub condition: Box, } @@ -560,7 +640,7 @@ impl EqIgnoreSpan for SupportsOr { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SupportsInParens { #[tag("SupportsCondition")] @@ -573,7 +653,7 @@ pub enum SupportsInParens { GeneralEnclosed(GeneralEnclosed), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SupportsFeature { #[tag("Declaration")] @@ -582,7 +662,7 @@ pub enum SupportsFeature { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum GeneralEnclosed { #[tag("Function")] @@ -602,7 +682,15 @@ pub struct PageSelectorList { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct PageSelector { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub page_type: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub pseudos: Option>, } @@ -620,7 +708,7 @@ pub struct PageSelectorPseudo { pub value: Ident, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum LayerPrelude { #[tag("LayerName")] @@ -647,11 +735,15 @@ pub struct LayerNameList { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct ContainerCondition { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, pub query: ContainerQuery, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ContainerName { #[tag("CustomIdent")] @@ -665,7 +757,7 @@ pub struct ContainerQuery { pub queries: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum ContainerQueryType { #[tag("ContainerQueryNot")] @@ -685,6 +777,10 @@ pub enum ContainerQueryType { #[derive(Eq, Hash)] pub struct ContainerQueryNot { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub query: QueryInParens, } @@ -699,6 +795,10 @@ impl EqIgnoreSpan for ContainerQueryNot { #[derive(Eq, Hash)] pub struct ContainerQueryAnd { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub query: QueryInParens, } @@ -713,6 +813,10 @@ impl EqIgnoreSpan for ContainerQueryAnd { #[derive(Eq, Hash)] pub struct ContainerQueryOr { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub keyword: Option, pub query: QueryInParens, } @@ -723,7 +827,7 @@ impl EqIgnoreSpan for ContainerQueryOr { } } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum QueryInParens { #[tag("ContainerQuery")] @@ -740,7 +844,7 @@ pub enum QueryInParens { GeneralEnclosed(GeneralEnclosed), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SizeFeature { #[tag("SizeFeaturePlain")] @@ -783,6 +887,10 @@ pub struct SizeFeatureBoolean { // archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + // rkyv::ser::Serializer")) //)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum SizeFeatureRangeComparison { /// `<` Lt, @@ -822,7 +930,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 +949,7 @@ pub enum SizeFeatureValue { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SizeFeatureName { #[tag("Ident")] @@ -853,6 +961,10 @@ pub enum SizeFeatureName { pub struct ExtensionName { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -893,7 +1005,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..ad0fa3f9b61c 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")] @@ -303,10 +303,14 @@ pub struct Declaration { pub name: DeclarationName, pub value: Vec, /// The span includes `!` + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] 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..aa2a56f67401 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")] @@ -96,6 +96,10 @@ pub enum ComplexSelectorChildren { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct RelativeSelector { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub combinator: Option, pub selector: ComplexSelector, } @@ -106,7 +110,15 @@ pub struct RelativeSelector { pub struct CompoundSelector { pub span: Span, /// "&" + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub nesting_selector: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_selector: Option>, pub subclass_selectors: Vec, } @@ -130,6 +142,10 @@ pub struct Combinator { )] #[cfg_attr(feature = "rkyv", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum CombinatorValue { /// ` ` Descendant, @@ -153,7 +169,7 @@ pub struct NestingSelector { pub span: Span, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum TypeSelector { #[tag("TagNameSelector")] @@ -173,6 +189,10 @@ pub struct TagNameSelector { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct UniversalSelector { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub prefix: Option, } @@ -180,10 +200,14 @@ pub struct UniversalSelector { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct NamespacePrefix { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub namespace: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Namespace { #[tag("NamedNamespace")] @@ -209,11 +233,15 @@ pub struct AnyNamespace { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct WqName { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub prefix: Option, pub value: Ident, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum SubclassSelector { #[tag("IdSelector")] @@ -253,8 +281,20 @@ pub struct ClassSelector { pub struct AttributeSelector { pub span: Span, pub name: WqName, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub matcher: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub modifier: Option, } @@ -270,6 +310,10 @@ pub struct AttributeSelector { // archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + // rkyv::ser::Serializer")) //)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum AttributeSelectorMatcherValue { /// `=` Equals, @@ -297,7 +341,7 @@ pub struct AttributeSelectorMatcher { pub value: AttributeSelectorMatcherValue, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AttributeSelectorValue { #[tag("String")] @@ -319,10 +363,14 @@ pub struct AttributeSelectorModifier { pub struct PseudoClassSelector { pub span: Span, pub name: Ident, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub children: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum PseudoClassSelectorChildren { #[tag("TokenAndSpan")] @@ -362,7 +410,7 @@ pub enum PseudoClassSelectorChildren { CompoundSelector(CompoundSelector), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AnPlusB { #[tag("Ident")] @@ -375,9 +423,25 @@ pub enum AnPlusB { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct AnPlusBNotation { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub a: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub a_raw: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub b: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub b_raw: Option, } @@ -386,10 +450,14 @@ pub struct AnPlusBNotation { pub struct PseudoElementSelector { pub span: Span, pub name: Ident, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub children: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum PseudoElementSelectorChildren { #[tag("TokenAndSpan")] @@ -408,6 +476,10 @@ pub struct CustomHighlightName { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } diff --git a/crates/swc_css_ast/src/token.rs b/crates/swc_css_ast/src/token.rs index ab89d6307a01..4e0eb5bdc287 100644 --- a/crates/swc_css_ast/src/token.rs +++ b/crates/swc_css_ast/src/token.rs @@ -30,6 +30,10 @@ impl Take for TokenAndSpan { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(C))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub struct UrlKeyValue(pub Atom, pub Atom); #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Is, EqIgnoreSpan)] @@ -45,6 +49,10 @@ pub struct UrlKeyValue(pub Atom, pub Atom); __S::Error: rkyv::rancor::Source)) )] #[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum NumberType { #[cfg_attr(feature = "serde-impl", serde(rename = "integer"))] Integer, @@ -60,6 +68,10 @@ pub enum NumberType { #[cfg_attr(feature = "rkyv", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv", repr(C))] #[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub struct DimensionToken { pub value: f64, pub raw_value: Atom, @@ -84,6 +96,10 @@ pub struct DimensionToken { __S::Error: rkyv::rancor::Source)) )] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum Token { Ident { value: Atom, @@ -122,6 +138,10 @@ pub enum Token { raw: Atom, }, Delim { + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "::swc_common::serializer::WithChar") + )] value: char, }, Number { @@ -134,7 +154,9 @@ pub enum Token { value: f64, raw: Atom, }, - Dimension(Box), + Dimension { + dimension: Box, + }, /// One or more whitespace. WhiteSpace { value: Atom, @@ -235,7 +257,7 @@ impl Hash for Token { integer_decode(*value).hash(state); raw.hash(state); } - Token::Dimension(dimension) => { + Token::Dimension { dimension } => { integer_decode(dimension.value).hash(state); dimension.unit.hash(state); dimension.type_flag.hash(state); diff --git a/crates/swc_css_ast/src/value.rs b/crates/swc_css_ast/src/value.rs index 5bde31084d6b..4203f4ddab3e 100644 --- a/crates/swc_css_ast/src/value.rs +++ b/crates/swc_css_ast/src/value.rs @@ -13,6 +13,10 @@ pub struct Ident { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -47,6 +51,10 @@ pub struct CustomIdent { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -63,6 +71,10 @@ pub struct DashedIdent { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -86,6 +98,10 @@ pub struct CustomPropertyName { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -102,6 +118,10 @@ pub struct Str { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -123,6 +143,10 @@ impl EqIgnoreSpan for Str { )] #[cfg_attr(feature = "rkyv", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum DelimiterValue { /// `,` Comma, @@ -141,7 +165,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 +177,7 @@ pub enum Color { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AbsoluteColorBase { #[tag("HexColor")] @@ -172,10 +196,14 @@ pub struct HexColor { /// Does **not** include `#` pub value: Atom, /// Does **not** include `#` + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AlphaValue { #[tag("Number")] @@ -184,7 +212,7 @@ pub enum AlphaValue { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Hue { #[tag("Number")] @@ -193,7 +221,7 @@ pub enum Hue { Angle(Angle), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CmykComponent { #[tag("Number")] @@ -204,7 +232,7 @@ pub enum CmykComponent { Function(Function), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum Dimension { #[tag("Length")] @@ -292,7 +320,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 +329,7 @@ pub enum LengthPercentage { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum FrequencyPercentage { #[tag("Frequency")] @@ -310,7 +338,7 @@ pub enum FrequencyPercentage { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum AnglePercentage { #[tag("Angle")] @@ -319,7 +347,7 @@ pub enum AnglePercentage { Percentage(Percentage), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum TimePercentage { #[tag("Time")] @@ -333,6 +361,10 @@ pub enum TimePercentage { pub struct Integer { pub span: Span, pub value: i64, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -346,6 +378,10 @@ impl EqIgnoreSpan for Integer { pub struct Number { pub span: Span, pub value: f64, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -385,6 +421,10 @@ impl EqIgnoreSpan for Number { pub struct Ratio { pub span: Span, pub left: Number, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub right: Option, } @@ -400,6 +440,10 @@ pub struct Ratio { )] #[cfg_attr(feature = "rkyv", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum BinOp { /// `+` Add, @@ -416,11 +460,19 @@ pub enum BinOp { pub struct Url { pub span: Span, pub name: Ident, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option>, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub modifiers: Option>, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum UrlValue { #[tag("Str")] @@ -435,10 +487,14 @@ pub struct UrlValueRaw { pub span: Span, pub value: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum UrlModifier { #[tag("Ident")] @@ -454,7 +510,15 @@ pub struct UnicodeRange { pub start: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub end: Option, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -472,7 +536,7 @@ pub struct CalcSum { pub expressions: Vec, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CalcProductOrOperator { #[tag("CalcProduct")] @@ -507,6 +571,10 @@ pub struct CalcOperator { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum CalcOperatorType { /// `+` Add, @@ -518,7 +586,7 @@ pub enum CalcOperatorType { Div, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CalcValueOrOperator { #[tag("CalcValue")] @@ -527,7 +595,7 @@ pub enum CalcValueOrOperator { Operator(CalcOperator), } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum CalcValue { #[tag("Number")] @@ -544,7 +612,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_css_codegen/src/lib.rs b/crates/swc_css_codegen/src/lib.rs index 8857afa2680f..0e1fc1a8c745 100644 --- a/crates/swc_css_codegen/src/lib.rs +++ b/crates/swc_css_codegen/src/lib.rs @@ -1865,7 +1865,7 @@ where write_raw!(self, span, &percentage); } - Token::Dimension(token) => { + Token::Dimension { dimension: token } => { let mut dimension = String::with_capacity(token.raw_value.len() + token.raw_unit.len()); diff --git a/crates/swc_css_lints/src/rules/unit_no_unknown.rs b/crates/swc_css_lints/src/rules/unit_no_unknown.rs index 94248a89438a..231b8fce227f 100644 --- a/crates/swc_css_lints/src/rules/unit_no_unknown.rs +++ b/crates/swc_css_lints/src/rules/unit_no_unknown.rs @@ -52,7 +52,7 @@ impl Visit for UnitNoUnknown { fn visit_component_value(&mut self, component_value: &ComponentValue) { if let Some(token_and_span) = component_value.as_preserved_token() { if let Some(unit) = match &token_and_span.token { - Token::Dimension(dimension_token) => Some(dimension_token.unit.as_ref()), + Token::Dimension { dimension: dimension_token } => Some(dimension_token.unit.as_ref()), _ => None, } { if self.ignored_units.iter().all(|item| !item.is_match(unit)) { diff --git a/crates/swc_css_minifier/src/compressor/mod.rs b/crates/swc_css_minifier/src/compressor/mod.rs index 7d91afab17f4..6e86da12796c 100644 --- a/crates/swc_css_minifier/src/compressor/mod.rs +++ b/crates/swc_css_minifier/src/compressor/mod.rs @@ -462,7 +462,7 @@ impl VisitMut for Compressor { Token::BadUrl { raw: value, .. } if !contains_only_ascii_characters(value) => { self.need_utf8_at_rule = true; } - Token::Dimension(dimension_token) + Token::Dimension { dimension: dimension_token } if !contains_only_ascii_characters(&dimension_token.unit) => { self.need_utf8_at_rule = true; diff --git a/crates/swc_css_parser/src/lexer/mod.rs b/crates/swc_css_parser/src/lexer/mod.rs index 3ff7cc011cd6..904633584aab 100644 --- a/crates/swc_css_parser/src/lexer/mod.rs +++ b/crates/swc_css_parser/src/lexer/mod.rs @@ -586,13 +586,14 @@ where let ident_sequence = self.read_ident_sequence()?; // Create a with the same value and type flag as number, and a // unit set initially to the empty string. - let token = Token::Dimension(Box::new(DimensionToken { + let token = Box::new(DimensionToken { value: number.0, raw_value: number.1, unit: ident_sequence.0, raw_unit: ident_sequence.1, type_flag: number.2, - })); + }); + let token = Token::Dimension { dimension: token }; // Return the . return Ok(token); diff --git a/crates/swc_css_parser/src/parser/selectors/mod.rs b/crates/swc_css_parser/src/parser/selectors/mod.rs index 9e50d65cc0ca..230726ea329d 100644 --- a/crates/swc_css_parser/src/parser/selectors/mod.rs +++ b/crates/swc_css_parser/src/parser/selectors/mod.rs @@ -1281,7 +1281,7 @@ where } tok!("dimension") => { let dimension = match bump!(self) { - Token::Dimension(dimension) => { + Token::Dimension { dimension } => { let DimensionToken { value, raw_value, unit, .. } = *dimension; (value, raw_value, unit) diff --git a/crates/swc_css_parser/src/parser/values_and_units/mod.rs b/crates/swc_css_parser/src/parser/values_and_units/mod.rs index 6860389eb95e..61ff87c138b6 100644 --- a/crates/swc_css_parser/src/parser/values_and_units/mod.rs +++ b/crates/swc_css_parser/src/parser/values_and_units/mod.rs @@ -1964,7 +1964,7 @@ where } match cur!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { match &dimension_token.unit { // unit if is_length_unit(unit) @@ -2004,7 +2004,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2050,7 +2050,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2101,7 +2101,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2149,7 +2149,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2197,7 +2197,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2248,7 +2248,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2296,7 +2296,7 @@ where } match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { let DimensionToken { value, unit, @@ -2805,7 +2805,7 @@ where } tok!("dimension") => { let raw = match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { (dimension_token.raw_value, dimension_token.raw_unit) } _ => { @@ -2833,7 +2833,7 @@ where // u '?'* tok!("dimension") => { let raw = match bump!(self) { - Token::Dimension(dimension_token) => { + Token::Dimension { dimension: dimension_token } => { (dimension_token.raw_value, dimension_token.raw_unit) } _ => { diff --git a/crates/swc_css_parser/tests/fixture/at-rule/media/output.json b/crates/swc_css_parser/tests/fixture/at-rule/media/output.json index 96139f503b41..be92500276c7 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/media/output.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/media/output.json @@ -13630,11 +13630,13 @@ }, "token": { "Dimension": { - "value": 600.0, - "raw_value": "600", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 600.0, + "raw_value": "600", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } @@ -14045,11 +14047,13 @@ }, "token": { "Dimension": { - "value": 600.0, - "raw_value": "600", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 600.0, + "raw_value": "600", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } @@ -14401,11 +14405,13 @@ }, "token": { "Dimension": { - "value": 100.0, - "raw_value": "100", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } @@ -14511,11 +14517,13 @@ }, "token": { "Dimension": { - "value": 100.0, - "raw_value": "100", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr b/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr index f7259f5017ac..ef1897e45911 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr @@ -18704,7 +18704,7 @@ : ^^^^^ 143 | @media (height foo bar) {} `---- - x Dimension(DimensionToken { value: 600.0, raw_value: "600", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 600.0, raw_value: "600", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/at-rule/media/input.css:142:1] 141 | 142 | @media (height << 600px) {} @@ -19180,7 +19180,7 @@ : ^^^^^ 146 | @media screen and (min-width: ) {} `---- - x Dimension(DimensionToken { value: 600.0, raw_value: "600", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 600.0, raw_value: "600", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/at-rule/media/input.css:145:1] 144 | @media (height foo("bar")) {} 145 | @media (height + 600px) {} @@ -19600,7 +19600,7 @@ : ^^^^^ 149 | @media screen and func(100px) {} `---- - x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/at-rule/media/input.css:148:1] 147 | @media (aspect-ratio: 12/) {} 148 | @media func(100px) {} @@ -19726,7 +19726,7 @@ : ^^^^^ 150 | @media(min-width:calc(10px + 10px)) {} `---- - x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/at-rule/media/input.css:149:1] 148 | @media func(100px) {} 149 | @media screen and func(100px) {} diff --git a/crates/swc_css_parser/tests/fixture/function/calc/output.json b/crates/swc_css_parser/tests/fixture/function/calc/output.json index fa6506e6ddcf..d40f430bc206 100644 --- a/crates/swc_css_parser/tests/fixture/function/calc/output.json +++ b/crates/swc_css_parser/tests/fixture/function/calc/output.json @@ -333,11 +333,13 @@ }, "token": { "Dimension": { - "value": 30.0, - "raw_value": "30", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 30.0, + "raw_value": "30", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr b/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr index 3b939c158668..69962be2ad3d 100644 --- a/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr @@ -609,7 +609,7 @@ 6 | --width: calc(10% + 30px); : ^^^^ `---- - x Dimension(DimensionToken { value: 30.0, raw_value: "30", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 30.0, raw_value: "30", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/function/calc/input.css:6:1] 5 | div { 6 | --width: calc(10% + 30px); diff --git a/crates/swc_css_parser/tests/fixture/function/unknown/output.json b/crates/swc_css_parser/tests/fixture/function/unknown/output.json index e9bb74918e52..c7377d4f1dac 100644 --- a/crates/swc_css_parser/tests/fixture/function/unknown/output.json +++ b/crates/swc_css_parser/tests/fixture/function/unknown/output.json @@ -179,11 +179,13 @@ }, "token": { "Dimension": { - "value": 100.0, - "raw_value": "100", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } @@ -232,11 +234,13 @@ }, "token": { "Dimension": { - "value": 100.0, - "raw_value": "100", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr b/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr index 7405a6260c64..df567bcfbd9d 100644 --- a/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr @@ -218,7 +218,7 @@ : ^^^^^ 4 | prod: --fn--fn(100px); `---- - x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] 2 | prod: fn(100px); 3 | prod: --fn(100px); @@ -281,7 +281,7 @@ : ^^^^^ 5 | } `---- - x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/function/unknown/input.css:4:1] 3 | prod: --fn(100px); 4 | prod: --fn--fn(100px); diff --git a/crates/swc_css_parser/tests/fixture/style-block/output.json b/crates/swc_css_parser/tests/fixture/style-block/output.json index e254185cbfe8..93cee01d624e 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/output.json +++ b/crates/swc_css_parser/tests/fixture/style-block/output.json @@ -3101,11 +3101,13 @@ }, "token": { "Dimension": { - "value": 100.0, - "raw_value": "100", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -3933,11 +3935,13 @@ }, "token": { "Dimension": { - "value": 16.0, - "raw_value": "16", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 16.0, + "raw_value": "16", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -4002,11 +4006,13 @@ }, "token": { "Dimension": { - "value": 16.0, - "raw_value": "16", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 16.0, + "raw_value": "16", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr b/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr index 82fd6410652e..d988fcfe6970 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr @@ -3985,7 +3985,7 @@ : ^^^^^ 93 | } `---- - x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 100.0, raw_value: "100", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/style-block/input.css:92:1] 91 | @mixin mobile { 92 | height: 100px; @@ -4914,7 +4914,7 @@ : ^^^^ 112 | height: 16px; `---- - x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/style-block/input.css:111:1] 110 | --small-icon: { 111 | width: 16px; @@ -4998,7 +4998,7 @@ : ^^^^ 113 | } `---- - x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/style-block/input.css:112:1] 111 | width: 16px; 112 | height: 16px; diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/output.json b/crates/swc_css_parser/tests/fixture/value/custom-property/output.json index 61a0c4951388..ede6baa475c5 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/output.json +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/output.json @@ -567,11 +567,13 @@ }, "token": { "Dimension": { - "value": 100.0, - "raw_value": "100", - "unit": "vw", - "type": "integer", - "raw_unit": "vw" + "dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "vw", + "type": "integer", + "raw_unit": "vw" + } } } } @@ -2546,11 +2548,13 @@ }, "token": { "Dimension": { - "value": 16.0, - "raw_value": "16", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 16.0, + "raw_value": "16", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -2615,11 +2619,13 @@ }, "token": { "Dimension": { - "value": 16.0, - "raw_value": "16", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 16.0, + "raw_value": "16", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr b/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr index 746efe7ab587..ce35d0d82424 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr @@ -899,7 +899,7 @@ : ^^^^^ 19 | --color: #06c; `---- - x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: "vw", type_flag: Integer, raw_unit: "vw" }) + x Dimension { dimension: DimensionToken { value: 100.0, raw_value: "100", unit: "vw", type_flag: Integer, raw_unit: "vw" } } ,-[$DIR/tests/fixture/value/custom-property/input.css:18:1] 17 | --number: 1; 18 | --unit: 100vw; @@ -3390,7 +3390,7 @@ : ^^^^ 54 | height: 16px; `---- - x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/value/custom-property/input.css:53:1] 52 | --small-icon: { 53 | width: 16px; @@ -3474,7 +3474,7 @@ : ^^^^ 55 | } `---- - x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 16.0, raw_value: "16", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/value/custom-property/input.css:54:1] 53 | width: 16px; 54 | height: 16px; diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json index 8d8d23323e78..78d9b2b3aa86 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json @@ -289,11 +289,13 @@ }, "token": { "Dimension": { - "value": 12.0, - "raw_value": "12", - "unit": "em", - "type": "integer", - "raw_unit": "em" + "dimension": { + "value": 12.0, + "raw_value": "12", + "unit": "em", + "type": "integer", + "raw_unit": "em" + } } } } @@ -324,11 +326,13 @@ }, "token": { "Dimension": { - "value": 75.0, - "raw_value": "75", - "unit": "ms", - "type": "integer", - "raw_unit": "ms" + "dimension": { + "value": 75.0, + "raw_value": "75", + "unit": "ms", + "type": "integer", + "raw_unit": "ms" + } } } } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr index d75308db7a46..43a27569daae 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr @@ -431,7 +431,7 @@ : ^^^^ 9 | --time: 75ms; `---- - x Dimension(DimensionToken { value: 12.0, raw_value: "12", unit: "em", type_flag: Integer, raw_unit: "em" }) + x Dimension { dimension: DimensionToken { value: 12.0, raw_value: "12", unit: "em", type_flag: Integer, raw_unit: "em" } } ,-[$DIR/tests/fixture/vendor/rome/custom-properties/input.css:8:1] 7 | --number: 37; 8 | --length: 12em; @@ -473,7 +473,7 @@ : ^^^^ 10 | --function: foo(); `---- - x Dimension(DimensionToken { value: 75.0, raw_value: "75", unit: "ms", type_flag: Integer, raw_unit: "ms" }) + x Dimension { dimension: DimensionToken { value: 75.0, raw_value: "75", unit: "ms", type_flag: Integer, raw_unit: "ms" } } ,-[$DIR/tests/fixture/vendor/rome/custom-properties/input.css:9:1] 8 | --length: 12em; 9 | --time: 75ms; diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json index 130d52e34322..290d30948b1b 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json @@ -95,11 +95,13 @@ }, "token": { "Dimension": { - "value": 2.0, - "raw_value": "2", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 2.0, + "raw_value": "2", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr index 82bf1a32a98e..8f4ba555a16b 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr @@ -119,7 +119,7 @@ : ^^^ 3 | border: var(--fancy); `---- - x Dimension(DimensionToken { value: 2.0, raw_value: "2", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 2.0, raw_value: "2", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/fixture/vendor/rome/functions/input.css:2:1] 1 | .style { 2 | --fancy: 2px; diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json index 009c0df107ee..c5988b01ad48 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json @@ -145,11 +145,13 @@ }, "token": { "Dimension": { - "value": 900.0, - "raw_value": "900", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 900.0, + "raw_value": "900", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } @@ -248,11 +250,13 @@ }, "token": { "Dimension": { - "value": 1200.0, - "raw_value": "1200", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 1200.0, + "raw_value": "1200", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr index ac01b6190027..b95bc44f045b 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr @@ -123,7 +123,7 @@ 1 | @media screen and (min-width: 900px) or (min-width: 1200px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 900.0, raw_value: "900", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 900.0, raw_value: "900", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/condition-and-or/input.css:1:1] 1 | @media screen and (min-width: 900px) or (min-width: 1200px) {} : ^^^^^ @@ -208,7 +208,7 @@ 1 | @media screen and (min-width: 900px) or (min-width: 1200px) {} : ^^^^^^ `---- - x Dimension(DimensionToken { value: 1200.0, raw_value: "1200", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 1200.0, raw_value: "1200", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/condition-and-or/input.css:1:1] 1 | @media screen and (min-width: 900px) or (min-width: 1200px) {} : ^^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json index 44efcdaf13dd..6aa1409f4696 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json @@ -62,11 +62,13 @@ }, "token": { "Dimension": { - "value": 20.0, - "raw_value": "20", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 20.0, + "raw_value": "20", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -98,11 +100,13 @@ }, "token": { "Dimension": { - "value": 20.0, - "raw_value": "20", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 20.0, + "raw_value": "20", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr index a8e26406f861..7da324bcde96 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr @@ -53,7 +53,7 @@ 1 | @media (20px: 20px) {} : ^^^^ `---- - x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-name-1/input.css:1:1] 1 | @media (20px: 20px) {} : ^^^^ @@ -83,7 +83,7 @@ 1 | @media (20px: 20px) {} : ^^^^ `---- - x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-name-1/input.css:1:1] 1 | @media (20px: 20px) {} : ^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json index caa4e0aa456d..881bceacff88 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json @@ -95,11 +95,13 @@ }, "token": { "Dimension": { - "value": 20.0, - "raw_value": "20", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 20.0, + "raw_value": "20", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr index de2cedd1780b..a0fd6a97d62a 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr @@ -83,7 +83,7 @@ 1 | @media ("min-width": 20px) {} : ^^^^ `---- - x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-name/input.css:1:1] 1 | @media ("min-width": 20px) {} : ^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json index d480183a2d8a..ff05bd5819b7 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json @@ -62,11 +62,13 @@ }, "token": { "Dimension": { - "value": 400.0, - "raw_value": "400", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 400.0, + "raw_value": "400", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -163,11 +165,13 @@ }, "token": { "Dimension": { - "value": 700.0, - "raw_value": "700", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 700.0, + "raw_value": "700", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr index 612ec3114ad1..e7413ddfd0b4 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr @@ -53,7 +53,7 @@ 1 | @media (400px > "width" > 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-2/input.css:1:1] 1 | @media (400px > "width" > 700px) {} : ^^^^^ @@ -133,7 +133,7 @@ 1 | @media (400px > "width" > 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-2/input.css:1:1] 1 | @media (400px > "width" > 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json index ca7d303fbaaf..55fdeac26093 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json @@ -62,11 +62,13 @@ }, "token": { "Dimension": { - "value": 400.0, - "raw_value": "400", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 400.0, + "raw_value": "400", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -211,11 +213,13 @@ }, "token": { "Dimension": { - "value": 700.0, - "raw_value": "700", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 700.0, + "raw_value": "700", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr index 2bba7c771d03..5ba418961bde 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr @@ -53,7 +53,7 @@ 1 | @media (400px > = width > = 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-3/input.css:1:1] 1 | @media (400px > = width > = 700px) {} : ^^^^^ @@ -173,7 +173,7 @@ 1 | @media (400px > = width > = 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-3/input.css:1:1] 1 | @media (400px > = width > = 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json index 1f84b68c99fc..9a52ff05ea8c 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json @@ -62,11 +62,13 @@ }, "token": { "Dimension": { - "value": 400.0, - "raw_value": "400", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 400.0, + "raw_value": "400", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -175,11 +177,13 @@ }, "token": { "Dimension": { - "value": 700.0, - "raw_value": "700", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 700.0, + "raw_value": "700", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr index 2e2f4e2d89b2..a4f306d8a959 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr @@ -53,7 +53,7 @@ 1 | @media (400px >= width ! 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-4/input.css:1:1] 1 | @media (400px >= width ! 700px) {} : ^^^^^ @@ -143,7 +143,7 @@ 1 | @media (400px >= width ! 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-4/input.css:1:1] 1 | @media (400px >= width ! 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json index cb6a5e67d58f..e218f69af72c 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json @@ -62,11 +62,13 @@ }, "token": { "Dimension": { - "value": 400.0, - "raw_value": "400", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 400.0, + "raw_value": "400", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -187,11 +189,13 @@ }, "token": { "Dimension": { - "value": 700.0, - "raw_value": "700", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 700.0, + "raw_value": "700", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr index 39eb7a69f4be..88e15c2d82d1 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr @@ -53,7 +53,7 @@ 1 | @media (400px <= width >= 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-5/input.css:1:1] 1 | @media (400px <= width >= 700px) {} : ^^^^^ @@ -153,7 +153,7 @@ 1 | @media (400px <= width >= 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-5/input.css:1:1] 1 | @media (400px <= width >= 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json index 0a920ef27427..050da4f7fb93 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json @@ -62,11 +62,13 @@ }, "token": { "Dimension": { - "value": 400.0, - "raw_value": "400", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 400.0, + "raw_value": "400", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -187,11 +189,13 @@ }, "token": { "Dimension": { - "value": 700.0, - "raw_value": "700", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 700.0, + "raw_value": "700", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr index 6340b599f010..4500d296e8df 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr @@ -53,7 +53,7 @@ 1 | @media (400px >= width <= 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 400.0, raw_value: "400", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-6/input.css:1:1] 1 | @media (400px >= width <= 700px) {} : ^^^^^ @@ -153,7 +153,7 @@ 1 | @media (400px >= width <= 700px) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 700.0, raw_value: "700", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/feature-range-6/input.css:1:1] 1 | @media (400px >= width <= 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json index e94fccfdeda7..99dea231648f 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json @@ -152,11 +152,13 @@ }, "token": { "Dimension": { - "value": 1024.0, - "raw_value": "1024", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 1024.0, + "raw_value": "1024", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr index 5f51b3211d25..43f868ee4dfb 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr @@ -180,7 +180,7 @@ : ^^^^^^ 3 | } `---- - x Dimension(DimensionToken { value: 1024.0, raw_value: "1024", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 1024.0, raw_value: "1024", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/at-rule/media/invalid-nesting/input.css:2:1] 1 | @media (min-width: 480px) { 2 | max-inline-size: 1024px; diff --git a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json index 5ee4b3e90f9e..ce92fdee9bfc 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json @@ -311,11 +311,13 @@ }, "token": { "Dimension": { - "value": 10.0, - "raw_value": "10", - "unit": "deg", - "type": "integer", - "raw_unit": "deg" + "dimension": { + "value": 10.0, + "raw_value": "10", + "unit": "deg", + "type": "integer", + "raw_unit": "deg" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr index 3cfba09e1c1a..fab855e81184 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr @@ -268,7 +268,7 @@ 1 | @supports (transition-property: color) or (animation-name: foo) and (transform: rotate(10deg)) {} : ^^^^^ `---- - x Dimension(DimensionToken { value: 10.0, raw_value: "10", unit: "deg", type_flag: Integer, raw_unit: "deg" }) + x Dimension { dimension: DimensionToken { value: 10.0, raw_value: "10", unit: "deg", type_flag: Integer, raw_unit: "deg" } } ,-[$DIR/tests/recovery/at-rule/supports/wrong-or-and/input.css:1:1] 1 | @supports (transition-property: color) or (animation-name: foo) and (transform: rotate(10deg)) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json index 6f2e165294db..660b928eda4d 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json +++ b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json @@ -108,11 +108,13 @@ }, "token": { "Dimension": { - "value": 20.0, - "raw_value": "20", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 20.0, + "raw_value": "20", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr index 13e42667c863..0196892e1740 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr @@ -105,7 +105,7 @@ : ^^^^ 3 | } `---- - x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 20.0, raw_value: "20", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/declaration/wrong-name-3/input.css:2:1] 1 | a { 2 | func(20px); diff --git a/crates/swc_css_parser/tests/recovery/function/calc/space/output.json b/crates/swc_css_parser/tests/recovery/function/calc/space/output.json index 7f9de925724a..804943b16006 100644 --- a/crates/swc_css_parser/tests/recovery/function/calc/space/output.json +++ b/crates/swc_css_parser/tests/recovery/function/calc/space/output.json @@ -111,11 +111,13 @@ }, "token": { "Dimension": { - "value": 2.0, - "raw_value": "2", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 2.0, + "raw_value": "2", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, @@ -127,11 +129,13 @@ }, "token": { "Dimension": { - "value": 1.0, - "raw_value": "+1", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 1.0, + "raw_value": "+1", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr index 6a3de1b5d526..086c39a0caff 100644 --- a/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr @@ -120,7 +120,7 @@ : ^^^ 3 | } `---- - x Dimension(DimensionToken { value: 2.0, raw_value: "2", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 2.0, raw_value: "2", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/function/calc/space/input.css:2:1] 1 | .style { 2 | width: calc(2px+1px); @@ -134,7 +134,7 @@ : ^^^^ 3 | } `---- - x Dimension(DimensionToken { value: 1.0, raw_value: "+1", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 1.0, raw_value: "+1", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/function/calc/space/input.css:2:1] 1 | .style { 2 | width: calc(2px+1px); diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json b/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json index a202d133a98f..1bb497209493 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json +++ b/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json @@ -187,11 +187,13 @@ }, "token": { "Dimension": { - "value": 12.0, - "raw_value": "12", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 12.0, + "raw_value": "12", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr index d7e7b2b268a1..4579ef34f05e 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr @@ -207,7 +207,7 @@ : ^^^^ 3 | } `---- - x Dimension(DimensionToken { value: 12.0, raw_value: "12", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 12.0, raw_value: "12", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/function/unclosed-2/input.css:2:1] 1 | .style { 2 | grid-template-columns: repeat(4, [col-start] 12px diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed/output.json b/crates/swc_css_parser/tests/recovery/function/unclosed/output.json index f62ed3696d34..c6f2fb4c7715 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed/output.json +++ b/crates/swc_css_parser/tests/recovery/function/unclosed/output.json @@ -111,11 +111,13 @@ }, "token": { "Dimension": { - "value": 500.0, - "raw_value": "500", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 500.0, + "raw_value": "500", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr index 99a29c17a41b..47f411671295 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr @@ -116,7 +116,7 @@ : ^^^^^ 3 | } `---- - x Dimension(DimensionToken { value: 500.0, raw_value: "500", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 500.0, raw_value: "500", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/function/unclosed/input.css:2:1] 1 | .style { 2 | width: min(500px; diff --git a/crates/swc_css_parser/tests/recovery/number/output.json b/crates/swc_css_parser/tests/recovery/number/output.json index f60b4c7e419a..028c708a4258 100644 --- a/crates/swc_css_parser/tests/recovery/number/output.json +++ b/crates/swc_css_parser/tests/recovery/number/output.json @@ -101,11 +101,13 @@ }, "token": { "Dimension": { - "value": 10.1, - "raw_value": "10.10", - "unit": "px", - "type": "number", - "raw_unit": "px" + "dimension": { + "value": 10.1, + "raw_value": "10.10", + "unit": "px", + "type": "number", + "raw_unit": "px" + } } } }, @@ -162,11 +164,13 @@ }, "token": { "Dimension": { - "value": 10.0, - "raw_value": "10", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 10.0, + "raw_value": "10", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/number/span.swc-stderr b/crates/swc_css_parser/tests/recovery/number/span.swc-stderr index f82038163bc5..6b1ee6f0bd64 100644 --- a/crates/swc_css_parser/tests/recovery/number/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/number/span.swc-stderr @@ -121,7 +121,7 @@ : ^^^^^^^ 3 | prop1: 10px `---- - x Dimension(DimensionToken { value: 10.1, raw_value: "10.10", unit: "px", type_flag: Number, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 10.1, raw_value: "10.10", unit: "px", type_flag: Number, raw_unit: "px" } } ,-[$DIR/tests/recovery/number/input.css:2:1] 1 | a { 2 | prop: 10.10px @@ -191,7 +191,7 @@ : ^^^^ 4 | prop2: 10 `---- - x Dimension(DimensionToken { value: 10.0, raw_value: "10", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 10.0, raw_value: "10", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/number/input.css:3:1] 2 | prop: 10.10px 3 | prop1: 10px diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json index 73b7be28adfd..d67a9a0f544f 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json @@ -205,11 +205,13 @@ }, "token": { "Dimension": { - "value": 1.0, - "raw_value": "1", - "unit": "em", - "type": "integer", - "raw_unit": "em" + "dimension": { + "value": 1.0, + "raw_value": "1", + "unit": "em", + "type": "integer", + "raw_unit": "em" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr index 90ce3276869b..42c3e32d324b 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr @@ -244,7 +244,7 @@ : ^^^ 6 | } `---- - x Dimension(DimensionToken { value: 1.0, raw_value: "1", unit: "em", type_flag: Integer, raw_unit: "em" }) + x Dimension { dimension: DimensionToken { value: 1.0, raw_value: "1", unit: "em", type_flag: Integer, raw_unit: "em" } } ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested-1/input.css:5:1] 4 | input { 5 | margin: 1em; diff --git a/crates/swc_css_parser/tests/recovery/unicode-range/output.json b/crates/swc_css_parser/tests/recovery/unicode-range/output.json index a323d033cc8f..2e120b393205 100644 --- a/crates/swc_css_parser/tests/recovery/unicode-range/output.json +++ b/crates/swc_css_parser/tests/recovery/unicode-range/output.json @@ -108,11 +108,13 @@ }, "token": { "Dimension": { - "value": 1.0, - "raw_value": "+1", - "unit": "Z1ee1-FFFFFF", - "type": "integer", - "raw_unit": "Z1ee1-FFFFFF" + "dimension": { + "value": 1.0, + "raw_value": "+1", + "unit": "Z1ee1-FFFFFF", + "type": "integer", + "raw_unit": "Z1ee1-FFFFFF" + } } } } @@ -156,11 +158,13 @@ }, "token": { "Dimension": { - "value": 10.0, - "raw_value": "+1e1", - "unit": "ee1-FFZFFF", - "type": "number", - "raw_unit": "ee1-FFZFFF" + "dimension": { + "value": 10.0, + "raw_value": "+1e1", + "unit": "ee1-FFZFFF", + "type": "number", + "raw_unit": "ee1-FFZFFF" + } } } } diff --git a/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr b/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr index aaa38fb53b0e..126632701fc7 100644 --- a/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr @@ -117,7 +117,7 @@ : ^^^^^^^^^^^^^^ 3 | unicode-range: U+1e1ee1-FFZFFF; `---- - x Dimension(DimensionToken { value: 1.0, raw_value: "+1", unit: "Z1ee1-FFFFFF", type_flag: Integer, raw_unit: "Z1ee1-FFFFFF" }) + x Dimension { dimension: DimensionToken { value: 1.0, raw_value: "+1", unit: "Z1ee1-FFFFFF", type_flag: Integer, raw_unit: "Z1ee1-FFFFFF" } } ,-[$DIR/tests/recovery/unicode-range/input.css:2:1] 1 | .class { 2 | unicode-range: U+1Z1ee1-FFFFFF; @@ -173,7 +173,7 @@ : ^^^^^^^^^^^^^^ 4 | } `---- - x Dimension(DimensionToken { value: 10.0, raw_value: "+1e1", unit: "ee1-FFZFFF", type_flag: Number, raw_unit: "ee1-FFZFFF" }) + x Dimension { dimension: DimensionToken { value: 10.0, raw_value: "+1e1", unit: "ee1-FFZFFF", type_flag: Number, raw_unit: "ee1-FFZFFF" } } ,-[$DIR/tests/recovery/unicode-range/input.css:3:1] 2 | unicode-range: U+1Z1ee1-FFFFFF; 3 | unicode-range: U+1e1ee1-FFZFFF; diff --git a/crates/swc_css_parser/tests/recovery/vercel/004/output.json b/crates/swc_css_parser/tests/recovery/vercel/004/output.json index 774f4330bc19..46149574d88b 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/004/output.json +++ b/crates/swc_css_parser/tests/recovery/vercel/004/output.json @@ -195,11 +195,13 @@ }, "token": { "Dimension": { - "value": 7.0, - "raw_value": "7", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 7.0, + "raw_value": "7", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr b/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr index 791a92d37c15..af906bd06092 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr @@ -238,7 +238,7 @@ : ^^^ 5 | color: white; `---- - x Dimension(DimensionToken { value: 7.0, raw_value: "7", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 7.0, raw_value: "7", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/vercel/004/input.css:4:1] 3 | __ident__ 4 | border-radius: 7px; diff --git a/crates/swc_css_parser/tests/recovery/vercel/005/output.json b/crates/swc_css_parser/tests/recovery/vercel/005/output.json index 679288e13968..57202733533f 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/005/output.json +++ b/crates/swc_css_parser/tests/recovery/vercel/005/output.json @@ -137,11 +137,13 @@ }, "token": { "Dimension": { - "value": 7.0, - "raw_value": "7", - "unit": "px", - "type": "integer", - "raw_unit": "px" + "dimension": { + "value": 7.0, + "raw_value": "7", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } }, diff --git a/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr b/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr index 1225e3a56dbe..40bbb9b0424a 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr @@ -190,7 +190,7 @@ : ^^^ 5 | color: white; `---- - x Dimension(DimensionToken { value: 7.0, raw_value: "7", unit: "px", type_flag: Integer, raw_unit: "px" }) + x Dimension { dimension: DimensionToken { value: 7.0, raw_value: "7", unit: "px", type_flag: Integer, raw_unit: "px" } } ,-[$DIR/tests/recovery/vercel/005/input.css:4:1] 3 | __ident__ 4 | border-radius: 7px; diff --git a/crates/swc_css_visit/src/generated.rs b/crates/swc_css_visit/src/generated.rs index a7973ca8edba..2d17abdefb3e 100644 --- a/crates/swc_css_visit/src/generated.rs +++ b/crates/swc_css_visit/src/generated.rs @@ -11490,8 +11490,10 @@ impl VisitWith for Token { >::visit_with(raw, visitor) }; } - Token::Dimension { 0: _field_0 } => { - as VisitWith>::visit_with(_field_0, visitor); + Token::Dimension { dimension } => { + { + as VisitWith>::visit_with(dimension, visitor) + }; } Token::WhiteSpace { value } => { { @@ -35223,16 +35225,22 @@ impl VisitWithAstPath for Token { ) }; } - Token::Dimension { 0: _field_0 } => { + Token::Dimension { dimension } => { let mut __ast_path = __ast_path.with_guard(AstParentNodeRef::Token( self, self::fields::TokenField::Dimension, )); - as VisitWithAstPath>::visit_with_ast_path( - _field_0, - visitor, - &mut *__ast_path, - ); + { + let mut __ast_path = __ast_path.with_guard(AstParentNodeRef::Token( + self, + self::fields::TokenField::Dimension, + )); + as VisitWithAstPath>::visit_with_ast_path( + dimension, + visitor, + &mut *__ast_path, + ) + }; } Token::WhiteSpace { value } => { let mut __ast_path = __ast_path.with_guard(AstParentNodeRef::Token( @@ -49517,8 +49525,10 @@ impl VisitMutWith for Token { >::visit_mut_with(raw, visitor) }; } - Token::Dimension { 0: _field_0 } => { - as VisitMutWith>::visit_mut_with(_field_0, visitor); + Token::Dimension { dimension } => { + { + as VisitMutWith>::visit_mut_with(dimension, visitor) + }; } Token::WhiteSpace { value } => { { @@ -70444,14 +70454,18 @@ impl VisitMutWithAstPath for Token { ) }; } - Token::Dimension { 0: _field_0 } => { + Token::Dimension { dimension } => { let mut __ast_path = __ast_path .with_guard(AstParentKind::Token(self::fields::TokenField::Dimension)); - as VisitMutWithAstPath>::visit_mut_with_ast_path( - _field_0, - visitor, - &mut *__ast_path, - ); + { + let mut __ast_path = __ast_path + .with_guard(AstParentKind::Token(self::fields::TokenField::Dimension)); + as VisitMutWithAstPath>::visit_mut_with_ast_path( + dimension, + visitor, + &mut *__ast_path, + ) + }; } Token::WhiteSpace { value } => { let mut __ast_path = __ast_path @@ -84590,7 +84604,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, @@ -84608,9 +84624,10 @@ impl FoldWith for Token { let raw = { >::fold_with(raw, visitor) }; Token::Percentage { value, raw } } - Token::Dimension { 0: _field_0 } => { - let _field_0 = as FoldWith>::fold_with(_field_0, visitor); - Token::Dimension { 0: _field_0 } + Token::Dimension { dimension } => { + let dimension = + { as FoldWith>::fold_with(dimension, visitor) }; + Token::Dimension { dimension } } Token::WhiteSpace { value } => { let value = { >::fold_with(value, visitor) }; @@ -106250,15 +106267,19 @@ impl FoldWithAstPath for Token { }; Token::Percentage { value, raw } } - Token::Dimension { 0: _field_0 } => { + Token::Dimension { dimension } => { let mut __ast_path = __ast_path .with_guard(AstParentKind::Token(self::fields::TokenField::Dimension)); - let _field_0 = as FoldWithAstPath>::fold_with_ast_path( - _field_0, - visitor, - &mut *__ast_path, - ); - Token::Dimension { 0: _field_0 } + let dimension = { + let mut __ast_path = __ast_path + .with_guard(AstParentKind::Token(self::fields::TokenField::Dimension)); + as FoldWithAstPath>::fold_with_ast_path( + dimension, + visitor, + &mut *__ast_path, + ) + }; + Token::Dimension { dimension } } Token::WhiteSpace { value } => { let mut __ast_path = __ast_path @@ -114710,7 +114731,9 @@ impl<'ast> NodeRef<'ast> { _ => Box::new(::std::iter::empty::>()), }, NodeRef::Token(node) => match node { - Token::Dimension(v0) => Box::new(::std::iter::once(NodeRef::DimensionToken(v0))), + Token::Dimension { dimension: v0 } => { + Box::new(::std::iter::once(NodeRef::DimensionToken(v0))) + } _ => Box::new(::std::iter::empty::>()), }, NodeRef::TokenAndSpan(node) => { diff --git a/crates/swc_ecma_ast/Cargo.toml b/crates/swc_ecma_ast/Cargo.toml index 48c1dfe7a3b0..36bacad5174b 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 = [] @@ -28,13 +31,13 @@ rkyv-impl = [ "swc_common/rkyv-impl", ] serde-impl = ["serde"] +encoding-impl = ["cbor4ii", "swc_atoms/encoding-impl", "swc_common/encoding-impl"] shrink-to-fit = [ "dep:shrink-to-fit", "swc_atoms/shrink-to-fit", "swc_common/shrink-to-fit", ] - [dependencies] arbitrary = { workspace = true, features = ["derive"], optional = true } bitflags = { workspace = true } @@ -55,5 +58,7 @@ swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_common = { version = "14.0.4", path = "../swc_common" } swc_visit = { version = "2.0.1", path = "../swc_visit" } +cbor4ii = { workspace = true, features = [ "use_std" ], optional = true } + [dev-dependencies] serde_json = { workspace = true } diff --git a/crates/swc_ecma_ast/src/class.rs b/crates/swc_ecma_ast/src/class.rs index b14aa3ed870b..b3591a11ed43 100644 --- a/crates/swc_ecma_ast/src/class.rs +++ b/crates/swc_ecma_ast/src/class.rs @@ -30,15 +30,27 @@ pub struct Class { pub body: Vec, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub super_class: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] pub is_abstract: bool, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub super_type_params: Option>, /// Typescript extension. @@ -102,9 +114,17 @@ pub struct ClassProp { pub key: PropName, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option>, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -115,6 +135,10 @@ pub struct ClassProp { /// Typescript extension. #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, /// Typescript extension. @@ -151,9 +175,17 @@ pub struct PrivateProp { pub key: PrivateName, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option>, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -164,6 +196,10 @@ pub struct PrivateProp { /// Typescript extension. #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -193,6 +229,10 @@ pub struct ClassMethod { pub is_static: bool, #[doc = r" Typescript extension."] #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, #[doc = r" Typescript extension."] #[cfg_attr(feature = "serde-impl", serde(default))] @@ -217,6 +257,10 @@ pub struct PrivateMethod { pub is_static: bool, #[doc = r" Typescript extension."] #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, #[doc = r" Typescript extension."] #[cfg_attr(feature = "serde-impl", serde(default))] @@ -241,9 +285,17 @@ pub struct Constructor { pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub body: Option, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -271,6 +323,11 @@ 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 = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum MethodKind { #[default] #[cfg_attr(feature = "serde-impl", serde(rename = "method"))] @@ -345,9 +402,17 @@ pub struct AutoAccessor { pub key: Key, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option>, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -358,6 +423,10 @@ pub struct AutoAccessor { /// Typescript extension. #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, #[cfg_attr(feature = "serde-impl", serde(default))] diff --git a/crates/swc_ecma_ast/src/decl.rs b/crates/swc_ecma_ast/src/decl.rs index 69fdaf7d589b..8e8ecfd40232 100644 --- a/crates/swc_ecma_ast/src/decl.rs +++ b/crates/swc_ecma_ast/src/decl.rs @@ -179,6 +179,11 @@ 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 = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum VarDeclKind { /// `var` #[default] @@ -200,6 +205,10 @@ pub struct VarDeclarator { /// Initialization expression. #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub init: Option>, /// Typescript only diff --git a/crates/swc_ecma_ast/src/expr.rs b/crates/swc_ecma_ast/src/expr.rs index af7d6c2f5b05..4d564ae81f1c 100644 --- a/crates/swc_ecma_ast/src/expr.rs +++ b/crates/swc_ecma_ast/src/expr.rs @@ -376,6 +376,8 @@ impl Expr { Expr::PrivateName(e) => e.span = span, Expr::OptChain(e) => e.span = span, Expr::Lit(e) => e.set_span(span), + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } @@ -386,6 +388,8 @@ impl Clone for Expr { fn clone(&self) -> Self { use Expr::*; match self { + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + Unknown(tag, v) => Unknown(*tag, v.clone()), This(e) => This(e.clone()), Array(e) => Array(e.clone()), Object(e) => Object(e.clone()), @@ -513,6 +517,7 @@ pub struct ArrayLit { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default, rename = "elements"))] + #[cfg_attr(feature = "encoding-impl", encoding(with = "swc_common::serializer::ArrayOption"))] pub elems: Vec>, } @@ -564,6 +569,8 @@ impl ObjectLit { } _ => return None, }, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } @@ -760,6 +767,10 @@ impl Take for BinExpr { #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] pub struct FnExpr { #[cfg_attr(feature = "serde-impl", serde(default, rename = "identifier"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ident: Option, #[cfg_attr(feature = "serde-impl", serde(flatten))] @@ -795,6 +806,10 @@ bridge_expr_from!(FnExpr, Box); #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] pub struct ClassExpr { #[cfg_attr(feature = "serde-impl", serde(default, rename = "identifier"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub ident: Option, #[cfg_attr(feature = "serde-impl", serde(flatten))] @@ -984,6 +999,10 @@ pub struct CallExpr { pub args: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_args: Option>, // pub type_params: Option, } @@ -1006,9 +1025,17 @@ pub struct NewExpr { pub callee: Box, #[cfg_attr(feature = "serde-impl", serde(default, rename = "arguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "::cbor4ii::core::types::Maybe") + )] pub args: Option>, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "::cbor4ii::core::types::Maybe") + )] pub type_args: Option>, // pub type_params: Option, } @@ -1060,9 +1087,17 @@ pub struct ArrowExpr { pub is_generator: bool, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeParameters"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub return_type: Option>, } @@ -1082,6 +1117,10 @@ pub struct YieldExpr { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default, rename = "argument"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub arg: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -1116,6 +1155,11 @@ 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 = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum MetaPropKind { /// `new.target` NewTarget, @@ -1169,6 +1213,10 @@ pub struct TaggedTpl { pub tag: Box, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeParameters"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, /// This is boxed to reduce the type size of [Expr]. @@ -1194,6 +1242,10 @@ pub struct TplElement { /// /// If you are going to use codegen right after creating a [TplElement], you /// don't have to worry about this value. + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub cooked: Option, /// You may need to perform. `.replace("\r\n", "\n").replace('\r', "\n")` on @@ -1333,9 +1385,17 @@ impl Take for Import { )] #[cfg_attr(feature = "rkyv-impl", repr(C))] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub struct ExprOrSpread { #[cfg_attr(feature = "serde-impl", serde(default))] #[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub spread: Option, #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))] @@ -1496,6 +1556,8 @@ impl From for Pat { AssignTargetPat::Array(a) => a.into(), AssignTargetPat::Object(o) => o.into(), AssignTargetPat::Invalid(i) => i.into(), + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } @@ -1617,6 +1679,8 @@ impl From for Box { SimpleAssignTarget::TsTypeAssertion(a) => a.into(), SimpleAssignTarget::TsInstantiation(a) => a.into(), SimpleAssignTarget::Invalid(i) => i.into(), + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } @@ -1686,6 +1750,10 @@ pub struct OptCall { pub args: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_args: Option>, // pub type_params: Option, } @@ -1717,6 +1785,8 @@ impl From for Expr { ctxt, }), OptChainBase::Member(member) => Self::Member(member), + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } diff --git a/crates/swc_ecma_ast/src/function.rs b/crates/swc_ecma_ast/src/function.rs index 7236bd89b49a..3d0747b3a00b 100644 --- a/crates/swc_ecma_ast/src/function.rs +++ b/crates/swc_ecma_ast/src/function.rs @@ -24,6 +24,10 @@ pub struct Function { pub ctxt: SyntaxContext, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub body: Option, /// if it's a generator. @@ -35,9 +39,17 @@ pub struct Function { pub is_async: bool, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeParameters"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub return_type: Option>, } diff --git a/crates/swc_ecma_ast/src/ident.rs b/crates/swc_ecma_ast/src/ident.rs index bff302b894c7..38a68175f0a4 100644 --- a/crates/swc_ecma_ast/src/ident.rs +++ b/crates/swc_ecma_ast/src/ident.rs @@ -40,6 +40,10 @@ use crate::{typescript::TsTypeAnn, Expr}; #[cfg_attr(feature = "rkyv-impl", repr(C))] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub struct BindingIdent { #[cfg_attr(feature = "serde-impl", serde(flatten))] #[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))] @@ -47,6 +51,10 @@ pub struct BindingIdent { #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] #[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } diff --git a/crates/swc_ecma_ast/src/jsx.rs b/crates/swc_ecma_ast/src/jsx.rs index 455293cd2668..cc8a091e2a3c 100644 --- a/crates/swc_ecma_ast/src/jsx.rs +++ b/crates/swc_ecma_ast/src/jsx.rs @@ -126,6 +126,10 @@ pub struct JSXOpeningElement { /// Note: This field's name is different from one from babel because it is /// misleading #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_args: Option>, } @@ -170,6 +174,10 @@ pub struct JSXAttr { pub span: Span, pub name: JSXAttrName, /// Babel uses Expr instead of JSXAttrValue + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option, } @@ -236,6 +244,10 @@ pub struct JSXElement { pub span: Span, pub opening: JSXOpeningElement, pub children: Vec, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub closing: Option, } diff --git a/crates/swc_ecma_ast/src/lit.rs b/crates/swc_ecma_ast/src/lit.rs index b2eb23046fbf..fa498ef5d6a7 100644 --- a/crates/swc_ecma_ast/src/lit.rs +++ b/crates/swc_ecma_ast/src/lit.rs @@ -72,6 +72,8 @@ impl Lit { Lit::BigInt(n) => n.span = span, Lit::Regex(n) => n.span = span, Lit::JSXText(n) => n.span = span, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } @@ -81,10 +83,15 @@ impl Lit { pub struct BigInt { pub span: Span, #[cfg_attr(any(feature = "rkyv-impl"), rkyv(with = EncodeBigInt))] + #[cfg_attr(feature = "encoding-impl", encoding(with = "EncodeBigInt2"))] pub value: Box, /// Use `None` value only for transformations to avoid recalculate /// characters in big integer + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -100,6 +107,33 @@ impl EqIgnoreSpan for BigInt { } } +#[cfg(feature = "encoding-impl")] +struct EncodeBigInt2(T); + +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for EncodeBigInt2<&'_ Box> { + #[inline] + fn encode( + &self, + writer: &mut W, + ) -> Result<(), cbor4ii::core::enc::Error> { + cbor4ii::core::types::Bytes(self.0.to_signed_bytes_le().as_slice()).encode(writer) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de> cbor4ii::core::dec::Decode<'de> for EncodeBigInt2> { + #[inline] + fn decode>( + reader: &mut R, + ) -> Result> { + let buf = >::decode(reader)?; + Ok(EncodeBigInt2(Box::new(BigIntValue::from_signed_bytes_le( + buf.0, + )))) + } +} + #[cfg(feature = "rkyv-impl")] #[derive(Debug, Clone, Copy)] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] @@ -189,6 +223,10 @@ pub struct Str { /// Use `None` value only for transformations to avoid recalculate escaped /// characters in strings + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } @@ -398,6 +436,10 @@ pub struct Number { /// Use `None` value only for transformations to avoid recalculate /// characters in number literal + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub raw: Option, } diff --git a/crates/swc_ecma_ast/src/module.rs b/crates/swc_ecma_ast/src/module.rs index 0f60dac3add4..339f4c45f72f 100644 --- a/crates/swc_ecma_ast/src/module.rs +++ b/crates/swc_ecma_ast/src/module.rs @@ -30,6 +30,10 @@ pub struct Module { pub body: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "interpreter"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub shebang: Option, } @@ -66,6 +70,10 @@ pub struct Script { pub body: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "interpreter"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub shebang: Option, } diff --git a/crates/swc_ecma_ast/src/module_decl.rs b/crates/swc_ecma_ast/src/module_decl.rs index f3ec54af99dd..5de6c1d6005e 100644 --- a/crates/swc_ecma_ast/src/module_decl.rs +++ b/crates/swc_ecma_ast/src/module_decl.rs @@ -130,6 +130,10 @@ pub struct ImportDecl { pub type_only: bool, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub with: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -146,6 +150,11 @@ 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 = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum ImportPhase { #[default] #[cfg_attr(feature = "serde-impl", serde(rename = "evaluation"))] @@ -184,6 +193,10 @@ pub struct ExportAll { pub type_only: bool, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub with: Option>, } @@ -210,12 +223,20 @@ pub struct NamedExport { pub specifiers: Vec, #[cfg_attr(feature = "serde-impl", serde(rename = "source"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub src: Option>, #[cfg_attr(feature = "serde-impl", serde(rename = "typeOnly"))] pub type_only: bool, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub with: Option>, } @@ -275,6 +296,8 @@ impl ImportSpecifier { match self { ImportSpecifier::Named(named) => named.is_type_only, ImportSpecifier::Default(..) | ImportSpecifier::Namespace(..) => false, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } @@ -283,6 +306,8 @@ impl ImportSpecifier { ImportSpecifier::Named(named) => &named.local, ImportSpecifier::Default(default) => &default.local, ImportSpecifier::Namespace(ns) => &ns.local, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } @@ -291,6 +316,8 @@ impl ImportSpecifier { ImportSpecifier::Named(named) => &mut named.local, ImportSpecifier::Default(default) => &mut default.local, ImportSpecifier::Namespace(ns) => &mut ns.local, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } @@ -328,6 +355,10 @@ pub struct ImportNamedSpecifier { pub local: Ident, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub imported: Option, #[cfg_attr(feature = "serde-impl", serde(default))] @@ -380,6 +411,10 @@ pub struct ExportNamedSpecifier { pub orig: ModuleExportName, /// `Some(bar)` in `export { foo as bar }` #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub exported: Option, /// `type` in `export { type foo as bar }` #[cfg_attr(feature = "serde-impl", serde(default))] @@ -408,6 +443,8 @@ impl ModuleExportName { match self { ModuleExportName::Ident(i) => &i.sym, ModuleExportName::Str(s) => &s.value, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } diff --git a/crates/swc_ecma_ast/src/operators.rs b/crates/swc_ecma_ast/src/operators.rs index 89160a819240..27c4b0b435b1 100644 --- a/crates/swc_ecma_ast/src/operators.rs +++ b/crates/swc_ecma_ast/src/operators.rs @@ -10,6 +10,11 @@ use swc_common::EqIgnoreSpan; )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum BinaryOp { /// `==` #[default] @@ -123,6 +128,11 @@ impl BinaryOp { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum AssignOp { /// `=` #[default] @@ -200,6 +210,11 @@ impl AssignOp { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum UpdateOp { /// `++` #[default] @@ -217,6 +232,11 @@ pub enum UpdateOp { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum UnaryOp { /// `-` Minus, diff --git a/crates/swc_ecma_ast/src/pat.rs b/crates/swc_ecma_ast/src/pat.rs index d33339e8f68c..8729924db151 100644 --- a/crates/swc_ecma_ast/src/pat.rs +++ b/crates/swc_ecma_ast/src/pat.rs @@ -43,6 +43,8 @@ impl Clone for Pat { fn clone(&self) -> Self { use Pat::*; match self { + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + Unknown(tag, v) => Unknown(*tag, v.clone()), Ident(p) => Ident(p.clone()), Array(p) => Array(p.clone()), Rest(p) => Rest(p.clone()), @@ -91,6 +93,7 @@ pub struct ArrayPat { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(rename = "elements"))] + #[cfg_attr(feature = "encoding-impl", encoding(with = "swc_common::serializer::ArrayOption"))] pub elems: Vec>, /// Only in an ambient context @@ -98,6 +101,10 @@ pub struct ArrayPat { pub optional: bool, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -116,6 +123,10 @@ pub struct ObjectPat { pub optional: bool, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -146,6 +157,10 @@ pub struct RestPat { pub arg: Box, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -188,5 +203,9 @@ pub struct AssignPatProp { pub key: BindingIdent, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option>, } diff --git a/crates/swc_ecma_ast/src/prop.rs b/crates/swc_ecma_ast/src/prop.rs index ee3110f85545..569a235ccf59 100644 --- a/crates/swc_ecma_ast/src/prop.rs +++ b/crates/swc_ecma_ast/src/prop.rs @@ -70,8 +70,16 @@ pub struct GetterProp { pub span: Span, pub key: PropName, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub body: Option, } #[ast_node("SetterProperty")] @@ -81,9 +89,17 @@ pub struct GetterProp { pub struct SetterProp { pub span: Span, pub key: PropName, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub this_param: Option, pub param: Box, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub body: Option, } #[ast_node("MethodProperty")] @@ -149,6 +165,8 @@ impl From for MemberProp { span: DUMMY_SP, expr: p.into(), }), + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } diff --git a/crates/swc_ecma_ast/src/stmt.rs b/crates/swc_ecma_ast/src/stmt.rs index 478a4e53c298..328308aec6d2 100644 --- a/crates/swc_ecma_ast/src/stmt.rs +++ b/crates/swc_ecma_ast/src/stmt.rs @@ -176,6 +176,8 @@ impl Clone for Stmt { fn clone(&self) -> Self { use Stmt::*; match self { + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + Unknown(tag, v) => Unknown(*tag, v.clone()), Block(s) => Block(s.clone()), Empty(s) => Empty(s.clone()), Debugger(s) => Debugger(s.clone()), @@ -256,6 +258,10 @@ pub struct WithStmt { pub struct ReturnStmt { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default, rename = "argument"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub arg: Option>, } @@ -276,6 +282,10 @@ pub struct LabeledStmt { pub struct BreakStmt { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub label: Option, } @@ -286,6 +296,10 @@ pub struct BreakStmt { pub struct ContinueStmt { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub label: Option, } @@ -301,6 +315,10 @@ pub struct IfStmt { pub cons: Box, #[cfg_attr(feature = "serde-impl", serde(default, rename = "alternate"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub alt: Option>, } @@ -334,9 +352,17 @@ pub struct TryStmt { pub block: BlockStmt, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub handler: Option, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub finalizer: Option, } @@ -368,12 +394,24 @@ pub struct ForStmt { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub init: Option, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub test: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub update: Option>, pub body: Box, @@ -423,6 +461,10 @@ pub struct SwitchCase { /// None for `default:` #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub test: Option>, #[cfg_attr(feature = "serde-impl", serde(rename = "consequent"))] @@ -450,6 +492,10 @@ pub struct CatchClause { /// The param is null if the catch binding is omitted. E.g., try { foo() } /// catch { bar() } #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub param: Option, pub body: BlockStmt, diff --git a/crates/swc_ecma_ast/src/typescript.rs b/crates/swc_ecma_ast/src/typescript.rs index 0fb25f40c096..4c5556b6547d 100644 --- a/crates/swc_ecma_ast/src/typescript.rs +++ b/crates/swc_ecma_ast/src/typescript.rs @@ -62,9 +62,17 @@ pub struct TsTypeParam { pub is_const: bool, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub constraint: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub default: Option>, } @@ -87,6 +95,10 @@ pub struct TsParamProp { pub decorators: Vec, /// At least one of `accessibility` or `readonly` must be set. #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub accessibility: Option, #[cfg_attr(feature = "serde-impl", serde(rename = "override"))] pub is_override: bool, @@ -168,8 +180,16 @@ pub struct TsCallSignatureDecl { pub span: Span, pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, } @@ -181,8 +201,16 @@ pub struct TsConstructSignatureDecl { pub span: Span, pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, } @@ -197,6 +225,10 @@ pub struct TsPropertySignature { pub computed: bool, pub optional: bool, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -209,6 +241,10 @@ pub struct TsGetterSignature { pub key: Box, pub computed: bool, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -234,8 +270,16 @@ pub struct TsMethodSignature { pub optional: bool, pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, } @@ -246,6 +290,10 @@ pub struct TsMethodSignature { pub struct TsIndexSignature { pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, pub readonly: bool, @@ -332,6 +380,8 @@ impl Clone for TsType { fn clone(&self) -> Self { use TsType::*; match self { + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + Unknown(tag, v) => Unknown(*tag, v.clone()), TsKeywordType(t) => TsKeywordType(t.clone()), TsThisType(t) => TsThisType(t.clone()), TsFnOrConstructorType(t) => TsFnOrConstructorType(t.clone()), @@ -410,6 +460,11 @@ 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 = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum TsKeywordTypeKind { #[cfg_attr(feature = "serde-impl", serde(rename = "any"))] TsAnyKeyword, @@ -486,6 +541,10 @@ pub struct TsFnType { pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))] pub type_ann: Box, @@ -499,6 +558,10 @@ pub struct TsConstructorType { pub span: Span, pub params: Vec, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))] pub type_ann: Box, @@ -513,6 +576,10 @@ pub struct TsTypeRef { pub span: Span, pub type_name: TsEntityName, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, } @@ -525,6 +592,10 @@ pub struct TsTypePredicate { pub asserts: bool, pub param_name: TsThisTypeOrIdent, #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -550,6 +621,10 @@ pub struct TsTypeQuery { pub span: Span, pub expr_name: TsTypeQueryExpr, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_args: Option>, } @@ -583,10 +658,22 @@ pub struct TsImportType { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(rename = "argument"))] pub arg: Str, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub qualifier: Option, #[cfg_attr(feature = "serde-impl", serde(rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_args: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub attributes: Option, } @@ -624,6 +711,10 @@ pub struct TsTupleType { pub struct TsTupleElement { pub span: Span, /// `Ident` or `RestPat { arg: Ident }` + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub label: Option, pub ty: Box, } @@ -729,6 +820,11 @@ pub struct TsTypeOperator { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum TsTypeOperatorOp { /// `keyof` KeyOf, @@ -759,6 +855,11 @@ pub struct TsIndexedAccessType { )] #[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))] #[cfg_attr(feature = "rkyv-impl", repr(u32))] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[cfg_attr(swc_ast_unknown, non_exhaustive)] pub enum TruePlusMinus { True, Plus, @@ -829,13 +930,29 @@ impl<'de> Deserialize<'de> for TruePlusMinus { pub struct TsMappedType { pub span: Span, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub readonly: Option, pub type_param: TsTypeParam, #[cfg_attr(feature = "serde-impl", serde(default, rename = "nameType"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name_type: Option>, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub optional: Option, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_ann: Option>, } @@ -895,6 +1012,10 @@ pub struct TsInterfaceDecl { pub id: Ident, pub declare: bool, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, pub extends: Vec, pub body: TsInterfaceBody, @@ -918,6 +1039,10 @@ pub struct TsExprWithTypeArgs { #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))] pub expr: Box, #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_args: Option>, } @@ -930,6 +1055,10 @@ pub struct TsTypeAliasDecl { pub declare: bool, pub id: Ident, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub type_params: Option>, #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))] pub type_ann: Box, @@ -955,6 +1084,10 @@ pub struct TsEnumMember { pub span: Span, pub id: TsEnumMemberId, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub init: Option>, } @@ -977,6 +1110,8 @@ impl AsRef for TsEnumMemberId { match &self { TsEnumMemberId::Str(Str { value: ref sym, .. }) | TsEnumMemberId::Ident(Ident { ref sym, .. }) => sym, + #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))] + _ => swc_common::unknown(), } } } @@ -994,6 +1129,10 @@ pub struct TsModuleDecl { pub id: TsModuleName, #[cfg_attr(feature = "serde-impl", serde(default))] + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub body: Option, } @@ -1162,6 +1301,11 @@ 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 = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] +#[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/Cargo.toml b/crates/swc_ecma_regexp_ast/Cargo.toml index ae7572ce1cc6..e5227dfa3def 100644 --- a/crates/swc_ecma_regexp_ast/Cargo.toml +++ b/crates/swc_ecma_regexp_ast/Cargo.toml @@ -16,11 +16,13 @@ __rkyv = [] default = [] rkyv-impl = [] serde-impl = ["serde"] +encoding-impl = ["cbor4ii", "swc_atoms/encoding-impl", "swc_common/encoding-impl"] [dependencies] bitflags = { workspace = true } is-macro = { workspace = true } serde = { workspace = true, features = ["derive"], optional = true } +cbor4ii = { workspace = true, features = [ "use_std" ], optional = true } swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_common = { version = "14.0.4", path = "../swc_common" } diff --git a/crates/swc_ecma_regexp_ast/src/lib.rs b/crates/swc_ecma_regexp_ast/src/lib.rs index df083f2936d9..103e635c6dd5 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 @@ -85,6 +85,10 @@ pub struct BoundaryAssertion { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum BoundaryAssertionKind { Start = 0, End = 1, @@ -104,6 +108,10 @@ pub struct LookAroundAssertion { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum LookAroundAssertionKind { Lookahead = 0, NegativeLookahead = 1, @@ -119,6 +127,10 @@ pub struct Quantifier { pub span: Span, pub min: u64, /// `None` means no upper bound. + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub max: Option, pub greedy: bool, pub body: Term, @@ -138,6 +150,10 @@ pub struct Character { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum CharacterKind { ControlLetter = 0, HexadecimalEscape = 1, @@ -163,6 +179,10 @@ pub struct CharacterClassEscape { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum CharacterClassEscapeKind { D = 0, NegativeD = 1, @@ -183,6 +203,10 @@ pub struct UnicodePropertyEscape { /// strings. pub strings: bool, pub name: Atom, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub value: Option, } @@ -211,6 +235,10 @@ pub struct CharacterClass { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "encoding-impl", + derive(::swc_common::Encode, ::swc_common::Decode) +)] pub enum CharacterClassContentsKind { Union = 0, /// `UnicodeSetsMode` only. @@ -219,7 +247,7 @@ pub enum CharacterClassContentsKind { Subtraction = 2, } -#[ast_node] +#[ast_node(no_unknown)] #[derive(Eq, Hash, EqIgnoreSpan, Is)] pub enum CharacterClassContents { #[tag("CharacterClassRange")] @@ -281,6 +309,10 @@ pub struct ClassString { pub struct CapturingGroup { pub span: Span, /// Group name to be referenced by [`NamedReference`]. + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub name: Option, pub body: Disjunction, } @@ -291,6 +323,10 @@ pub struct CapturingGroup { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct IgnoreGroup { pub span: Span, + #[cfg_attr( + feature = "encoding-impl", + encoding(with = "cbor4ii::core::types::Maybe") + )] pub modifiers: Option, pub body: Disjunction, } @@ -338,6 +374,29 @@ pub struct NamedReference { pub name: Atom, } +#[cfg(feature = "encoding-impl")] +impl cbor4ii::core::enc::Encode for Modifier { + fn encode( + &self, + writer: &mut W, + ) -> Result<(), cbor4ii::core::enc::Error> { + self.bits().encode(writer) + } +} + +#[cfg(feature = "encoding-impl")] +impl<'de> cbor4ii::core::dec::Decode<'de> for Modifier { + fn decode>( + reader: &mut R, + ) -> Result> { + let n = u8::decode(reader)?; + Modifier::from_bits(n).ok_or_else(|| cbor4ii::core::dec::Error::Mismatch { + name: &"Modifier", + found: 0, + }) + } +} + #[cfg(target_pointer_width = "64")] #[test] fn size_asserts() { 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 } => {