evanw/esbuild · error · Error
Unsupported input syntax
Error message
Unsupported input syntax
What it means
Thrown by to_toplevel() in scripts/uglify-tests.js:470. After parsing the test's `input:` value, the harness requires it to be an AST_BlockStatement (a brace-enclosed block). If the parsed input is any other node type (a single expression, a declaration, etc.), this error is raised before scope analysis.
Source
Thrown at scripts/uglify-tests.js:470
});
block.walk(tw);
return test;
}
}
function run_code(code, toplevel) {
const sandbox = require(path.join(uglifyDir, 'test', 'sandbox'));
var result = sandbox.run_code(code, toplevel);
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
}
function tmpl() {
return U.string_template.apply(null, arguments);
}
function to_toplevel(input, mangle_options) {
if (!(input instanceof U.AST_BlockStatement)) throw new Error("Unsupported input syntax");
var directive = true;
var offset = input.start.line;
var tokens = [];
var toplevel = new U.AST_Toplevel(input.transform(new U.TreeTransformer(function (node) {
if (U.push_uniq(tokens, node.start)) node.start.line -= offset;
if (!directive || node === input) return;
if (node instanceof U.AST_SimpleStatement && node.body instanceof U.AST_String) {
return new U.AST_Directive(node.body);
} else {
directive = false;
}
})));
toplevel.figure_out_scope(mangle_options);
return toplevel;
}
View on GitHub (pinned to f6058f8364)
Solutions
- Wrap the input body in `{ ... }` so it parses as a block statement.
- Verify the input still reproduces the original bug after wrapping.
Example fix
// before
input: var a = 1; console.log(a);
// after
input: { var a = 1; console.log(a); } Defensive patterns
Strategy: type-guard
Validate before calling
function isBlockInput(parsedInput) {
return parsedInput instanceof U.AST_BlockStatement;
} Type guard
const isBlockStatement = (node) => node instanceof U.AST_BlockStatement;
Try / catch
try { to_toplevel(input, mangle); }
catch (e) {
if (/Unsupported input syntax/.test(e.message)) console.error('Wrap the input field body in { ... }');
throw e;
} Prevention
- Always wrap an uglify test's `input:` value in curly braces so it parses as a block.
- Validate the input is a block before calling to_toplevel.
When it happens
Trigger: An uglify test's `input:` field is not wrapped in curly braces, so it parses to something other than an AST_BlockStatement. For example `input: var a = 1;` instead of `input: { var a = 1; }`.
Common situations: Contributor writes an input as a bare statement or omits the enclosing braces required by the compress-test DSL.
Related errors
- Duplicated test name "${name}" in ${file}
- Can't understand test file {file} [{line},{col}] {code}
- Should be array of strings
- Should be string or array of strings
- Can't understand test file {file} [{line},{col}] {code}
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/ddc32039162b11bf.
Report an issue: GitHub.