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]