Skip to content

Commit 17b10e8

Browse files
authored
Merge pull request microsoft#25397 from a-tarasyuk/bug/25356-instance-property-is-not-a-block-scoped-variable
25356 - Instance property is not a block scoped variable
2 parents dcb74a6 + 6897932 commit 17b10e8

13 files changed

+32
-27
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17483,7 +17483,7 @@ namespace ts {
1748317483
if (isInPropertyInitializer(node) &&
1748417484
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
1748517485
&& !isPropertyDeclaredInAncestorClass(prop)) {
17486-
diagnosticMessage = error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName);
17486+
diagnosticMessage = error(right, Diagnostics.Property_0_is_used_before_its_initialization, declarationName);
1748717487
}
1748817488
else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration &&
1748917489
node.parent.kind !== SyntaxKind.TypeReference &&

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,10 @@
24012401
"category": "Error",
24022402
"code": 2728
24032403
},
2404+
"Property '{0}' is used before its initialization.": {
2405+
"category": "Error",
2406+
"code": 2729
2407+
},
24042408

24052409
"Import declaration '{0}' is using private name '{1}'.": {
24062410
"category": "Error",

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,6 +5423,7 @@ declare namespace ts {
54235423
Cannot_find_lib_definition_for_0: DiagnosticMessage;
54245424
Cannot_find_lib_definition_for_0_Did_you_mean_1: DiagnosticMessage;
54255425
_0_was_declared_here: DiagnosticMessage;
5426+
Property_0_is_used_before_its_initialization: DiagnosticMessage;
54265427
Import_declaration_0_is_using_private_name_1: DiagnosticMessage;
54275428
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage;
54285429
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage;

tests/baselines/reference/classMergedWithInterfaceMultipleBasesNoError.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): error TS2448: Block-scoped variable 'handleIntersection' used before its declaration.
1+
tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): error TS2729: Property 'handleIntersection' is used before its initialization.
22

33

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

tests/baselines/reference/classStaticInitializersUsePropertiesBeforeDeclaration.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,25): error TS2450: Enum 'Enum' used before its declaration.
2-
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,30): error TS2448: Block-scoped variable 'A' used before its declaration.
2+
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,30): error TS2729: Property 'A' is used before its initialization.
33
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,31): error TS2448: Block-scoped variable 'ObjLiteral' used before its declaration.
4-
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,42): error TS2448: Block-scoped variable 'A' used before its declaration.
5-
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,40): error TS2448: Block-scoped variable 'A' used before its declaration.
4+
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,42): error TS2729: Property 'A' is used before its initialization.
5+
tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,40): error TS2729: Property 'A' is used before its initialization.
66

77

88
==== tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts (5 errors) ====
@@ -12,18 +12,18 @@ tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,
1212
!!! error TS2450: Enum 'Enum' used before its declaration.
1313
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:7:6: 'Enum' was declared here.
1414
~
15-
!!! error TS2448: Block-scoped variable 'A' used before its declaration.
15+
!!! error TS2729: Property 'A' is used before its initialization.
1616
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:8:5: 'A' was declared here.
1717
static objLiteralMember = ObjLiteral.A;
1818
~~~~~~~~~~
1919
!!! error TS2448: Block-scoped variable 'ObjLiteral' used before its declaration.
2020
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:11:7: 'ObjLiteral' was declared here.
2121
~
22-
!!! error TS2448: Block-scoped variable 'A' used before its declaration.
22+
!!! error TS2729: Property 'A' is used before its initialization.
2323
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:12:5: 'A' was declared here.
2424
static namespaceMember = Namespace.A;
2525
~
26-
!!! error TS2448: Block-scoped variable 'A' used before its declaration.
26+
!!! error TS2729: Property 'A' is used before its initialization.
2727
!!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:16:16: 'A' was declared here.
2828
}
2929

tests/baselines/reference/forwardRefInClassProperties.errors.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/forwardRefInClassProperties.ts(3,15): error TS2448: Block-scoped variable '_a' used before its declaration.
2-
tests/cases/compiler/forwardRefInClassProperties.ts(6,22): error TS2448: Block-scoped variable '_A' used before its declaration.
1+
tests/cases/compiler/forwardRefInClassProperties.ts(3,15): error TS2729: Property '_a' is used before its initialization.
2+
tests/cases/compiler/forwardRefInClassProperties.ts(6,22): error TS2729: Property '_A' is used before its initialization.
33
tests/cases/compiler/forwardRefInClassProperties.ts(11,17): error TS2448: Block-scoped variable 'b' used before its declaration.
44

55

