{"record":{"id":"b5757ad4423630f1","repo":"evanw/esbuild","slug":"should-be-array-of-strings-b5757a","errorCode":null,"errorMessage":"Should be array of strings","messagePattern":"Should be array of strings","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/uglify-tests.js","lineNumber":391,"sourceCode":"  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;\n          }).join(\"\\n\");\n      }\n    }\n    throw new Error(\"Should be string or array of strings\");\n  }\n\n  function get_one_test(name, block) {\n    var test = { name: name, options: {} };\n    var tw = new U.TreeWalker(function (node, descend) {\n      if (node instanceof U.AST_Assign) {\n        if (!(node.left instanceof U.AST_SymbolRef)) {\n          croak(node);\n        }\n        var name = node.left.name;\n        test[name] = evaluate(node.right);\n        return true;\n      }","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/uglify-tests.js#L373-L409","documentation":"Thrown by read_string() in scripts/uglify-tests.js:391. When a string field's value is an array literal, each element must be an AST_String; a non-string element triggers this error. The array elements are joined with newlines to form a single multi-line string.","triggerScenarios":"Writing `expect: [\"a\", 1, \"b\"];` or `expect: [\"a\", x];` in an uglify test file. Only string literals are permitted inside such arrays.","commonSituations":"Contributor splits a long expected-output string across lines and accidentally includes a number or identifier in the array.","solutions":["Ensure every array element is a quoted string literal.","Concatenate manually or use a single multi-line string if a non-string value is genuinely needed."],"exampleFix":"// before\nexpect: [\"var a = 1;\", 2];\n\n// after\nexpect: [\"var a = 1;\", \"2\"];","handlingStrategy":"type-guard","validationCode":"function allElementsAreStrings(arrNode) {\n  return arrNode instanceof U.AST_Array &&\n    arrNode.elements.every(el => el instanceof U.AST_String);\n}","typeGuard":"const isStringArray = (node) =>\n  node instanceof U.AST_Array && node.elements.every(el => el.TYPE === 'String');","tryCatchPattern":"try { read_string(stat); }\ncatch (e) {\n  if (/Should be array of strings/.test(e.message)) console.error('Every array element must be a string literal');\n  throw e;\n}","preventionTips":["Quote every element in a string-array field.","Do not mix numbers, identifiers, or calls into these arrays."],"tags":["test-harness","uglify","validation","string-array","contributor"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}