diff options
| author | 2022-02-01 14:41:36 -0800 | |
|---|---|---|
| committer | 2022-02-01 14:41:36 -0800 | |
| commit | d47e0de1750c9d234febdebeac4415470deea008 (patch) | |
| tree | befbde5c2f428023f263258800d98b9ed8244861 /src | |
| parent | 8c470194ce13781af550a74b2b4f2c1ed06670ac (diff) | |
| download | bun-d47e0de1750c9d234febdebeac4415470deea008.tar.gz bun-d47e0de1750c9d234febdebeac4415470deea008.tar.zst bun-d47e0de1750c9d234febdebeac4415470deea008.zip | |
[JS Printer] Fix printing edgecase with nested vars that use object destructuring
Diffstat (limited to 'src')
| -rw-r--r-- | src/js_printer.zig | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig index 0300630dc..2da9703fb 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -2041,7 +2041,6 @@ pub fn NewPrinter( p.printExpr(item.value.?, .comma, ExprFlag.None()); return; } - const _key = item.key orelse unreachable; if (item.flags.is_static) { p.print("static"); @@ -2082,8 +2081,21 @@ pub fn NewPrinter( }, else => {}, } + + // If var is declared in a parent scope and var is then written via destructuring pattern, key is null + // example: + // var foo = 1; + // if (true) { + // var { foo } = { foo: 2 }; + // } + if (item.key == null) { + p.printExpr(val, .comma, ExprFlag.None()); + return; + } } + const _key = item.key.?; + if (item.flags.is_computed) { p.print("["); p.printExpr(_key, .comma, ExprFlag.None()); |
