{"record":{"id":"66ebcd051eb2fb8b","repo":"swc-project/swc","slug":"unable-to-access-unknown-nodes-66ebcd","errorCode":null,"errorMessage":"unable to access unknown nodes","messagePattern":"unable to access unknown nodes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_typescript/src/fast_dts/decl.rs","lineNumber":127,"sourceCode":"                }\n                for type_element in ts_interface.body.body.iter() {\n                    self.check_ts_signature(type_element);\n                }\n            }\n            Decl::TsTypeAlias(ts_type_alias) => {\n                if let Some(internal_annotations) = self.internal_annotations.as_ref() {\n                    ts_type_alias.visit_mut_children_with(&mut InternalAnnotationTransformer::new(\n                        internal_annotations,\n                    ))\n                }\n                if let Some(ts_lit) = ts_type_alias.type_ann.as_ts_type_lit() {\n                    for type_element in ts_lit.members.iter() {\n                        self.check_ts_signature(type_element);\n                    }\n                }\n            }\n            #[cfg(swc_ast_unknown)]\n            _ => panic!(\"unable to access unknown nodes\"),\n        }\n    }\n\n    pub(crate) fn transform_variables_declarator(\n        &mut self,\n        kind: VarDeclKind,\n        decl: &mut VarDeclarator,\n        check_binding: bool,\n    ) {\n        let pat = match &decl.name {\n            Pat::Assign(assign_pat) => &assign_pat.left,\n            _ => &decl.name,\n        };\n\n        if matches!(pat, Pat::Array(_) | Pat::Object(_)) {\n            pat.bound_names(&mut |ident| {\n                if !check_binding || self.used_refs.used_as_value(&ident.to_id()) {\n                    self.binding_element_export(ident.span);","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_typescript/src/fast_dts/decl.rs#L109-L145","documentation":"fast_dts's transform_decl matches Decl (Class/Fn/Var/Using/TsEnum/TsModule/TsInterface/TsTypeAlias) to rewrite top-level declarations for .d.ts output. Under the swc_ast_unknown cfg (wasm plugin builds pass `--cfg=swc_ast_unknown`, giving enums an Unknown(tag, payload) variant for kinds unknown to this swc_core) this trailing arm panics: an unknown declaration kind cannot be classified as value or type, so no correct .d.ts can be produced.","triggerScenarios":"Running fast_dts on a module whose top-level declaration deserialized as Unknown — a plugin built with --cfg=swc_ast_unknown receiving a Program from a host @swc/core newer than its pinned swc_core, where the host emitted a new Decl variant.","commonSituations":"Version skew between host and plugin; new declaration kinds added to swc_ecma_ast in a release; plugins distributed as prebuilt wasm not rebuilt after host upgrades.","solutions":["Rebuild the plugin against the swc_core version that matches the host @swc/core","Bump swc_core to the latest release so the declaration decodes concretely","Pre-scan module items for Decl::Unknown and skip .d.ts emission for that file","Treat any Unknown-node panic as a signal to resync versions, not to patch the match"],"exampleFix":"// before\nfor item in module.body.iter_mut() {\n    // fast_dts internally matches Decl; Decl::Unknown -> panic\n}\n\n// after (guard, only meaningful under the plugin cfg)\n#[cfg(swc_ast_unknown)]\nfn module_has_unknown_decl(m: &swc_ecma_ast::Module) -> bool {\n    m.body.iter().any(|i| matches!(i, swc_ecma_ast::ModuleItem::Stmt(\n        swc_ecma_ast::Stmt::Decl(swc_ecma_ast::Decl::Unknown(..)))))\n}\nif !module_has_unknown_decl(&module) { /* run fast_dts */ }","handlingStrategy":"type-guard","validationCode":"#[cfg(swc_ast_unknown)]\nfn module_contains_unknown_decl(m: &swc_ecma_ast::Module) -> bool {\n    use swc_ecma_ast::*;\n    m.body.iter().any(|i| matches!(i, ModuleItem::Stmt(\n        Stmt::Decl(Decl::Unknown(..)))))\n}","typeGuard":"#[cfg(swc_ast_unknown)]\nfn decl_is_unknown(d: &swc_ecma_ast::Decl) -> bool {\n    matches!(d, swc_ecma_ast::Decl::Unknown(..))\n}","tryCatchPattern":"let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    run_fast_dts(&mut program)\n}));\nif out.is_err() {\n    handler.struct_err(\"fast_dts skipped file: unknown declaration (version mismatch)\").emit();\n}","preventionTips":["Rebuild plugins with the swc_core matching the host @swc/core","Pre-scan module bodies for Unknown declarations before fast_dts","Track swc_ecma_ast changelogs for new Decl variants","Never mix a prebuilt plugin wasm with a newer host without testing"],"tags":["fast-dts","swc-plugin","wasm","version-skew","unknown-node","declaration"],"backgroundTag":"ast-version-mismatch","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}