{"record":{"id":"dded5689bbdd91ac","repo":"swc-project/swc","slug":"expected-name-to-be-a-function","errorCode":null,"errorMessage":"Expected '${name}' to be a function","messagePattern":"Expected '(.+?)' to be a function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs","lineNumber":257,"sourceCode":"        throw new TypeError(\"A class descriptor's .kind property must be \\\"class\\\", but a decorator\" + \" created a class descriptor with .kind \\\"\" + kind + \"\\\"\");\n    }\n    _disallowProperty(obj, \"key\", \"A class descriptor\");\n    _disallowProperty(obj, \"placement\", \"A class descriptor\");\n    _disallowProperty(obj, \"descriptor\", \"A class descriptor\");\n    _disallowProperty(obj, \"initializer\", \"A class descriptor\");\n    _disallowProperty(obj, \"extras\", \"A class descriptor\");\n    var finisher = _optionalCallableProperty(obj, \"finisher\");\n    var elements = _toElementDescriptors(obj.elements);\n\n    return { elements: elements, finisher: finisher };\n}\nfunction _disallowProperty(obj, name, objectType) {\n    if (obj[name] !== undefined) throw new TypeError(objectType + \" can't have a .\" + name + \" property.\");\n}\nfunction _optionalCallableProperty(obj, name) {\n    var value = obj[name];\n    if (value !== undefined && typeof value !== \"function\") {\n        throw new TypeError(\"Expected '\" + name + \"' to be a function\");\n    }\n\n    return value;\n}\nfunction _runClassFinishers(constructor, finishers) {\n    for (var i = 0; i < finishers.length; i++) {\n        var newConstructor = (0, finishers[i])(constructor);\n        if (newConstructor !== undefined) {\n            if (typeof newConstructor !== \"function\") throw new TypeError(\"Finishers must return a constructor.\");\n            constructor = newConstructor;\n        }\n    }\n\n    return constructor;\n}\n\"#,\n    #[cfg(feature = \"inline-helpers\")]\n    deps: super::HelperBitmap::from_bits(0x0000000601a000044000080000000018),","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs#L239-L275","documentation":"The #[proc_macro_derive(Spanned)] entry point parses the incoming TokenStream as a syn::DeriveInput and unwraps with .expect(\"failed to parse input as DeriveInput\"). rustc only feeds derive macros with the AST of the annotated item, so in normal builds this never fails; if it does, the token stream handed to the macro was not a valid derive target (struct/enum/union item), and the proc macro panics with 'proc-macro panicked' plus this message.","triggerScenarios":"Using #[derive(Spanned)] on something that is not a plain item (e.g. inside macro-generated code whose expansion is not a valid DeriveInput), invoking the macro directly with raw tokens (macro playgrounds, quote-and-invoke tooling), or a syn version mismatch between the macro crate and what produced the tokens.","commonSituations":"Almost always a tooling/implementation accident rather than user code: nightly vs stable parser differences, third-party crates re-exporting the derive with incompatible syn versions, or test harnesses that call proc macros with hand-built token streams.","solutions":["Confirm #[derive(Spanned)] from swc is placed on a plain struct/enum/union definition with valid syntax (let rustc's own parse errors surface first - fix any preceding syntax errors in the item).","If the item is macro-generated, expand the outer macro (cargo expand) and check the emitted item is a well-formed struct/enum/union.","Check for duplicate/conflicting derives or attributes that rewrite the item before derivation.","If it persists on valid code, report it to the swc repo with the item source and rustc/cargo versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place #[derive(Spanned)] only on ordinary struct/enum/union items that already compile without the derive.","When the item comes from another macro, expand it (cargo expand) to confirm it is a plain item before adding derives."],"tags":["rust","proc-macro","derive","spanned","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"}