aboutsummaryrefslogtreecommitdiff
path: root/src/js_parser/js_parser.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-06-29 17:47:58 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-06-29 17:47:58 -0700
commit3f197d1ce0c197864ad4c7c7b8238af4370275b4 (patch)
tree7d76dcc182e80c5b67db1568e769977229649980 /src/js_parser/js_parser.zig
parent26745bb5f300481fc242c8e81de6f252f698c863 (diff)
downloadbun-3f197d1ce0c197864ad4c7c7b8238af4370275b4.tar.gz
bun-3f197d1ce0c197864ad4c7c7b8238af4370275b4.tar.zst
bun-3f197d1ce0c197864ad4c7c7b8238af4370275b4.zip
Fix crash, fix detecting node_modules, fix undefined not being simplified
Diffstat (limited to 'src/js_parser/js_parser.zig')
-rw-r--r--src/js_parser/js_parser.zig18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 63af5964d..be442728b 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -1892,8 +1892,8 @@ pub const Parser = struct {
},
loc,
);
- // Otherwise, it looks like this
- // var
+ // Otherwise, it looks like this
+ // var
} else {
jsx_part_stmts[stmt_i] = p.s(S.Import{
.namespace_ref = automatic_namespace_ref,
@@ -2196,6 +2196,7 @@ pub const Prefill = struct {
};
pub const Value = struct {
pub var EThis = E.This{};
+ pub var Zero = E.Number{ .value = 0.0 };
};
pub const String = struct {
pub var Key = E.String{ .value = &Prefill.StringLiteral.Key };
@@ -2218,6 +2219,7 @@ pub const Prefill = struct {
pub var LineNumber = Expr.Data{ .e_string = &Prefill.String.LineNumber };
pub var ColumnNumber = Expr.Data{ .e_string = &Prefill.String.ColumnNumber };
pub var This = Expr.Data{ .e_this = E.This{} };
+ pub var Zero = Expr.Data{ .e_number = &Value.Zero };
};
pub const Runtime = struct {
pub var JSXFilename = "__jsxFilename";
@@ -10781,7 +10783,19 @@ pub fn NewParser(
.e_unary => |e_| {
switch (e_.op) {
.un_typeof => {
+ const id_before = std.meta.activeTag(e_.value.data) == Expr.Tag.e_identifier;
e_.value = p.visitExprInOut(e_.value, ExprIn{ .assign_target = e_.op.unaryAssignTarget() });
+ const id_after = std.meta.activeTag(e_.value.data) == Expr.Tag.e_identifier;
+
+ // The expression "typeof (0, x)" must not become "typeof x" if "x"
+ // is unbound because that could suppress a ReferenceError from "x"
+ if (!id_before and id_after and p.symbols.items[e_.value.data.e_identifier.ref.inner_index].kind == .unbound) {
+ e_.value = Expr.joinWithComma(
+ Expr{ .loc = e_.value.loc, .data = Prefill.Data.Zero },
+ e_.value,
+ p.allocator,
+ );
+ }
if (SideEffects.toTypeof(e_.value.data)) |typeof| {
return p.e(E.String{ .utf8 = typeof }, expr.loc);