mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(minifier): compress typeof addition string (#8301)
This commit is contained in:
parent
4d2888d6fc
commit
6afc590db8
1 changed files with 20 additions and 0 deletions
|
|
@ -334,6 +334,18 @@ impl<'a, 'b> PeepholeFoldConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typeof foo + ""
|
||||||
|
if let Expression::UnaryExpression(left) = &e.left {
|
||||||
|
if left.operator.is_typeof() {
|
||||||
|
if let Expression::StringLiteral(right) = &e.right {
|
||||||
|
if right.value.is_empty() {
|
||||||
|
return Some(ctx.ast.move_expression(&mut e.left));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1777,4 +1789,12 @@ mod test {
|
||||||
test("true.toString()", "'true'");
|
test("true.toString()", "'true'");
|
||||||
test("false.toString()", "'false'");
|
test("false.toString()", "'false'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fold_typeof_addition_string() {
|
||||||
|
test_same("typeof foo");
|
||||||
|
test_same("typeof foo + '123'");
|
||||||
|
test("typeof foo + ''", "typeof foo");
|
||||||
|
test_same("typeof foo - ''");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue