Fix two parser bugs

Former-commit-id: 884b0e3e31e562e4f0e0676819c442842ba9040b
This commit is contained in:
Jarred Sumner
2021-08-11 15:54:15 -07:00
parent 3b0a19efe0
commit c3c14ff9ce
3 changed files with 22 additions and 2 deletions

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -0,0 +1,2 @@
var ho = true;
console.log(([, len]) => true);