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
6 changes: 6 additions & 0 deletions crates/oxc_minifier/src/peephole/replace_known_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,9 @@ mod test {
test("x = 'ca'.replace('c','xxx')", "x = 'xxxa'");
test_same("x = 'c'.replace((foo(), 'c'), 'b')");

test_same("x = '[object Object]'.replace({}, 'x')"); // can be folded to "x"
test_same("x = 'a'.replace({ [Symbol.replace]() { return 'x' } }, 'c')"); // can be folded to "x"

// only one instance replaced
test("x = 'acaca'.replace('c','x')", "x = 'axaca'");
test("x = 'ab'.replace('','x')", "x = 'xab'");
Expand Down Expand Up @@ -1185,6 +1188,9 @@ mod test {
test("x = 'c_c_c'.replaceAll('c','x')", "x = 'x_x_x'");
test("x = 'acaca'.replaceAll('c',/x/)", "x = 'a/x/a/x/a'");

test_same("x = '[object Object]'.replaceAll({}, 'x')"); // can be folded to "x"
test_same("x = 'a'.replaceAll({ [Symbol.replace]() { return 'x' } }, 'c')"); // can be folded to "x"

test_same("x = 'acaca'.replaceAll(/c/,'x')"); // this should throw
test_same("x = 'acaca'.replaceAll(/c/g,'x')"); // this will affect the global RegExp props

Expand Down
Loading