{"id":"6b34d0236b823261","repo":"babel/babel","slug":"unexpected-replacement-overlap","errorCode":null,"errorMessage":"Unexpected replacement overlap.","messagePattern":"Unexpected replacement overlap\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-template/src/literal.ts","lineNumber":26,"sourceCode":"  formatter: Formatter<T>,\n  tpl: string[],\n  opts: TemplateOpts,\n): (_: unknown[]) => (_: unknown) => T {\n  const { metadata, names } = buildLiteralData(formatter, tpl, opts);\n\n  return arg => {\n    const defaultReplacements: TemplateReplacements = {};\n    arg.forEach((replacement, i) => {\n      defaultReplacements[names[i]] = replacement;\n    });\n\n    return (arg: unknown) => {\n      const replacements = normalizeReplacements(arg);\n\n      if (replacements) {\n        Object.keys(replacements).forEach(key => {\n          if (Object.hasOwn(defaultReplacements, key)) {\n            throw new Error(\"Unexpected replacement overlap.\");\n          }\n        });\n      }\n\n      return formatter.unwrap(\n        populatePlaceholders(\n          metadata,\n          replacements\n            ? Object.assign(replacements, defaultReplacements)\n            : defaultReplacements,\n        ),\n      );\n    };\n  };\n}\n\nfunction buildLiteralData<T>(\n  formatter: Formatter<T>,","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/babel/babel/blob/06b6eae39da4ce0689fad64e2c48a6375a464208/packages/babel-template/src/literal.ts#L8-L44","documentation":"Tagged-literal templates generate internal placeholder names (prefixed with BABEL_TPL$, e.g. $$BABEL_TPL$0) for the ${} interpolation slots, then merge them with user-named replacements. If a user-supplied replacement key collides with one of these generated names, substitution is ambiguous and rejected.","triggerScenarios":"Calling a tagged-literal builder with a replacements object whose key matches a generated name, e.g. tpl`...`({ '$$BABEL_TPL$0': node }) or any key beginning with the BABEL_TPL$ prefix.","commonSituations":"Rare; occurs when user replacement keys happen to match the generated prefix, or when array-form and object-form replacements are mixed in a way that collides.","solutions":["Rename replacement keys to avoid the BABEL_TPL$ prefix.","Do not mix positional ${x} substitutions with object keys that resemble the generated names.","If you need control over names, use the string form template(\"code\", opts) with explicit %%foo%% placeholders."],"exampleFix":"// before\ntpl`x`({ '$$BABEL_TPL$0': node })\n// after\ntpl`x`({ myKey: node })","handlingStrategy":"validation","validationCode":"function assertNoBabelPrefix(replacements) {\n  for (const k of Object.keys(replacements || {})) {\n    if (k.includes('BABEL_TPL$')) throw new Error(`replacement key ${k} collides with internal prefix`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid the BABEL_TPL$ substring in replacement keys.","Do not mix positional ${} slots with object keys that resemble generated names.","Use string-form templates with %%foo%% for full control of placeholder names."],"tags":["replacements","literal","placeholder"],"analyzedSha":"06b6eae39da4ce0689fad64e2c48a6375a464208","analyzedAt":"2026-08-03T20:13:43.465Z","schemaVersion":2}