mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(minifier): compress new Array(7n) -> [7n] (#8343)
`Array(7n)` evaluates to `[7n]`
This commit is contained in:
parent
e085d66c78
commit
819c47536c
1 changed files with 2 additions and 1 deletions
|
|
@ -762,7 +762,7 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax {
|
|||
Some(ctx.ast.expression_array(span, ctx.ast.vec(), None))
|
||||
}
|
||||
// `new Array(8)` -> `Array(8)`
|
||||
else if arg.is_number_literal() {
|
||||
else if let Expression::NumericLiteral(_) = arg {
|
||||
let callee = ctx.ast.expression_identifier_reference(SPAN, "Array");
|
||||
let args = ctx.ast.move_vec(args);
|
||||
Some(ctx.ast.expression_call(span, callee, NONE, args, false))
|
||||
|
|
@ -1144,6 +1144,7 @@ mod test {
|
|||
test("x = new Array(0)", "x = []");
|
||||
test("x = new Array(\"a\")", "x = [\"a\"]");
|
||||
test("x = new Array(7)", "x = Array(7)");
|
||||
test("x = new Array(7n)", "x = [7n]");
|
||||
test("x = new Array(y)", "x = Array(y)");
|
||||
test("x = new Array(foo())", "x = Array(foo())");
|
||||
test("x = Array(0)", "x = []");
|
||||
|
|
|
|||
Loading…
Reference in a new issue