{"record":{"id":"3aad846b124db894","repo":"evanw/esbuild","slug":"can-t-understand-test-file-file-line-col-3aad84","errorCode":null,"errorMessage":"Can't understand test file {file} [{line},{col}]\n{code}","messagePattern":"Can't understand test file (.+?) \\[(.+?),(.+?)\\]\n(.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/uglify-tests.js","lineNumber":374,"sourceCode":"  }\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\n  function read_string(stat) {\n    if (stat.TYPE == \"SimpleStatement\") {\n      var body = stat.body;\n      switch (body.TYPE) {\n        case \"String\":\n          return body.value;\n        case \"Array\":\n          return body.elements.map(function (element) {\n            if (element.TYPE !== \"String\")\n              throw new Error(\"Should be array of strings\");\n            return element.value;","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/uglify-tests.js#L356-L392","documentation":"Thrown by croak() inside parse_test() in esbuild's uglify test harness (scripts/uglify-tests.js:374). Identical in purpose to the terser variant: the AST TreeWalker expects every top-level node to be an AST_LabeledStatement; any other node type besides AST_Toplevel causes the harness to reject the file as malformed, reporting file, line, column, and the offending code.","triggerScenarios":"An uglify compress-test file has top-level content that is not a `label: { ... }` test block, or an AST_Assign inside a block has a left-hand side that is not an AST_SymbolRef (croak is called at line 404).","commonSituations":"Contributor adds a helper function, import, or stray statement at the top of an uglify test file, or uglify's DSL changes shape in a way the copied harness code does not understand.","solutions":["Inspect the file/line/column in the message and make the offending top-level construct a labeled test block.","For assignment errors, ensure the left-hand side is a bare symbol reference.","If uglify's test format changed, extend parse_test/get_one_test to handle the new node type."],"exampleFix":"// before\nfunction helper() { return 1 }\nmy_test: { input: { a: helper() }; expect: { a: 1 } }\n\n// after\nmy_test: { input: { a: 1 }; expect: { a: 1 } }","handlingStrategy":"validation","validationCode":"function validateUglifyTestFile(file) {\n  const ast = U.parse(fs.readFileSync(file, 'utf8'), { filename: file });\n  for (const stmt of ast.body) {\n    if (!(stmt instanceof U.AST_LabeledStatement)) {\n      throw new Error(`${file}:${stmt.start.line}:${stmt.start.col} top-level node is not a labeled test block`);\n    }\n  }\n}","typeGuard":"const isLabeledTopLevel = (node, parent) =>\n  node instanceof U.AST_LabeledStatement && parent instanceof U.AST_Toplevel;","tryCatchPattern":"try { parse_test(file); }\ncatch (e) {\n  if (/Can't understand test file/.test(e.message)) console.error('Malformed uglify test file:', e.message);\n  throw e;\n}","preventionTips":["Model new uglify tests on an existing passing file's label:block structure.","Keep all top-level statements inside labeled blocks; put no helper code at file root.","Ensure assignment left-hand sides are bare symbol references."],"tags":["test-harness","uglify","parser","ast","contributor"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}