@@ -8,19 +8,19 @@ tests/cases/compiler/forwardRefInClassProperties.ts(11,17): error TS2448: Block-
88
{
99
_b = this._a; // undefined, no error/warning
1010
~~
11-
!!! error TS2448: Block-scoped variable '_a' used before its declaration.
11+
!!! error TS2729: Property '_a' is used before its initialization.
1212
!!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:4:5: '_a' was declared here.
1313
_a = 3;
1414

1515
static _B = Test._A; // undefined, no error/warning
1616
~~
17-
!!! error TS2448: Block-scoped variable '_A' used before its declaration.
17+
!!! error TS2729: Property '_A' is used before its initialization.
1818
!!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:7:12: '_A' was declared here.
1919
static _A = 3;
2020

2121
method()
2222
{
23-
let a = b; // Block-scoped variable 'b' used before its declaration
23+
let a = b; // Property 'b' is used before its initialization.
2424
~
2525
!!! error TS2448: Block-scoped variable 'b' used before its declaration.
2626
!!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:12:13: 'b' was declared here.

tests/baselines/reference/forwardRefInClassProperties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Test
99

1010
method()
1111
{
12-
let a = b; // Block-scoped variable 'b' used before its declaration
12+
let a = b; // Property 'b' is used before its initialization.
1313
let b = 3;
1414
}
1515
}
@@ -22,7 +22,7 @@ var Test = /** @class */ (function () {
2222
this._a = 3;
2323
}
2424
Test.prototype.method = function () {
25-
var a = b; // Block-scoped variable 'b' used before its declaration
25+
var a = b; // Property 'b' is used before its initialization.
2626
var b = 3;
2727
};
2828
Test._B = Test._A; // undefined, no error/warning

tests/baselines/reference/forwardRefInClassProperties.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Test
2323
method()
2424
>method : Symbol(Test.method, Decl(forwardRefInClassProperties.ts, 6, 18))
2525
{
26-
let a = b; // Block-scoped variable 'b' used before its declaration
26+
let a = b; // Property 'b' is used before its initialization.
2727
>a : Symbol(a, Decl(forwardRefInClassProperties.ts, 10, 11))
2828
>b : Symbol(b, Decl(forwardRefInClassProperties.ts, 11, 11))
2929

tests/baselines/reference/forwardRefInClassProperties.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Test
2525
method()
2626
>method : () => void
2727
{
28-
let a = b; // Block-scoped variable 'b' used before its declaration
28+
let a = b; // Property 'b' is used before its initialization.
2929
>a : number
3030
>b : number
3131

tests/baselines/reference/scopeCheckStaticInitializer.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2448: Block-scoped variable 'data' used before its declaration.
1+
tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2729: Property 'data' is used before its initialization.
22
tests/cases/compiler/scopeCheckStaticInitializer.ts(5,23): error TS2449: Class 'After' used before its declaration.
3-
tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2448: Block-scoped variable 'data' used before its declaration.
3+
tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2729: Property 'data' is used before its initialization.
44
tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class 'After' used before its declaration.
55

66

77
==== tests/cases/compiler/scopeCheckStaticInitializer.ts (4 errors) ====
88
class X {
99
static illegalBeforeProperty = X.data;
1010
~~~~
11-
!!! error TS2448: Block-scoped variable 'data' used before its declaration.
11+
!!! error TS2729: Property 'data' is used before its initialization.
1212
!!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:7:12: 'data' was declared here.
1313
static okBeforeMethod = X.method;
1414

@@ -17,7 +17,7 @@ tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class '
1717
!!! error TS2449: Class 'After' used before its declaration.
1818
!!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:10:7: 'After' was declared here.
1919
~~~~
20-
!!! error TS2448: Block-scoped variable 'data' used before its declaration.
20+
!!! error TS2729: Property 'data' is used before its initialization.
2121
!!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:11:12: 'data' was declared here.
2222
static illegal3 = After.method;
2323
~~~~~

tests/baselines/reference/useBeforeDeclaration_propertyAssignment.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts(2,27): error TS2448: Block-scoped variable 'b' used before its declaration.
1+
tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts(2,27): error TS2729: Property 'b' is used before its initialization.
22

33

44
==== tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts (1 errors) ====
55
export class C {
66
public a = { b: this.b };
77
~
8-
!!! error TS2448: Block-scoped variable 'b' used before its declaration.
8+
!!! error TS2729: Property 'b' is used before its initialization.
99
!!! related TS2728 tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts:3:13: 'b' was declared here.
1010
private b = 0;
1111
}

tests/baselines/reference/useBeforeDeclaration_superClass.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2448: Block-scoped variable 'x' used before its declaration.
1+
tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2729: Property 'x' is used before its initialization.
22

33

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

tests/cases/compiler/forwardRefInClassProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Test
88

99
method()
1010
{
11-
let a = b; // Block-scoped variable 'b' used before its declaration
11+
let a = b; // Property 'b' is used before its initialization.
1212
let b = 3;
1313
}
1414
}

0 commit comments

Comments
 (0)