Skip to content

Commit b81eb6c

Browse files
authored
fix(45182): allow property access in arrow function (microsoft#45193)
1 parent 85e0e5a commit b81eb6c

6 files changed

+91
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27782,6 +27782,7 @@ namespace ts {
2778227782
case SyntaxKind.ExpressionWithTypeArguments:
2778327783
case SyntaxKind.HeritageClause:
2778427784
return false;
27785+
case SyntaxKind.ArrowFunction:
2778527786
case SyntaxKind.ExpressionStatement:
2778627787
return isBlock(node.parent) && isClassStaticBlockDeclaration(node.parent.parent) ? true : "quit";
2778727788
default:

tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.errors.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,13 @@ tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterProper
6262
}
6363
constructor(public p1: number) {}
6464
}
65+
class H {
66+
constructor(public p1: C) {}
67+
68+
public p2 = () => {
69+
return this.p1.foo;
70+
}
71+
72+
public p3 = () => this.p1.foo;
73+
}
6574

tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class G {
4040
}
4141
constructor(public p1: number) {}
4242
}
43+
class H {
44+
constructor(public p1: C) {}
45+
46+
public p2 = () => {
47+
return this.p1.foo;
48+
}
49+
50+
public p3 = () => this.p1.foo;
51+
}
4352

4453

4554
//// [assignParameterPropertyToPropertyDeclarationESNext.js]
@@ -90,3 +99,13 @@ class G {
9099
this.p1 = p1;
91100
}
92101
}
102+
class H {
103+
p1;
104+
constructor(p1) {
105+
this.p1 = p1;
106+
}
107+
p2 = () => {
108+
return this.p1.foo;
109+
};
110+
p3 = () => this.p1.foo;
111+
}

tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.symbols

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,30 @@ class G {
136136
constructor(public p1: number) {}
137137
>p1 : Symbol(G.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 39, 16))
138138
}
139+
class H {
140+
>H : Symbol(H, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 40, 1))
141+
142+
constructor(public p1: C) {}
143+
>p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16))
144+
>C : Symbol(C, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 0, 0))
145+
146+
public p2 = () => {
147+
>p2 : Symbol(H.p2, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 32))
148+
149+
return this.p1.foo;
150+
>this.p1.foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16))
151+
>this.p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16))
152+
>this : Symbol(H, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 40, 1))
153+
>p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16))
154+
>foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16))
155+
}
156+
157+
public p3 = () => this.p1.foo;
158+
>p3 : Symbol(H.p3, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 46, 5))
159+
>this.p1.foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16))
160+
>this.p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16))
161+
>this : Symbol(H, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 40, 1))
162+
>p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16))
163+
>foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16))
164+
}
139165

tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.types

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,31 @@ class G {
145145
constructor(public p1: number) {}
146146
>p1 : number
147147
}
148+
class H {
149+
>H : H
150+
151+
constructor(public p1: C) {}
152+
>p1 : C
153+
154+
public p2 = () => {
155+
>p2 : () => string
156+
>() => { return this.p1.foo; } : () => string
157+
158+
return this.p1.foo;
159+
>this.p1.foo : string
160+
>this.p1 : C
161+
>this : this
162+
>p1 : C
163+
>foo : string
164+
}
165+
166+
public p3 = () => this.p1.foo;
167+
>p3 : () => string
168+
>() => this.p1.foo : () => string
169+
>this.p1.foo : string
170+
>this.p1 : C
171+
>this : this
172+
>p1 : C
173+
>foo : string
174+
}
148175

tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ class G {
4141
}
4242
constructor(public p1: number) {}
4343
}
44+
class H {
45+
constructor(public p1: C) {}
46+
47+
public p2 = () => {
48+
return this.p1.foo;
49+
}
50+
51+
public p3 = () => this.p1.foo;
52+
}

0 commit comments

Comments
 (0)