{"record":{"id":"1d46c61c2d5fb461","repo":"evanw/esbuild","slug":"duplicated-test-name-name-in-file-1d46c6","errorCode":null,"errorMessage":"Duplicated test name \"${name}\" in ${file}","messagePattern":"Duplicated test name \"(.+?)\" in (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/uglify-tests.js","lineNumber":363,"sourceCode":"function parse_test(file) {\n  var script = fs.readFileSync(file, \"utf8\");\n  // TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS/issues/348\n  try {\n    var ast = U.parse(script, {\n      filename: file\n    });\n  } catch (e) {\n    console.error(\"Caught error while parsing tests in \" + file);\n    console.error(e);\n    process.exit(1);\n  }\n  var tests = Object.create(null);\n  var tw = new U.TreeWalker(function (node, descend) {\n    if (node instanceof U.AST_LabeledStatement\n      && tw.parent() instanceof U.AST_Toplevel) {\n      var name = node.label.name;\n      if (name in tests) {\n        throw new Error('Duplicated test name \"' + name + '\" in ' + file);\n      }\n      tests[name] = get_one_test(name, node.body);\n      return true;\n    }\n    if (!(node instanceof U.AST_Toplevel)) croak(node);\n  });\n  ast.walk(tw);\n  return tests;\n\n  function croak(node) {\n    throw new Error(tmpl(\"Can't understand test file {file} [{line},{col}]\\n{code}\", {\n      file: file,\n      line: node.start.line,\n      col: node.start.col,\n      code: make_code(node, { beautify: false })\n    }));\n  }\n","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/uglify-tests.js#L345-L381","documentation":"Thrown by parse_test() in scripts/uglify-tests.js:363. The harness collects each top-level labeled statement into a `tests` object keyed by label name; if a label name already exists in the same file, this error is raised. Test names must be unique within a single uglify compress-test file.","triggerScenarios":"Two `label: { ... }` blocks in one uglify test file share the same label name. The second occurrence overwrites the first's slot, so the harness aborts to prevent silently dropping a test.","commonSituations":"A contributor copies a test block to create a variant and forgets to rename the label, or merges two test files that both define `issue_1234`.","solutions":["Find both occurrences of the duplicated label name in the file named in the error.","Rename the second block's label to a unique, descriptive name."],"exampleFix":"// before\nissue_1234: { input: { a: 1 }; expect: { a: 1 } }\nissue_1234: { input: { b: 2 }; expect: { b: 2 } }\n\n// after\nissue_1234_a: { input: { a: 1 }; expect: { a: 1 } }\nissue_1234_b: { input: { b: 2 }; expect: { b: 2 } }","handlingStrategy":"validation","validationCode":"function assertUniqueLabels(ast, file) {\n  const seen = new Set();\n  for (const stmt of ast.body) {\n    if (stmt instanceof U.AST_LabeledStatement) {\n      const name = stmt.label.name;\n      if (seen.has(name)) throw new Error(`Duplicate label '${name}' in ${file}`);\n      seen.add(name);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try { parse_test(file); }\ncatch (e) {\n  if (/Duplicated test name/.test(e.message)) console.error('Rename one of the colliding labels in', file);\n  throw e;\n}","preventionTips":["Give every test block a unique, descriptive label within its file.","When copying a block to make a variant, rename the label immediately.","Lint for duplicate labels when merging test files."],"tags":["test-harness","uglify","duplicate","validation","contributor"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}