From 40afe4a4dd5b398c5882069488e3bab4b7976f27 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 11 May 2016 13:54:50 -0700 Subject: [PATCH] Don't report error twice for readonly in method --- src/compiler/checker.ts | 4 ++-- tests/baselines/reference/readonlyInAmbientClass.errors.txt | 6 +++++- tests/baselines/reference/readonlyInAmbientClass.js | 1 + .../constructorParameters/readonlyInAmbientClass.ts | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3350a4f08fb..e516a6319ec 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17651,8 +17651,8 @@ namespace ts { if (flags & NodeFlags.Readonly) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "readonly"); } - else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature && - !(node.kind == SyntaxKind.Parameter && isParameterPropertyDeclaration( node))) { + else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature && node.kind !== SyntaxKind.Parameter) { + // If node.kind === SyntaxKind.Parameter, checkParameter report an error if it's not a parameter property. return grammarErrorOnNode(modifier, Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature); } flags |= NodeFlags.Readonly; diff --git a/tests/baselines/reference/readonlyInAmbientClass.errors.txt b/tests/baselines/reference/readonlyInAmbientClass.errors.txt index 303f04038f3..844e8b58ef8 100644 --- a/tests/baselines/reference/readonlyInAmbientClass.errors.txt +++ b/tests/baselines/reference/readonlyInAmbientClass.errors.txt @@ -1,9 +1,13 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts(2,14): error TS2369: A parameter property is only allowed in a constructor implementation. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts(3,9): error TS2369: A parameter property is only allowed in a constructor implementation. -==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts (1 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts (2 errors) ==== declare class C{ constructor(readonly x: number); ~~~~~~~~~~~~~~~~~~ +!!! error TS2369: A parameter property is only allowed in a constructor implementation. + method(readonly x: number); + ~~~~~~~~~~~~~~~~~~ !!! error TS2369: A parameter property is only allowed in a constructor implementation. } \ No newline at end of file diff --git a/tests/baselines/reference/readonlyInAmbientClass.js b/tests/baselines/reference/readonlyInAmbientClass.js index 9be7c1702c9..0e199b5ca4f 100644 --- a/tests/baselines/reference/readonlyInAmbientClass.js +++ b/tests/baselines/reference/readonlyInAmbientClass.js @@ -1,6 +1,7 @@ //// [readonlyInAmbientClass.ts] declare class C{ constructor(readonly x: number); + method(readonly x: number); } //// [readonlyInAmbientClass.js] diff --git a/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts b/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts index ca710532dd3..c84594eb4f0 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/readonlyInAmbientClass.ts @@ -1,3 +1,4 @@ declare class C{ constructor(readonly x: number); + method(readonly x: number); } \ No newline at end of file