Skip to content

add test case and fix regression #26726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}());
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}