diff options
author | 2021-04-23 17:04:30 -0700 | |
---|---|---|
committer | 2021-04-23 17:04:30 -0700 | |
commit | fe7acb13da80477cce47af843753d9efb7e9bbb9 (patch) | |
tree | 4ffaf5123cd6e97dfcd55b7468c6a762de4dded1 /src/js_parser.zig | |
parent | a75f0c1eea438e6decfddd3228f6925f9670b963 (diff) | |
download | bun-fe7acb13da80477cce47af843753d9efb7e9bbb9.tar.gz bun-fe7acb13da80477cce47af843753d9efb7e9bbb9.tar.zst bun-fe7acb13da80477cce47af843753d9efb7e9bbb9.zip |
return! !continue! !break
Diffstat (limited to 'src/js_parser.zig')
-rw-r--r-- | src/js_parser.zig | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index 66e4beb2e..a3bc2b298 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -1187,6 +1187,16 @@ const P = struct { return ref; } + pub fn parseLabelName(p: *P) !?js_ast.LocRef { + if (p.lexer.token != .t_identifier or p.lexer.has_newline_before) { + return null; + } + + const name = LocRef{ .loc = p.lexer.loc(), .ref = try p.storeNameInRef(p.lexer.identifier) }; + p.lexer.next(); + return name; + } + pub fn parseClassStmt(p: *P, loc: logger.Loc, opts: *ParseStatementOptions) Stmt { var name: ?js_ast.LocRef = null; var class_keyword = p.lexer.range(); @@ -2173,13 +2183,31 @@ const P = struct { return p.s(stmt, loc); }, .t_break => { - notimpl(); + p.lexer.next(); + const name = try p.parseLabelName(); + p.lexer.expectOrInsertSemicolon(); + return p.s(S.Break{ .label = name }, loc); }, .t_continue => { - notimpl(); + p.lexer.next(); + const name = try p.parseLabelName(); + p.lexer.expectOrInsertSemicolon(); + return p.s(S.Continue{ .label = name }, loc); }, .t_return => { - notimpl(); + p.lexer.next(); + var value: ?Expr = null; + if ((p.lexer.token != .t_semicolon and + !p.lexer.has_newline_before and + p.lexer.token != .t_close_brace and + p.lexer.token != .t_end_of_file)) + { + value = p.parseExpr(.lowest); + } + p.latest_return_had_semicolon = p.lexer.token == .t_semicolon; + p.lexer.expectOrInsertSemicolon(); + + return p.s(S.Return{ .value = value }, loc); }, .t_throw => { notimpl(); |