From 2f3a9dc74c6b5ce9ebda3f9114d357e23e9f53a6 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 10 Jan 2025 04:04:05 +0000 Subject: [PATCH] fix(minifier): cannot transform property key `#constructor` (#8405) --- .../src/ast_passes/peephole_substitute_alternate_syntax.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs index b7fe7f63ae9ce..2048f8e828f43 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs @@ -1032,7 +1032,9 @@ impl<'a, 'b> PeepholeSubstituteAlternateSyntax { }; let PropertyKey::StringLiteral(s) = key else { return }; let value = s.value.as_str(); - if matches!(value, "__proto__" | "constructor" | "prototype") { + // Uncaught SyntaxError: Classes may not have a field named 'constructor' + // Uncaught SyntaxError: Class constructor may not be a private method + if matches!(value, "__proto__" | "prototype" | "constructor" | "#constructor") { return; } if *computed { @@ -1785,6 +1787,7 @@ mod test { test_same("class C { ['prototype']() {} }"); test_same("class C { ['__proto__']() {} }"); test_same("class C { ['constructor']() {} }"); + test_same("class C { ['#constructor']() {} }"); } #[test]