diff options
Diffstat (limited to 'src/js_parser/js_parser.zig')
-rw-r--r-- | src/js_parser/js_parser.zig | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index ef114cd25..f8e782b65 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -40,6 +40,7 @@ pub const StmtNodeList = js_ast.StmtNodeList; pub const BindingNodeList = js_ast.BindingNodeList; fn _disabledAssert(_: bool) void { + if (!Environment.allow_assert) @compileLog("assert is missing an if (Environment.allow_assert)"); unreachable; } @@ -2643,7 +2644,8 @@ pub const Parser = struct { p.recordUsage(p.jsx_refresh_runtime.ref); if (!p.options.jsx.use_embedded_refresh_runtime) { - if (Environment.allow_assert) assert(!p.options.enable_bundling); + if (comptime Environment.allow_assert) + assert(!p.options.enable_bundling); var declared_symbols = try p.allocator.alloc(js_ast.DeclaredSymbol, 1); const loc = logger.Loc.Empty; const import_record_id = p.addImportRecord(.require, loc, p.options.jsx.refresh_runtime); @@ -3830,7 +3832,7 @@ fn NewParser_( // during minification. These counts shouldn't include references inside dead // code regions since those will be culled. if (!p.is_control_flow_dead) { - if (Environment.allow_assert) assert(p.symbols.items.len > ref.innerIndex()); + if (comptime Environment.allow_assert) assert(p.symbols.items.len > ref.innerIndex()); p.symbols.items[ref.innerIndex()].use_count_estimate += 1; var result = p.symbol_uses.getOrPut(p.allocator, ref) catch unreachable; if (!result.found_existing) { @@ -4340,7 +4342,8 @@ fn NewParser_( // errors if a statement in the function body tries to re-declare any of the // arguments. if (comptime kind == js_ast.Scope.Kind.function_body) { - if (Environment.allow_assert) assert(parent.kind == js_ast.Scope.Kind.function_args); + if (comptime Environment.allow_assert) + assert(parent.kind == js_ast.Scope.Kind.function_args); var iter = scope.parent.?.members.iterator(); while (iter.next()) |entry| { @@ -7707,9 +7710,9 @@ fn NewParser_( } // If we end with a .t_close_paren, that's a bug. It means we aren't following the last parenthese - if (Environment.isDebug) { - if (Environment.allow_assert) assert(p.lexer.token != .t_close_paren); - } + + if (comptime Environment.allow_assert) + assert(p.lexer.token != .t_close_paren); } if (p.lexer.token == .t_equals) { @@ -8427,7 +8430,8 @@ fn NewParser_( if (ref.isSourceContentsSlice()) { return p.source.contents[ref.sourceIndex() .. ref.sourceIndex() + ref.innerIndex()]; } else if (ref.sourceIndex() == std.math.maxInt(Ref.Int)) { - if (Environment.allow_assert) assert(ref.innerIndex() < p.allocated_names.items.len); + if (comptime Environment.allow_assert) + assert(ref.innerIndex() < p.allocated_names.items.len); return p.allocated_names.items[ref.innerIndex()]; } else { return p.symbols.items[ref.innerIndex()].original_name; @@ -9293,7 +9297,8 @@ fn NewParser_( try p.lexer.next(); break :parseTemplatePart; } - if (comptime Environment.allow_assert) if (Environment.allow_assert) assert(p.lexer.token != .t_end_of_file); + if (comptime Environment.allow_assert) + assert(p.lexer.token != .t_end_of_file); } p.allow_in = oldAllowIn; @@ -10629,7 +10634,7 @@ fn NewParser_( var propertyOpts = PropertyOpts{}; if (try p.parseProperty(.normal, &propertyOpts, &self_errors)) |prop| { if (comptime Environment.allow_assert) { - if (Environment.allow_assert) assert(prop.key != null or prop.value != null); + assert(prop.key != null or prop.value != null); } properties.append(prop) catch unreachable; } @@ -13273,7 +13278,7 @@ fn NewParser_( var scope = p.current_scope; while (!scope.kindStopsHoisting()) { - if (Environment.allow_assert) assert(scope.parent != null); + if (comptime Environment.allow_assert) assert(scope.parent != null); scope = scope.parent.?; } @@ -13796,7 +13801,7 @@ fn NewParser_( // we do not attempt to preserve all the semantics of with data.value = p.visitExpr(data.value); // This stmt should be a block - if (comptime Environment.allow_assert) if (Environment.allow_assert) assert(data.body.data == .s_block); + if (comptime Environment.allow_assert) assert(data.body.data == .s_block); data.body = p.visitSingleStmt(data.body, StmtsKind.none); }, .s_while => |data| { @@ -15319,7 +15324,7 @@ fn NewParser_( p.scopes_in_order.items[scope_index] = null; // Remove the last child from the parent scope const last = parent.children.items.len - 1; - assert(parent.children.items[last] == to_flatten); + if (comptime Environment.allow_assert) assert(parent.children.items[last] == to_flatten); _ = parent.children.popOrNull(); for (to_flatten.children.items) |item| { @@ -15570,7 +15575,7 @@ fn NewParser_( curr_stmts = curr_stmts[export_all_function_body_stmts.len..]; // This is the original part statements + 1 var part_stmts = curr_stmts; - if (Environment.allow_assert) assert(part_stmts.len == end_iife_stmts_count); + if (comptime Environment.allow_assert) assert(part_stmts.len == end_iife_stmts_count); var part_stmts_i: usize = 0; var import_list_i: usize = 0; |