{"record":{"id":"2ca23a6315c5feab","repo":"evanw/esbuild","slug":"unsupported-input-syntax","errorCode":null,"errorMessage":"Unsupported input syntax","messagePattern":"Unsupported input syntax","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/terser-tests.js","lineNumber":212,"sourceCode":"// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\n// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n// SUCH DAMAGE.\n\nfunction tmpl() {\n  return U.string_template.apply(this, arguments);\n}\n\nfunction as_toplevel(input, mangle_options) {\n  if (!(input instanceof U.AST_BlockStatement))\n    throw new Error(\"Unsupported input syntax\");\n  for (var i = 0; i < input.body.length; i++) {\n    var stat = input.body[i];\n    if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)\n      input.body[i] = new U.AST_Directive(stat.body);\n    else break;\n  }\n  var toplevel = new U.AST_Toplevel(input);\n  toplevel.figure_out_scope(mangle_options);\n  return toplevel;\n}\n\nfunction parse_test(file) {\n  var script = fs.readFileSync(file, \"utf8\");\n  // TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348\n  try {\n    var ast = U.parse(script, {\n      filename: file\n    });","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/terser-tests.js#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — fixture body is a bare expression statement at top level\n// after — wrap fixture statements so they parse as AST_BlockStatement per terser test format","handlingStrategy":"validation","validationCode":"// In the terser test harness, validate the AST type before calling as_toplevel\nconst U = require('./demo/terser');\nfunction safeAsToplevel(input) {\n  if (!(input instanceof U.AST_BlockStatement)) throw new Error('Unsupported input syntax');\n  return as_toplevel(input);\n}","typeGuard":"function isBlockStatement(node: any, U: any): boolean {\n  return node instanceof U.AST_BlockStatement;\n}","tryCatchPattern":null,"preventionTips":["Pin the terser version whose fixture AST shape this harness supports.","Wrap fixtures in blocks per the terser compress-test format."],"tags":["tests","terser","internal","ast","test-tooling"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}