{"record":{"id":"3c648d0ba70656ba","repo":"evanw/esbuild","slug":"unexpected","errorCode":null,"errorMessage":"Unexpected \":\"","messagePattern":"Unexpected \":\"","errorType":"panic","errorClass":"LexerPanic","httpStatus":null,"severity":"error","filePath":"internal/js_parser/js_parser.go","lineNumber":3331,"sourceCode":"\t\t\t\tneedsAsyncLoc: loc,\n\t\t\t\tawait:         await,\n\t\t\t})\n\t\t\tarrow.IsAsync = isAsync\n\t\t\tarrow.HasRestArg = spreadRange.Len > 0\n\t\t\tp.popScope()\n\t\t\treturn js_ast.Expr{Loc: loc, Data: arrow}\n\t\t}\n\t}\n\n\t// If we get here, it's not an arrow function so undo the pushing of the\n\t// scope we did earlier. This needs to flatten any child scopes into the\n\t// parent scope as if the scope was never pushed in the first place.\n\tp.popAndFlattenScope(scopeIndex)\n\n\t// If this isn't an arrow function, then types aren't allowed\n\tif typeColonRange.Len > 0 {\n\t\tp.log.AddError(&p.tracker, typeColonRange, \"Unexpected \\\":\\\"\")\n\t\tpanic(js_lexer.LexerPanic{})\n\t}\n\n\t// Are these arguments for a call to a function named \"async\"?\n\tif isAsync {\n\t\tp.logExprErrors(&errors)\n\t\tasync := js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{\n\t\t\tRef: p.storeNameInRef(js_lexer.MaybeSubstring{String: \"async\"})}}\n\t\treturn js_ast.Expr{Loc: loc, Data: &js_ast.ECall{\n\t\t\tTarget: async,\n\t\t\tArgs:   items,\n\t\t}}\n\t}\n\n\t// Is this a chain of expressions and comma operators?\n\tif len(items) > 0 {\n\t\tp.logExprErrors(&errors)\n\t\tif spreadRange.Len > 0 {\n\t\t\tp.log.AddError(&p.tracker, spreadRange, \"Unexpected \\\"...\\\"\")","sourceCodeStart":3313,"sourceCodeEnd":3349,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/js_parser/js_parser.go#L3313-L3349","documentation":"After parsing a parenthesized group that turned out NOT to be an arrow function, esbuild still saw a TypeScript-style ':' type annotation (typeColonRange non-empty). Type annotations are only legal on arrow-function parameters, so the ':' is unexpected and parsing fails.","triggerScenarios":"'(x: number)' used as a standalone parenthesized expression with no '=>', or TS annotations parsed under a non-TS loader.","commonSituations":"TypeScript type annotation left in a .js file (wrong loader); a parameter list missing its '=> body'; refactoring a signature into an expression.","solutions":["Add the '=> body' to make it an arrow function.","If the file is TypeScript, build with the ts/tsx loader (esbuild default for .ts/.tsx).","Remove the ':' annotation for plain JavaScript."],"exampleFix":"// before\nconst f = (x: number)\n// after\nconst f = (x: number) => x","handlingStrategy":"validation","validationCode":"import \"github.com/evanw/esbuild/pkg/api\"\nopts := api.TransformOptions{Loader: api.LoaderTS} // correct loader for TS annotations\nres := api.Transform(src, opts)\nfor _, m := range res.Errors {\n  if strings.Contains(m.Text, \"Unexpected \\\":\\\"\") {\n    // annotation parsed outside an arrow; fix the source or loader\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the file extension to the right loader (.ts/.tsx -> TS, .js -> JS).","Run tsc to ensure arrow functions have a body after their typed params.","When porting TS to JS, strip type annotations with a tool, not by hand."],"tags":["syntax-error","parser","typescript","arrow-function"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}