diff --git a/internal/js_parser/js_parser.go b/internal/js_parser/js_parser.go index b43e4033..d7f18813 100644 --- a/internal/js_parser/js_parser.go +++ b/internal/js_parser/js_parser.go @@ -9074,7 +9074,10 @@ func (p *parser) visitClass(nameScopeLoc logger.Loc, class *js_ast.Class) js_ast } } - if !isInvalidConstructor { + // A static property must not be called "prototype" + isInvalidPrototype := property.IsStatic && js_lexer.UTF16EqualsString(str.Value, "prototype") + + if !isInvalidConstructor && !isInvalidPrototype { class.Properties[i].IsComputed = false } } diff --git a/internal/js_parser/js_parser_test.go b/internal/js_parser/js_parser_test.go index 8b845ee4..fbda0eca 100644 --- a/internal/js_parser/js_parser_test.go +++ b/internal/js_parser/js_parser_test.go @@ -1314,6 +1314,20 @@ func TestClass(t *testing.T) { expectPrintedMangle(t, "class Foo { static get ['constructor']() {} }", "class Foo {\n static get constructor() {\n }\n}\n") expectPrintedMangle(t, "class Foo { static set ['constructor'](x) {} }", "class Foo {\n static set constructor(x) {\n }\n}\n") expectPrintedMangle(t, "class Foo { static async ['constructor']() {} }", "class Foo {\n static async constructor() {\n }\n}\n") + + expectPrintedMangle(t, "class Foo { ['prototype'] = 0 }", "class Foo {\n prototype = 0;\n}\n") + expectPrintedMangle(t, "class Foo { ['prototype']() {} }", "class Foo {\n prototype() {\n }\n}\n") + expectPrintedMangle(t, "class Foo { *['prototype']() {} }", "class Foo {\n *prototype() {\n }\n}\n") + expectPrintedMangle(t, "class Foo { get ['prototype']() {} }", "class Foo {\n get prototype() {\n }\n}\n") + expectPrintedMangle(t, "class Foo { set ['prototype'](x) {} }", "class Foo {\n set prototype(x) {\n }\n}\n") + expectPrintedMangle(t, "class Foo { async ['prototype']() {} }", "class Foo {\n async prototype() {\n }\n}\n") + + expectPrintedMangle(t, "class Foo { static ['prototype'] = 0 }", "class Foo {\n static [\"prototype\"] = 0;\n}\n") + expectPrintedMangle(t, "class Foo { static ['prototype']() {} }", "class Foo {\n static [\"prototype\"]() {\n }\n}\n") + expectPrintedMangle(t, "class Foo { static *['prototype']() {} }", "class Foo {\n static *[\"prototype\"]() {\n }\n}\n") + expectPrintedMangle(t, "class Foo { static get ['prototype']() {} }", "class Foo {\n static get [\"prototype\"]() {\n }\n}\n") + expectPrintedMangle(t, "class Foo { static set ['prototype'](x) {} }", "class Foo {\n static set [\"prototype\"](x) {\n }\n}\n") + expectPrintedMangle(t, "class Foo { static async ['prototype']() {} }", "class Foo {\n static async [\"prototype\"]() {\n }\n}\n") } func TestSuperCall(t *testing.T) {