evanw/esbuild · error · Error

Duplicated test name "${name}" in ${file}

Error message

Duplicated test name "${name}" in ${file}

What it means

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.

Source

Thrown at scripts/uglify-tests.js:363

function parse_test(file) {
  var script = fs.readFileSync(file, "utf8");
  // TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS/issues/348
  try {
    var ast = U.parse(script, {
      filename: file
    });
  } catch (e) {
    console.error("Caught error while parsing tests in " + file);
    console.error(e);
    process.exit(1);
  }
  var tests = Object.create(null);
  var tw = new U.TreeWalker(function (node, descend) {
    if (node instanceof U.AST_LabeledStatement
      && tw.parent() instanceof U.AST_Toplevel) {
      var name = node.label.name;
      if (name in tests) {
        throw new Error('Duplicated test name "' + name + '" in ' + file);
      }
      tests[name] = get_one_test(name, node.body);
      return true;
    }
    if (!(node instanceof U.AST_Toplevel)) croak(node);
  });
  ast.walk(tw);
  return tests;

  function croak(node) {
    throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
      file: file,
      line: node.start.line,
      col: node.start.col,
      code: make_code(node, { beautify: false })
    }));
  }

View on GitHub (pinned to f6058f8364)

Solutions

  1. Find both occurrences of the duplicated label name in the file named in the error.
  2. Rename the second block's label to a unique, descriptive name.

Example fix

// before
issue_1234: { input: { a: 1 }; expect: { a: 1 } }
issue_1234: { input: { b: 2 }; expect: { b: 2 } }

// after
issue_1234_a: { input: { a: 1 }; expect: { a: 1 } }
issue_1234_b: { input: { b: 2 }; expect: { b: 2 } }
Defensive patterns

Strategy: validation

Validate before calling

function assertUniqueLabels(ast, file) {
  const seen = new Set();
  for (const stmt of ast.body) {
    if (stmt instanceof U.AST_LabeledStatement) {
      const name = stmt.label.name;
      if (seen.has(name)) throw new Error(`Duplicate label '${name}' in ${file}`);
      seen.add(name);
    }
  }
}

Try / catch

try { parse_test(file); }
catch (e) {
  if (/Duplicated test name/.test(e.message)) console.error('Rename one of the colliding labels in', file);
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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`.

Related errors


AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09). Data as JSON: /api/errors/1d46c61c2d5fb461. Report an issue: GitHub.