From b81eb6cfe1d9908ba971fd722a9902dee6630cb7 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 27 Jul 2021 19:46:17 +0300 Subject: [PATCH] fix(45182): allow property access in arrow function (#45193) --- src/compiler/checker.ts | 1 + ...ertyToPropertyDeclarationESNext.errors.txt | 9 +++++++ ...eterPropertyToPropertyDeclarationESNext.js | 19 +++++++++++++ ...ropertyToPropertyDeclarationESNext.symbols | 26 ++++++++++++++++++ ...rPropertyToPropertyDeclarationESNext.types | 27 +++++++++++++++++++ ...eterPropertyToPropertyDeclarationESNext.ts | 9 +++++++ 6 files changed, 91 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b9e6c0c8f21..718f2edaef5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27782,6 +27782,7 @@ namespace ts { case SyntaxKind.ExpressionWithTypeArguments: case SyntaxKind.HeritageClause: return false; + case SyntaxKind.ArrowFunction: case SyntaxKind.ExpressionStatement: return isBlock(node.parent) && isClassStaticBlockDeclaration(node.parent.parent) ? true : "quit"; default: diff --git a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.errors.txt b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.errors.txt index b8d6ddc136c..91310fd3814 100644 --- a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.errors.txt +++ b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.errors.txt @@ -62,4 +62,13 @@ tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterProper } constructor(public p1: number) {} } + class H { + constructor(public p1: C) {} + + public p2 = () => { + return this.p1.foo; + } + + public p3 = () => this.p1.foo; + } \ No newline at end of file diff --git a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.js b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.js index d4e0de0d8c5..20afc664a4e 100644 --- a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.js +++ b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.js @@ -40,6 +40,15 @@ class G { } constructor(public p1: number) {} } +class H { + constructor(public p1: C) {} + + public p2 = () => { + return this.p1.foo; + } + + public p3 = () => this.p1.foo; +} //// [assignParameterPropertyToPropertyDeclarationESNext.js] @@ -90,3 +99,13 @@ class G { this.p1 = p1; } } +class H { + p1; + constructor(p1) { + this.p1 = p1; + } + p2 = () => { + return this.p1.foo; + }; + p3 = () => this.p1.foo; +} diff --git a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.symbols b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.symbols index 27d3f243966..b94171e52b6 100644 --- a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.symbols +++ b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.symbols @@ -136,4 +136,30 @@ class G { constructor(public p1: number) {} >p1 : Symbol(G.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 39, 16)) } +class H { +>H : Symbol(H, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 40, 1)) + + constructor(public p1: C) {} +>p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16)) +>C : Symbol(C, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 0, 0)) + + public p2 = () => { +>p2 : Symbol(H.p2, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 32)) + + return this.p1.foo; +>this.p1.foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16)) +>this.p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16)) +>this : Symbol(H, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 40, 1)) +>p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16)) +>foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16)) + } + + public p3 = () => this.p1.foo; +>p3 : Symbol(H.p3, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 46, 5)) +>this.p1.foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16)) +>this.p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16)) +>this : Symbol(H, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 40, 1)) +>p1 : Symbol(H.p1, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 42, 16)) +>foo : Symbol(C.foo, Decl(assignParameterPropertyToPropertyDeclarationESNext.ts, 10, 16)) +} diff --git a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.types b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.types index d4b3cd9d958..a041399c6be 100644 --- a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.types +++ b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationESNext.types @@ -145,4 +145,31 @@ class G { constructor(public p1: number) {} >p1 : number } +class H { +>H : H + + constructor(public p1: C) {} +>p1 : C + + public p2 = () => { +>p2 : () => string +>() => { return this.p1.foo; } : () => string + + return this.p1.foo; +>this.p1.foo : string +>this.p1 : C +>this : this +>p1 : C +>foo : string + } + + public p3 = () => this.p1.foo; +>p3 : () => string +>() => this.p1.foo : () => string +>this.p1.foo : string +>this.p1 : C +>this : this +>p1 : C +>foo : string +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext.ts index d778149c428..9604ba4dfe0 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext.ts @@ -41,3 +41,12 @@ class G { } constructor(public p1: number) {} } +class H { + constructor(public p1: C) {} + + public p2 = () => { + return this.p1.foo; + } + + public p3 = () => this.p1.foo; +}