Skip to content

Commit

Permalink
fix(minifier): constant fold strings with tab char (#8096)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 24, 2024
1 parent 6bd9ddb commit b605baa
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,8 @@ impl<'a, 'b> PeepholeFoldConstants {
let left_string = ctx.get_side_free_string_value(left_expr);
let right_string = ctx.get_side_free_string_value(right_expr);
if let (Some(left_string), Some(right_string)) = (left_string, right_string) {
// In JS, browsers parse \v differently. So do not compare strings if one contains \v.
if left_string.contains('\u{000B}') || right_string.contains('\u{000B}') {
return None;
}

return Some(left_string == right_string);
}

None
}
ValueType::Undefined | ValueType::Null => Some(true),
Expand Down Expand Up @@ -812,6 +806,8 @@ mod test {
test_same("'' + x <= '' + x"); // potentially foldable
test_same("'' + x != '' + x"); // potentially foldable
test_same("'' + x === '' + x"); // potentially foldable

test(r#"if (" str ing " !== "\u000Bstr\u000Bing\u000B") {}"#, "if (false) {}\n");
}

#[test]
Expand Down

0 comments on commit b605baa

Please sign in to comment.