From d9d67d90038270694696d4d77305582ffe64bae9 Mon Sep 17 00:00:00 2001 From: Nathan Yee Date: Fri, 27 Nov 2015 22:17:35 -0800 Subject: [PATCH] Move initializer checks into checkGrammarProperty --- src/compiler/checker.ts | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0b889a4204..50189b0340 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15735,16 +15735,6 @@ namespace ts { } } - // Report an error if an interface property has an initializer - if (node.members) { - const members = >node.members; - for (const element of members) { - if (element.initializer) { - return grammarErrorOnFirstToken(element.initializer, Diagnostics.An_interface_property_cannot_have_an_initializer); - } - } - } - return false; } @@ -16095,18 +16085,6 @@ namespace ts { } } - if (node.type) { - const typeLiteralNode = node.type; - if (typeLiteralNode.members) { - for (const element of typeLiteralNode.members) { - const propertySignature = element; - if (propertySignature.initializer) { - return grammarErrorOnNode(propertySignature.initializer, Diagnostics.An_object_type_literal_property_cannot_have_an_initializer); - } - } - } - } - const checkLetConstNames = languageVersion >= ScriptTarget.ES6 && (isLet(node) || isConst(node)); // 1. LexicalDeclaration : LetOrConst BindingList ; @@ -16249,11 +16227,17 @@ namespace ts { if (checkGrammarForNonSymbolComputedProperty(node.name, Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } + if (node.initializer) { + return grammarErrorOnNode(node.initializer, Diagnostics.An_interface_property_cannot_have_an_initializer); + } } else if (node.parent.kind === SyntaxKind.TypeLiteral) { if (checkGrammarForNonSymbolComputedProperty(node.name, Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } + if (node.initializer) { + return grammarErrorOnNode(node.initializer, Diagnostics.An_object_type_literal_property_cannot_have_an_initializer); + } } if (isInAmbientContext(node) && node.initializer) {