Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,9 @@ impl<'a> LatePeepholeOptimizations {

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

let is_all_string = array
.elements
.iter()
.all(|element| element.as_expression().is_some_and(Expression::is_string_literal));
let is_all_string = array.elements.iter().all(|element| {
element.as_expression().is_some_and(|expr| matches!(expr, Expression::StringLiteral(_)))
});
if !is_all_string {
return None;
}
Expand Down Expand Up @@ -1323,13 +1322,15 @@ mod test {

test_same_with_longer_args("'1','2','3','4'");
test_same_with_longer_args("'1','2','3','4','5'");
test_same_with_longer_args("`1${a}`,'2','3','4','5','6'");
test_with_longer_args("'1','2','3','4','5','6'", "123456", "");
test_with_longer_args("'1','2','3','4','5','00'", "1.2.3.4.5.00", ".");
test_with_longer_args("'1','2','3','4','5','6','7'", "1234567", "");
test_with_longer_args("'1','2','3','4','5','6','00'", "1.2.3.4.5.6.00", ".");
test_with_longer_args("'.,',',',',',',',',',','", ".,(,(,(,(,(,", "(");
test_with_longer_args("',,','.',',',',',',',','", ",,(.(,(,(,(,", "(");
test_with_longer_args("'a,','.',',',',',',',','", "a,(.(,(,(,(,", "(");
test_with_longer_args("`1`,'2','3','4','5','6'", "123456", "");

// all possible delimiters used, leave it alone
test_same_with_longer_args("'.', ',', '(', ')', ' '");
Expand Down
Loading