Emit error on class fields named "constructor"

This commit is contained in:
Andrew Branch
2019-04-25 17:30:41 -07:00
parent 9f601ff154
commit e81fa2198d
7 changed files with 85 additions and 0 deletions

View File

@@ -31789,6 +31789,9 @@ namespace ts {
function checkGrammarProperty(node: PropertyDeclaration | PropertySignature) {
if (isClassLike(node.parent)) {
if (isStringLiteral(node.name) && node.name.text === "constructor") {
return grammarErrorOnNode(node.name, Diagnostics.Classes_may_not_have_a_field_named_constructor);
}
if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type)) {
return true;
}

View File

@@ -4958,5 +4958,9 @@
"Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '[\"constructor\"]()' to write a method.": {
"category": "Error",
"code": 18005
},
"Classes may not have a field named 'constructor'.": {
"category": "Error",
"code": 18006
}
}