{"record":{"id":"e41f32dcec684155","repo":"swc-project/swc","slug":"duplicated-element-element-key","errorCode":null,"errorMessage":"Duplicated element (${element.key})","messagePattern":"Duplicated element \\((.+?)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs","lineNumber":131,"sourceCode":"        _addElementPlacement(element, placements);\n    });\n    elements.forEach(function(element) {\n        if (!_hasDecorators(element)) return newElements.push(element);\n        var elementFinishersExtras = _decorateElement(element, placements);\n        newElements.push(elementFinishersExtras.element);\n        newElements.push.apply(newElements, elementFinishersExtras.extras);\n        finishers.push.apply(finishers, elementFinishersExtras.finishers);\n    });\n    if (!decorators) return { elements: newElements, finishers: finishers };\n    var result = _decorateConstructor(newElements, decorators);\n    finishers.push.apply(finishers, result.finishers);\n    result.finishers = finishers;\n\n    return result;\n}\nfunction _addElementPlacement(element, placements, silent) {\n    var keys = placements[element.placement];\n    if (!silent && keys.indexOf(element.key) !== -1) throw new TypeError(\"Duplicated element (\" + element.key + \")\");\n    keys.push(element.key);\n}\nfunction _decorateElement(element, placements) {\n    var extras = [];\n    var finishers = [];\n    for (var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--) {\n        var keys = placements[element.placement];\n        keys.splice(keys.indexOf(element.key), 1);\n        var elementObject = _fromElementDescriptor(element);\n        var elementFinisherExtras = _toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject);\n        element = elementFinisherExtras.element;\n        _addElementPlacement(element, placements);\n        if (elementFinisherExtras.finisher) finishers.push(elementFinisherExtras.finisher);\n        var newExtras = elementFinisherExtras.extras;\n        if (newExtras) {\n            for (var j = 0; j < newExtras.length; j++) _addElementPlacement(newExtras[j], placements);\n            extras.push.apply(extras, newExtras);\n        }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs#L113-L149","documentation":"This wasm support crate wraps operations in try_with_json_handler: it installs a swc Handler whose emitter collects diagnostics, runs the op, and if the handler saw no errors it unwraps the op result with .expect(\"it should not fail without emitting errors to handler\"). The panic fires only when the inner operation returns Err while emitting nothing to the handler - an invariant violation inside the library (here on the path used by swc_ts_fast_strip / node wasm support), not a user-input parse error.","triggerScenarios":"A code path in the wrapped operation that returns Err (e.g. anyhow::Error from swc_ts_fast_strip::operate or a non-emitting internal error) without calling handler.struct_err/span_err first. Reproducing typically requires the specific input that makes the transform bail early - malformed or edge-case TypeScript that triggers an unlogged internal failure path.","commonSituations":"Hitting an untested corner of the TypeScript-stripping pipeline (exotic syntax, very large/deep inputs) in an @swc/wasm-based tool; upgrading a wasm binding where a new early-return was added without handler emission; running the wasm build in browser/edge runtimes where an auxiliary error (e.g. allocation) surfaces as a plain Err.","solutions":["Minimize the failing input and check the panic location via the wasm stack trace; confirm it is this expect and not an input syntax error (syntax errors normally come back as JSON diagnostics).","Update to the latest version of the wasm binding - these invariant gaps are treated as bugs and fixed upstream.","Report the issue to the swc repo (SWC_REPO) with the minimized input, binding version, and stack trace.","As a stopgap, catch the JS exception from the wasm call and fall back to a conservative transform for that file."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = await transformWasm(source, options);\n} catch (e) {\n  if (/it should not fail without emitting errors to handler/.test(String(e?.message))) {\n    // library invariant violation, not a user-syntax error\n    console.error('swc wasm internal error; input saved for bug report:', source);\n    throw e;\n  }\n  throw e; // normal diagnostics arrive as JSON, not this message\n}","preventionTips":["Pin known-good versions of wasm bindings; test upgrades against your corpus of inputs.","Keep a fallback transform path (e.g. esbuild or older binding) for files that trigger the panic.","Log the exact input with the panic so upstream can reproduce and fix the missing handler emission."],"tags":["swc","wasm","internal-error","invariant","panic","typescript-strip"],"backgroundTag":"wasm-binding-panic","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}