{"record":{"id":"3266f779a0349c03","repo":"evanw/esbuild","slug":"unexpected-newline-before","errorCode":null,"errorMessage":"Unexpected newline before \"=>\"","messagePattern":"Unexpected newline before \"=>\"","errorType":"panic","errorClass":"LexerPanic","httpStatus":null,"severity":"error","filePath":"internal/js_parser/js_parser.go","lineNumber":2935,"sourceCode":"\t\t\tTarget: target,\n\t\t\tIndex:  js_ast.Expr{Loc: nameLoc, Data: &js_ast.ENameOfSymbol{Ref: p.symbolForMangledProp(name)}},\n\t\t}\n\t}\n\n\treturn &js_ast.EDot{\n\t\tTarget:  target,\n\t\tName:    name,\n\t\tNameLoc: nameLoc,\n\t}\n}\n\nfunc (p *parser) parseArrowBody(args []js_ast.Arg, data fnOrArrowDataParse) *js_ast.EArrow {\n\tarrowLoc := p.lexer.Loc()\n\n\t// Newlines are not allowed before \"=>\"\n\tif p.lexer.HasNewlineBefore {\n\t\tp.log.AddError(&p.tracker, p.lexer.Range(), \"Unexpected newline before \\\"=>\\\"\")\n\t\tpanic(js_lexer.LexerPanic{})\n\t}\n\n\tp.lexer.Expect(js_lexer.TEqualsGreaterThan)\n\n\tfor _, arg := range args {\n\t\tp.declareBinding(ast.SymbolHoisted, arg.Binding, parseStmtOpts{})\n\t}\n\n\t// The ability to use \"this\" and \"super\" is inherited by arrow functions\n\tdata.isThisDisallowed = p.fnOrArrowDataParse.isThisDisallowed\n\tdata.allowSuperCall = p.fnOrArrowDataParse.allowSuperCall\n\tdata.allowSuperProperty = p.fnOrArrowDataParse.allowSuperProperty\n\n\tif p.lexer.Token == js_lexer.TOpenBrace {\n\t\tbody := p.parseFnBody(data)\n\t\tp.afterArrowBodyLoc = p.lexer.Loc()\n\t\treturn &js_ast.EArrow{Args: args, Body: body}\n\t}","sourceCodeStart":2917,"sourceCodeEnd":2953,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/js_parser/js_parser.go#L2917-L2953","documentation":"In parseArrowBody, esbuild enforces the spec's NoLineHere rule for arrow functions: a line terminator is not permitted between the parameter list and the '=>'. If HasNewlineBefore is true when the '=>' is expected (js_parser.go:2933), parsing fails.","triggerScenarios":"An arrow function where the '=>' is on a separate line from the parameter list, e.g. 'const f = (a)\\n => a'.","commonSituations":"Hand-editing that wrapped the '=>' onto its own line; a misconfigured formatter; refactor that moved tokens across lines.","solutions":["Move '=>' onto the same line as the closing parenthesis / parameter list.","If line-wrapping is desired, wrap the parameters but keep '=>' adjacent to ')'.","Reformat with a correct arrow-function style."],"exampleFix":"// before\nconst f = (a, b)\n  => a + b\n// after\nconst f = (a, b) => a + b","handlingStrategy":"validation","validationCode":"import \"github.com/evanw/esbuild/pkg/api\"\nres := api.Transform(src, api.TransformOptions{Loader: api.LoaderTS})\nfor _, m := range res.Errors {\n  if strings.Contains(m.Text, \"Unexpected newline before\") {\n    // point the editor at m.Location and reject\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run tsc/eslint before bundling; both flag malformed arrow functions.","Configure prettier with arrow-body rules that keep '=>' on the parameter line.","Review any refactor that line-wraps an arrow function."],"tags":["syntax-error","parser","arrow-function","newline"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}