8000 fix(minifier): fix crash with `[]['concat'](1)` by sapphi-red · Pull Request #8750 · oxc-project/oxc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(minifier): fix crash with []['concat'](1) #8750

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/oxc_minifier/src/peephole/replace_known_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,12 @@ impl<'a> PeepholeOptimizations {
}
}

let Expression::StaticMemberExpression(member) = callee else { unreachable!() };
let Expression::ArrayExpression(array_expr) = &mut member.object else { return None };
let object = match callee {
Expression::StaticMemberExpression(member) => &mut member.object,
Expression::ComputedMemberExpression(member) => &mut member.object,
_ => unreachable!(),
};
let Expression::ArrayExpression(array_expr) = object else { return None };

let can_merge_ 8FCC until = args
.iter()
Expand Down Expand Up @@ -574,7 +578,7 @@ impl<'a> PeepholeOptimizations {
}

if args.is_empty() {
Some(ctx.ast.move_expression(&mut member.object))
Some(ctx.ast.move_expression(object))
} else if can_merge_until.is_some() {
Some(ctx.ast.expression_call(
span,
Expand Down Expand Up @@ -1438,6 +1442,7 @@ mod test {
test("var x; ''.concat(x.a).concat(x)", "var x; ''.concat(x.a, x)"); // x.a might have a getter that updates x, but that side effect is preserved correctly

// other
test("x = []['concat'](1)", "x = [1]");
test_same("obj.concat([1,2]).concat(1)");
}

Expand Down
Loading
0