diff options
author | 2023-04-17 00:32:21 -0700 | |
---|---|---|
committer | 2023-04-17 00:32:21 -0700 | |
commit | 0514f59288c62b297b931bf3fc9876655d26df10 (patch) | |
tree | 3ddbb12bfe5aaf17dc3af34953652316c7676548 | |
parent | 5a8cfd839041af3492f2637bfd6cc8dd9b2d1fd4 (diff) | |
download | bun-0514f59288c62b297b931bf3fc9876655d26df10.tar.gz bun-0514f59288c62b297b931bf3fc9876655d26df10.tar.zst bun-0514f59288c62b297b931bf3fc9876655d26df10.zip |
DCE for some global constructor calls
-rw-r--r-- | src/js_parser.zig | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index 05966b745..2ee274e92 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -4388,7 +4388,7 @@ pub const KnownGlobal = enum { pub const map = bun.ComptimeEnumMap(KnownGlobal); - pub fn maybeMarkConstructorAsPure(e: *E.New, symbols: []const Symbol) void { + pub noinline fn maybeMarkConstructorAsPure(e: *E.New, symbols: []const Symbol) void { const id = if (e.target.data == .e_identifier) e.target.data.e_identifier.ref else return; const symbol = &symbols[id.innerIndex()]; if (symbol.kind != .unbound) @@ -4407,7 +4407,7 @@ pub const KnownGlobal = enum { } if (n == 1) { - switch (e.args[0].data) { + switch (e.args.ptr[0].data) { .e_null, .e_undefined => { // "new WeakSet(null)" is pure // "new WeakSet(void 0)" is pure @@ -4437,7 +4437,7 @@ pub const KnownGlobal = enum { } if (n == 1) { - switch (e.args[0].knownPrimitiveType()) { + switch (e.args.ptr[0].knownPrimitive()) { .null, .undefined, .boolean, .number, .string => { // "new Date('')" is pure // "new Date(0)" is pure @@ -4465,7 +4465,7 @@ pub const KnownGlobal = enum { } if (n == 1) { - switch (e.args[0].data) { + switch (e.args.ptr[0].data) { .e_array, .e_null, .e_undefined => { // "new Set([a, b, c])" is pure // "new Set(null)" is pure @@ -4489,7 +4489,7 @@ pub const KnownGlobal = enum { } if (n == 1) { - switch (e.args[0].data) { + switch (e.args.ptr[0].data) { .e_null, .e_undefined => { // "new Map(null)" is pure // "new Map(void 0)" is pure @@ -4497,7 +4497,7 @@ pub const KnownGlobal = enum { }, .e_array => |array| { var all_items_are_arrays = true; - for (array.items) |item| { + for (array.items.slice()) |item| { if (item.data != .e_array) { all_items_are_arrays = false; break; @@ -16343,6 +16343,10 @@ fn NewParser_( for (e_.args.slice()) |*arg| { arg.* = p.visitExpr(arg.*); } + + if (p.options.features.minify_syntax) { + KnownGlobal.maybeMarkConstructorAsPure(e_, p.symbols.items); + } }, .e_arrow => |e_| { if (p.is_revisit_for_substitution) { |