diff options
| author | 2021-08-11 15:54:15 -0700 | |
|---|---|---|
| committer | 2021-08-11 15:54:15 -0700 | |
| commit | c3c14ff9ce2c8e02ee09b44d3f17a063d2d37ff2 (patch) | |
| tree | 38a18842a6b86891a1666bce0e98fd774de2c444 | |
| parent | 3b0a19efe02825d72c5ea4ac6b9bc69734a9c9d2 (diff) | |
| download | bun-c3c14ff9ce2c8e02ee09b44d3f17a063d2d37ff2.tar.gz bun-c3c14ff9ce2c8e02ee09b44d3f17a063d2d37ff2.tar.zst bun-c3c14ff9ce2c8e02ee09b44d3f17a063d2d37ff2.zip | |
Fix two parser bugs
Former-commit-id: 884b0e3e31e562e4f0e0676819c442842ba9040b
| -rw-r--r-- | src/js_parser/js_parser.zig | 17 | ||||
| -rw-r--r-- | src/panic_handler.zig | 5 | ||||
| -rw-r--r-- | src/test/fixtures/array-binding-none.js | 2 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 3aeee0865..c341300c7 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -3447,7 +3447,15 @@ pub fn NewParser( item = item.getSpread().value; } const res = p.convertExprToBindingAndInitializer(&item, invalid_loc, is_spread); - items.append(js_ast.ArrayBinding{ .binding = res.binding orelse unreachable, .default_value = res.override_expr }) catch unreachable; + + items.append(js_ast.ArrayBinding{ + // It's valid for it to be missing + // An example: + // Promise.all(promises).then(([, len]) => true); + // ^ Binding is missing there + .binding = res.binding orelse p.b(B.Missing{}, item.loc), + .default_value = res.override_expr, + }) catch unreachable; } return p.b(B.Array{ @@ -11162,6 +11170,13 @@ pub fn NewParser( }, .e_import => |e_| { const state = TransposeState{ + // we must check that the await_target is an e_import or it will crash + // example from next.js where not checking causes a panic: + // ``` + // const { + // normalizeLocalePath, + // } = require('../shared/lib/i18n/normalize-locale-path') as typeof import('../shared/lib/i18n/normalize-locale-path') + // ``` .is_await_target = if (p.await_target != null) p.await_target.? == .e_import and p.await_target.?.e_import == e_ else false, .is_then_catch_target = p.then_catch_chain.has_catch and std.meta.activeTag(p.then_catch_chain.next_target) == .e_import and expr.data.e_import == p.then_catch_chain.next_target.e_import, .loc = e_.expr.loc, diff --git a/src/panic_handler.zig b/src/panic_handler.zig index 475d55514..3f49bf6ab 100644 --- a/src/panic_handler.zig +++ b/src/panic_handler.zig @@ -1,6 +1,7 @@ const std = @import("std"); const logger = @import("logger.zig"); const root = @import("root"); +usingnamespace @import("global.zig"); const USERLAND_PANIC_MESSAGE = "iNtErNaL sErVeR eRrOr"; @@ -47,7 +48,9 @@ pub fn NewPanicHandler(panic_func: fn handle_panic(msg: []const u8, error_return .log = log, }; } - pub fn handle_panic(msg: []const u8, error_return_type: ?*std.builtin.StackTrace) callconv(.Inline) noreturn { + pub inline fn handle_panic(msg: []const u8, error_return_type: ?*std.builtin.StackTrace) noreturn { + Output.flush(); + if (@This().Singleton) |singleton| { singleton.panic_count += 1; } diff --git a/src/test/fixtures/array-binding-none.js b/src/test/fixtures/array-binding-none.js new file mode 100644 index 000000000..2ca6fe7b9 --- /dev/null +++ b/src/test/fixtures/array-binding-none.js @@ -0,0 +1,2 @@ +var ho = true; +console.log(([, len]) => true); |
