{"record":{"id":"e021cb72eca6c558","repo":"swc-project/swc","slug":"please-confirm-if-plugin-macro-is-specified-for-th","errorCode":null,"errorMessage":"Please confirm if plugin macro is specified for the function","messagePattern":"Please confirm if plugin macro is specified for the function","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_plugin_macro/src/lib.rs","lineNumber":16,"sourceCode":"extern crate proc_macro;\nuse proc_macro::TokenStream;\nuse proc_macro2::{Ident, Span};\nuse quote::quote;\nuse syn::{Item as SynItem, ItemFn};\n\n#[proc_macro_attribute]\npub fn plugin_transform(\n    _args: proc_macro::TokenStream,\n    input: proc_macro::TokenStream,\n) -> proc_macro::TokenStream {\n    let token = proc_macro2::TokenStream::from(input);\n    let parsed_results = syn::parse2::<SynItem>(token).expect(\"Failed to parse tokens\");\n    match parsed_results {\n        SynItem::Fn(func) => handle_func(func, Ident::new(\"Program\", Span::call_site())),\n        _ => panic!(\"Please confirm if plugin macro is specified for the function\"),\n    }\n}\n\n#[allow(clippy::redundant_clone)]\nfn handle_func(func: ItemFn, ast_type: Ident) -> TokenStream {\n    let ident = func.sig.ident.clone();\n    let transform_process_impl_ident =\n        Ident::new(\"__transform_plugin_process_impl\", Span::call_site());\n    let transform_core_pkg_diag_ident =\n        Ident::new(\"__get_transform_plugin_core_pkg_diag\", Span::call_site());\n\n    let ret = quote! {\n        #func\n\n        // Declaration for imported function from swc host.\n        // Refer swc_plugin_runner for the actual implementation.\n        #[cfg(target_arch = \"wasm32\")] // Allow testing\n        #[link(wasm_import_module = \"env\")]","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_plugin_macro/src/lib.rs#L1-L34","documentation":"#[plugin_transform] is the attribute proc macro from swc_plugin_macro that wraps a SWC plugin's WASM transform entry point. It parses the annotated item with syn and only accepts an ItemFn (see the `SynItem::Fn(func)` arm); any other item kind makes the macro panic at compile time with this message.","triggerScenarios":"Applying #[plugin_transform] to anything other than a free function: a struct (e.g. a config struct), an impl block, a module, a trait, or a use item. Also happens when the attribute is left on an outer item after refactoring moved the transform fn elsewhere.","commonSituations":"Bootstrapping a plugin from a modified `swc plugin new` template; splitting the transform into helper items and accidentally relocating the attribute; copy-pasting the attribute above config/state types.","solutions":["Move #[plugin_transform] so it decorates the plugin's transform function itself, with no other item between","Give that function the required plugin signature: fn process(program: &mut Program, metadata: TransformPluginContextMetadata, config: String, should_enable_comments_proxy: bool, ast: &AstNode<PathBuf>) -> Program","Delete stray copies of the attribute from structs/impls/modules and run `cargo check --target wasm32-wasip1` to confirm the macro expands"],"exampleFix":"// before\n#[plugin_transform]\npub struct Config { pub opt: bool } // proc macro panics: not a function\n\n// after\npub struct Config { pub opt: bool }\n\n#[plugin_transform]\npub fn process_transform(\n    program: &mut Program,\n    _metadata: TransformPluginContextMetadata,\n    _config: String,\n    _should_enable_comments_proxy: bool,\n    _ast: &AstNode<PathBuf>,\n) -> Program {\n    program.clone()\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep #[plugin_transform] directly above the transform function and nowhere else","Start from the `swc plugin new` template so item placement and signature are correct","Run `cargo check --target wasm32-wasip1` (or build-wasip1 alias) immediately after moving plugin code","Copy the exact entry-point signature (program, metadata, config, should_enable_comments_proxy, ast) from the template docs"],"tags":["swc-plugin","proc-macro","compile-time","attribute-macro","rust"],"backgroundTag":"attribute-macro-misapplied","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"}