keep computed "prototype" when required

This commit is contained in:
Evan Wallace
2021-04-22 00:29:06 -07:00
parent 0d211f37e8
commit 6ebbdb09e3
2 changed files with 18 additions and 1 deletions

View File

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

View File

@@ -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) {