Skip to content

Commit f8548ec

Browse files
committed
fix(minifier): unreachable error when compressing string literal arrays with .split() (#8806)
1 parent e353a01 commit f8548ec

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,9 @@ impl<'a> LatePeepholeOptimizations {
950950

951951
let Expression::ArrayExpression(array) = expr else { unreachable!() };
952952

953-
let is_all_string = array
954-
.elements
955-
.iter()
956-
.all(|element| element.as_expression().is_some_and(Expression::is_string_literal));
953+
let is_all_string = array.elements.iter().all(|element| {
954+
element.as_expression().is_some_and(|expr| matches!(expr, Expression::StringLiteral(_)))
955+
});
957956
if !is_all_string {
958957
return None;
959958
}
@@ -1323,13 +1322,15 @@ mod test {
13231322

13241323
test_same_with_longer_args("'1','2','3','4'");
13251324
test_same_with_longer_args("'1','2','3','4','5'");
1325+
test_same_with_longer_args("`1${a}`,'2','3','4','5','6'");
13261326
test_with_longer_args("'1','2','3','4','5','6'", "123456", "");
13271327
test_with_longer_args("'1','2','3','4','5','00'", "1.2.3.4.5.00", ".");
13281328
test_with_longer_args("'1','2','3','4','5','6','7'", "1234567", "");
13291329
test_with_longer_args("'1','2','3','4','5','6','00'", "1.2.3.4.5.6.00", ".");
13301330
test_with_longer_args("'.,',',',',',',',',',','", ".,(,(,(,(,(,", "(");
13311331
test_with_longer_args("',,','.',',',',',',',','", ",,(.(,(,(,(,", "(");
13321332
test_with_longer_args("'a,','.',',',',',',',','", "a,(.(,(,(,(,", "(");
1333+
test_with_longer_args("`1`,'2','3','4','5','6'", "123456", "");
13331334

13341335
// all possible delimiters used, leave it alone
13351336
test_same_with_longer_args("'.', ',', '(', ')', ' '");

0 commit comments

Comments
 (0)