From 3e0a78bc0d94989a46314b09109d2a8eedf1e032 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 11 Aug 2021 20:22:03 -0700 Subject: Fix parser/printer bugs Former-commit-id: 8d5fa093546432e803eb066190a3b4b48e5c95f2 --- src/js_parser/js_parser.zig | 4 +++- src/js_printer.zig | 9 +++------ src/test/fixtures/compilation-prototype.js | 15 +++++++++++++++ .../nested-destructuring-should-print-correctly.js | 7 +++++++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/test/fixtures/compilation-prototype.js create mode 100644 src/test/fixtures/nested-destructuring-should-print-correctly.js (limited to 'src') diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 22464b4da..9801e7e32 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -10855,6 +10855,8 @@ pub fn NewParser( )) |val| { return val; } + } else { + e_.index = p.visitExpr(e_.index); } // Create an error for assigning to an import namespace when bundling. Even @@ -12095,8 +12097,8 @@ pub fn NewParser( // TODO: simplify boolean expression }, .s_do_while => |data| { - data.test_ = p.visitExpr(data.test_); data.body = p.visitLoopBody(data.body); + data.test_ = p.visitExpr(data.test_); // TODO: simplify boolean expression }, diff --git a/src/js_printer.zig b/src/js_printer.zig index 0940b92cb..1f43479a6 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -340,6 +340,7 @@ pub fn NewPrinter( } p.printBinding(arg.binding); + if (arg.default) |default| { p.printSpace(); p.print("="); @@ -2019,9 +2020,7 @@ pub fn NewPrinter( continue; } }, - else => { - p.printExpr(property.key, .lowest, ExprFlag.None()); - }, + else => {}, } } else if (p.canPrintIdentifierUTF16(str.value)) { p.addSourceMapping(property.key.loc); @@ -2036,9 +2035,7 @@ pub fn NewPrinter( continue; } }, - else => { - p.printExpr(property.key, .lowest, ExprFlag.None()); - }, + else => {}, } } else { p.printExpr(property.key, .lowest, ExprFlag.None()); diff --git a/src/test/fixtures/compilation-prototype.js b/src/test/fixtures/compilation-prototype.js new file mode 100644 index 000000000..6d6f8d1ef --- /dev/null +++ b/src/test/fixtures/compilation-prototype.js @@ -0,0 +1,15 @@ +// The bug is: +// when there are even number of scopes which have property accesses that themselves declare scopes, + +// the scope counter is wrong, causing an invariant check to fail. +class f {} +prop[class {}]; +class a {} + +// prop[class {}]; + +// prop[ +// function (match) { +// return 0; +// } +// ]; diff --git a/src/test/fixtures/nested-destructuring-should-print-correctly.js b/src/test/fixtures/nested-destructuring-should-print-correctly.js new file mode 100644 index 000000000..072c4f93f --- /dev/null +++ b/src/test/fixtures/nested-destructuring-should-print-correctly.js @@ -0,0 +1,7 @@ +function hey({ + config: { + options: { ignore: e, only: t }, + }, +}) { + return shouldIgnore(a, e, t, u); +} -- cgit v1.2.3