Merge pull request #25397 from a-tarasyuk/bug/25356-instance-property-is-not-a-block-scoped-variable

25356 - Instance property is not a block scoped variable
This commit is contained in:
Mohamed Hegazy 2018-07-03 14:11:28 -07:00 committed by GitHub
commit 17b10e8293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 32 additions and 27 deletions

View file

@ -17483,7 +17483,7 @@ namespace ts {
if (isInPropertyInitializer(node) &&
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
&& !isPropertyDeclaredInAncestorClass(prop)) {
diagnosticMessage = error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName);
diagnosticMessage = error(right, Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
}
else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration &&
node.parent.kind !== SyntaxKind.TypeReference &&

View file

@ -2401,6 +2401,10 @@
"category": "Error",
"code": 2728
},
"Property '{0}' is used before its initialization.": {
"category": "Error",
"code": 2729
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",

View file

@ -5423,6 +5423,7 @@ declare namespace ts {
Cannot_find_lib_definition_for_0: DiagnosticMessage;
Cannot_find_lib_definition_for_0_Did_you_mean_1: DiagnosticMessage;
_0_was_declared_here: DiagnosticMessage;
Property_0_is_used_before_its_initialization: DiagnosticMessage;
Import_declaration_0_is_using_private_name_1: DiagnosticMessage;
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage;
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage;

View file

@ -1,4 +1,4 @@
tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): error TS2448: Block-scoped variable 'handleIntersection' used before its declaration.
tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): error TS2729: Property 'handleIntersection' is used before its initialization.
==== tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts (1 errors) ====
@ -11,7 +11,7 @@ tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): erro
export default class extends Foo {
readonly observer = this.handleIntersection;
~~~~~~~~~~~~~~~~~~
!!! error TS2448: Block-scoped variable 'handleIntersection' used before its declaration.
!!! error TS2729: Property 'handleIntersection' is used before its initialization.
!!! related TS2728 tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts:9:14: 'handleIntersection' was declared here.
readonly handleIntersection = () => { }
}

View file

@ -1,8 +1,8 @@
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,25): error TS2450: Enum 'Enum' used before its declaration.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,30): error TS2448: Block-scoped variable 'A' used before its declaration.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,30): error TS2729: Property 'A' is used before its initialization.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,31): error TS2448: Block-scoped variable 'ObjLiteral' used before its declaration.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,42): error TS2448: Block-scoped variable 'A' used before its declaration.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,40): error TS2448: Block-scoped variable 'A' used before its declaration.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,42): error TS2729: Property 'A' is used before its initialization.
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,40): error TS2729: Property 'A' is used before its initialization.
==== tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts (5 errors) ====
@ -12,18 +12,18 @@ tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,
!!! error TS2450: Enum 'Enum' used before its declaration.
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:7:6: 'Enum' was declared here.
~
!!! error TS2448: Block-scoped variable 'A' used before its declaration.
!!! error TS2729: Property 'A' is used before its initialization.
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:8:5: 'A' was declared here.
static objLiteralMember = ObjLiteral.A;
~~~~~~~~~~
!!! error TS2448: Block-scoped variable 'ObjLiteral' used before its declaration.
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:11:7: 'ObjLiteral' was declared here.
~
!!! error TS2448: Block-scoped variable 'A' used before its declaration.
!!! error TS2729: Property 'A' is used before its initialization.
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:12:5: 'A' was declared here.
static namespaceMember = Namespace.A;
~
!!! error TS2448: Block-scoped variable 'A' used before its declaration.
!!! error TS2729: Property 'A' is used before its initialization.
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:16:16: 'A' was declared here.
}

View file

