evanw/esbuild · error · Error
Unsupported input syntax
Error message
Unsupported input syntax
What it means
In the terser-test harness (scripts/terser-tests.js:210), `as_toplevel` expects the parsed input to be an `AST_BlockStatement`; if it is any other AST node type, it throws 'Unsupported input syntax'. This is internal test-tooling validation used while converting terser test fixtures into esbuild-compatible ASTs — it is not part of the esbuild library's public API.
Source
Thrown at scripts/terser-tests.js:212
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
function tmpl() {
return U.string_template.apply(this, arguments);
}
function as_toplevel(input, mangle_options) {
if (!(input instanceof U.AST_BlockStatement))
throw new Error("Unsupported input syntax");
for (var i = 0; i < input.body.length; i++) {
var stat = input.body[i];
if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)
input.body[i] = new U.AST_Directive(stat.body);
else break;
}
var toplevel = new U.AST_Toplevel(input);
toplevel.figure_out_scope(mangle_options);
return toplevel;
}
function parse_test(file) {
var script = fs.readFileSync(file, "utf8");
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348
try {
var ast = U.parse(script, {
filename: file
});View on GitHub (pinned to f6058f8364)
Solutions
- Ensure the test fixture parses to an `AST_BlockStatement` as expected by `as_toplevel`.
- Regenerate or restore the test fixture to the terser format the harness expects.
- Pin the terser version to one whose test AST shape matches this harness.
Example fix
// before — fixture body is a bare expression statement at top level // after — wrap fixture statements so they parse as AST_BlockStatement per terser test format
Defensive patterns
Strategy: validation
Validate before calling
// In the terser test harness, validate the AST type before calling as_toplevel
const U = require('./demo/terser');
function safeAsToplevel(input) {
if (!(input instanceof U.AST_BlockStatement)) throw new Error('Unsupported input syntax');
return as_toplevel(input);
} Type guard
function isBlockStatement(node: any, U: any): boolean {
return node instanceof U.AST_BlockStatement;
} Prevention
- Pin the terser version whose fixture AST shape this harness supports.
- Wrap fixtures in blocks per the terser compress-test format.
When it happens
Trigger: Running `scripts/terser-tests.js` against a terser test fixture whose source parses to a non-block top-level construct, or calling `as_toplevel` with malformed input during local test development.
Common situations: Vendoring a newer/older terser test format that changes the AST shape; editing a compress test fixture so it no longer wraps statements in a block; running the harness against an unsupported terser version.
Related errors
- Duplicated test name "${name}" in ${file}
- Can't understand test file {file} [{line},{col}] {code}
- Should be boolean
- Should be array of strings
- Should be string or array of strings
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/2ca23a6315c5feab.
Report an issue: GitHub.