add test case and fix regression (#26726)

This commit is contained in:
Wenlu Wang
2018-08-29 21:58:55 +08:00
committed by Nathan Shively-Sanders
parent 30f611b055
commit f67d7e01cf
11 changed files with 79 additions and 2 deletions

View File

@@ -1211,8 +1211,8 @@ namespace ts {
: false;
}
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
// parameter initializer will lookup as normal variable scope when targeting es2015+
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && result.valueDeclaration !== lastLocation) {
// expression inside parameter will lookup as normal variable scope when targeting es2015+
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration !== lastLocation) {
useResult = false;
}
else if (result.flags & SymbolFlags.FunctionScopedVariable) {

View File

@@ -51,4 +51,8 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(29
!!! related TS2728 tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts:30:9: 'foo' is declared here.
let foo: number = 2;
}
class Foo {
constructor(public x = 12, public y = x) {}
}

View File

@@ -30,6 +30,10 @@ function f6 (async = async) {
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
class Foo {
constructor(public x = 12, public y = x) {}
}
//// [parameterInitializersForwardReferencing1.js]
@@ -68,3 +72,12 @@ function f7(_a) {
var _b = foo, bar = _a[_b];
var foo = 2;
}
var Foo = /** @class */ (function () {
function Foo(x, y) {
if (x === void 0) { x = 12; }
if (y === void 0) { y = x; }
this.x = x;
this.y = y;
}
return Foo;
}());

View File

@@ -75,3 +75,12 @@ function f7({[foo]: bar}: any[]) {
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1.ts, 29, 7))
}
class Foo {
>Foo : Symbol(Foo, Decl(parameterInitializersForwardReferencing1.ts, 30, 1))
constructor(public x = 12, public y = x) {}
>x : Symbol(Foo.x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
>y : Symbol(Foo.y, Decl(parameterInitializersForwardReferencing1.ts, 33, 30))
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
}

View File

@@ -82,3 +82,13 @@ function f7({[foo]: bar}: any[]) {
>2 : 2
}
class Foo {
>Foo : Foo
constructor(public x = 12, public y = x) {}
>x : number
>12 : 12
>y : number
>x : number
}

View File

@@ -38,4 +38,8 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
class Foo {
constructor(public x = 12, public y = x) {}
}

View File

@@ -30,6 +30,10 @@ function f6 (async = async) {
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
class Foo {
constructor(public x = 12, public y = x) {}
}
//// [parameterInitializersForwardReferencing1_es6.js]
@@ -57,3 +61,9 @@ function f6(async = async) {
function f7({ [foo]: bar }) {
let foo = 2;
}
class Foo {
constructor(x = 12, y = x) {
this.x = x;
this.y = y;
}
}

View File

@@ -75,3 +75,12 @@ function f7({[foo]: bar}: any[]) {
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 29, 7))
}
class Foo {
>Foo : Symbol(Foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 30, 1))
constructor(public x = 12, public y = x) {}
>x : Symbol(Foo.x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
>y : Symbol(Foo.y, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 30))
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
}

View File

@@ -82,3 +82,13 @@ function f7({[foo]: bar}: any[]) {
>2 : 2
}
class Foo {
>Foo : Foo
constructor(public x = 12, public y = x) {}
>x : number
>12 : 12
>y : number
>x : number
}

View File

@@ -29,3 +29,7 @@ function f6 (async = async) {
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
class Foo {
constructor(public x = 12, public y = x) {}
}

View File

@@ -31,3 +31,7 @@ function f6 (async = async) {
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
class Foo {
constructor(public x = 12, public y = x) {}
}