@ -1,5 +1,5 @@
tests/cases/compiler/forwardRefInClassProperties.ts(3,15): error TS2448: Block-scoped variable '_a' used before its declaration.
tests/cases/compiler/forwardRefInClassProperties.ts(6,22): error TS2448: Block-scoped variable '_A' used before its declaration.
tests/cases/compiler/forwardRefInClassProperties.ts(3,15): error TS2729: Property '_a' is used before its initialization.
tests/cases/compiler/forwardRefInClassProperties.ts(6,22): error TS2729: Property '_A' is used before its initialization.
tests/cases/compiler/forwardRefInClassProperties.ts(11,17): error TS2448: Block-scoped variable 'b' used before its declaration.
@ -8,19 +8,19 @@ tests/cases/compiler/forwardRefInClassProperties.ts(11,17): error TS2448: Block-
{
_b = this._a; // undefined, no error/warning
~~
!!! error TS2448: Block-scoped variable '_a' used before its declaration.
!!! error TS2729: Property '_a' is used before its initialization.
!!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:4:5: '_a' was declared here.
_a = 3;
static _B = Test._A; // undefined, no error/warning
~~
!!! error TS2448: Block-scoped variable '_A' used before its declaration.
!!! error TS2729: Property '_A' is used before its initialization.
!!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:7:12: '_A' was declared here.
static _A = 3;
method()
{
let a = b; // Block-scoped variable 'b' used before its declaration
let a = b; // Property 'b' is used before its initialization.
~
!!! error TS2448: Block-scoped variable 'b' used before its declaration.
!!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:12:13: 'b' was declared here.

View file

@ -9,7 +9,7 @@ class Test
method()
{
let a = b; // Block-scoped variable 'b' used before its declaration
let a = b; // Property 'b' is used before its initialization.
let b = 3;
}
}
@ -22,7 +22,7 @@ var Test = /** @class */ (function () {
this._a = 3;
}
Test.prototype.method = function () {
var a = b; // Block-scoped variable 'b' used before its declaration
var a = b; // Property 'b' is used before its initialization.
var b = 3;
};
Test._B = Test._A; // undefined, no error/warning

View file

@ -23,7 +23,7 @@ class Test
method()
>method : Symbol(Test.method, Decl(forwardRefInClassProperties.ts, 6, 18))
{
let a = b; // Block-scoped variable 'b' used before its declaration
let a = b; // Property 'b' is used before its initialization.
>a : Symbol(a, Decl(forwardRefInClassProperties.ts, 10, 11))
>b : Symbol(b, Decl(forwardRefInClassProperties.ts, 11, 11))

View file

@ -25,7 +25,7 @@ class Test
method()
>method : () => void
{
let a = b; // Block-scoped variable 'b' used before its declaration
let a = b; // Property 'b' is used before its initialization.
>a : number
>b : number

View file

@ -1,6 +1,6 @@
tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2448: Block-scoped variable 'data' used before its declaration.
tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2729: Property 'data' is used before its initialization.
tests/cases/compiler/scopeCheckStaticInitializer.ts(5,23): error TS2449: Class 'After' used before its declaration.
tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2448: Block-scoped variable 'data' used before its declaration.
tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2729: Property 'data' is used before its initialization.
tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class 'After' used before its declaration.
@ -8,7 +8,7 @@ tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class '
class X {
static illegalBeforeProperty = X.data;
~~~~
!!! error TS2448: Block-scoped variable 'data' used before its declaration.
!!! error TS2729: Property 'data' is used before its initialization.
!!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:7:12: 'data' was declared here.
static okBeforeMethod = X.method;
@ -17,7 +17,7 @@ tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class '
!!! error TS2449: Class 'After' used before its declaration.
!!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:10:7: 'After' was declared here.
~~~~
!!! error TS2448: Block-scoped variable 'data' used before its declaration.
!!! error TS2729: Property 'data' is used before its initialization.
!!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:11:12: 'data' was declared here.
static illegal3 = After.method;
~~~~~

View file

@ -1,11 +1,11 @@
tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts(2,27): error TS2448: Block-scoped variable 'b' used before its declaration.
tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts(2,27): error TS2729: Property 'b' is used before its initialization.
==== tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts (1 errors) ====
export class C {
public a = { b: this.b };
~
!!! error TS2448: Block-scoped variable 'b' used before its declaration.
!!! error TS2729: Property 'b' is used before its initialization.
!!! related TS2728 tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts:3:13: 'b' was declared here.
private b = 0;
}

View file

@ -1,4 +1,4 @@
tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2448: Block-scoped variable 'x' used before its declaration.
tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2729: Property 'x' is used before its initialization.
==== tests/cases/compiler/useBeforeDeclaration_superClass.ts (1 errors) ====
@ -28,7 +28,7 @@ tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2448: Bl
class J implements I {
old_x = this.x;
~
!!! error TS2448: Block-scoped variable 'x' used before its declaration.
!!! error TS2729: Property 'x' is used before its initialization.
!!! related TS2728 tests/cases/compiler/useBeforeDeclaration_superClass.ts:26:5: 'x' was declared here.
x = 1;
}

View file

@ -8,7 +8,7 @@ class Test
method()
{
let a = b; // Block-scoped variable 'b' used before its declaration
let a = b; // Property 'b' is used before its initialization.
let b = 3;
}
}