{"record":{"id":"e79f007c170dca79","repo":"swc-project/swc","slug":"duplicate-variable-name-ident-str","errorCode":null,"errorMessage":"Duplicate variable name: {ident_str}","messagePattern":"Duplicate variable name: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_quote_macros/src/ctxt.rs","lineNumber":135,"sourceCode":"                    var.ty\n                )\n            }\n        };\n\n        let var_ident = syn::Ident::new(&format!(\"quote_var_{ident}\"), ident.span());\n\n        let old = init_map.entry(pos).or_default().insert(\n            ident_str.clone(),\n            VarData {\n                pos,\n                is_counting: true,\n                clone: Default::default(),\n                ident: var_ident.clone(),\n            },\n        );\n\n        if let Some(old) = old {\n            panic!(\"Duplicate variable name: {ident_str}\");\n        }\n\n        let type_name = Ident::new(\n            match pos {\n                VarPos::Ident => \"Ident\",\n                VarPos::Expr => \"Expr\",\n                VarPos::Pat => \"Pat\",\n                VarPos::AssignTarget => \"AssignTarget\",\n                VarPos::Str => \"Str\",\n            },\n            call_site(),\n        );\n        stmts.push(parse_quote! {\n            let #var_ident: swc_core::ecma::ast::#type_name = #value;\n        });\n    }\n\n    // Use `ToCode` to count how many times each variable is used.","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_quote_macros/src/ctxt.rs#L117-L153","documentation":"Within one quote! invocation, each interpolated variable name may be bound exactly once: the macro records every name in an init map and panics with 'Duplicate variable name: {ident_str}' when a name is inserted twice. Even binding the same name with two different type annotations triggers it.","triggerScenarios":"Writing quote!(name as Ident; name as Expr;) or repeating an interpolation binding for the same variable name inside a single quote! block.","commonSituations":"Large hand-written quote blocks edited over time where a variable gets interpolated twice, copy-paste of interpolation statements, refactors that rename one binding but leave a stale duplicate.","solutions":["Rename one of the duplicate interpolations so each name binds once per quote! block","If the same value is needed twice, bind it once and reference the generated quote_var_* identifier, or split into two quote! invocations","Grep the macro body for the reported identifier to find both binding sites quickly"],"exampleFix":"// before\nquote!(name as Ident; name as Expr; log(name););\n\n// after\nquote!(name as Ident; expr as Expr; log(name, expr););","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind each interpolated name exactly once per quote! block","When a name is needed twice, interpolate it once and reuse the generated variable","Search the macro body for the reported identifier after any rename refactor"],"tags":["proc-macro","quote","duplicate-binding","compile-time"],"backgroundTag":"duplicate-binding","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"}