{"record":{"id":"c09790f170ad9688","repo":"babel/babel","slug":"decorating-two-elements-with-the-same-name-desc","errorCode":null,"errorMessage":"Decorating two elements with the same name (${desc[key].name}) is not supported yet","messagePattern":"Decorating two elements with the same name \\((.+?)\\) is not supported yet","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-helpers/src/helpers/applyDecs2311.ts","lineNumber":344,"sourceCode":"            },\n          };\n        } else {\n          desc[key] = decVal;\n        }\n\n        if (!isField) {\n          setFunctionName(desc[key], name, isMethod ? \"\" : key);\n        }\n      } else if (!isField) {\n        desc = Object.getOwnPropertyDescriptor(Class, name)!;\n      }\n\n      if (!isField && !isPrivate) {\n        _ = existingNonFields[+isStatic!][name];\n        // flag is 1, 3, or 4; kind is 0, 1, 2, 3, or 4\n        // flag ^ kind is 7 if and only if one of them is 3 and the other one is 4.\n        if (_ && (_ ^ kind) !== 7) {\n          throw new Error(\n            \"Decorating two elements with the same name (\" +\n              desc[key].name +\n              \") is not supported yet\",\n          );\n        }\n        // We use PROP_KIND.ACCESSOR to mark a name as \"fully used\":\n        // either a get/set pair, or a non-getter/setter.\n        existingNonFields[+isStatic!][name] =\n          kind < PROP_KIND.GETTER\n            ? PROP_KIND.ACCESSOR\n            : (kind as PROP_KIND.GETTER | PROP_KIND.SETTER);\n      }\n    }\n\n    var newValue = Class;\n\n    for (var i = decs.length - 1; i >= 0; i -= decoratorsHaveThis ? 2 : 1) {\n      var dec = assertCallable(decs[i], \"A decorator\", \"be\", true) as Function,","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/babel/babel/blob/1eac4481473df52fbbcb452c4dca8d79039dbb63/packages/babel-helpers/src/helpers/applyDecs2311.ts#L326-L362","documentation":"Thrown inside applyDecs2311 when two non-field, non-private class elements sharing the same name are both decorated, and they are not a complementary getter/setter pair (the flag^kind check `!== 7` distinguishes a get+set pair from a duplicate). The current decorator runtime does not support decorating two distinct elements with the same name beyond an accessor get/set duo, so it aborts rather than silently dropping a decorator.","triggerScenarios":"A class declares two methods with the same name (one shadowing the other) and both carry decorators, or a method and a getter with the same name both decorated. The check at line 343 (_ && (_ ^ kind) !== 7) fires for the second decorated element after existingNonFields already recorded the first.","commonSituations":"Refactoring that accidentally creates duplicate method names while decorators are attached, or merging mixin definitions that collide on a name. Also when a developer expects the second definition to win but both are decorated.","solutions":["Rename one of the colliding decorated elements so names are unique.","Remove the decorator from the shadowed element if only one should take effect.","If you intended a getter/setter pair, ensure they are decorated as `accessor`/get+set, not two methods.","Audit the class for accidental duplicate method declarations introduced during a merge."],"exampleFix":"// before\nclass C {\n  @dec handle() {}\n  @dec handle() {} // duplicate name\n}\n// after\nclass C {\n  @dec handleClick() {}\n  @dec handleTouch() {}\n}","handlingStrategy":"validation","validationCode":"// Detect duplicate decorated element names at author time\nfunction findDuplicateDecoratedNames(classBody) {\n  const seen = new Map();\n  const dups = [];\n  for (const el of classBody) {\n    if (el.decorators?.length && el.key) {\n      if (seen.has(el.key)) dups.push(el.key);\n      seen.set(el.key, el.kind);\n    }\n  }\n  return dups;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use unique names for decorated class elements.","Run a lint pass that flags duplicate method names within a class body.","Review merge commits for accidental duplicate method declarations."],"tags":["babel","decorators","duplicate-name","runtime","class"],"backgroundTag":null,"analyzedSha":"1eac4481473df52fbbcb452c4dca8d79039dbb63","analyzedAt":"2026-08-08T11:11:04.395Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}