Skip to content

Commit

Permalink
fix(minifier): Unknown.fromCharCode should not be treated as `Strin…
Browse files Browse the repository at this point in the history
…g.fromCharCode`
  • Loading branch information
sapphi-red committed Jan 25, 2025
1 parent f15bdce commit c82f04d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/oxc_minifier/src/peephole/replace_known_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<'a> PeepholeOptimizations {
) -> Option<Expression<'a>> {
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;
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit c82f04d

Please sign in to comment.