aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-04-23 13:48:18 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-04-23 13:48:18 -0700
commit36fd4be1501e9169b49ec3ccd1d42ef9dcb5eb9d (patch)
treec25da526bd3f02374cd02248b56d6fd827e833ac /src
parentb5174cf95f10c40da0d2a5d7715d450f4e7d4136 (diff)
downloadbun-36fd4be1501e9169b49ec3ccd1d42ef9dcb5eb9d.tar.gz
bun-36fd4be1501e9169b49ec3ccd1d42ef9dcb5eb9d.tar.zst
bun-36fd4be1501e9169b49ec3ccd1d42ef9dcb5eb9d.zip
with do while
Diffstat (limited to 'src')
-rw-r--r--src/js_parser.zig39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 1b9fa2785..0c2c4a214 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -1656,13 +1656,46 @@ const P = struct {
}, loc);
},
.t_do => {
- notimpl();
+ p.lexer.next();
+ var stmtOpts = ParseStatementOptions{};
+ const body = p.parseStmt(&stmtOpts) catch unreachable;
+ p.lexer.expect(.t_while);
+ p.lexer.expect(.t_open_paren);
+ const test_ = p.parseExpr(.lowest);
+ p.lexer.expect(.t_close_paren);
+
+ // This is a weird corner case where automatic semicolon insertion applies
+ // even without a newline present
+ if (p.lexer.token == .t_semicolon) {
+ p.lexer.next();
+ }
+ return p.s(S.DoWhile{ .body = body, .test_ = test_ }, loc);
},
.t_while => {
- notimpl();
+ p.lexer.next();
+
+ p.lexer.expect(.t_open_paren);
+ const test_ = p.parseExpr(.lowest);
+ const body_loc = p.lexer.loc();
+ p.lexer.expect(.t_close_paren);
+
+ var stmtOpts = ParseStatementOptions{};
+
+ // Push a scope so we make sure to prevent any bare identifiers referenced
+ // within the body from being renamed. Renaming them might change the
+ // semantics of the code.
+ _ = try p.pushScopeForParsePass(.with, body_loc);
+ const body = p.parseStmt(&stmtOpts) catch unreachable;
+ p.popScope();
+
+ return p.s(S.With{ .body = body, .value = test_, .body_loc = body_loc }, loc);
},
.t_with => {
- notimpl();
+ p.lexer.next();
+ p.lexer.expect(.t_open_paren);
+ const test_ = p.parseExpr(.lowest);
+ const body_loc = p.lexer.loc();
+ p.lexer.expect(.t_close_paren);
},
.t_switch => {
notimpl();