From b5174cf95f10c40da0d2a5d7715d450f4e7d4136 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 23 Apr 2021 13:42:27 -0700 Subject: [PATCH] if --- src/js_parser.zig | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/js_parser.zig b/src/js_parser.zig index 8ac4eb2388..1b9fa27858 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -1632,7 +1632,28 @@ const P = struct { return p.s(S.Local{ .kind = .k_const, .decls = decls, .is_export = opts.is_export }, loc); }, .t_if => { - notimpl(); + p.lexer.next(); + p.lexer.expect(.t_open_paren); + const test_ = p.parseExpr(.lowest); + p.lexer.expect(.t_close_paren); + var stmtOpts = ParseStatementOptions{ + .lexical_decl = .allow_fn_inside_if, + }; + const yes = p.parseStmt(&stmtOpts) catch unreachable; + var no: ?Stmt = null; + if (p.lexer.token == .t_else) { + p.lexer.next(); + stmtOpts = ParseStatementOptions{ + .lexical_decl = .allow_fn_inside_if, + }; + no = p.parseStmt(&stmtOpts) catch unreachable; + } + + return p.s(S.If{ + .test_ = test_, + .yes = yes, + .no = no, + }, loc); }, .t_do => { notimpl();