aboutsummaryrefslogtreecommitdiff
path: root/src/js_parser.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-12-28 00:51:22 -0800
committerGravatar GitHub <noreply@github.com> 2022-12-28 00:51:22 -0800
commitc0dd2841362b67fdb5ede262b19688004a4eb9a4 (patch)
treea3cd6b353c25c30d66489de61b394af7d5568fed /src/js_parser.zig
parent504972fa5deb92f2d0510d42f11b085351915a32 (diff)
downloadbun-c0dd2841362b67fdb5ede262b19688004a4eb9a4.tar.gz
bun-c0dd2841362b67fdb5ede262b19688004a4eb9a4.tar.zst
bun-c0dd2841362b67fdb5ede262b19688004a4eb9a4.zip
Upgrade to latest Zig (#1610)
* @min and @max * builtins and some trivial ones * Most of them * more * more! * More Progress * wip * Update tagged_pointer.zig * Update http_client_async.zig * Most of the iterable dir changes * alright * Remove usages of deprecated formatters * :camera: * fmt * Update shimmer.zig * wip * wip * wip * progress * more * Latest * stuck on error * latest * workaround stage2 * wip * Update string_immutable.zig * wip * Migrate `Dirent` and `require("fs')` to use JSC<>Zig bindings * Fix build errors * Fixup most of the test failures * Fix `make headers` * Fix "outside package path" error * Fixup aligned alloc * Add missing file * linux * More linux fixes * use latest peechy * Fix transpiler test failure * Forgot about these * Fixup test failure * Update node-timers.test.ts * [node:htt] Fix `undefined is not an object` error Fixes https://github.com/oven-sh/bun/issues/1618 * Update http.exports.js * Make this test less flaky * fix hashes * Fix hex formatting and zls issues * Download zig version * Update Dockerfile * Update Dockerfile * Update uws * Update Dockerfile * Set llvm version * Update README.md * Update uws * Update Dockerfile * Update io_linux.zig * Update bun.zig * Log output * workaround strange @cInclude error * Make ffi tests better * Don't use cImport * Update c.zig * Update c-bindings.cpp * call setOutputDir * Update Dockerfile * Use a longer name * latest * Update serve.test.ts Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Veikka Tuominen <git@vexu.eu>
Diffstat (limited to 'src/js_parser.zig')
-rw-r--r--src/js_parser.zig824
1 files changed, 413 insertions, 411 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 6063f613d..1fa86041f 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -166,7 +166,7 @@ const BunJSX = struct {
};
pub fn ExpressionTransposer(
comptime Kontext: type,
- visitor: fn (ptr: *Kontext, arg: Expr, state: anytype) Expr,
+ comptime visitor: fn (ptr: *Kontext, arg: Expr, state: anytype) Expr,
) type {
return struct {
pub const Context = Kontext;
@@ -261,7 +261,7 @@ const JSXTag = struct {
// <Hello-:Button
if (strings.containsComptime(name, "-:") or (p.lexer.token != .t_dot and name[0] >= 'a' and name[0] <= 'z')) {
return JSXTag{
- .data = Data{ .tag = p.e(E.String{
+ .data = Data{ .tag = p.newExpr(E.String{
.data = name,
}, loc) },
.range = tag_range,
@@ -270,7 +270,7 @@ const JSXTag = struct {
// Otherwise, this is an identifier
// <Button>
- var tag = p.e(E.Identifier{ .ref = try p.storeNameInRef(name) }, loc);
+ var tag = p.newExpr(E.Identifier{ .ref = try p.storeNameInRef(name) }, loc);
// Parse a member expression chain
// <Button.Red>
@@ -291,7 +291,7 @@ const JSXTag = struct {
std.mem.copy(u8, _name[name.len + 1 .. _name.len], member);
name = _name;
tag_range.len = member_range.loc.start + member_range.len - tag_range.loc.start;
- tag = p.e(E.Dot{ .target = tag, .name = member, .name_loc = member_range.loc }, loc);
+ tag = p.newExpr(E.Dot{ .target = tag, .name = member, .name_loc = member_range.loc }, loc);
}
return JSXTag{ .data = Data{ .tag = tag }, .range = tag_range, .name = name };
@@ -856,7 +856,7 @@ pub const ImportScanner = struct {
}
var decls = try allocator.alloc(G.Decl, 1);
- decls[0] = G.Decl{ .binding = p.b(B.Identifier{ .ref = st.default_name.ref.? }, stmt.loc), .value = p.e(E.Function{ .func = func.func }, stmt.loc) };
+ decls[0] = G.Decl{ .binding = p.b(B.Identifier{ .ref = st.default_name.ref.? }, stmt.loc), .value = p.newExpr(E.Function{ .func = func.func }, stmt.loc) };
stmt = p.s(S.Local{
.decls = decls,
@@ -876,7 +876,7 @@ pub const ImportScanner = struct {
var decls = try allocator.alloc(G.Decl, 1);
decls[0] = G.Decl{
.binding = p.b(B.Identifier{ .ref = st.default_name.ref.? }, stmt.loc),
- .value = p.e(E.Class{
+ .value = p.newExpr(E.Class{
.class_keyword = class.class.class_keyword,
.ts_decorators = class.class.ts_decorators,
.class_name = class.class.class_name,
@@ -904,10 +904,10 @@ pub const ImportScanner = struct {
.stmt => |s2| brk2: {
switch (s2.data) {
.s_function => |func| {
- break :brk2 p.e(E.Function{ .func = func.func }, s2.loc);
+ break :brk2 p.newExpr(E.Function{ .func = func.func }, s2.loc);
},
.s_class => |class| {
- break :brk2 p.e(class.class, s2.loc);
+ break :brk2 p.newExpr(class.class, s2.loc);
},
else => unreachable,
}
@@ -952,7 +952,7 @@ pub const ImportScanner = struct {
try p.import_records_for_current_part.append(allocator, st.import_record_index);
for (st.items) |item| {
- const ref = item.name.ref orelse p.panic("Expected export from item to have a name {s}", .{st});
+ const ref = item.name.ref orelse p.panic("Expected export from item to have a name {any}", .{st});
// Note that the imported alias is not item.Alias, which is the
// exported alias. This is somewhat confusing because each
// SExportFrom statement is basically SImport + SExportClause in one.
@@ -985,16 +985,18 @@ const StaticSymbolName = struct {
pub const List = struct {
fn NewStaticSymbol(comptime basename: string) StaticSymbolName {
+ const hash_value = std.hash.Wyhash.hash(0, basename);
return comptime StaticSymbolName{
- .internal = basename ++ "_" ++ std.fmt.comptimePrint("{x}", .{std.hash.Wyhash.hash(0, basename)}),
+ .internal = basename ++ "_" ++ std.fmt.comptimePrint("{any}", .{bun.fmt.hexIntLower(hash_value)}),
.primary = basename,
.backup = "_" ++ basename ++ "$",
};
}
fn NewStaticSymbolWithBackup(comptime basename: string, comptime backup: string) StaticSymbolName {
+ const hash_value = std.hash.Wyhash.hash(0, basename);
return comptime StaticSymbolName{
- .internal = basename ++ "_" ++ std.fmt.comptimePrint("{x}", .{std.hash.Wyhash.hash(0, basename)}),
+ .internal = basename ++ "_" ++ std.fmt.comptimePrint("{any}", .{bun.fmt.hexIntLower(hash_value)}),
.primary = basename,
.backup = backup,
};
@@ -1253,7 +1255,7 @@ pub const SideEffects = enum(u1) {
} else if (!prop.flags.contains(.is_computed)) {
continue;
} else {
- prop.value = p.e(E.Number{ .value = 0.0 }, prop.value.?.loc);
+ prop.value = p.newExpr(E.Number{ .value = 0.0 }, prop.value.?.loc);
}
}
}
@@ -1384,7 +1386,7 @@ pub const SideEffects = enum(u1) {
findIdentifiers(decl.binding, &decls);
}
- local.decls = decls.toOwnedSlice();
+ local.decls = decls.toOwnedSlice() catch @panic("TODO");
return true;
},
@@ -2425,7 +2427,7 @@ pub const Parser = struct {
// var decls = try p.allocator.alloc(G.Decl, 1);
// decls[0] = Decl{ .binding = p.b(B.Identifier{
// .ref = p.import_meta_ref,
- // }, logger.Loc.Empty), .value = p.e(E.Object{}, logger.Loc.Empty) };
+ // }, logger.Loc.Empty), .value = p.newExpr(E.Object{}, logger.Loc.Empty) };
// var importMetaStatement = p.s(S.Local{
// .kind = .k_const,
// .decls = decls,
@@ -2487,7 +2489,7 @@ pub const Parser = struct {
if (uses_dirname) {
decls[0] = .{
.binding = p.b(B.Identifier{ .ref = p.dirname_ref }, logger.Loc.Empty),
- .value = p.e(
+ .value = p.newExpr(
// TODO: test UTF-8 file paths
E.String.init(p.source.path.name.dir),
logger.Loc.Empty,
@@ -2498,7 +2500,7 @@ pub const Parser = struct {
if (uses_filename) {
decls[@as(usize, @boolToInt(uses_dirname))] = .{
.binding = p.b(B.Identifier{ .ref = p.filename_ref }, logger.Loc.Empty),
- .value = p.e(
+ .value = p.newExpr(
E.String.init(p.source.path.text),
logger.Loc.Empty,
),
@@ -2681,14 +2683,14 @@ pub const Parser = struct {
},
loc,
),
- .value = p.e(
+ .value = p.newExpr(
E.Call{
// Symbol.for
- .target = p.e(
+ .target = p.newExpr(
E.Dot{
.name = "for",
.name_loc = logger.Loc.Empty,
- .target = p.e(
+ .target = p.newExpr(
E.Identifier{
.ref = p.es6_symbol_global.ref,
.can_be_removed_if_unused = true,
@@ -2715,7 +2717,7 @@ pub const Parser = struct {
declared_symbols[declared_symbols_i] = .{ .ref = automatic_namespace_ref, .is_top_level = true };
declared_symbols_i += 1;
- const automatic_identifier = p.e(E.ImportIdentifier{ .ref = automatic_namespace_ref }, loc);
+ const automatic_identifier = p.newExpr(E.ImportIdentifier{ .ref = automatic_namespace_ref }, loc);
// We do not mark this as .require becuase we are already wrapping it manually.
// unless it's bun and you're not bundling
@@ -2727,7 +2729,7 @@ pub const Parser = struct {
if (use_automatic_identifier) {
break :brk automatic_identifier;
} else if (p.options.features.dynamic_require) {
- break :brk p.e(E.Require{ .import_record_index = import_record_id }, loc);
+ break :brk p.newExpr(E.Require{ .import_record_index = import_record_id }, loc);
} else {
require_call_args_base[require_call_args_i] = automatic_identifier;
require_call_args_i += 1;
@@ -2746,7 +2748,7 @@ pub const Parser = struct {
},
loc,
),
- .value = p.e(
+ .value = p.newExpr(
E.Dot{
.target = dot_call_target,
.name = p.options.jsx.jsx,
@@ -2771,7 +2773,7 @@ pub const Parser = struct {
},
loc,
),
- .value = p.e(
+ .value = p.newExpr(
E.Dot{
.target = dot_call_target,
.name = p.options.jsx.jsx_static,
@@ -2795,7 +2797,7 @@ pub const Parser = struct {
// },
// loc,
// ),
- // .value = p.e(E.String{ .data = p.source.path.pretty }, loc),
+ // .value = p.newExpr(E.String{ .data = p.source.path.pretty }, loc),
// };
// decl_i += 1;
// }
@@ -2825,13 +2827,13 @@ pub const Parser = struct {
.import_record_index = import_record_id,
},
) catch unreachable;
- p.is_import_item.put(p.allocator, automatic_namespace_ref, .{}) catch unreachable;
+ p.is_import_item.put(p.allocator, automatic_namespace_ref, {}) catch unreachable;
import_records[import_record_i] = import_record_id;
import_record_i += 1;
}
if (jsx_classic_symbol.use_count_estimate > 0) {
- const classic_identifier = p.e(E.ImportIdentifier{ .ref = classic_namespace_ref }, loc);
+ const classic_identifier = p.newExpr(E.ImportIdentifier{ .ref = classic_namespace_ref }, loc);
const import_record_id = p.addImportRecord(.require, loc, p.options.jsx.classic_import_source);
const dot_call_target = brk: {
// var react = $aopaSD123();
@@ -2839,7 +2841,7 @@ pub const Parser = struct {
if (p.options.can_import_from_bundle or p.options.enable_bundling or !p.options.features.allow_runtime) {
break :brk classic_identifier;
} else if (p.options.features.dynamic_require) {
- break :brk p.e(E.Require{ .import_record_index = import_record_id }, loc);
+ break :brk p.newExpr(E.Require{ .import_record_index = import_record_id }, loc);
} else {
const require_call_args_start = require_call_args_i;
require_call_args_base[require_call_args_i] = classic_identifier;
@@ -2908,7 +2910,7 @@ pub const Parser = struct {
.import_record_index = import_record_id,
},
) catch unreachable;
- p.is_import_item.put(p.allocator, classic_namespace_ref, .{}) catch unreachable;
+ p.is_import_item.put(p.allocator, classic_namespace_ref, {}) catch unreachable;
import_records[import_record_i] = import_record_id;
declared_symbols[declared_symbols_i] = .{ .ref = classic_namespace_ref, .is_top_level = true };
declared_symbols_i += 1;
@@ -2943,7 +2945,7 @@ pub const Parser = struct {
.import_record_index = import_record_id,
},
) catch unreachable;
- p.is_import_item.put(p.allocator, p.jsx_refresh_runtime.ref, .{}) catch unreachable;
+ p.is_import_item.put(p.allocator, p.jsx_refresh_runtime.ref, {}) catch unreachable;
import_records[import_record_i] = import_record_id;
}
p.recordUsage(p.jsx_refresh_runtime.ref);
@@ -2979,14 +2981,14 @@ pub const Parser = struct {
},
logger.Loc.Empty,
),
- .value = p.e(
+ .value = p.newExpr(
E.Call{
// Symbol.for
- .target = p.e(
+ .target = p.newExpr(
E.Dot{
.name = "for",
.name_loc = logger.Loc.Empty,
- .target = p.e(
+ .target = p.newExpr(
E.Identifier{
.ref = p.es6_symbol_global.ref,
.can_be_removed_if_unused = true,
@@ -3089,7 +3091,7 @@ pub const Parser = struct {
.import_record_index = import_record_id,
},
) catch unreachable;
- p.is_import_item.put(p.allocator, p.jsx_refresh_runtime.ref, .{}) catch unreachable;
+ p.is_import_item.put(p.allocator, p.jsx_refresh_runtime.ref, {}) catch unreachable;
var import_records = try p.allocator.alloc(@TypeOf(import_record_id), 1);
import_records[0] = import_record_id;
declared_symbols[0] = .{ .ref = p.jsx_refresh_runtime.ref, .is_top_level = true };
@@ -3152,7 +3154,7 @@ pub const Parser = struct {
// HMRClient.activate(true)
var args_list: []Expr = if (Environment.isDebug) &Prefill.HotModuleReloading.DebugEnabledArgs else &Prefill.HotModuleReloading.DebugDisabled;
- var hmr_module_class_ident = p.e(E.Identifier{ .ref = p.runtime_imports.__HMRClient.?.ref }, logger.Loc.Empty);
+ var hmr_module_class_ident = p.newExpr(E.Identifier{ .ref = p.runtime_imports.__HMRClient.?.ref }, logger.Loc.Empty);
const imports = [_]u16{entry.key};
// TODO: remove these unnecessary allocations
p.generateImportStmt(
@@ -3162,8 +3164,8 @@ pub const Parser = struct {
p.runtime_imports,
p.s(
S.SExpr{
- .value = p.e(E.Call{
- .target = p.e(E.Dot{
+ .value = p.newExpr(E.Call{
+ .target = p.newExpr(E.Dot{
.target = hmr_module_class_ident,
.name = "activate",
.name_loc = logger.Loc.Empty,
@@ -3376,10 +3378,10 @@ pub const Prefill = struct {
pub var @"$$typeof" = E.String{ .data = "$$typeof" };
pub var @"type" = E.String{ .data = "type" };
- pub var @"ref" = E.String{ .data = "ref" };
- pub var @"props" = E.String{ .data = "props" };
- pub var @"_owner" = E.String{ .data = "_owner" };
- pub var @"REACT_ELEMENT_TYPE" = E.String{ .data = "react.element" };
+ pub var ref = E.String{ .data = "ref" };
+ pub var props = E.String{ .data = "props" };
+ pub var _owner = E.String{ .data = "_owner" };
+ pub var REACT_ELEMENT_TYPE = E.String{ .data = "react.element" };
};
pub const Data = struct {
pub var BMissing = B{ .b_missing = BMissing_ };
@@ -3395,12 +3397,12 @@ pub const Prefill = struct {
pub var LineNumber = Expr.Data{ .e_string = &Prefill.String.LineNumber };
pub var ColumnNumber = Expr.Data{ .e_string = &Prefill.String.ColumnNumber };
pub var @"$$typeof" = Expr.Data{ .e_string = &Prefill.String.@"$$typeof" };
- pub var @"key" = Expr.Data{ .e_string = &Prefill.String.@"Key" };
- pub var @"type" = Expr.Data{ .e_string = &Prefill.String.@"type" };
- pub var @"ref" = Expr.Data{ .e_string = &Prefill.String.@"ref" };
- pub var @"props" = Expr.Data{ .e_string = &Prefill.String.@"props" };
- pub var @"_owner" = Expr.Data{ .e_string = &Prefill.String.@"_owner" };
- pub var @"REACT_ELEMENT_TYPE" = Expr.Data{ .e_string = &Prefill.String.@"REACT_ELEMENT_TYPE" };
+ pub var key = Expr.Data{ .e_string = &Prefill.String.Key };
+ pub var @"type" = Expr.Data{ .e_string = &Prefill.String.type };
+ pub var ref = Expr.Data{ .e_string = &Prefill.String.ref };
+ pub var props = Expr.Data{ .e_string = &Prefill.String.props };
+ pub var _owner = Expr.Data{ .e_string = &Prefill.String._owner };
+ pub var REACT_ELEMENT_TYPE = Expr.Data{ .e_string = &Prefill.String.REACT_ELEMENT_TYPE };
pub const This = Expr.Data{ .e_this = E.This{} };
pub const Zero = Expr.Data{ .e_number = Value.Zero };
};
@@ -3816,13 +3818,13 @@ fn NewParser_(
// We don't want to spend time scanning the required files if they will
// never be used.
if (p.is_control_flow_dead) {
- return p.e(E.Null{}, arg.loc);
+ return p.newExpr(E.Null{}, arg.loc);
}
const import_record_index = p.addImportRecord(.dynamic, arg.loc, arg.data.e_string.slice(p.allocator));
p.import_records.items[import_record_index].handles_import_errors = (state.is_await_target and p.fn_or_arrow_data_visit.try_body_count != 0) or state.is_then_catch_target;
p.import_records_for_current_part.append(p.allocator, import_record_index) catch unreachable;
- return p.e(E.Import{
+ return p.newExpr(E.Import{
.expr = arg,
.import_record_index = Ref.toInt(import_record_index),
// .leading_interior_comments = arg.getString().
@@ -3835,7 +3837,7 @@ fn NewParser_(
p.log.addRangeDebug(p.source, r, "This \"import\" expression cannot be bundled because the argument is not a string literal") catch unreachable;
}
- return p.e(E.Import{
+ return p.newExpr(E.Import{
.expr = arg,
.import_record_index = Ref.None.sourceIndex(),
}, state.loc);
@@ -3848,13 +3850,13 @@ fn NewParser_(
// We don't want to spend time scanning the required files if they will
// never be used.
if (p.is_control_flow_dead) {
- return p.e(E.Null{}, arg.loc);
+ return p.newExpr(E.Null{}, arg.loc);
}
const import_record_index = p.addImportRecord(.require, arg.loc, arg.data.e_string.string(p.allocator) catch unreachable);
p.import_records.items[import_record_index].handles_import_errors = p.fn_or_arrow_data_visit.try_body_count != 0;
p.import_records_for_current_part.append(p.allocator, import_record_index) catch unreachable;
- return p.e(E.RequireOrRequireResolve{
+ return p.newExpr(E.RequireOrRequireResolve{
.import_record_index = Ref.toInt(import_record_index),
// .leading_interior_comments = arg.getString().
}, arg.loc);
@@ -3887,25 +3889,27 @@ fn NewParser_(
p.import_records_for_current_part.append(p.allocator, import_record_index) catch unreachable;
if (!p.options.transform_require_to_import) {
- return p.e(E.Require{ .import_record_index = import_record_index }, arg.loc);
+ return p.newExpr(E.Require{ .import_record_index = import_record_index }, arg.loc);
}
p.import_records.items[import_record_index].was_originally_require = true;
p.import_records.items[import_record_index].contains_import_star = true;
- const symbol_name = p.import_records.items[import_record_index].path.name.nonUniqueNameString(p.allocator);
+ const symbol_name = p.import_records.items[import_record_index].path.name.nonUniqueNameString(p.allocator) catch unreachable;
+ const hash_value = @truncate(
+ u16,
+ std.hash.Wyhash.hash(
+ 0,
+ p.import_records.items[import_record_index].path.text,
+ ),
+ );
+
const cjs_import_name = std.fmt.allocPrint(
p.allocator,
- "{s}_{x}_{d}",
+ "{s}_{any}_{d}",
.{
symbol_name,
- @truncate(
- u16,
- std.hash.Wyhash.hash(
- 0,
- p.import_records.items[import_record_index].path.text,
- ),
- ),
+ bun.fmt.hexIntLower(hash_value),
p.cjs_import_stmts.items.len,
},
) catch unreachable;
@@ -3925,7 +3929,7 @@ fn NewParser_(
) catch unreachable;
const args = p.allocator.alloc(Expr, 1) catch unreachable;
- args[0] = p.e(
+ args[0] = p.newExpr(
E.ImportIdentifier{
.ref = namespace_ref,
},
@@ -3993,7 +3997,7 @@ fn NewParser_(
for (parts_) |part, i| {
if (part.tag == .none) {
stmts_count += part.stmts.len;
- first_none_part = @minimum(i, first_none_part);
+ first_none_part = @min(i, first_none_part);
}
}
@@ -4175,7 +4179,7 @@ fn NewParser_(
}
}
- pub fn e(p: *P, t: anytype, loc: logger.Loc) Expr {
+ pub fn newExpr(p: *P, t: anytype, loc: logger.Loc) Expr {
const Type = @TypeOf(t);
comptime {
@@ -4339,7 +4343,7 @@ fn NewParser_(
}
},
else => {
- p.panic("Unexpected binding export type {s}", .{binding});
+ p.panic("Unexpected binding export type {any}", .{binding});
},
}
}
@@ -4442,7 +4446,7 @@ fn NewParser_(
// Substitute an EImportIdentifier now if this is an import item
if (p.is_import_item.contains(ref)) {
- return p.e(
+ return p.newExpr(
E.ImportIdentifier{ .ref = ref, .was_originally_identifier = opts.was_originally_identifier },
loc,
);
@@ -4456,14 +4460,14 @@ fn NewParser_(
// If this is a known enum value, inline the value of the enum
if (p.known_enum_values.get(ns_ref)) |enum_values| {
if (enum_values.get(name)) |number| {
- return p.e(E.Number{ .value = number }, loc);
+ return p.newExpr(E.Number{ .value = number }, loc);
}
}
// Otherwise, create a property access on the namespace
p.recordUsage(ns_ref);
- return p.e(E.Dot{ .target = p.e(E.Identifier{ .ref = ns_ref }, loc), .name = name, .name_loc = loc }, loc);
+ return p.newExpr(E.Dot{ .target = p.newExpr(E.Identifier{ .ref = ns_ref }, loc), .name = name, .name_loc = loc }, loc);
}
}
@@ -4471,10 +4475,10 @@ fn NewParser_(
const result = p.findSymbol(loc, original_name) catch unreachable;
var _ident = ident;
_ident.ref = result.ref;
- return p.e(_ident, loc);
+ return p.newExpr(_ident, loc);
}
- return p.e(ident, loc);
+ return p.newExpr(ident, loc);
}
pub fn generateImportStmt(
@@ -4516,7 +4520,7 @@ fn NewParser_(
.name = LocRef{ .ref = ref, .loc = logger.Loc{} },
};
declared_symbols[i] = js_ast.DeclaredSymbol{ .ref = ref, .is_top_level = true };
- try p.is_import_item.put(allocator, ref, .{});
+ try p.is_import_item.put(allocator, ref, {});
try p.named_imports.put(ref, js_ast.NamedImport{
.alias = alias_name,
.alias_loc = logger.Loc{},
@@ -5381,7 +5385,7 @@ fn NewParser_(
// Sanity-check that the scopes generated by the first and second passes match
if (order.loc.start != loc.start or order.scope.kind != kind) {
- p.panic("Expected scope ({s}, {d}) in {s}, found scope ({s}, {d})", .{ kind, loc.start, p.source.path.pretty, order.scope.kind, order.loc.start });
+ p.panic("Expected scope ({any}, {d}) in {s}, found scope ({any}, {d})", .{ kind, loc.start, p.source.path.pretty, order.scope.kind, order.loc.start });
}
p.current_scope = order.scope;
@@ -5536,7 +5540,7 @@ fn NewParser_(
.is_spread = is_spread,
.is_computed = item.flags.contains(.is_computed),
}),
- .key = item.key orelse p.e(E.Missing{}, expr.loc),
+ .key = item.key orelse p.newExpr(E.Missing{}, expr.loc),
.value = tup.binding orelse p.b(B.Missing{}, expr.loc),
.default_value = initializer,
});
@@ -6512,14 +6516,14 @@ fn NewParser_(
if (stmt.default_name) |name_loc| {
const name = p.loadNameFromRef(name_loc.ref.?);
const ref = try p.declareSymbol(.other, name_loc.loc, name);
- try p.is_import_item.put(p.allocator, ref, .{});
+ try p.is_import_item.put(p.allocator, ref, {});
try p.macro.refs.put(ref, id);
}
for (stmt.items) |item| {
const name = p.loadNameFromRef(item.name.ref.?);
const ref = try p.declareSymbol(.other, item.name.loc, name);
- try p.is_import_item.put(p.allocator, ref, .{});
+ try p.is_import_item.put(p.allocator, ref, {});
try p.macro.refs.put(ref, id);
}
@@ -6535,7 +6539,7 @@ fn NewParser_(
if (strings.eqlComptime(item.alias, "plugin")) {
const name = p.loadNameFromRef(item.name.ref.?);
const ref = try p.declareSymbol(.other, item.name.loc, name);
- try p.is_import_item.put(p.allocator, ref, .{});
+ try p.is_import_item.put(p.allocator, ref, {});
p.bun_plugin.ref = ref;
plugin_i = i;
break;
@@ -6601,7 +6605,7 @@ fn NewParser_(
const name = p.loadNameFromRef(name_loc.ref.?);
const ref = try p.declareSymbol(.import, name_loc.loc, name);
name_loc.ref = ref;
- try p.is_import_item.put(p.allocator, ref, .{});
+ try p.is_import_item.put(p.allocator, ref, {});
if (macro_remap) |*remap| {
if (remap.get("default")) |remapped_path| {
@@ -6652,7 +6656,7 @@ fn NewParser_(
const ref = try p.declareSymbol(.import, item.name.loc, name);
item.name.ref = ref;
- try p.is_import_item.put(p.allocator, ref, .{});
+ try p.is_import_item.put(p.allocator, ref, {});
p.checkForNonBMPCodePoint(item.alias_loc, item.alias);
if (macro_remap) |*remap| {
@@ -8354,8 +8358,8 @@ fn NewParser_(
// This assumes the caller has already parsed the "import" token
fn importMetaRequire(p: *P, loc: logger.Loc) Expr {
- return p.e(E.Dot{
- .target = p.e(E.ImportMeta{}, loc),
+ return p.newExpr(E.Dot{
+ .target = p.newExpr(E.ImportMeta{}, loc),
.name = "require",
.name_loc = loc,
}, loc);
@@ -8366,19 +8370,19 @@ fn NewParser_(
const kind = S.Local.Kind.k_const;
const name = p.lexer.identifier;
- const target = p.e(E.Identifier{ .ref = p.storeNameInRef(name) catch unreachable }, p.lexer.loc());
+ const target = p.newExpr(E.Identifier{ .ref = p.storeNameInRef(name) catch unreachable }, p.lexer.loc());
var value = target;
try p.lexer.expect(.t_identifier);
if (strings.eqlComptime(name, "require") and p.lexer.token == .t_open_paren) {
// "import ns = require('x')"
try p.lexer.next();
- const path = p.e(p.lexer.toEString(), p.lexer.loc());
+ const path = p.newExpr(p.lexer.toEString(), p.lexer.loc());
try p.lexer.expect(.t_string_literal);
try p.lexer.expect(.t_close_paren);
if (!opts.is_typescript_declare) {
const args = try ExprNodeList.one(p.allocator, path);
- value = p.e(E.Call{ .target = target, .close_paren_loc = p.lexer.loc(), .args = args }, loc);
+ value = p.newExpr(E.Call{ .target = target, .close_paren_loc = p.lexer.loc(), .args = args }, loc);
}
} else {
// "import Foo = Bar"
@@ -8386,7 +8390,7 @@ fn NewParser_(
var prev_value = value;
while (p.lexer.token == .t_dot) : (prev_value = value) {
try p.lexer.next();
- value = p.e(E.Dot{ .target = prev_value, .name = p.lexer.identifier, .name_loc = p.lexer.loc() }, loc);
+ value = p.newExpr(E.Dot{ .target = prev_value, .name = p.lexer.identifier, .name_loc = p.lexer.loc() }, loc);
try p.lexer.expect(.t_identifier);
}
}
@@ -8644,7 +8648,7 @@ fn NewParser_(
}
const ref = p.storeNameInRef(raw) catch unreachable;
- const expr = p.e(E.Identifier{ .ref = ref }, let_range.loc);
+ const expr = p.newExpr(E.Identifier{ .ref = ref }, let_range.loc);
return ExprOrLetStmt{ .stmt_or_expr = js_ast.StmtOrExpr{ .expr = try p.parseSuffix(expr, .lowest, null, Expr.EFlags.none) } };
}
@@ -8817,14 +8821,14 @@ fn NewParser_(
);
try p.lexer.expect(.t_identifier);
return B.Property{
- .key = p.e(E.Missing{}, p.lexer.loc()),
+ .key = p.newExpr(E.Missing{}, p.lexer.loc()),
.flags = Flags.Property.init(.{ .is_spread = true }),
.value = value,
};
},
.t_numeric_literal => {
- key = p.e(E.Number{
+ key = p.newExpr(E.Number{
.value = p.lexer.number,
}, p.lexer.loc());
// check for legacy octal literal
@@ -8834,7 +8838,7 @@ fn NewParser_(
key = try p.parseStringLiteral();
},
.t_big_integer_literal => {
- key = p.e(E.BigInt{
+ key = p.newExpr(E.BigInt{
.value = p.lexer.identifier,
}, p.lexer.loc());
// p.markSyntaxFeature(compat.BigInt, p.lexer.Range())
@@ -8856,7 +8860,7 @@ fn NewParser_(
try p.lexer.next();
- key = p.e(E.String{ .data = name }, loc);
+ key = p.newExpr(E.String{ .data = name }, loc);
if (p.lexer.token != .t_colon and p.lexer.token != .t_open_paren) {
const ref = p.storeNameInRef(name) catch unreachable;
@@ -9054,7 +9058,7 @@ fn NewParser_(
return p.s(S.Enum{
.name = name,
.arg = arg_ref,
- .values = values.toOwnedSlice(),
+ .values = try values.toOwnedSlice(),
.is_export = opts.is_export,
}, loc);
}
@@ -9372,7 +9376,7 @@ fn NewParser_(
}
}
- return stmts.toOwnedSlice();
+ return try stmts.toOwnedSlice();
}
fn markStrictModeFeature(p: *P, feature: StrictModeFeature, r: logger.Range, detail: string) !void {
@@ -9484,7 +9488,7 @@ fn NewParser_(
}
fn declareSymbol(p: *P, kind: Symbol.Kind, loc: logger.Loc, name: string) !Ref {
- return try @call(.{ .modifier = .always_inline }, declareSymbolMaybeGenerated, .{ p, kind, loc, name, false });
+ return try @call(.always_inline, declareSymbolMaybeGenerated, .{ p, kind, loc, name, false });
}
fn declareSymbolMaybeGenerated(p: *P, kind: Symbol.Kind, loc: logger.Loc, name: string, comptime is_generated: bool) !Ref {
@@ -9554,7 +9558,7 @@ fn NewParser_(
} else {
// Ensure that EImportIdentifier is created for the symbol in handleIdentifier
if (symbol.kind == .import and kind != .import) {
- try p.is_import_item.put(p.allocator, ref, .{});
+ try p.is_import_item.put(p.allocator, ref, {});
}
p.symbols.items[ref.innerIndex()].link = existing.ref;
@@ -9633,7 +9637,7 @@ fn NewParser_(
p.validateFunctionName(func, .expr);
p.popScope();
- return p.e(js_ast.E.Function{
+ return p.newExpr(js_ast.E.Function{
.func = func,
}, loc);
}
@@ -9799,7 +9803,7 @@ fn NewParser_(
var data = FnOrArrowDataParse{};
var arrow_body = try p.parseArrowBody(args, &data);
p.popScope();
- return p.e(arrow_body, async_range.loc);
+ return p.newExpr(arrow_body, async_range.loc);
}
},
// "async x => {}"
@@ -9825,7 +9829,7 @@ fn NewParser_(
};
var arrowBody = try p.parseArrowBody(args, &data);
arrowBody.is_async = true;
- return p.e(arrowBody, async_range.loc);
+ return p.newExpr(arrowBody, async_range.loc);
}
},
@@ -9851,7 +9855,7 @@ fn NewParser_(
// "async"
// "async + 1"
- return p.e(
+ return p.newExpr(
E.Identifier{ .ref = try p.storeNameInRef("async") },
async_range.loc,
);
@@ -10082,7 +10086,7 @@ fn NewParser_(
},
}
- return p.e(E.Yield{
+ return p.newExpr(E.Yield{
.value = value,
.is_star = isStar,
}, loc);
@@ -10095,7 +10099,7 @@ fn NewParser_(
switch (p.lexer.token) {
.t_numeric_literal => {
- key = p.e(E.Number{
+ key = p.newExpr(E.Number{
.value = p.lexer.number,
}, p.lexer.loc());
// p.checkForLegacyOctalLiteral()
@@ -10105,7 +10109,7 @@ fn NewParser_(
key = try p.parseStringLiteral();
},
.t_big_integer_literal => {
- key = p.e(E.BigInt{ .value = p.lexer.identifier }, p.lexer.loc());
+ key = p.newExpr(E.BigInt{ .value = p.lexer.identifier }, p.lexer.loc());
// markSyntaxFeature
try p.lexer.next();
},
@@ -10114,7 +10118,7 @@ fn NewParser_(
try p.lexer.expected(.t_identifier);
}
- key = p.e(E.PrivateIdentifier{ .ref = p.storeNameInRef(p.lexer.identifier) catch unreachable }, p.lexer.loc());
+ key = p.newExpr(E.PrivateIdentifier{ .ref = p.storeNameInRef(p.lexer.identifier) catch unreachable }, p.lexer.loc());
try p.lexer.next();
},
.t_open_bracket => {
@@ -10255,7 +10259,7 @@ fn NewParser_(
}
}
- key = p.e(E.String{ .data = name }, name_range.loc);
+ key = p.newExpr(E.String{ .data = name }, name_range.loc);
// Parse a shorthand property
const isShorthandProperty = !opts.is_class and
@@ -10281,7 +10285,7 @@ fn NewParser_(
}
const ref = p.storeNameInRef(name) catch unreachable;
- const value = p.e(E.Identifier{ .ref = ref }, key.loc);
+ const value = p.newExpr(E.Identifier{ .ref = ref }, key.loc);
// Destructuring patterns have an optional default value
var initializer: ?Expr = null;
@@ -10455,7 +10459,7 @@ fn NewParser_(
p.popScope();
func.flags.insert(.is_unique_formal_parameters);
- const value = p.e(E.Function{ .func = func }, loc);
+ const value = p.newExpr(E.Function{ .func = func }, loc);
// Enforce argument rules for accessors
switch (kind) {
@@ -10618,7 +10622,7 @@ fn NewParser_(
// Forbid decorators on class constructors
if (opts.ts_decorators.len > 0) {
- switch ((property.key orelse p.panic("Internal error: Expected property {s} to have a key.", .{property})).data) {
+ switch ((property.key orelse p.panic("Internal error: Expected property {any} to have a key.", .{property})).data) {
.e_string => |str| {
if (str.eqlComptime("constructor")) {
p.log.addError(p.source, first_decorator_loc, "TypeScript does not allow decorators on class constructors") catch unreachable;
@@ -10650,7 +10654,7 @@ fn NewParser_(
.ts_decorators = ExprNodeList.init(class_opts.ts_decorators),
.class_keyword = class_keyword,
.body_loc = body_loc,
- .properties = properties.toOwnedSlice(),
+ .properties = try properties.toOwnedSlice(),
.has_decorators = has_decorators or class_opts.ts_decorators.len > 0,
};
}
@@ -10709,7 +10713,7 @@ fn NewParser_(
p.allow_in = oldAllowIn;
- return parts.toOwnedSlice();
+ return try parts.toOwnedSlice();
}
// This assumes the caller has already checked for TStringLiteral or TNoSubstitutionTemplateLiteral
@@ -10718,7 +10722,7 @@ fn NewParser_(
var str = p.lexer.toEString();
str.prefer_template = p.lexer.token == .t_no_substitution_template_literal;
- const expr = p.e(str, loc);
+ const expr = p.newExpr(str, loc);
try p.lexer.next();
return expr;
}
@@ -10741,7 +10745,7 @@ fn NewParser_(
}
var arg = try p.parseExpr(.comma);
if (is_spread) {
- arg = p.e(E.Spread{ .value = arg }, loc);
+ arg = p.newExpr(E.Spread{ .value = arg }, loc);
}
args.append(arg) catch unreachable;
if (p.lexer.token != .t_comma) {
@@ -10767,7 +10771,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{
+ left = p.newExpr(E.Binary{
.op = .bin_comma,
.left = left,
.right = try p.parseExpr(.comma),
@@ -10808,9 +10812,9 @@ fn NewParser_(
const name_loc = p.lexer.loc();
try p.lexer.next();
const ref = p.storeNameInRef(name) catch unreachable;
- left = p.e(E.Index{
+ left = p.newExpr(E.Index{
.target = left,
- .index = p.e(
+ .index = p.newExpr(
E.PrivateIdentifier{
.ref = ref,
},
@@ -10829,7 +10833,7 @@ fn NewParser_(
const name_loc = p.lexer.loc();
try p.lexer.next();
- left = p.e(E.Dot{ .target = left, .name = name, .name_loc = name_loc, .optional_chain = old_optional_chain }, left.loc);
+ left = p.newExpr(E.Dot{ .target = left, .name = name, .name_loc = name_loc, .optional_chain = old_optional_chain }, left.loc);
}
optional_chain = old_optional_chain;
@@ -10859,7 +10863,7 @@ fn NewParser_(
p.allow_in = old_allow_in;
try p.lexer.expect(.t_close_bracket);
- left = p.e(
+ left = p.newExpr(
E.Index{ .target = left, .index = index, .optional_chain = optional_start },
left.loc,
);
@@ -10872,7 +10876,7 @@ fn NewParser_(
}
const list_loc = try p.parseCallArgs();
- left = p.e(E.Call{
+ left = p.newExpr(E.Call{
.target = left,
.args = list_loc.list,
.close_paren_loc = list_loc.loc,
@@ -10896,7 +10900,7 @@ fn NewParser_(
}
const list_loc = try p.parseCallArgs();
- left = p.e(E.Call{
+ left = p.newExpr(E.Call{
.target = left,
.args = list_loc.list,
.close_paren_loc = list_loc.loc,
@@ -10910,9 +10914,9 @@ fn NewParser_(
const name_loc = p.lexer.loc();
try p.lexer.next();
const ref = p.storeNameInRef(name) catch unreachable;
- left = p.e(E.Index{
+ left = p.newExpr(E.Index{
.target = left,
- .index = p.e(
+ .index = p.newExpr(
E.PrivateIdentifier{
.ref = ref,
},
@@ -10929,7 +10933,7 @@ fn NewParser_(
const name_loc = p.lexer.loc();
try p.lexer.next();
- left = p.e(E.Dot{
+ left = p.newExpr(E.Dot{
.target = left,
.name = name,
.name_loc = name_loc,
@@ -10951,7 +10955,7 @@ fn NewParser_(
// p.markSyntaxFeature(compat.TemplateLiteral, p.lexer.Range());
const head = p.lexer.toEString();
try p.lexer.next();
- left = p.e(E.Template{
+ left = p.newExpr(E.Template{
.tag = left,
.head = head,
}, left.loc);
@@ -10964,7 +10968,7 @@ fn NewParser_(
const head = p.lexer.toEString();
const partsGroup = try p.parseTemplateParts(true);
const tag = left;
- left = p.e(E.Template{ .tag = tag, .head = head, .parts = partsGroup }, left.loc);
+ left = p.newExpr(E.Template{ .tag = tag, .head = head, .parts = partsGroup }, left.loc);
},
.t_open_bracket => {
// When parsing a decorator, ignore EIndex expressions since they may be
@@ -10991,7 +10995,7 @@ fn NewParser_(
try p.lexer.expect(.t_close_bracket);
- left = p.e(E.Index{
+ left = p.newExpr(E.Index{
.target = left,
.index = index,
.optional_chain = old_optional_chain,
@@ -11004,7 +11008,7 @@ fn NewParser_(
}
const list_loc = try p.parseCallArgs();
- left = p.e(
+ left = p.newExpr(
E.Call{
.target = left,
.args = list_loc.list,
@@ -11047,7 +11051,7 @@ fn NewParser_(
try p.lexer.expect(.t_colon);
const no = try p.parseExpr(.comma);
- left = p.e(E.If{
+ left = p.newExpr(E.If{
.test_ = left,
.yes = yes,
.no = no,
@@ -11077,7 +11081,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Unary{ .op = .un_post_dec, .value = left }, left.loc);
+ left = p.newExpr(E.Unary{ .op = .un_post_dec, .value = left }, left.loc);
},
.t_plus_plus => {
if (p.lexer.has_newline_before or level.gte(.postfix)) {
@@ -11085,7 +11089,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Unary{ .op = .un_post_inc, .value = left }, left.loc);
+ left = p.newExpr(E.Unary{ .op = .un_post_inc, .value = left }, left.loc);
},
.t_comma => {
if (level.gte(.comma)) {
@@ -11093,7 +11097,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_comma, .left = left, .right = try p.parseExpr(.comma) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_comma, .left = left, .right = try p.parseExpr(.comma) }, left.loc);
},
.t_plus => {
if (level.gte(.add)) {
@@ -11101,7 +11105,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_add, .left = left, .right = try p.parseExpr(.add) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_add, .left = left, .right = try p.parseExpr(.add) }, left.loc);
},
.t_plus_equals => {
if (level.gte(.assign)) {
@@ -11109,7 +11113,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_add_assign, .left = left, .right = try p.parseExpr(@intToEnum(Op.Level, @enumToInt(Op.Level.assign) - 1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_add_assign, .left = left, .right = try p.parseExpr(@intToEnum(Op.Level, @enumToInt(Op.Level.assign) - 1)) }, left.loc);
},
.t_minus => {
if (level.gte(.add)) {
@@ -11117,7 +11121,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_sub, .left = left, .right = try p.parseExpr(.add) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_sub, .left = left, .right = try p.parseExpr(.add) }, left.loc);
},
.t_minus_equals => {
if (level.gte(.assign)) {
@@ -11125,7 +11129,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_sub_assign, .left = left, .right = try p.parseExpr(Op.Level.sub(Op.Level.assign, 1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_sub_assign, .left = left, .right = try p.parseExpr(Op.Level.sub(Op.Level.assign, 1)) }, left.loc);
},
.t_asterisk => {
if (level.gte(.multiply)) {
@@ -11133,7 +11137,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_mul, .left = left, .right = try p.parseExpr(.multiply) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_mul, .left = left, .right = try p.parseExpr(.multiply) }, left.loc);
},
.t_asterisk_asterisk => {
if (level.gte(.exponentiation)) {
@@ -11141,7 +11145,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_pow, .left = left, .right = try p.parseExpr(Op.Level.exponentiation.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_pow, .left = left, .right = try p.parseExpr(Op.Level.exponentiation.sub(1)) }, left.loc);
},
.t_asterisk_asterisk_equals => {
if (level.gte(.assign)) {
@@ -11149,7 +11153,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_pow_assign, .left = left, .right = try p.parseExpr(Op.Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_pow_assign, .left = left, .right = try p.parseExpr(Op.Level.assign.sub(1)) }, left.loc);
},
.t_asterisk_equals => {
if (level.gte(.assign)) {
@@ -11157,7 +11161,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_mul_assign, .left = left, .right = try p.parseExpr(Op.Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_mul_assign, .left = left, .right = try p.parseExpr(Op.Level.assign.sub(1)) }, left.loc);
},
.t_percent => {
if (level.gte(.multiply)) {
@@ -11165,7 +11169,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_rem, .left = left, .right = try p.parseExpr(Op.Level.multiply) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_rem, .left = left, .right = try p.parseExpr(Op.Level.multiply) }, left.loc);
},
.t_percent_equals => {
if (level.gte(.assign)) {
@@ -11173,7 +11177,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_rem_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_rem_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_slash => {
if (level.gte(.multiply)) {
@@ -11181,7 +11185,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_div, .left = left, .right = try p.parseExpr(Level.multiply) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_div, .left = left, .right = try p.parseExpr(Level.multiply) }, left.loc);
},
.t_slash_equals => {
if (level.gte(.assign)) {
@@ -11189,7 +11193,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_div_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_div_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_equals_equals => {
if (level.gte(.equals)) {
@@ -11197,7 +11201,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_loose_eq, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_loose_eq, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
},
.t_exclamation_equals => {
if (level.gte(.equals)) {
@@ -11205,7 +11209,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_loose_ne, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_loose_ne, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
},
.t_equals_equals_equals => {
if (level.gte(.equals)) {
@@ -11213,7 +11217,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_strict_eq, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_strict_eq, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
},
.t_exclamation_equals_equals => {
if (level.gte(.equals)) {
@@ -11221,7 +11225,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_strict_ne, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_strict_ne, .left = left, .right = try p.parseExpr(Level.equals) }, left.loc);
},
.t_less_than => {
// TypeScript allows type arguments to be specified with angle brackets
@@ -11236,35 +11240,35 @@ fn NewParser_(
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_lt, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_lt, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
},
.t_less_than_equals => {
if (level.gte(.compare)) {
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_le, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_le, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
},
.t_greater_than => {
if (level.gte(.compare)) {
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_gt, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_gt, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
},
.t_greater_than_equals => {
if (level.gte(.compare)) {
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_ge, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_ge, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
},
.t_less_than_less_than => {
if (level.gte(.shift)) {
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_shl, .left = left, .right = try p.parseExpr(.shift) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_shl, .left = left, .right = try p.parseExpr(.shift) }, left.loc);
},
.t_less_than_less_than_equals => {
if (level.gte(.assign)) {
@@ -11272,14 +11276,14 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_shl_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_shl_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_greater_than_greater_than => {
if (level.gte(.shift)) {
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_shr, .left = left, .right = try p.parseExpr(.shift) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_shr, .left = left, .right = try p.parseExpr(.shift) }, left.loc);
},
.t_greater_than_greater_than_equals => {
if (level.gte(.assign)) {
@@ -11287,14 +11291,14 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_shr_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_shr_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_greater_than_greater_than_greater_than => {
if (level.gte(.shift)) {
return left;
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_u_shr, .left = left, .right = try p.parseExpr(.shift) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_u_shr, .left = left, .right = try p.parseExpr(.shift) }, left.loc);
},
.t_greater_than_greater_than_greater_than_equals => {
if (level.gte(.assign)) {
@@ -11302,7 +11306,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_u_shr_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_u_shr_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_question_question => {
if (level.gte(.nullish_coalescing)) {
@@ -11310,7 +11314,7 @@ fn NewParser_(
}
try p.lexer.next();
const prev = left;
- left = p.e(E.Binary{ .op = .bin_nullish_coalescing, .left = prev, .right = try p.parseExpr(.nullish_coalescing) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_nullish_coalescing, .left = prev, .right = try p.parseExpr(.nullish_coalescing) }, left.loc);
},
.t_question_question_equals => {
if (level.gte(.assign)) {
@@ -11318,7 +11322,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_nullish_coalescing_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_nullish_coalescing_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_bar_bar => {
if (level.gte(.logical_or)) {
@@ -11333,10 +11337,10 @@ fn NewParser_(
try p.lexer.next();
const right = try p.parseExpr(.logical_or);
- left = p.e(E.Binary{ .op = Op.Code.bin_logical_or, .left = left, .right = right }, left.loc);
+ left = p.newExpr(E.Binary{ .op = Op.Code.bin_logical_or, .left = left, .right = right }, left.loc);
if (level.lt(.nullish_coalescing)) {
- left = try p.parseSuffix(left, Level.nullish_coalescing.add(1), null, flags);
+ left = try p.parseSuffix(left, Level.nullish_coalescing.addF(1), null, flags);
if (p.lexer.token == .t_question_question) {
try p.lexer.unexpected();
@@ -11350,7 +11354,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_logical_or_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_logical_or_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_ampersand_ampersand => {
if (level.gte(.logical_and)) {
@@ -11364,11 +11368,11 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_logical_and, .left = left, .right = try p.parseExpr(.logical_and) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_logical_and, .left = left, .right = try p.parseExpr(.logical_and) }, left.loc);
// Prevent "&&" inside "??" from the left
if (level.lt(.nullish_coalescing)) {
- left = try p.parseSuffix(left, Level.nullish_coalescing.add(1), null, flags);
+ left = try p.parseSuffix(left, Level.nullish_coalescing.addF(1), null, flags);
if (p.lexer.token == .t_question_question) {
try p.lexer.unexpected();
@@ -11382,7 +11386,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_logical_and_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_logical_and_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_bar => {
if (level.gte(.bitwise_or)) {
@@ -11390,7 +11394,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_bitwise_or, .left = left, .right = try p.parseExpr(.bitwise_or) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_bitwise_or, .left = left, .right = try p.parseExpr(.bitwise_or) }, left.loc);
},
.t_bar_equals => {
if (level.gte(.assign)) {
@@ -11398,7 +11402,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_bitwise_or_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_bitwise_or_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_ampersand => {
if (level.gte(.bitwise_and)) {
@@ -11406,7 +11410,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_bitwise_and, .left = left, .right = try p.parseExpr(.bitwise_and) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_bitwise_and, .left = left, .right = try p.parseExpr(.bitwise_and) }, left.loc);
},
.t_ampersand_equals => {
if (level.gte(.assign)) {
@@ -11414,7 +11418,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_bitwise_and_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_bitwise_and_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_caret => {
if (level.gte(.bitwise_xor)) {
@@ -11422,7 +11426,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_bitwise_xor, .left = left, .right = try p.parseExpr(.bitwise_xor) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_bitwise_xor, .left = left, .right = try p.parseExpr(.bitwise_xor) }, left.loc);
},
.t_caret_equals => {
if (level.gte(.assign)) {
@@ -11430,7 +11434,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_bitwise_xor_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_bitwise_xor_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_equals => {
if (level.gte(.assign)) {
@@ -11439,7 +11443,7 @@ fn NewParser_(
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_assign, .left = left, .right = try p.parseExpr(Level.assign.sub(1)) }, left.loc);
},
.t_in => {
if (level.gte(.compare) or !p.allow_in) {
@@ -11458,7 +11462,7 @@ fn NewParser_(
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_in, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_in, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
},
.t_instanceof => {
if (level.gte(.compare)) {
@@ -11479,7 +11483,7 @@ fn NewParser_(
}
}
try p.lexer.next();
- left = p.e(E.Binary{ .op = .bin_instanceof, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
+ left = p.newExpr(E.Binary{ .op = .bin_instanceof, .left = left, .right = try p.parseExpr(.compare) }, left.loc);
},
else => {
// Handle the TypeScript "as" operator
@@ -11554,7 +11558,7 @@ fn NewParser_(
const name_ref = p.declareSymbol(.import, this.loc, clause.original_name) catch unreachable;
clause.name = LocRef{ .loc = this.loc, .ref = name_ref };
- p.is_import_item.putAssumeCapacity(name_ref, .{});
+ p.is_import_item.putAssumeCapacity(name_ref, {});
p.macro.imports.putAssumeCapacity(js_ast.Macro.JSNode.SymbolMap.generateImportHash(import_hash_name, import_data.path), name_ref);
@@ -11590,19 +11594,19 @@ fn NewParser_(
switch (p.lexer.token) {
.t_open_paren => {
if (l < @enumToInt(Level.call) and p.fn_or_arrow_data_parse.allow_super_call) {
- return p.e(E.Super{}, loc);
+ return p.newExpr(E.Super{}, loc);
}
},
.t_dot, .t_open_bracket => {
if (p.fn_or_arrow_data_parse.allow_super_property) {
- return p.e(E.Super{}, loc);
+ return p.newExpr(E.Super{}, loc);
}
},
else => {},
}
p.log.addRangeError(p.source, superRange, "Unexpected \"super\"") catch unreachable;
- return p.e(E.Super{}, loc);
+ return p.newExpr(E.Super{}, loc);
},
.t_open_paren => {
try p.lexer.next();
@@ -11625,15 +11629,15 @@ fn NewParser_(
},
.t_false => {
try p.lexer.next();
- return p.e(E.Boolean{ .value = false }, loc);
+ return p.newExpr(E.Boolean{ .value = false }, loc);
},
.t_true => {
try p.lexer.next();
- return p.e(E.Boolean{ .value = true }, loc);
+ return p.newExpr(E.Boolean{ .value = true }, loc);
},
.t_null => {
try p.lexer.next();
- return p.e(E.Null{}, loc);
+ return p.newExpr(E.Null{}, loc);
},
.t_this => {
if (p.fn_or_arrow_data_parse.is_this_disallowed) {
@@ -11656,7 +11660,7 @@ fn NewParser_(
try p.lexer.expected(.t_in);
}
- return p.e(E.PrivateIdentifier{ .ref = try p.storeNameInRef(name) }, loc);
+ return p.newExpr(E.PrivateIdentifier{ .ref = try p.storeNameInRef(name) }, loc);
},
.t_identifier => {
const name = p.lexer.identifier;
@@ -11696,7 +11700,7 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Await{ .value = value }, loc);
+ return p.newExpr(E.Await{ .value = value }, loc);
}
},
else => {},
@@ -11754,7 +11758,7 @@ fn NewParser_(
defer p.popScope();
var fn_or_arrow_data = FnOrArrowDataParse{};
- const ret = p.e(try p.parseArrowBody(args, &fn_or_arrow_data), loc);
+ const ret = p.newExpr(try p.parseArrowBody(args, &fn_or_arrow_data), loc);
return ret;
}
@@ -11773,13 +11777,13 @@ fn NewParser_(
// Check if TemplateLiteral is unsupported. We don't care for this product.`
// if ()
- return p.e(E.Template{
+ return p.newExpr(E.Template{
.head = head,
.parts = parts,
}, loc);
},
.t_numeric_literal => {
- const value = p.e(E.Number{ .value = p.lexer.number }, loc);
+ const value = p.newExpr(E.Number{ .value = p.lexer.number }, loc);
// p.checkForLegacyOctalLiteral()
try p.lexer.next();
return value;
@@ -11788,7 +11792,7 @@ fn NewParser_(
const value = p.lexer.identifier;
// markSyntaxFeature bigInt
try p.lexer.next();
- return p.e(E.BigInt{ .value = value }, loc);
+ return p.newExpr(E.BigInt{ .value = value }, loc);
},
.t_slash, .t_slash_equals => {
try p.lexer.scanRegExp();
@@ -11797,7 +11801,7 @@ fn NewParser_(
const value = p.lexer.raw();
try p.lexer.next();
- return p.e(E.RegExp{ .value = value, .flags_offset = p.lexer.regex_flags_start }, loc);
+ return p.newExpr(E.RegExp{ .value = value, .flags_offset = p.lexer.regex_flags_start }, loc);
},
.t_void => {
try p.lexer.next();
@@ -11807,7 +11811,7 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Unary{
+ return p.newExpr(E.Unary{
.op = .un_void,
.value = value,
}, loc);
@@ -11820,7 +11824,7 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Unary{ .op = .un_typeof, .value = value }, loc);
+ return p.newExpr(E.Unary{ .op = .un_typeof, .value = value }, loc);
},
.t_delete => {
try p.lexer.next();
@@ -11838,7 +11842,7 @@ fn NewParser_(
}
}
- return p.e(E.Unary{ .op = .un_delete, .value = value }, loc);
+ return p.newExpr(E.Unary{ .op = .un_delete, .value = value }, loc);
},
.t_plus => {
try p.lexer.next();
@@ -11848,7 +11852,7 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Unary{ .op = .un_pos, .value = value }, loc);
+ return p.newExpr(E.Unary{ .op = .un_pos, .value = value }, loc);
},
.t_minus => {
try p.lexer.next();
@@ -11858,7 +11862,7 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Unary{ .op = .un_neg, .value = value }, loc);
+ return p.newExpr(E.Unary{ .op = .un_neg, .value = value }, loc);
},
.t_tilde => {
try p.lexer.next();
@@ -11868,7 +11872,7 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Unary{ .op = .un_cpl, .value = value }, loc);
+ return p.newExpr(E.Unary{ .op = .un_cpl, .value = value }, loc);
},
.t_exclamation => {
try p.lexer.next();
@@ -11878,15 +11882,15 @@ fn NewParser_(
return error.SyntaxError;
}
- return p.e(E.Unary{ .op = .un_not, .value = value }, loc);
+ return p.newExpr(E.Unary{ .op = .un_not, .value = value }, loc);
},
.t_minus_minus => {
try p.lexer.next();
- return p.e(E.Unary{ .op = .un_pre_dec, .value = try p.parseExpr(.prefix) }, loc);
+ return p.newExpr(E.Unary{ .op = .un_pre_dec, .value = try p.parseExpr(.prefix) }, loc);
},
.t_plus_plus => {
try p.lexer.next();
- return p.e(E.Unary{ .op = .un_pre_inc, .value = try p.parseExpr(.prefix) }, loc);
+ return p.newExpr(E.Unary{ .op = .un_pre_inc, .value = try p.parseExpr(.prefix) }, loc);
},
.t_function => {
return try p.parseFnExpr(loc, false, logger.Range.None);
@@ -11926,7 +11930,7 @@ fn NewParser_(
const class = try p.parseClass(classKeyword, name, ParseClassOptions{});
p.popScope();
- return p.e(class, loc);
+ return p.newExpr(class, loc);
},
.t_new => {
try p.lexer.next();
@@ -11942,7 +11946,7 @@ fn NewParser_(
const range = logger.Range{ .loc = loc, .len = p.lexer.range().end().start - loc.start };
try p.lexer.next();
- return p.e(E.NewTarget{ .range = range }, loc);
+ return p.newExpr(E.NewTarget{ .range = range }, loc);
}
const target = try p.parseExprWithFlags(.member, flags);
@@ -11967,7 +11971,7 @@ fn NewParser_(
close_parens_loc = call_args.loc;
}
- return p.e(E.New{
+ return p.newExpr(E.New{
.target = target,
.args = args,
.close_parens_loc = close_parens_loc,
@@ -11996,7 +12000,7 @@ fn NewParser_(
const dots_loc = p.lexer.loc();
try p.lexer.next();
items.append(
- p.e(E.Spread{ .value = try p.parseExprOrBindings(.comma, &self_errors) }, dots_loc),
+ p.newExpr(E.Spread{ .value = try p.parseExprOrBindings(.comma, &self_errors) }, dots_loc),
) catch unreachable;
// Commas are not allowed here when destructuring
@@ -12044,7 +12048,7 @@ fn NewParser_(
// In this case, we can't distinguish between the two yet
self_errors.mergeInto(errors.?);
}
- return p.e(E.Array{
+ return p.newExpr(E.Array{
.items = ExprNodeList.fromList(items),
.comma_after_spread = comma_after_spread.toNullable(),
.is_single_line = is_single_line,
@@ -12115,7 +12119,7 @@ fn NewParser_(
self_errors.mergeInto(errors.?);
}
- return p.e(E.Object{
+ return p.newExpr(E.Object{
.properties = G.Property.List.fromList(properties),
.comma_after_spread = if (comma_after_spread.start > 0)
comma_after_spread
@@ -12235,7 +12239,7 @@ fn NewParser_(
// do people do <API_URL>?
fn jsxRefToMemberExpression(p: *P, loc: logger.Loc, ref: Ref) Expr {
p.recordUsage(ref);
- return p.e(E.Identifier{
+ return p.newExpr(E.Identifier{
.ref = ref,
.can_be_removed_if_unused = true,
.call_can_be_unwrapped_if_unused = true,
@@ -12277,7 +12281,7 @@ fn NewParser_(
)) |rewrote| {
value = rewrote;
} else {
- value = p.e(
+ value = p.newExpr(
E.Dot{
.target = value,
.name = part,
@@ -12302,7 +12306,7 @@ fn NewParser_(
if (p.lexer.isContextualKeyword("meta")) {
try p.lexer.next();
p.has_import_meta = true;
- return p.e(E.ImportMeta{}, loc);
+ return p.newExpr(E.ImportMeta{}, loc);
} else {
try p.lexer.expectedString("\"meta\"");
}
@@ -12319,7 +12323,7 @@ fn NewParser_(
p.lexer.preserve_all_comments_before = true;
try p.lexer.expect(.t_open_paren);
- const comments = p.lexer.comments_to_preserve_before.toOwnedSlice();
+ const comments = try p.lexer.comments_to_preserve_before.toOwnedSlice();
p.lexer.preserve_all_comments_before = false;
const value = try p.parseExpr(.comma);
@@ -12348,7 +12352,7 @@ fn NewParser_(
if (value.data == .e_string and value.data.e_string.isUTF8() and value.data.e_string.isPresent()) {
const import_record_index = p.addImportRecord(.dynamic, value.loc, value.data.e_string.slice(p.allocator));
- return p.e(E.Import{
+ return p.newExpr(E.Import{
.expr = value,
.leading_interior_comments = comments,
.import_record_index = import_record_index,
@@ -12356,7 +12360,7 @@ fn NewParser_(
}
}
- return p.e(E.Import{ .expr = value, .leading_interior_comments = comments, .import_record_index = 0 }, loc);
+ return p.newExpr(E.Import{ .expr = value, .leading_interior_comments = comments, .import_record_index = 0 }, loc);
}
fn parseJSXPropValueIdentifier(p: *P, previous_string_with_backslash_loc: *logger.Loc) !Expr {
@@ -12364,7 +12368,7 @@ fn NewParser_(
try p.lexer.nextInsideJSXElement();
if (p.lexer.token == .t_string_literal) {
previous_string_with_backslash_loc.start = std.math.max(p.lexer.loc().start, p.lexer.previous_backslash_quote_in_jsx.loc.start);
- const expr = p.e(p.lexer.toEString(), previous_string_with_backslash_loc.*);
+ const expr = p.newExpr(p.lexer.toEString(), previous_string_with_backslash_loc.*);
try p.lexer.nextInsideJSXElement();
return expr;
@@ -12434,7 +12438,7 @@ fn NewParser_(
can_be_inlined = can_be_inlined and special_prop != .ref;
- const prop_name = p.e(E.String{ .data = prop_name_literal }, key_range.loc);
+ const prop_name = p.newExpr(E.String{ .data = prop_name_literal }, key_range.loc);
// Parse the value
var value: Expr = undefined;
@@ -12442,7 +12446,7 @@ fn NewParser_(
// Implicitly true value
// <button selected>
- value = p.e(E.Boolean{ .value = true }, logger.Loc{ .start = key_range.loc.start + key_range.len });
+ value = p.newExpr(E.Boolean{ .value = true }, logger.Loc{ .start = key_range.loc.start + key_range.len });
} else {
value = try p.parseJSXPropValueIdentifier(&previous_string_with_backslash_loc);
}
@@ -12475,13 +12479,13 @@ fn NewParser_(
const key = brk: {
switch (expr.data) {
.e_import_identifier => |ident| {
- break :brk p.e(E.String{ .data = p.loadNameFromRef(ident.ref) }, expr.loc);
+ break :brk p.newExpr(E.String{ .data = p.loadNameFromRef(ident.ref) }, expr.loc);
},
.e_identifier => |ident| {
- break :brk p.e(E.String{ .data = p.loadNameFromRef(ident.ref) }, expr.loc);
+ break :brk p.newExpr(E.String{ .data = p.loadNameFromRef(ident.ref) }, expr.loc);
},
.e_dot => |dot| {
- break :brk p.e(E.String{ .data = dot.name }, dot.name_loc);
+ break :brk p.newExpr(E.String{ .data = dot.name }, dot.name_loc);
},
.e_index => |index| {
if (index.index.data == .e_string) {
@@ -12505,7 +12509,7 @@ fn NewParser_(
// <div foo="foo" />
// note: template literals are not supported, operations on strings are not supported either
T.t_string_literal => {
- const key = p.e(p.lexer.toEString(), p.lexer.loc());
+ const key = p.newExpr(p.lexer.toEString(), p.lexer.loc());
try p.lexer.next();
try props.append(G.Property{ .value = key, .key = key, .kind = .normal });
},
@@ -12565,7 +12569,7 @@ fn NewParser_(
flags.insert(.can_be_inlined);
}
- return p.e(E.JSXElement{
+ return p.newExpr(E.JSXElement{
.tag = start_tag,
.properties = properties,
.key = key_prop,
@@ -12582,7 +12586,7 @@ fn NewParser_(
while (true) {
switch (p.lexer.token) {
.t_string_literal => {
- try children.append(p.e(p.lexer.toEString(), loc));
+ try children.append(p.newExpr(p.lexer.toEString(), loc));
try p.lexer.nextJSXElementChild();
},
.t_open_brace => {
@@ -12639,7 +12643,7 @@ fn NewParser_(
flags.insert(.can_be_inlined);
}
- return p.e(E.JSXElement{
+ return p.newExpr(E.JSXElement{
.tag = end_tag.data.asExpr(),
.children = ExprNodeList.fromList(children),
.properties = properties,
@@ -12724,7 +12728,7 @@ fn NewParser_(
}
if (partStmts.items.len > 0) {
- const _stmts = partStmts.toOwnedSlice();
+ const _stmts = try partStmts.toOwnedSlice();
// -- hoist_bun_plugin --
if (_stmts.len == 1 and p.options.features.hoist_bun_plugin and !p.bun_plugin.ref.isNull()) {
@@ -12772,13 +12776,13 @@ fn NewParser_(
try parts.append(js_ast.Part{
.stmts = _stmts,
.symbol_uses = p.symbol_uses,
- .declared_symbols = p.declared_symbols.toOwnedSlice(
+ .declared_symbols = try p.declared_symbols.toOwnedSlice(
p.allocator,
),
- .import_record_indices = p.import_records_for_current_part.toOwnedSlice(
+ .import_record_indices = try p.import_records_for_current_part.toOwnedSlice(
p.allocator,
),
- .scopes = p.scopes_for_current_part.toOwnedSlice(p.allocator),
+ .scopes = try p.scopes_for_current_part.toOwnedSlice(p.allocator),
.can_be_removed_if_unused = p.stmtsCanBeRemovedIfUnused(_stmts),
});
p.symbol_uses = .{};
@@ -12895,7 +12899,7 @@ fn NewParser_(
}
},
else => {
- Global.panic("Unexpected type in export default: {s}", .{s2});
+ Global.panic("Unexpected type in export default: {any}", .{s2});
},
}
},
@@ -12915,7 +12919,7 @@ fn NewParser_(
return true;
}
- fn visitStmtsAndPrependTempRefs(p: *P, stmts: *ListManaged(Stmt), opts: *PrependTempRefsOpts) !void {
+ fn visitStmtsAndPrependTempRefs(p: *P, stmts: *ListManaged(Stmt), opts: *PrependTempRefsOpts) anyerror!void {
if (only_scan_imports_and_do_not_visit) {
@compileError("only_scan_imports_and_do_not_visit must not run this.");
}
@@ -12932,7 +12936,7 @@ fn NewParser_(
if (p.fn_only_data_visit.this_capture_ref) |ref| {
try p.temp_refs_to_declare.append(p.allocator, TempRef{
.ref = ref,
- .value = p.e(E.This{}, opts.fn_body_loc orelse p.panic("Internal error: Expected opts.fn_body_loc to exist", .{})),
+ .value = p.newExpr(E.This{}, opts.fn_body_loc orelse p.panic("Internal error: Expected opts.fn_body_loc to exist", .{})),
});
}
}
@@ -12992,7 +12996,7 @@ fn NewParser_(
var stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, body.stmts);
var temp_opts = PrependTempRefsOpts{ .kind = StmtsKind.fn_body, .fn_body_loc = body.loc };
p.visitStmtsAndPrependTempRefs(&stmts, &temp_opts) catch unreachable;
- func.body = G.FnBody{ .stmts = stmts.toOwnedSlice(), .loc = body.loc };
+ func.body = G.FnBody{ .stmts = stmts.toOwnedSlice() catch @panic("TODO"), .loc = body.loc };
p.popScope();
p.popScope();
@@ -13010,7 +13014,7 @@ fn NewParser_(
// Substitute "this" if we're inside a static class property initializer
if (p.fn_only_data_visit.this_class_static_ref) |ref| {
p.recordUsage(ref);
- return p.e(E.Identifier{ .ref = ref }, loc);
+ return p.newExpr(E.Identifier{ .ref = ref }, loc);
}
// oroigianlly was !=- modepassthrough
@@ -13025,7 +13029,7 @@ fn NewParser_(
// Instead of doing this at runtime using "fn.call(module.exports)", we
// do it at compile time using expression substitution here.
p.recordUsage(p.exports_ref);
- return p.e(E.Identifier{ .ref = p.exports_ref }, loc);
+ return p.newExpr(E.Identifier{ .ref = p.exports_ref }, loc);
}
}
@@ -13095,7 +13099,7 @@ fn NewParser_(
if (!p.import_meta_ref.isNull()) {
p.recordUsage(p.import_meta_ref);
- return p.e(E.Identifier{ .ref = p.import_meta_ref }, expr.loc);
+ return p.newExpr(E.Identifier{ .ref = p.import_meta_ref }, expr.loc);
}
},
.e_spread => |exp| {
@@ -13239,13 +13243,13 @@ fn NewParser_(
var props = p.allocator.alloc(G.Property, e_.properties.len + 1) catch unreachable;
std.mem.copy(G.Property, props, e_.properties.slice());
props[props.len - 1] = G.Property{ .key = Expr{ .loc = key.loc, .data = keyExprData }, .value = key };
- args[1] = p.e(E.Object{ .properties = G.Property.List.init(props) }, expr.loc);
+ args[1] = p.newExpr(E.Object{ .properties = G.Property.List.init(props) }, expr.loc);
} else {
- args[1] = p.e(E.Object{ .properties = e_.properties }, expr.loc);
+ args[1] = p.newExpr(E.Object{ .properties = e_.properties }, expr.loc);
}
i = 2;
} else {
- args[1] = p.e(E.Null{}, expr.loc);
+ args[1] = p.newExpr(E.Null{}, expr.loc);
i = 2;
}
@@ -13256,7 +13260,7 @@ fn NewParser_(
}
// Call createElement()
- return p.e(E.Call{
+ return p.newExpr(E.Call{
.target = p.jsxRefToMemberExpression(expr.loc, p.jsx_factory.ref),
.args = ExprNodeList.init(args[0..i]),
// Enable tree shaking
@@ -13314,7 +13318,7 @@ fn NewParser_(
else => {
props.append(allocator, G.Property{
.key = children_key,
- .value = p.e(E.Array{
+ .value = p.newExpr(E.Array{
.items = e_.children,
.is_single_line = e_.children.len < 2,
}, e_.close_tag_loc),
@@ -13341,27 +13345,27 @@ fn NewParser_(
// key: void 0 === key ? null : "" + key,
break :brk switch (key_.data) {
.e_string => break :brk key_,
- .e_undefined, .e_null => p.e(E.Null{}, key_.loc),
- else => p.e(E.If{
- .test_ = p.e(E.Binary{
- .left = p.e(E.Undefined{}, key_.loc),
+ .e_undefined, .e_null => p.newExpr(E.Null{}, key_.loc),
+ else => p.newExpr(E.If{
+ .test_ = p.newExpr(E.Binary{
+ .left = p.newExpr(E.Undefined{}, key_.loc),
.op = Op.Code.bin_strict_eq,
.right = key_,
}, key_.loc),
- .yes = p.e(E.Null{}, key_.loc),
- .no = p.e(
+ .yes = p.newExpr(E.Null{}, key_.loc),
+ .no = p.newExpr(
E.Binary{
.op = Op.Code.bin_add,
- .left = p.e(&E.String.empty, key_.loc),
+ .left = p.newExpr(&E.String.empty, key_.loc),
.right = key_,
},
key_.loc,
),
}, key_.loc),
};
- } else p.e(E.Null{}, expr.loc);
+ } else p.newExpr(E.Null{}, expr.loc);
var jsx_element = p.allocator.alloc(G.Property, 6) catch unreachable;
- const props_object = p.e(
+ const props_object = p.newExpr(
E.Object{
.properties = G.Property.List.fromList(props),
.close_brace_loc = e_.close_tag_loc,
@@ -13374,7 +13378,7 @@ fn NewParser_(
if (tag.data != .e_string) {
// We assume defaultProps is supposed to _not_ have side effects
// We do not support "key" or "ref" in defaultProps.
- const defaultProps = p.e(E.Dot{
+ const defaultProps = p.newExpr(E.Dot{
.name = "defaultProps",
.name_loc = tag.loc,
.target = tag,
@@ -13382,7 +13386,7 @@ fn NewParser_(
}, tag.loc);
// props: MyComponent.defaultProps || {}
if (props.items.len == 0) {
- props_expression = p.e(E.Binary{ .op = Op.Code.bin_logical_or, .left = defaultProps, .right = props_object }, defaultProps.loc);
+ props_expression = p.newExpr(E.Binary{ .op = Op.Code.bin_logical_or, .left = defaultProps, .right = props_object }, defaultProps.loc);
} else {
var call_args = p.allocator.alloc(Expr, 2) catch unreachable;
call_args[0..2].* = .{
@@ -13405,7 +13409,7 @@ fn NewParser_(
[_]G.Property{
G.Property{
.key = Expr{ .data = Prefill.Data.@"$$typeof", .loc = tag.loc },
- .value = p.e(
+ .value = p.newExpr(
E.Identifier{
.ref = p.react_element_type.ref,
.can_be_removed_if_unused = true,
@@ -13414,33 +13418,33 @@ fn NewParser_(
),
},
G.Property{
- .key = Expr{ .data = Prefill.Data.@"type", .loc = tag.loc },
+ .key = Expr{ .data = Prefill.Data.type, .loc = tag.loc },
.value = tag,
},
G.Property{
- .key = Expr{ .data = Prefill.Data.@"key", .loc = key.loc },
+ .key = Expr{ .data = Prefill.Data.key, .loc = key.loc },
.value = key,
},
// this is a de-opt
// any usage of ref should make it impossible for this code to be reached
G.Property{
- .key = Expr{ .data = Prefill.Data.@"ref", .loc = expr.loc },
- .value = p.e(E.Null{}, expr.loc),
+ .key = Expr{ .data = Prefill.Data.ref, .loc = expr.loc },
+ .value = p.newExpr(E.Null{}, expr.loc),
},
G.Property{
- .key = Expr{ .data = Prefill.Data.@"props", .loc = expr.loc },
+ .key = Expr{ .data = Prefill.Data.props, .loc = expr.loc },
.value = props_expression,
},
G.Property{
- .key = Expr{ .data = Prefill.Data.@"_owner", .loc = key.loc },
- .value = p.e(
+ .key = Expr{ .data = Prefill.Data._owner, .loc = key.loc },
+ .value = p.newExpr(
E.Null{},
expr.loc,
),
},
};
- const output = p.e(
+ const output = p.newExpr(
E.Object{
.properties = G.Property.List.init(jsx_element),
.close_brace_loc = e_.close_tag_loc,
@@ -13458,7 +13462,7 @@ fn NewParser_(
const args = p.allocator.alloc(Expr, if (p.options.jsx.development) @as(usize, 6) else @as(usize, 2) + @as(usize, @boolToInt(e_.key != null))) catch unreachable;
args[0] = tag;
- args[1] = p.e(E.Object{
+ args[1] = p.newExpr(E.Object{
.properties = G.Property.List.fromList(props),
}, expr.loc);
@@ -13487,11 +13491,11 @@ fn NewParser_(
},
};
- args[4] = p.e(E.Undefined{}, expr.loc);
+ args[4] = p.newExpr(E.Undefined{}, expr.loc);
args[5] = Expr{ .data = Prefill.Data.This, .loc = expr.loc };
}
- return p.e(E.Call{
+ return p.newExpr(E.Call{
.target = p.jsxRefToMemberExpressionAutomatic(expr.loc, is_static_jsx),
.args = ExprNodeList.init(args),
// Enable tree shaking
@@ -13520,7 +13524,7 @@ fn NewParser_(
const name = p.symbols.items[ref.innerIndex()].original_name;
p.ignoreUsage(ref);
if (p.is_control_flow_dead) {
- return p.e(E.Undefined{}, e_.tag.?.loc);
+ return p.newExpr(E.Undefined{}, e_.tag.?.loc);
}
p.macro_call_count += 1;
const record = &p.import_records.items[import_record_id];
@@ -13563,7 +13567,7 @@ fn NewParser_(
p.recordUsage(ref);
}
- return p.e(
+ return p.newExpr(
E.ImportIdentifier{
.was_originally_identifier = false,
.ref = ref,
@@ -13666,13 +13670,13 @@ fn NewParser_(
call_args[0] = p.visitExpr(call_args[0]);
}
- return p.e(
+ return p.newExpr(
E.Call{
- .target = p.e(
+ .target = p.newExpr(
E.Dot{
.name = "isNodeType",
.name_loc = expr.loc,
- .target = p.e(BunJSX.bun_jsx_identifier, expr.loc),
+ .target = p.newExpr(BunJSX.bun_jsx_identifier, expr.loc),
.can_be_removed_if_unused = true,
.call_can_be_unwrapped_if_unused = true,
},
@@ -13755,7 +13759,7 @@ fn NewParser_(
.bin_loose_eq => {
const equality = e_.left.data.eql(e_.right.data, p.allocator);
if (equality.ok) {
- return p.e(
+ return p.newExpr(
E.Boolean{ .value = equality.equal },
expr.loc,
);
@@ -13769,7 +13773,7 @@ fn NewParser_(
.bin_strict_eq => {
const equality = e_.left.data.eql(e_.right.data, p.allocator);
if (equality.ok) {
- return p.e(E.Boolean{ .value = equality.equal }, expr.loc);
+ return p.newExpr(E.Boolean{ .value = equality.equal }, expr.loc);
}
// const after_op_loc = locAfterOp(e_.);
@@ -13779,7 +13783,7 @@ fn NewParser_(
.bin_loose_ne => {
const equality = e_.left.data.eql(e_.right.data, p.allocator);
if (equality.ok) {
- return p.e(E.Boolean{ .value = !equality.equal }, expr.loc);
+ return p.newExpr(E.Boolean{ .value = !equality.equal }, expr.loc);
}
// const after_op_loc = locAfterOp(e_.);
// TODO: warn about equality check
@@ -13787,13 +13791,13 @@ fn NewParser_(
// "x != void 0" => "x != null"
if (@as(Expr.Tag, e_.right.data) == .e_undefined) {
- e_.right = p.e(E.Null{}, e_.right.loc);
+ e_.right = p.newExpr(E.Null{}, e_.right.loc);
}
},
.bin_strict_ne => {
const equality = e_.left.data.eql(e_.right.data, p.allocator);
if (equality.ok) {
- return p.e(E.Boolean{ .value = !equality.equal }, expr.loc);
+ return p.newExpr(E.Boolean{ .value = !equality.equal }, expr.loc);
}
},
.bin_nullish_coalescing => {
@@ -13853,7 +13857,7 @@ fn NewParser_(
.bin_add => {
if (p.should_fold_numeric_constants) {
if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- return p.e(E.Number{ .value = vals[0] + vals[1] }, expr.loc);
+ return p.newExpr(E.Number{ .value = vals[0] + vals[1] }, expr.loc);
}
}
@@ -13864,21 +13868,21 @@ fn NewParser_(
.bin_sub => {
if (p.should_fold_numeric_constants) {
if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- return p.e(E.Number{ .value = vals[0] - vals[1] }, expr.loc);
+ return p.newExpr(E.Number{ .value = vals[0] - vals[1] }, expr.loc);
}
}
},
.bin_mul => {
if (p.should_fold_numeric_constants) {
if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- return p.e(E.Number{ .value = vals[0] * vals[1] }, expr.loc);
+ return p.newExpr(E.Number{ .value = vals[0] * vals[1] }, expr.loc);
}
}
},
.bin_div => {
if (p.should_fold_numeric_constants) {
if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- return p.e(E.Number{ .value = vals[0] / vals[1] }, expr.loc);
+ return p.newExpr(E.Number{ .value = vals[0] / vals[1] }, expr.loc);
}
}
},
@@ -13886,14 +13890,14 @@ fn NewParser_(
if (p.should_fold_numeric_constants) {
if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
// is this correct?
- return p.e(E.Number{ .value = std.math.mod(f64, vals[0], vals[1]) catch 0.0 }, expr.loc);
+ return p.newExpr(E.Number{ .value = std.math.mod(f64, vals[0], vals[1]) catch 0.0 }, expr.loc);
}
}
},
.bin_pow => {
if (p.should_fold_numeric_constants) {
if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- return p.e(E.Number{ .value = std.math.pow(f64, vals[0], vals[1]) }, expr.loc);
+ return p.newExpr(E.Number{ .value = std.math.pow(f64, vals[0], vals[1]) }, expr.loc);
}
}
},
@@ -13901,7 +13905,7 @@ fn NewParser_(
// TODO:
// if (p.should_fold_numeric_constants) {
// if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- // return p.e(E.Number{ .value = ((@floatToInt(i32, vals[0]) << @floatToInt(u32, vals[1])) & 31) }, expr.loc);
+ // return p.newExpr(E.Number{ .value = ((@floatToInt(i32, vals[0]) << @floatToInt(u32, vals[1])) & 31) }, expr.loc);
// }
// }
},
@@ -13909,7 +13913,7 @@ fn NewParser_(
// TODO:
// if (p.should_fold_numeric_constants) {
// if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- // return p.e(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
+ // return p.newExpr(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
// }
// }
},
@@ -13917,7 +13921,7 @@ fn NewParser_(
// TODO:
// if (p.should_fold_numeric_constants) {
// if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- // return p.e(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
+ // return p.newExpr(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
// }
// }
},
@@ -13925,7 +13929,7 @@ fn NewParser_(
// TODO:
// if (p.should_fold_numeric_constants) {
// if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- // return p.e(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
+ // return p.newExpr(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
// }
// }
},
@@ -13933,7 +13937,7 @@ fn NewParser_(
// TODO:
// if (p.should_fold_numeric_constants) {
// if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- // return p.e(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
+ // return p.newExpr(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
// }
// }
},
@@ -13941,7 +13945,7 @@ fn NewParser_(
// TODO:
// if (p.should_fold_numeric_constants) {
// if (Expr.extractNumericValues(e_.left.data, e_.right.data)) |vals| {
- // return p.e(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
+ // return p.newExpr(E.Number{ .value = ((@floatToInt(i32, vals[0]) >> @floatToInt(u32, vals[1])) & 31) }, expr.loc);
// }
// }
},
@@ -14077,7 +14081,7 @@ fn NewParser_(
return p.valueForDefine(expr.loc, in.assign_target, is_delete_target, &define.data);
}
- return p.e(E.Undefined{}, expr.loc);
+ return p.newExpr(E.Undefined{}, expr.loc);
}
}
}
@@ -14087,7 +14091,7 @@ fn NewParser_(
const literal = target.data.e_string.slice(p.allocator);
const index = e_.index.data.e_number.toUsize();
if (literal.len > index) {
- return p.e(E.String{ .data = literal[index .. index + 1] }, expr.loc);
+ return p.newExpr(E.String{ .data = literal[index .. index + 1] }, expr.loc);
}
}
// Create an error for assigning to an import namespace when bundling. Even
@@ -14105,7 +14109,7 @@ fn NewParser_(
) catch unreachable;
}
- return p.e(e_, expr.loc);
+ return p.newExpr(e_, expr.loc);
},
.e_unary => |e_| {
switch (e_.op) {
@@ -14125,7 +14129,7 @@ fn NewParser_(
}
if (SideEffects.typeof(e_.value.data)) |typeof| {
- return p.e(E.String{ .data = typeof }, expr.loc);
+ return p.newExpr(E.String{ .data = typeof }, expr.loc);
}
},
.un_delete => {
@@ -14142,7 +14146,7 @@ fn NewParser_(
const side_effects = SideEffects.toBoolean(e_.value.data);
if (side_effects.ok) {
- return p.e(E.Boolean{ .value = !side_effects.value }, expr.loc);
+ return p.newExpr(E.Boolean{ .value = !side_effects.value }, expr.loc);
}
if (e_.value.maybeSimplifyNot(p.allocator)) |exp| {
@@ -14151,17 +14155,17 @@ fn NewParser_(
},
.un_void => {
if (p.exprCanBeRemovedIfUnused(&e_.value)) {
- return p.e(E.Undefined{}, e_.value.loc);
+ return p.newExpr(E.Undefined{}, e_.value.loc);
}
},
.un_pos => {
if (SideEffects.toNumber(e_.value.data)) |num| {
- return p.e(E.Number{ .value = num }, expr.loc);
+ return p.newExpr(E.Number{ .value = num }, expr.loc);
}
},
.un_neg => {
if (SideEffects.toNumber(e_.value.data)) |num| {
- return p.e(E.Number{ .value = -num }, expr.loc);
+ return p.newExpr(E.Number{ .value = -num }, expr.loc);
}
},
@@ -14192,7 +14196,7 @@ fn NewParser_(
if (comma.op == .bin_comma) {
return Expr.joinWithComma(
comma.left,
- p.e(
+ p.newExpr(
E.Unary{
.op = e_.op,
.value = comma.right,
@@ -14296,14 +14300,14 @@ fn NewParser_(
p.is_control_flow_dead = old;
if (side_effects.side_effects == .could_have_side_effects) {
- return Expr.joinWithComma(SideEffects.simpifyUnusedExpr(p, e_.test_) orelse p.e(E.Missing{}, e_.test_.loc), e_.yes, p.allocator);
+ return Expr.joinWithComma(SideEffects.simpifyUnusedExpr(p, e_.test_) orelse p.newExpr(E.Missing{}, e_.test_.loc), e_.yes, p.allocator);
}
// "(1 ? fn : 2)()" => "fn()"
// "(1 ? this.fn : 2)" => "this.fn"
// "(1 ? this.fn : 2)()" => "(0, this.fn)()"
if (is_call_target and e_.yes.hasValueForThisInCall()) {
- return p.e(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.yes, p.allocator);
+ return p.newExpr(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.yes, p.allocator);
}
return e_.yes;
@@ -14317,14 +14321,14 @@ fn NewParser_(
// "(a, false) ? b : c" => "a, c"
if (side_effects.side_effects == .could_have_side_effects) {
- return Expr.joinWithComma(SideEffects.simpifyUnusedExpr(p, e_.test_) orelse p.e(E.Missing{}, e_.test_.loc), e_.no, p.allocator);
+ return Expr.joinWithComma(SideEffects.simpifyUnusedExpr(p, e_.test_) orelse p.newExpr(E.Missing{}, e_.test_.loc), e_.no, p.allocator);
}
// "(1 ? fn : 2)()" => "fn()"
// "(1 ? this.fn : 2)" => "this.fn"
// "(1 ? this.fn : 2)()" => "(0, this.fn)()"
if (is_call_target and e_.no.hasValueForThisInCall()) {
- return p.e(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.no, p.allocator);
+ return p.newExpr(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.no, p.allocator);
}
return e_.no;
}
@@ -14536,11 +14540,11 @@ fn NewParser_(
// dead here. We don't want to spend time scanning the required files
// if they will never be used.
if (p.is_control_flow_dead) {
- return p.e(E.Null{}, expr.loc);
+ return p.newExpr(E.Null{}, expr.loc);
}
p.ignoreUsage(p.require_ref);
- return p.e(
+ return p.newExpr(
E.Call{
.target = p.importMetaRequire(expr.loc),
.args = e_.args,
@@ -14563,18 +14567,18 @@ fn NewParser_(
// dead here. We don't want to spend time scanning the required files
// if they will never be used.
if (p.is_control_flow_dead) {
- return p.e(E.Null{}, expr.loc);
+ return p.newExpr(E.Null{}, expr.loc);
}
if (p.options.features.dynamic_require) {
p.ignoreUsage(p.require_ref);
// require.resolve(FOO) => import.meta.resolveSync(FOO)
// require.resolve(FOO) => import.meta.resolveSync(FOO, pathsObject)
- return p.e(
+ return p.newExpr(
E.Call{
- .target = p.e(
+ .target = p.newExpr(
E.Dot{
- .target = p.e(E.ImportMeta{}, e_.target.loc),
+ .target = p.newExpr(E.ImportMeta{}, e_.target.loc),
.name = "resolveSync",
.name_loc = e_.target.data.e_dot.name_loc,
},
@@ -14610,7 +14614,7 @@ fn NewParser_(
const import_record_id = p.macro.refs.get(ref).?;
p.ignoreUsage(ref);
if (p.is_control_flow_dead) {
- return p.e(E.Undefined{}, e_.target.loc);
+ return p.newExpr(E.Undefined{}, e_.target.loc);
}
const name = p.symbols.items[ref.innerIndex()].original_name;
const record = &p.import_records.items[import_record_id];
@@ -14688,7 +14692,7 @@ fn NewParser_(
var temp_opts = PrependTempRefsOpts{ .kind = StmtsKind.fn_body };
p.visitStmtsAndPrependTempRefs(&stmts_list, &temp_opts) catch unreachable;
p.allocator.free(e_.body.stmts);
- e_.body.stmts = stmts_list.toOwnedSlice();
+ e_.body.stmts = stmts_list.toOwnedSlice() catch @panic("TODO");
p.popScope();
p.popScope();
@@ -14775,7 +14779,7 @@ fn NewParser_(
// var start = p.expr_list.items.len;
// p.expr_list.ensureUnusedCapacity(2) catch unreachable;
// p.expr_list.appendAssumeCapacity(_value);
- // p.expr_list.appendAssumeCapacity(p.e(E.String{
+ // p.expr_list.appendAssumeCapacity(p.newExpr(E.String{
// .utf8 = name,
// }, _value.loc));
@@ -15397,14 +15401,14 @@ fn NewParser_(
if (is_call_target and id.ref.eql(p.module_ref) and strings.eqlComptime(name, "require")) {
p.ignoreUsage(p.module_ref);
p.recordUsage(p.require_ref);
- return p.e(E.Identifier{ .ref = p.require_ref }, name_loc);
+ return p.newExpr(E.Identifier{ .ref = p.require_ref }, name_loc);
}
// If this is a known enum value, inline the value of the enum
if (is_typescript_enabled) {
if (p.known_enum_values.get(id.ref)) |enum_value_map| {
if (enum_value_map.get(name)) |enum_value| {
- return p.e(E.Number{ .value = enum_value }, loc);
+ return p.newExpr(E.Number{ .value = enum_value }, loc);
}
}
}
@@ -15416,7 +15420,7 @@ fn NewParser_(
if (str.is_utf16)
return null;
- return p.e(E.Number{ .value = @intToFloat(f64, str.len()) }, loc);
+ return p.newExpr(E.Number{ .value = @intToFloat(f64, str.len()) }, loc);
}
},
else => {},
@@ -15629,7 +15633,7 @@ fn NewParser_(
var items = try List(js_ast.ClauseItem).initCapacity(p.allocator, 1);
items.appendAssumeCapacity(js_ast.ClauseItem{ .alias = alias.original_name, .original_name = alias.original_name, .alias_loc = alias.loc, .name = LocRef{ .loc = alias.loc, .ref = data.namespace_ref } });
- stmts.appendAssumeCapacity(p.s(S.ExportClause{ .items = items.toOwnedSlice(p.allocator), .is_single_line = true }, stmt.loc));
+ stmts.appendAssumeCapacity(p.s(S.ExportClause{ .items = items.toOwnedSlice(p.allocator) catch @panic("TODO"), .is_single_line = true }, stmt.loc));
return;
}
},
@@ -15745,12 +15749,12 @@ fn NewParser_(
export_default_args[0] = p.@"module.exports"(s2.loc);
if (had_name) {
- export_default_args[1] = p.e(E.Identifier{ .ref = func.func.name.?.ref.? }, s2.loc);
+ export_default_args[1] = p.newExpr(E.Identifier{ .ref = func.func.name.?.ref.? }, s2.loc);
stmts.ensureUnusedCapacity(2) catch unreachable;
stmts.appendAssumeCapacity(s2);
} else {
- export_default_args[1] = p.e(E.Function{ .func = func.func }, s2.loc);
+ export_default_args[1] = p.newExpr(E.Function{ .func = func.func }, s2.loc);
}
stmts.append(p.s(S.SExpr{ .value = p.callRuntime(s2.loc, "__exportDefault", export_default_args) }, s2.loc)) catch unreachable;
@@ -15804,9 +15808,9 @@ fn NewParser_(
if (class_name_ref) |ref| {
stmts.ensureUnusedCapacity(2) catch unreachable;
stmts.appendAssumeCapacity(s2);
- export_default_args[1] = p.e(E.Identifier{ .ref = ref }, s2.loc);
+ export_default_args[1] = p.newExpr(E.Identifier{ .ref = ref }, s2.loc);
} else {
- export_default_args[1] = p.e(class.class, s2.loc);
+ export_default_args[1] = p.newExpr(class.class, s2.loc);
}
stmts.append(p.s(S.SExpr{ .value = p.callRuntime(s2.loc, "__exportDefault", export_default_args) }, s2.loc)) catch unreachable;
@@ -15980,7 +15984,7 @@ fn NewParser_(
const kind = if (std.meta.eql(p.loop_body, stmt.data)) StmtsKind.loop_body else StmtsKind.none;
var _stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, data.stmts);
p.visitStmts(&_stmts, kind) catch unreachable;
- data.stmts = _stmts.toOwnedSlice();
+ data.stmts = _stmts.toOwnedSlice() catch @panic("TODO");
p.popScope();
}
@@ -16013,7 +16017,7 @@ fn NewParser_(
data.test_ = SideEffects.simplifyBoolean(p, data.test_);
const result = SideEffects.toBoolean(data.test_.data);
if (result.ok and result.side_effects == .no_side_effects) {
- data.test_ = p.e(E.Boolean{ .value = result.value }, data.test_.loc);
+ data.test_ = p.newExpr(E.Boolean{ .value = result.value }, data.test_.loc);
}
},
.s_do_while => |data| {
@@ -16076,8 +16080,6 @@ fn NewParser_(
}
}
- // if (false) {
- // }
if (data.no == null) {
return;
}
@@ -16160,7 +16162,7 @@ fn NewParser_(
p.fn_or_arrow_data_visit.try_body_count += 1;
p.visitStmts(&_stmts, StmtsKind.none) catch unreachable;
p.fn_or_arrow_data_visit.try_body_count -= 1;
- data.body = _stmts.toOwnedSlice();
+ data.body = _stmts.toOwnedSlice() catch @panic("TODO");
}
p.popScope();
@@ -16172,7 +16174,7 @@ fn NewParser_(
}
var _stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, catch_.body);
p.visitStmts(&_stmts, StmtsKind.none) catch unreachable;
- catch_.body = _stmts.toOwnedSlice();
+ catch_.body = _stmts.toOwnedSlice() catch @panic("TODO");
}
p.popScope();
}
@@ -16182,7 +16184,7 @@ fn NewParser_(
{
var _stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, finally.stmts);
p.visitStmts(&_stmts, StmtsKind.none) catch unreachable;
- finally.stmts = _stmts.toOwnedSlice();
+ finally.stmts = _stmts.toOwnedSlice() catch @panic("TODO");
}
p.popScope();
}
@@ -16206,7 +16208,7 @@ fn NewParser_(
}
var _stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, case.body);
p.visitStmts(&_stmts, StmtsKind.none) catch unreachable;
- data.cases[i].body = _stmts.toOwnedSlice();
+ data.cases[i].body = _stmts.toOwnedSlice() catch @panic("TODO");
}
}
// TODO: duplicate case checker
@@ -16236,11 +16238,11 @@ fn NewParser_(
const enclosing_namespace_arg_ref = p.enclosing_namespace_arg_ref orelse unreachable;
stmts.ensureUnusedCapacity(3) catch unreachable;
stmts.appendAssumeCapacity(stmt.*);
- stmts.appendAssumeCapacity(Expr.assignStmt(p.e(E.Dot{
- .target = p.e(E.Identifier{ .ref = enclosing_namespace_arg_ref }, stmt.loc),
+ stmts.appendAssumeCapacity(Expr.assignStmt(p.newExpr(E.Dot{
+ .target = p.newExpr(E.Identifier{ .ref = enclosing_namespace_arg_ref }, stmt.loc),
.name = p.loadNameFromRef(data.func.name.?.ref.?),
.name_loc = data.func.name.?.loc,
- }, stmt.loc), p.e(E.Identifier{ .ref = data.func.name.?.ref.? }, data.func.name.?.loc), p.allocator));
+ }, stmt.loc), p.newExpr(E.Identifier{ .ref = data.func.name.?.ref.? }, data.func.name.?.loc), p.allocator));
} else if (!mark_as_dead) {
stmts.append(stmt.*) catch unreachable;
} else if (mark_as_dead) {
@@ -16297,11 +16299,11 @@ fn NewParser_(
// Handle exporting this class from a namespace
if (was_export_inside_namespace) {
- stmts.appendAssumeCapacity(Expr.assignStmt(p.e(E.Dot{
- .target = p.e(E.Identifier{ .ref = p.enclosing_namespace_arg_ref.? }, stmt.loc),
+ stmts.appendAssumeCapacity(Expr.assignStmt(p.newExpr(E.Dot{
+ .target = p.newExpr(E.Identifier{ .ref = p.enclosing_namespace_arg_ref.? }, stmt.loc),
.name = p.symbols.items[data.class.class_name.?.ref.?.innerIndex()].original_name,
.name_loc = data.class.class_name.?.loc,
- }, stmt.loc), p.e(E.Identifier{ .ref = data.class.class_name.?.ref.? }, data.class.class_name.?.loc), p.allocator));
+ }, stmt.loc), p.newExpr(E.Identifier{ .ref = data.class.class_name.?.ref.? }, data.class.class_name.?.loc), p.allocator));
}
return;
@@ -16365,19 +16367,19 @@ fn NewParser_(
else => {},
}
} else if (has_numeric_value) {
- enum_value.value = p.e(E.Number{ .value = next_numeric_value }, enum_value.loc);
+ enum_value.value = p.newExpr(E.Number{ .value = next_numeric_value }, enum_value.loc);
values_so_far.put(allocator, name.string(allocator) catch unreachable, next_numeric_value) catch unreachable;
next_numeric_value += 1;
} else {
- enum_value.value = p.e(E.Undefined{}, enum_value.loc);
+ enum_value.value = p.newExpr(E.Undefined{}, enum_value.loc);
}
// "Enum['Name'] = value"
- assign_target = Expr.assign(p.e(E.Index{
- .target = p.e(
+ assign_target = Expr.assign(p.newExpr(E.Index{
+ .target = p.newExpr(
E.Identifier{ .ref = data.arg },
enum_value.loc,
),
- .index = p.e(
+ .index = p.newExpr(
enum_value.name,
enum_value.loc,
),
@@ -16392,14 +16394,14 @@ fn NewParser_(
// "Enum[assignTarget] = 'Name'"
value_exprs.append(
Expr.assign(
- p.e(E.Index{
- .target = p.e(
+ p.newExpr(E.Index{
+ .target = p.newExpr(
E.Identifier{ .ref = data.arg },
enum_value.loc,
),
.index = assign_target,
}, enum_value.loc),
- p.e(enum_value.name, enum_value.loc),
+ p.newExpr(enum_value.name, enum_value.loc),
allocator,
),
) catch unreachable;
@@ -16422,7 +16424,7 @@ fn NewParser_(
data.name.loc,
data.name.ref.?,
data.arg,
- value_stmts.toOwnedSlice(),
+ try value_stmts.toOwnedSlice(),
);
return;
},
@@ -16451,7 +16453,7 @@ fn NewParser_(
p.enclosing_namespace_arg_ref = data.arg;
p.pushScopeForVisitPass(.entry, stmt.loc) catch unreachable;
p.recordDeclaredSymbol(data.arg) catch unreachable;
- p.visitStmtsAndPrependTempRefs(&prepend_list, &prepend_temp_refs) catch unreachable;
+ try p.visitStmtsAndPrependTempRefs(&prepend_list, &prepend_temp_refs);
p.popScope();
p.enclosing_namespace_arg_ref = old_enclosing_namespace_arg_ref;
@@ -16662,12 +16664,12 @@ fn NewParser_(
{
var array = expr.data.e_array;
- array.items.len = @minimum(array.items.len, @truncate(u32, bound_array.items.len));
+ array.items.len = @min(array.items.len, @truncate(u32, bound_array.items.len));
var slice = array.items.slice();
for (bound_array.items[0..array.items.len]) |item, item_i| {
const child_expr = slice[item_i];
if (item.binding.data == .b_missing) {
- slice[item_i] = p.e(E.Missing{}, expr.loc);
+ slice[item_i] = p.newExpr(E.Missing{}, expr.loc);
continue;
}
@@ -16767,7 +16769,7 @@ fn NewParser_(
}
},
else => {
- Global.panic("Unexpected binding type in namespace. This is a bug. {s}", .{binding});
+ Global.panic("Unexpected binding type in namespace. This is a bug. {any}", .{binding});
},
}
}
@@ -16795,7 +16797,7 @@ fn NewParser_(
// Make sure to only emit a variable once for a given namespace, since there
// can be multiple namespace blocks for the same namespace
if (symbol.kind == .ts_namespace or symbol.kind == .ts_enum and !p.emitted_namespace_vars.contains(name_ref)) {
- p.emitted_namespace_vars.put(allocator, name_ref, .{}) catch unreachable;
+ p.emitted_namespace_vars.put(allocator, name_ref, {}) catch unreachable;
var decls = allocator.alloc(G.Decl, 1) catch unreachable;
decls[0] = G.Decl{ .binding = p.b(B.Identifier{ .ref = name_ref }, name_loc) };
@@ -16834,10 +16836,10 @@ fn NewParser_(
const name = p.symbols.items[name_ref.innerIndex()].original_name;
arg_expr = Expr.assign(
Expr.initIdentifier(name_ref, name_loc),
- p.e(
+ p.newExpr(
E.Binary{
.op = .bin_logical_or,
- .left = p.e(
+ .left = p.newExpr(
E.Dot{
.target = Expr.initIdentifier(namespace, name_loc),
.name = name,
@@ -16846,7 +16848,7 @@ fn NewParser_(
name_loc,
),
.right = Expr.assign(
- p.e(
+ p.newExpr(
E.Dot{
.target = Expr.initIdentifier(namespace, name_loc),
.name = name,
@@ -16854,7 +16856,7 @@ fn NewParser_(
},
name_loc,
),
- p.e(E.Object{}, name_loc),
+ p.newExpr(E.Object{}, name_loc),
allocator,
),
},
@@ -16867,12 +16869,12 @@ fn NewParser_(
p.recordUsage(name_ref);
} else {
// "name || (name = {})"
- arg_expr = p.e(E.Binary{
+ arg_expr = p.newExpr(E.Binary{
.op = .bin_logical_or,
.left = Expr.initIdentifier(name_ref, name_loc),
.right = Expr.assign(
Expr.initIdentifier(name_ref, name_loc),
- p.e(
+ p.newExpr(
E.Object{},
name_loc,
),
@@ -16896,14 +16898,14 @@ fn NewParser_(
.stmts = try allocator.dupe(StmtNodeIndex, stmts_inside_closure),
},
};
- const target = p.e(
+ const target = p.newExpr(
E.Function{
.func = func,
},
stmt_loc,
);
- const call = p.e(
+ const call = p.newExpr(
E.Call{
.target = target,
.args = ExprNodeList.init(args_list),
@@ -16956,7 +16958,7 @@ fn NewParser_(
for (arg.ts_decorators.ptr[0..arg.ts_decorators.len]) |arg_decorator| {
var decorators = if (is_constructor) class.ts_decorators.listManaged(p.allocator) else prop.ts_decorators.listManaged(p.allocator);
const args = p.allocator.alloc(Expr, 2) catch unreachable;
- args[0] = p.e(E.Number{ .value = @intToFloat(f64, i) }, arg_decorator.loc);
+ args[0] = p.newExpr(E.Number{ .value = @intToFloat(f64, i) }, arg_decorator.loc);
args[1] = arg_decorator;
decorators.append(p.callRuntime(arg_decorator.loc, "__decorateParam", args)) catch unreachable;
if (is_constructor) {
@@ -16988,9 +16990,9 @@ fn NewParser_(
if (prop.ts_decorators.len > 0) {
const loc = prop.key.?.loc;
const descriptor_key = switch (prop.key.?.data) {
- .e_identifier => |k| p.e(E.Identifier{ .ref = k.ref }, loc),
- .e_number => |k| p.e(E.Number{ .value = k.value }, loc),
- .e_string => |k| p.e(E.String{ .data = k.data }, loc),
+ .e_identifier => |k| p.newExpr(E.Identifier{ .ref = k.ref }, loc),
+ .e_number => |k| p.newExpr(E.Number{ .value = k.value }, loc),
+ .e_string => |k| p.newExpr(E.String{ .data = k.data }, loc),
else => undefined,
};
@@ -16999,16 +17001,16 @@ fn NewParser_(
var target: Expr = undefined;
if (prop.flags.contains(.is_static)) {
p.recordUsage(class.class_name.?.ref.?);
- target = p.e(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc);
+ target = p.newExpr(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc);
} else {
- target = p.e(E.Dot{ .target = p.e(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc), .name = "prototype", .name_loc = loc }, loc);
+ target = p.newExpr(E.Dot{ .target = p.newExpr(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc), .name = "prototype", .name_loc = loc }, loc);
}
const args = p.allocator.alloc(Expr, 4) catch unreachable;
- args[0] = p.e(E.Array{ .items = prop.ts_decorators }, loc);
+ args[0] = p.newExpr(E.Array{ .items = prop.ts_decorators }, loc);
args[1] = target;
args[2] = descriptor_key;
- args[3] = p.e(E.Number{ .value = descriptor_kind }, loc);
+ args[3] = p.newExpr(E.Number{ .value = descriptor_kind }, loc);
const decorator = p.callRuntime(prop.key.?.loc, "__decorateClass", args);
const decorator_stmt = p.s(S.SExpr{ .value = decorator }, decorator.loc);
@@ -17027,18 +17029,18 @@ fn NewParser_(
var target: Expr = undefined;
if (prop.flags.contains(.is_static)) {
p.recordUsage(class.class_name.?.ref.?);
- target = p.e(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc);
+ target = p.newExpr(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc);
} else {
- target = p.e(E.This{}, prop.key.?.loc);
+ target = p.newExpr(E.This{}, prop.key.?.loc);
}
if (prop.flags.contains(.is_computed)) {
- target = p.e(E.Index{
+ target = p.newExpr(E.Index{
.target = target,
.index = prop.key.?,
}, prop.key.?.loc);
} else {
- target = p.e(E.Dot{
+ target = p.newExpr(E.Dot{
.target = target,
.name = prop.key.?.data.e_string.data,
.name_loc = prop.key.?.loc,
@@ -17065,22 +17067,22 @@ fn NewParser_(
var constructor_stmts = ListManaged(Stmt).init(p.allocator);
if (class.extends != null) {
- const target = p.e(E.Super{}, stmt.loc);
+ const target = p.newExpr(E.Super{}, stmt.loc);
const arguments_ref = p.newSymbol(.unbound, "arguments") catch unreachable;
p.current_scope.generated.append(p.allocator, arguments_ref) catch unreachable;
- const super = p.e(E.Spread{ .value = p.e(E.Identifier{ .ref = arguments_ref }, stmt.loc) }, stmt.loc);
+ const super = p.newExpr(E.Spread{ .value = p.newExpr(E.Identifier{ .ref = arguments_ref }, stmt.loc) }, stmt.loc);
const args = ExprNodeList.one(p.allocator, super) catch unreachable;
- constructor_stmts.append(p.s(S.SExpr{ .value = p.e(E.Call{ .target = target, .args = args }, stmt.loc) }, stmt.loc)) catch unreachable;
+ constructor_stmts.append(p.s(S.SExpr{ .value = p.newExpr(E.Call{ .target = target, .args = args }, stmt.loc) }, stmt.loc)) catch unreachable;
}
constructor_stmts.appendSlice(instance_members.items) catch unreachable;
properties.insert(0, G.Property{
.flags = Flags.Property.init(.{ .is_method = true }),
- .key = p.e(E.String{ .data = "constructor" }, stmt.loc),
- .value = p.e(E.Function{ .func = G.Fn{
+ .key = p.newExpr(E.String{ .data = "constructor" }, stmt.loc),
+ .value = p.newExpr(E.Function{ .func = G.Fn{
.name = null,
.open_parens_loc = logger.Loc.Empty,
.args = &[_]Arg{},
@@ -17116,11 +17118,11 @@ fn NewParser_(
stmts.appendSliceAssumeCapacity(static_decorators.items);
if (class.ts_decorators.len > 0) {
const args = p.allocator.alloc(Expr, 2) catch unreachable;
- args[0] = p.e(E.Array{ .items = class.ts_decorators }, stmt.loc);
- args[1] = p.e(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc);
+ args[0] = p.newExpr(E.Array{ .items = class.ts_decorators }, stmt.loc);
+ args[1] = p.newExpr(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc);
stmts.appendAssumeCapacity(Expr.assignStmt(
- p.e(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc),
+ p.newExpr(E.Identifier{ .ref = class.class_name.?.ref.? }, class.class_name.?.loc),
p.callRuntime(stmt.loc, "__decorateClass", args),
p.allocator,
));
@@ -17157,7 +17159,7 @@ fn NewParser_(
// s.Kind = p.selectLocalKind(s.Kind)
},
else => {
- p.panic("Unexpected stmt in visitForLoopInit: {s}", .{stmt});
+ p.panic("Unexpected stmt in visitForLoopInit: {any}", .{stmt});
},
}
@@ -17172,7 +17174,7 @@ fn NewParser_(
const enclosing_ref = p.enclosing_namespace_arg_ref.?;
p.recordUsage(enclosing_ref);
- return p.e(E.Dot{
+ return p.newExpr(E.Dot{
.target = Expr.initIdentifier(enclosing_ref, loc),
.name = p.symbols.items[ref.innerIndex()].original_name,
.name_loc = loc,
@@ -17222,7 +17224,7 @@ fn NewParser_(
);
},
.e_string => |str| {
- return p.e(str, loc);
+ return p.newExpr(str, loc);
},
else => {},
}
@@ -17359,7 +17361,7 @@ fn NewParser_(
}
},
else => {
- p.panic("Unexpected binding {s}", .{binding});
+ p.panic("Unexpected binding {any}", .{binding});
},
}
}
@@ -17392,7 +17394,7 @@ fn NewParser_(
p.popScope();
}
- return p.stmtsToSingleStmt(stmt.loc, stmts.toOwnedSlice());
+ return p.stmtsToSingleStmt(stmt.loc, stmts.toOwnedSlice() catch @panic("TODO"));
}
// One statement could potentially expand to several statements
@@ -17605,11 +17607,11 @@ fn NewParser_(
switch (arg.binding.data) {
.b_identifier => |id| {
const name = p.symbols.items[id.ref.innerIndex()].original_name;
- const ident = p.e(E.Identifier{ .ref = id.ref }, arg.binding.loc);
+ const ident = p.newExpr(E.Identifier{ .ref = id.ref }, arg.binding.loc);
stmts.appendAssumeCapacity(
Expr.assignStmt(
- p.e(E.Dot{
- .target = p.e(E.This{}, arg.binding.loc),
+ p.newExpr(E.Dot{
+ .target = p.newExpr(E.This{}, arg.binding.loc),
.name = name,
.name_loc = arg.binding.loc,
}, arg.binding.loc),
@@ -17628,8 +17630,8 @@ fn NewParser_(
}
}
- class.properties = class_body.toOwnedSlice();
- constructor.func.body.stmts = stmts.toOwnedSlice();
+ class.properties = class_body.toOwnedSlice() catch unreachable;
+ constructor.func.body.stmts = stmts.toOwnedSlice() catch unreachable;
}
}
}
@@ -17658,10 +17660,10 @@ fn NewParser_(
fn keepStmtSymbolName(p: *P, loc: logger.Loc, ref: Ref, name: string) Stmt {
p.expr_list.ensureUnusedCapacity(2) catch unreachable;
const start = p.expr_list.items.len;
- p.expr_list.appendAssumeCapacity(p.e(E.Identifier{
+ p.expr_list.appendAssumeCapacity(p.newExpr(E.Identifier{
.ref = ref,
}, loc));
- p.expr_list.appendAssumeCapacity(p.e(E.String{ .data = name }, loc));
+ p.expr_list.appendAssumeCapacity(p.newExpr(E.String{ .data = name }, loc));
return p.s(S.SExpr{
// I believe that this is a spot we can do $RefreshReg$(name)
.value = p.callRuntime(loc, "__name", p.expr_list.items[start..p.expr_list.items.len]),
@@ -17692,8 +17694,8 @@ fn NewParser_(
}
p.recordUsage(ref);
- return p.e(E.Call{
- .target = p.e(E.Identifier{
+ return p.newExpr(E.Call{
+ .target = p.newExpr(E.Identifier{
.ref = ref,
}, loc),
.args = ExprNodeList.init(args),
@@ -17963,7 +17965,7 @@ fn NewParser_(
}
pub inline fn @"module.exports"(p: *P, loc: logger.Loc) Expr {
- return p.e(E.Dot{ .name = exports_string_name, .name_loc = loc, .target = p.e(E.Identifier{ .ref = p.module_ref }, loc) }, loc);
+ return p.newExpr(E.Dot{ .name = exports_string_name, .name_loc = loc, .target = p.newExpr(E.Identifier{ .ref = p.module_ref }, loc) }, loc);
}
// This assumes that the open parenthesis has already been parsed by the caller
@@ -18009,7 +18011,7 @@ fn NewParser_(
var item = try p.parseExprOrBindings(.comma, &errors);
if (is_spread) {
- item = p.e(E.Spread{ .value = item }, loc);
+ item = p.newExpr(E.Spread{ .value = item }, loc);
}
// Skip over types
@@ -18115,7 +18117,7 @@ fn NewParser_(
arrow.is_async = opts.is_async;
arrow.has_rest_arg = spread_range.len > 0;
p.popScope();
- return p.e(arrow, loc);
+ return p.newExpr(arrow, loc);
}
}
@@ -18133,8 +18135,8 @@ fn NewParser_(
// Are these arguments for a call to a function named "async"?
if (opts.is_async) {
p.logExprErrors(&errors);
- const async_expr = p.e(E.Identifier{ .ref = try p.storeNameInRef("async") }, loc);
- return p.e(E.Call{ .target = async_expr, .args = ExprNodeList.init(items) }, loc);
+ const async_expr = p.newExpr(E.Identifier{ .ref = try p.storeNameInRef("async") }, loc);
+ return p.newExpr(E.Call{ .target = async_expr, .args = ExprNodeList.init(items) }, loc);
}
// Is this a chain of expressions and comma operators?
@@ -18222,7 +18224,7 @@ fn NewParser_(
kept_import_equals = kept_import_equals or result.kept_import_equals;
removed_import_equals = removed_import_equals or result.removed_import_equals;
part.import_record_indices = part.import_record_indices;
- part.declared_symbols = p.declared_symbols.toOwnedSlice(allocator);
+ part.declared_symbols = try p.declared_symbols.toOwnedSlice(allocator);
part.stmts = result.stmts;
if (part.stmts.len > 0) {
if (p.module_scope.contains_direct_eval and part.declared_symbols.len > 0) {
@@ -18290,7 +18292,7 @@ fn NewParser_(
var new_stmts_list = allocator.alloc(Stmt, exports_from_count + imports_count + 1) catch unreachable;
var imports_list = new_stmts_list[0..imports_count];
- var exports_list = if (exports_from_count > 0) new_stmts_list[imports_list.len + 1 ..] else &[_]Stmt{};
+ var exports_list: []Stmt = if (exports_from_count > 0) new_stmts_list[imports_list.len + 1 ..] else &[_]Stmt{};
require_function_args[0] = G.Arg{ .binding = p.b(B.Identifier{ .ref = p.module_ref }, logger.Loc.Empty) };
require_function_args[1] = G.Arg{ .binding = p.b(B.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty) };
@@ -18317,7 +18319,7 @@ fn NewParser_(
}
}
- commonjs_wrapper.data.e_call.args.ptr[0] = p.e(
+ commonjs_wrapper.data.e_call.args.ptr[0] = p.newExpr(
E.Function{ .func = G.Fn{
.name = null,
.open_parens_loc = logger.Loc.Empty,
@@ -18336,7 +18338,7 @@ fn NewParser_(
sourcefile_name = sourcefile_name[end..];
}
}
- commonjs_wrapper.data.e_call.args.ptr[1] = p.e(E.String{ .data = sourcefile_name }, logger.Loc.Empty);
+ commonjs_wrapper.data.e_call.args.ptr[1] = p.newExpr(E.String{ .data = sourcefile_name }, logger.Loc.Empty);
new_stmts_list[imports_list.len] = p.s(
S.ExportDefault{
@@ -18459,13 +18461,13 @@ fn NewParser_(
const new_call_args_count: usize = if (p.options.features.react_fast_refresh) 3 else 2;
var call_args = try allocator.alloc(Expr, new_call_args_count + 1);
var new_call_args = call_args[0..new_call_args_count];
- var hmr_module_ident = p.e(E.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty);
+ var hmr_module_ident = p.newExpr(E.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty);
- new_call_args[0] = p.e(E.Number{ .value = @intToFloat(f64, p.options.filepath_hash_for_hmr) }, logger.Loc.Empty);
+ new_call_args[0] = p.newExpr(E.Number{ .value = @intToFloat(f64, p.options.filepath_hash_for_hmr) }, logger.Loc.Empty);
// This helps us provide better error messages
- new_call_args[1] = p.e(E.String{ .data = p.source.path.pretty }, logger.Loc.Empty);
+ new_call_args[1] = p.newExpr(E.String{ .data = p.source.path.pretty }, logger.Loc.Empty);
if (p.options.features.react_fast_refresh) {
- new_call_args[2] = p.e(E.Identifier{ .ref = p.jsx_refresh_runtime.ref }, logger.Loc.Empty);
+ new_call_args[2] = p.newExpr(E.Identifier{ .ref = p.jsx_refresh_runtime.ref }, logger.Loc.Empty);
}
var toplevel_stmts_i: u8 = 0;
@@ -18482,9 +18484,9 @@ fn NewParser_(
const hmr_import_ref = hmr_import_module_.ref;
first_decl[0] = G.Decl{
.binding = p.b(B.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty),
- .value = p.e(E.New{
+ .value = p.newExpr(E.New{
.args = ExprNodeList.init(new_call_args),
- .target = p.e(
+ .target = p.newExpr(
E.Identifier{
.ref = hmr_import_ref,
},
@@ -18495,8 +18497,8 @@ fn NewParser_(
};
first_decl[1] = G.Decl{
.binding = p.b(B.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty),
- .value = p.e(E.Dot{
- .target = p.e(E.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty),
+ .value = p.newExpr(E.Dot{
+ .target = p.newExpr(E.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty),
.name = "exports",
.name_loc = logger.Loc.Empty,
}, logger.Loc.Empty),
@@ -18514,7 +18516,7 @@ fn NewParser_(
var export_name_string_all = try allocator.alloc(u8, export_name_string_length);
var export_name_string_remainder = export_name_string_all;
- var hmr_module_exports_dot = p.e(
+ var hmr_module_exports_dot = p.newExpr(
E.Dot{
.target = hmr_module_ident,
.name = "exports",
@@ -18525,7 +18527,7 @@ fn NewParser_(
var exports_decls = decls[first_decl.len..];
named_exports_iter = p.named_exports.iterator();
var update_function_args = try allocator.alloc(G.Arg, 1);
- var exports_ident = p.e(E.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty);
+ var exports_ident = p.newExpr(E.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty);
update_function_args[0] = G.Arg{ .binding = p.b(B.Identifier{ .ref = p.exports_ref }, logger.Loc.Empty) };
while (named_exports_iter.next()) |named_export| {
@@ -18550,12 +18552,12 @@ fn NewParser_(
// was this originally a named import?
// preserve the identifier
S.Return{ .value = if (named_export_symbol.namespace_alias != null)
- p.e(E.ImportIdentifier{
+ p.newExpr(E.ImportIdentifier{
.ref = named_export_value.ref,
.was_originally_identifier = true,
}, logger.Loc.Empty)
else
- p.e(E.Identifier{
+ p.newExpr(E.Identifier{
.ref = named_export_value.ref,
}, logger.Loc.Empty) },
logger.Loc.Empty,
@@ -18567,7 +18569,7 @@ fn NewParser_(
.name = .{ .ref = name_ref, .loc = logger.Loc.Empty },
};
- var decl_value = p.e(
+ var decl_value = p.newExpr(
E.Dot{ .target = hmr_module_exports_dot, .name = named_export.key_ptr.*, .name_loc = logger.Loc.Empty },
logger.Loc.Empty,
);
@@ -18577,11 +18579,11 @@ fn NewParser_(
};
update_function_stmts[named_export_i] = Expr.assignStmt(
- p.e(
+ p.newExpr(
E.Identifier{ .ref = name_ref },
logger.Loc.Empty,
),
- p.e(E.Dot{
+ p.newExpr(E.Dot{
.target = exports_ident,
.name = named_export.key_ptr.*,
.name_loc = logger.Loc.Empty,
@@ -18590,8 +18592,8 @@ fn NewParser_(
);
export_properties[named_export_i] = G.Property{
- .key = p.e(E.String{ .data = named_export.key_ptr.* }, logger.Loc.Empty),
- .value = p.e(
+ .key = p.newExpr(E.String{ .data = named_export.key_ptr.* }, logger.Loc.Empty),
+ .value = p.newExpr(
E.Arrow{
.args = &[_]G.Arg{},
.body = .{
@@ -18606,16 +18608,16 @@ fn NewParser_(
named_export_i += 1;
}
var export_all_args = call_args[new_call_args.len..];
- export_all_args[0] = p.e(
+ export_all_args[0] = p.newExpr(
E.Object{ .properties = Property.List.init(export_properties[0..named_export_i]) },
logger.Loc.Empty,
);
part_stmts[part_stmts.len - 1] = p.s(
S.SExpr{
- .value = p.e(
+ .value = p.newExpr(
E.Call{
- .target = p.e(
+ .target = p.newExpr(
E.Dot{
.target = hmr_module_ident,
.name = "exportAll",
@@ -18642,7 +18644,7 @@ fn NewParser_(
const is_async = !p.top_level_await_keyword.isEmpty();
- var func = p.e(
+ var func = p.newExpr(
E.Function{
.func = .{
.body = .{ .loc = logger.Loc.Empty, .stmts = part_stmts[0 .. part_stmts_i + 1] },
@@ -18657,10 +18659,10 @@ fn NewParser_(
logger.Loc.Empty,
);
- const call_load = p.e(
+ const call_load = p.newExpr(
E.Call{
.target = Expr.assign(
- p.e(
+ p.newExpr(
E.Dot{
.name = "_load",
.target = hmr_module_ident,
@@ -18678,7 +18680,7 @@ fn NewParser_(
toplevel_stmts[toplevel_stmts_i] = p.s(
S.SExpr{
.value = if (is_async)
- p.e(E.Await{ .value = call_load }, logger.Loc.Empty)
+ p.newExpr(E.Await{ .value = call_load }, logger.Loc.Empty)
else
call_load,
},
@@ -18708,7 +18710,7 @@ fn NewParser_(
toplevel_stmts[toplevel_stmts_i] = p.s(
S.SExpr{
.value = Expr.assign(
- p.e(
+ p.newExpr(
E.Dot{
.name = "_update",
.target = hmr_module_ident,
@@ -18716,7 +18718,7 @@ fn NewParser_(
},
logger.Loc.Empty,
),
- p.e(
+ p.newExpr(
E.Function{
.func = .{
.body = .{ .loc = logger.Loc.Empty, .stmts = if (named_export_i > 0) update_function_stmts[0..named_export_i] else &.{} },