{"record":{"id":"4a490553c474aded","repo":"swc-project/swc","slug":"super-expression-must-either-be-null-or-a-function","errorCode":null,"errorMessage":"Super expression must either be null or a function","messagePattern":"Super expression must either be null or a function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_inherits.rs","lineNumber":12,"sourceCode":"// This file is generated by `cargo codegen helpers`. DO NOT MODIFY.\n\nuse super::{HelperDef, HelperName};\n\npub const DEF: HelperDef = HelperDef {\n    name: HelperName::inherits,\n    local: \"_inherits\",\n    import_path: \"@swc/helpers/_/_inherits\",\n    #[cfg(feature = \"inline-helpers\")]\n    source: r#\"function _inherits(subClass, superClass) {\n    if (typeof superClass !== \"function\" && superClass !== null) {\n        throw new TypeError(\"Super expression must either be null or a function\");\n    }\n\n    subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });\n\n    if (superClass) _set_prototype_of(subClass, superClass);\n}\n\"#,\n    #[cfg(feature = \"inline-helpers\")]\n    deps: super::HelperBitmap::from_bits(0x00000000000020000020000000000000),\n};\n\n#[cfg(feature = \"inline-helpers\")]\npub fn stmts() -> &'static [swc_ecma_ast::Stmt] {\n    static STMTS: once_cell::sync::Lazy<Vec<swc_ecma_ast::Stmt>> =\n        once_cell::sync::Lazy::new(|| super::super::parse(DEF.source, DEF.import_path));\n    &STMTS\n}\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_inherits.rs#L1-L30","documentation":"The #[proc_macro_derive(Encode, attributes(encoding))] entry point in swc's ast_node crate parses its input with syn::parse::<syn::DeriveInput>(input).expect(\"failed to parse input as DeriveInput\") before delegating to encoding::encode::expand. It is a defensive invariant on an input rustc guarantees to be a valid item, so a panic ('proc-macro panicked' + this message) indicates the token stream reaching the macro was not a parseable derive target.","triggerScenarios":"Applying #[derive(Encode)] to an item whose token stream is malformed or not an item (macro-generated edge cases), or calling the proc macro function directly with arbitrary tokens. The sibling Decode and Spanned entry points carry the identical guard.","commonSituations":"Practically unreachable through normal #[derive] usage; seen only with build-time code generation that synthesizes derive calls, custom test harnesses for proc macros, or version/toolchain mismatches that alter token stream shapes.","solutions":["Verify the annotated item compiles as plain Rust (a struct or enum with valid syntax) before adding the derive back.","Run cargo expand to inspect what tokens actually reach the derive when the item is macro-produced.","Check the swc/ast_node crate version for known proc-macro panics and upgrade.","File a minimal reproduction upstream if valid input still triggers it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply #[derive(Encode)] to syntactically complete structs/enums only.","Keep ast_node crate versions aligned with the swc_ecma_ast version you build against to avoid token-shape mismatches."],"tags":["rust","proc-macro","derive","encode","swc","compile-time"],"backgroundTag":"derive-input-parse-failure","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}