From c82f04dcd90173784289c7811da0074420ca8768 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Sat, 25 Jan 2025 19:48:36 +0900 Subject: [PATCH] fix(minifier): `Unknown.fromCharCode` should not be treated as `String.fromCharCode` --- crates/oxc_minifier/src/peephole/replace_known_methods.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_minifier/src/peephole/replace_known_methods.rs b/crates/oxc_minifier/src/peephole/replace_known_methods.rs index e377b7b4ac8cca..96567861a9ab6c 100644 --- a/crates/oxc_minifier/src/peephole/replace_known_methods.rs +++ b/crates/oxc_minifier/src/peephole/replace_known_methods.rs @@ -245,7 +245,7 @@ impl<'a> PeepholeOptimizations { ) -> Option> { let Expression::Identifier(ident) = object else { return None }; let ctx = Ctx(ctx); - if !ctx.is_global_reference(ident) { + if ident.name != "String" || !ctx.is_global_reference(ident) { return None; } let args = &ce.arguments; @@ -1422,6 +1422,8 @@ mod test { test_same("String.fromCharCode(x)"); test("x = String.fromCharCode('x')", "x = '\\0'"); test("x = String.fromCharCode('0.5')", "x = '\\0'"); + + test_same("x = Unknown.fromCharCode('0.5')"); } #[test]