{"record":{"id":"f50d36d6ed5c7648","repo":"evanw/esbuild","slug":"should-be-array-of-strings","errorCode":null,"errorMessage":"Should be array of strings","messagePattern":"Should be array of strings","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/terser-tests.js","lineNumber":280,"sourceCode":"    if (stat.TYPE == \"SimpleStatement\") {\n      var body = stat.body;\n      if (body instanceof U.AST_Boolean) {\n        return body.value;\n      }\n    }\n    throw new Error(\"Should be boolean\");\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 = {\n      name: name,\n      options: {},\n      reminify: true,\n    };\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        }","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/terser-tests.js#L262-L298","documentation":"Thrown by read_string() in scripts/terser-tests.js:280. When a test field value is an array literal, every element must be an AST_String. If any element is a number, identifier, template literal, or other expression, the `.map` callback throws this error.","triggerScenarios":"Writing a multi-line string field as an array that contains a non-string element, e.g. `expect: [\"a\", 42, \"b\"];` or `expect: [\"a\", foo];`. The array form is only valid when all elements are plain string literals (they get joined with newlines).","commonSituations":"A contributor mixes a variable reference or numeric value into what should be an array of string snippets, often when splitting a long expected output across lines.","solutions":["Make every element of the array a double- or single-quoted string literal.","If you need a non-string value, move it to the correct field type (e.g. a boolean field) instead of the string array."],"exampleFix":"// before\nexpect: [\"var a = 1;\", 2, \"console.log(a);\"];\n\n// after\nexpect: [\"var a = 1;\", \"console.log(a);\"];","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":["When splitting a string across lines as an array, quote each element.","Avoid pasting numbers or identifiers into string-array fields."],"tags":["test-harness","terser","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"}