{"record":{"id":"ca006dd9ca9f5f8d","repo":"evanw/esbuild","slug":"unexpected-after-rest-pattern","errorCode":null,"errorMessage":"Unexpected \",\" after rest pattern","messagePattern":"Unexpected \",\" after rest pattern","errorType":"panic","errorClass":"LexerPanic","httpStatus":null,"severity":"error","filePath":"internal/js_parser/js_parser.go","lineNumber":6068,"sourceCode":"\t\t\t\tp.saveExprCommentsHere()\n\t\t\t\tbinding := p.parseBinding(parseBindingOpts{})\n\n\t\t\t\tvar defaultValueOrNil js_ast.Expr\n\t\t\t\tif !hasSpread && p.lexer.Token == js_lexer.TEquals {\n\t\t\t\t\tp.lexer.Next()\n\t\t\t\t\tdefaultValueOrNil = p.parseExpr(js_ast.LComma)\n\t\t\t\t}\n\n\t\t\t\titems = append(items, js_ast.ArrayBinding{\n\t\t\t\t\tBinding:           binding,\n\t\t\t\t\tDefaultValueOrNil: defaultValueOrNil,\n\t\t\t\t\tLoc:               itemLoc,\n\t\t\t\t})\n\n\t\t\t\t// Commas after spread elements are not allowed\n\t\t\t\tif hasSpread && p.lexer.Token == js_lexer.TComma {\n\t\t\t\t\tp.log.AddError(&p.tracker, p.lexer.Range(), \"Unexpected \\\",\\\" after rest pattern\")\n\t\t\t\t\tpanic(js_lexer.LexerPanic{})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif p.lexer.Token != js_lexer.TComma {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif p.lexer.HasNewlineBefore {\n\t\t\t\tisSingleLine = false\n\t\t\t}\n\t\t\tp.lexer.Next()\n\t\t\tif p.lexer.HasNewlineBefore {\n\t\t\t\tisSingleLine = false\n\t\t\t}\n\t\t}\n\n\t\tp.allowIn = oldAllowIn\n\n\t\tif p.lexer.HasNewlineBefore {","sourceCodeStart":6050,"sourceCodeEnd":6086,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/js_parser/js_parser.go#L6050-L6086","documentation":"In array destructuring binding, a rest element '...rest' must be the last element and cannot be followed by a comma. When the parser sees a TComma right after a spread in the array-binding loop (js_parser.go:6066), it errors.","triggerScenarios":"const [a, ...rest,] = arr or ([a, ...b, c] = x) — a comma (and any further elements) after the rest in an array pattern.","commonSituations":"A trailing comma after spread; additional elements accidentally placed after the rest; formatter inserting trailing commas.","solutions":["Remove the comma and any elements after '...rest'.","Make the rest element truly last in the array pattern."],"exampleFix":"// before\nconst [a, ...rest,] = arr\n// after\nconst [a, ...rest] = arr","handlingStrategy":"validation","validationCode":"import \"github.com/evanw/esbuild/pkg/api\"\nres := api.Transform(src, api.TransformOptions{Loader: api.LoaderJS})\nfor _, m := range res.Errors {\n  if strings.Contains(m.Text, \"Unexpected \\\",\\\" after rest pattern\") {\n    // a trailing comma appeared after ...rest in an array binding\n  }\n}","typeGuard":"// Flag '...rest,' (comma after rest) inside an array destructuring binding.\nvar reRestCommaArray = regexp.MustCompile(`\\\\[[^\\\\]]*\\\\.\\\\.\\\\.[^\\\\]]*,\\\\s*[\\\\]\\\\)]`)\nfunc arrayRestHasTrailingComma(src string) bool { return reRestCommaArray.MatchString(src) }","tryCatchPattern":null,"preventionTips":["Keep the rest element last in array patterns with no trailing comma.","Configure prettier/eslint destructuring rules to flag post-rest commas.","Review any spread in destructuring that is followed by more elements."],"tags":["syntax-error","parser","destructuring","rest-spread"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}