Skip to content

Commit c036989

Browse files
committed
simplify implementation
1 parent 9e6603c commit c036989

6 files changed

Lines changed: 30 additions & 26 deletions

File tree

src/compiler/checker.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25347,7 +25347,7 @@ namespace ts {
2534725347
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
2534825348
// can explicitly bound arguments objects
2534925349
if (symbol === argumentsSymbol) {
25350-
if (isInPropertyInitializerOrClassStaticBlock(node, /* ignoreArrowFunctions */true)) {
25350+
if (isInPropertyInitializerOrClassStaticBlock(node, /* ignoreArrowFunctions */ true)) {
2535125351
error(node, Diagnostics.arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_block);
2535225352
return errorType;
2535325353
}
@@ -28874,28 +28874,16 @@ namespace ts {
2887428874
switch (node.kind) {
2887528875
case SyntaxKind.PropertyDeclaration:
2887628876
case SyntaxKind.ClassStaticBlockDeclaration:
28877-
return true;
28878-
case SyntaxKind.PropertyAssignment:
28879-
case SyntaxKind.MethodDeclaration:
28880-
case SyntaxKind.GetAccessor:
28881-
case SyntaxKind.SetAccessor:
28882-
case SyntaxKind.SpreadAssignment:
28883-
case SyntaxKind.ComputedPropertyName:
28884-
case SyntaxKind.TemplateSpan:
28885-
case SyntaxKind.JsxExpression:
28886-
case SyntaxKind.JsxAttribute:
28887-
case SyntaxKind.JsxAttributes:
28888-
case SyntaxKind.JsxSpreadAttribute:
28889-
case SyntaxKind.JsxOpeningElement:
28890-
case SyntaxKind.ExpressionWithTypeArguments:
28891-
case SyntaxKind.HeritageClause:
28892-
return false;
28877+
return true;
28878+
case SyntaxKind.TypeQuery:
2889328879
case SyntaxKind.JsxClosingElement: // already reported in JsxOpeningElement
2889428880
return "quit";
2889528881
case SyntaxKind.ArrowFunction:
2889628882
return ignoreArrowFunctions ? false : "quit";
28883+
case SyntaxKind.Block:
28884+
return isFunctionLikeDeclaration(node.parent) && node.parent.kind !== SyntaxKind.ArrowFunction ? "quit" : false;
2889728885
default:
28898-
return isFunctionLikeDeclaration(node) ? "quit" : false;
28886+
return false;
2889928887
}
2890028888
});
2890128889
}

tests/baselines/reference/classStaticBlock6.errors.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(45,17): er
1414
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(46,22): error TS1109: Expression expected.
1515
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization block.
1616
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(66,14): error TS2729: Property 'b' is used before its initialization.
17-
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(68,18): error TS2729: Property 'b' is used before its initialization.
17+
tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(69,18): error TS2729: Property 'b' is used before its initialization.
1818

1919

2020
==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (17 errors) ====
@@ -116,12 +116,13 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(68,18): er
116116
this.b // should error
117117
~
118118
!!! error TS2729: Property 'b' is used before its initialization.
119-
!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts:72:12: 'b' is declared here.
119+
!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts:73:12: 'b' is declared here.
120+
let b: typeof this.b; // ok
120121
if (1) {
121122
this.b; // should error
122123
~
123124
!!! error TS2729: Property 'b' is used before its initialization.
124-
!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts:72:12: 'b' is declared here.
125+
!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts:73:12: 'b' is declared here.
125126
}
126127
}
127128

tests/baselines/reference/classStaticBlock6.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function foo1 () {
6565
class foo2 {
6666
static {
6767
this.b // should error
68+
let b: typeof this.b; // ok
6869
if (1) {
6970
this.b; // should error
7071
}
@@ -229,6 +230,7 @@ var foo2 = /** @class */ (function () {
229230
_a = foo2;
230231
(function () {
231232
_a.b; // should error
233+
var b; // ok
232234
if (1) {
233235
_a.b; // should error
234236
}

tests/baselines/reference/classStaticBlock6.symbols

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,24 @@ class foo2 {
107107

108108
static {
109109
this.b // should error
110-
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 69, 5))
110+
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
111111
>this : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
112-
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 69, 5))
112+
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
113+
114+
let b: typeof this.b; // ok
115+
>b : Symbol(b, Decl(classStaticBlock6.ts, 66, 11))
116+
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
117+
>this : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
118+
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
113119

114120
if (1) {
115121
this.b; // should error
116-
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 69, 5))
122+
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
117123
>this : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
118-
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 69, 5))
124+
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
119125
}
120126
}
121127

122128
static b = 1;
123-
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 69, 5))
129+
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
124130
}

tests/baselines/reference/classStaticBlock6.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ class foo2 {
130130
this.b // should error
131131
>this.b : number
132132
>this : typeof foo2
133+
>b : number
134+
135+
let b: typeof this.b; // ok
136+
>b : number
137+
>this.b : number
138+
>this : typeof foo2
133139
>b : number
134140

135141
if (1) {

tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function foo1 () {
6464
class foo2 {
6565
static {
6666
this.b // should error
67+
let b: typeof this.b; // ok
6768
if (1) {
6869
this.b; // should error
6970
}

0 commit comments

Comments
 (0)