fix(minifier): cannot transform property key #constructor (#8405)

This commit is contained in:
Boshen 2025-01-10 04:04:05 +00:00
parent 438a6e7abc
commit 2f3a9dc74c

View file

@ -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]