diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 91f806e0518..154293870fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7155,6 +7155,11 @@ module ts { } function checkMethodDeclaration(node: MethodDeclaration) { + // Grammar checking + if (node.name.kind === SyntaxKind.ComputedPropertyName) { + checkGrammarComputedPropertyName(node.name); + } + checkFunctionLikeDeclaration(node); } @@ -7242,6 +7247,11 @@ module ts { } function checkAccessorDeclaration(node: AccessorDeclaration) { + // Grammar checking + if (node.name.kind === SyntaxKind.ComputedPropertyName) { + checkGrammarComputedPropertyName(node.name); + } + if (fullTypeCheck) { if (node.kind === SyntaxKind.GetAccessor) { if (!isInAmbientContext(node) && node.body && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { @@ -10000,12 +10010,18 @@ module ts { } function checkGrammarComputedPropertyName(node: ComputedPropertyName): void { + // Since computed properties are not supported in the type checker, disallow them in TypeScript 1.4 + // Once full support is added, remove this error. + grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_not_currently_supported); + + /* TODO (jfreeman) if (compilerOptions.target < ScriptTarget.ES6) { grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (node.expression.kind === SyntaxKind.BinaryExpression && (node.expression).operator === SyntaxKind.CommaToken) { grammarErrorOnNode(node.expression, Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } + */ } function hasParseDiagnostics(sourceFile: SourceFile): boolean { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 9d277bbe549..f955683dbff 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -433,8 +433,8 @@ module ts { _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, - Computed_property_names_are_not_currently_supported: { code: 9002, category: DiagnosticCategory.Error, key: "Computed property names are not currently supported." }, + yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported.", isEarly: true }, + Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported.", isEarly: true }, + Computed_property_names_are_not_currently_supported: { code: 9002, category: DiagnosticCategory.Error, key: "Computed property names are not currently supported.", isEarly: true }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 599009c6c82..261fc77db36 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1830,5 +1830,6 @@ "Computed property names are not currently supported.": { "category": "Error", "code": 9002, + "isEarly": true } } diff --git a/tests/baselines/reference/computedPropertyNames2.errors.txt b/tests/baselines/reference/computedPropertyNames2.errors.txt index e7cc84a8f6e..3dd4ac01d5f 100644 --- a/tests/baselines/reference/computedPropertyNames2.errors.txt +++ b/tests/baselines/reference/computedPropertyNames2.errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(4,5): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(5,12): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(7,9): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(9,16): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts (8 errors) ==== @@ -20,17 +20,17 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): !!! error TS9002: Computed property names are not currently supported. get [accessorName]() { } ~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - ~~~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~~~~~~~~~~~~~~ +!!! error TS9002: Computed property names are not currently supported. set [accessorName](v) { } ~~~~~~~~~~~~~~ !!! error TS9002: Computed property names are not currently supported. static get [accessorName]() { } ~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - ~~~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~~~~~~~~~~~~~~ +!!! error TS9002: Computed property names are not currently supported. static set [accessorName](v) { } ~~~~~~~~~~~~~~ !!! error TS9002: Computed property names are not currently supported. diff --git a/tests/baselines/reference/computedPropertyNames3.errors.txt b/tests/baselines/reference/computedPropertyNames3.errors.txt index a1d6e09421b..084a1f8889f 100644 --- a/tests/baselines/reference/computedPropertyNames3.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3.errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(3,5): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(8,16): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (8 errors) ==== @@ -19,17 +19,17 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): !!! error TS9002: Computed property names are not currently supported. get [delete id]() { } ~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - ~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~~~~~~~~~~~ +!!! error TS9002: Computed property names are not currently supported. set [[0, 1]](v) { } ~~~~~~~~ !!! error TS9002: Computed property names are not currently supported. static get [""]() { } ~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - ~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~~~~~~~~~~~~ +!!! error TS9002: Computed property names are not currently supported. static set [id.toString()](v) { } ~~~~~~~~~~~~~~~ !!! error TS9002: Computed property names are not currently supported.