evanw/esbuild · error · Error
Should be array of strings
Error message
Should be array of strings
What it means
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.
Source
Thrown at scripts/uglify-tests.js:391
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 })
}));
}
function read_string(stat) {
if (stat.TYPE == "SimpleStatement") {
var body = stat.body;
switch (body.TYPE) {
case "String":
return body.value;
case "Array":
return body.elements.map(function (element) {
if (element.TYPE !== "String")
throw new Error("Should be array of strings");
return element.value;
}).join("\n");
}
}
throw new Error("Should be string or array of strings");
}
function get_one_test(name, block) {
var test = { name: name, options: {} };
var tw = new U.TreeWalker(function (node, descend) {
if (node instanceof U.AST_Assign) {
if (!(node.left instanceof U.AST_SymbolRef)) {
croak(node);
}
var name = node.left.name;
test[name] = evaluate(node.right);
return true;
}View on GitHub (pinned to f6058f8364)
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.
Example fix
// before expect: ["var a = 1;", 2]; // after expect: ["var a = 1;", "2"];
Defensive patterns
Strategy: type-guard
Validate before calling
function allElementsAreStrings(arrNode) {
return arrNode instanceof U.AST_Array &&
arrNode.elements.every(el => el instanceof U.AST_String);
} Type guard
const isStringArray = (node) => node instanceof U.AST_Array && node.elements.every(el => el.TYPE === 'String');
Try / catch
try { read_string(stat); }
catch (e) {
if (/Should be array of strings/.test(e.message)) console.error('Every array element must be a string literal');
throw e;
} Prevention
- Quote every element in a string-array field.
- Do not mix numbers, identifiers, or calls into these arrays.
When it happens
Trigger: Writing `expect: ["a", 1, "b"];` or `expect: ["a", x];` in an uglify test file. Only string literals are permitted inside such arrays.
Common situations: Contributor splits a long expected-output string across lines and accidentally includes a number or identifier in the array.
Related errors
- Should be array of strings
- Duplicated test name "${name}" in ${file}
- Should be string or array of strings
- Unsupported input syntax
- Should be boolean
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/b5757ad4423630f1.
Report an issue: GitHub.