evanw/esbuild · error · Error

Duplicated test name

Error message

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

What it means

In the terser-test parser (scripts/terser-tests.js:241), fixtures are keyed by label names; if two labeled statements at the top level share the same label name, the harness throws 'Duplicated test name'. This prevents ambiguous/overridden tests within a single terser compress fixture file. The quoted name and file identify the collision.

Solutions

  1. Rename one of the duplicated labels so each test case in the file is uniquely named.
  2. Regenerate the local `.terser-tests` fixtures from upstream terser to clear stale duplicates.

Example fix

// before — in one fixture file
foo_test: { ... }
foo_test: { ... }
// after
foo_test: { ... }
foo_test_2: { ... }
Defensive patterns

Strategy: validation

Validate before calling

function assertUniqueTestNames(tests: Record<string, any>, file: string): void {
  const seen = new Set<string>();
  for (const name in tests) {
    if (seen.has(name)) throw new Error(`Duplicated test name "${name}" in ${file}`);
    seen.add(name);
  }
}

Prevention

When it happens

Trigger: A terser compress fixture file containing two `label_name: { ... }` test cases with the identical label name.

Common situations: Copying a test case and forgetting to rename the label; merging fixture files that each used a generic name like `default`; upstream terser adding a name that already exists locally.

Related errors


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

Appendix: source

Thrown at scripts/terser-tests.js:242

function parse_test(file) {
  var script = fs.readFileSync(file, "utf8");
  // TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348
  try {
    var ast = U.parse(script, {
      filename: file
    });
  } catch (e) {
    console.log("Caught error while parsing tests in " + file + "\n");
    console.log(e);
    throw e;
  }
  var tests = {};
  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)