diff options
author | 2023-04-20 23:57:26 -0700 | |
---|---|---|
committer | 2023-04-20 23:57:44 -0700 | |
commit | 541d16f8bed5f51a9861419d7273e733dae56549 (patch) | |
tree | 835e524ed78722ffcfb80c5e4227992a704aa3dc | |
parent | b609f9be2894f5237a0d058eaea884f330f02f77 (diff) | |
download | bun-541d16f8bed5f51a9861419d7273e733dae56549.tar.gz bun-541d16f8bed5f51a9861419d7273e733dae56549.tar.zst bun-541d16f8bed5f51a9861419d7273e733dae56549.zip |
Fix bug with merging adjacent vars
-rw-r--r-- | src/bundler/bundle_v2.zig | 2 | ||||
-rw-r--r-- | src/js_ast.zig | 5 | ||||
-rw-r--r-- | src/js_parser.zig | 4 |
3 files changed, 9 insertions, 2 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 44a6489cd..dda7d9659 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -5474,7 +5474,7 @@ const LinkerContext = struct { if (stmts.items[end - 1].data == .s_local) { var before = stmts.items[end - 1].data.s_local; // It must be the same kind of variable statement (i.e. let/var/const) - if (before.kind == after.kind and before.is_export == after.is_export) { + if (before.canMergeWith(after)) { if (did_merge_with_previous_local) { // Avoid O(n^2) behavior for repeated variable declarations // Appending to this decls list is safe because did_merge_with_previous_local is true diff --git a/src/js_ast.zig b/src/js_ast.zig index 2f0d8ddd6..dbd0fb010 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -5269,6 +5269,11 @@ pub const S = struct { was_commonjs_export: bool = false, + pub fn canMergeWith(this: *const Local, other: *const Local) bool { + return this.kind == other.kind and this.is_export == other.is_export and + this.was_commonjs_export == other.was_commonjs_export; + } + pub const Kind = enum(u2) { k_var, k_let, diff --git a/src/js_parser.zig b/src/js_parser.zig index 34db0e5ac..cf78826ea 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -20154,7 +20154,9 @@ fn NewParser_( // Merge adjacent local statements if (output.items.len > 0) { var prev_stmt = &output.items[output.items.len - 1]; - if (prev_stmt.data == .s_local and local.kind == prev_stmt.data.s_local.kind and local.is_export == prev_stmt.data.s_local.is_export) { + if (prev_stmt.data == .s_local and + local.canMergeWith(prev_stmt.data.s_local)) + { prev_stmt.data.s_local.decls.append(p.allocator, local.decls.slice()) catch unreachable; continue; } |