Skip to content
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ namespace ts {
}
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
// 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) {
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration.pos > lastLocation.end) {
useResult = false;
}
else if (result.flags & SymbolFlags.FunctionScopedVariable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(29
class Foo {
constructor(public x = 12, public y = x) {}
}

function f8(foo1: string, bar = foo1) { }

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}

function f8(foo1: string, bar = foo1) { }


//// [parameterInitializersForwardReferencing1.js]
Expand Down Expand Up @@ -81,3 +83,6 @@ var Foo = /** @class */ (function () {
}
return Foo;
}());
function f8(foo1, bar) {
if (bar === void 0) { bar = foo1; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ class Foo {
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1.ts, 33, 16))
}

function f8(foo1: string, bar = foo1) { }
>f8 : Symbol(f8, Decl(parameterInitializersForwardReferencing1.ts, 34, 1))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1.ts, 36, 12))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1.ts, 36, 25))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1.ts, 36, 12))

Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ class Foo {
>x : number
}

function f8(foo1: string, bar = foo1) { }
>f8 : (foo1: string, bar?: string) => void
>foo1 : string
>bar : string
>foo1 : string

Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
class Foo {
constructor(public x = 12, public y = x) {}
}

function f8(foo1: string, bar = foo1) { }

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}

function f8(foo1: string, bar = foo1) { }


//// [parameterInitializersForwardReferencing1_es6.js]
Expand Down Expand Up @@ -67,3 +69,4 @@ class Foo {
this.y = y;
}
}
function f8(foo1, bar = foo1) { }
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function f4 (foo, bar = foo) {
>f4 : Symbol(f4, Decl(parameterInitializersForwardReferencing1_es6.ts, 14, 1))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 13))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 17))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 13))

return bar
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 16, 17))
Expand Down Expand Up @@ -84,3 +84,9 @@ class Foo {
>x : Symbol(x, Decl(parameterInitializersForwardReferencing1_es6.ts, 33, 16))
}

function f8(foo1: string, bar = foo1) { }
>f8 : Symbol(f8, Decl(parameterInitializersForwardReferencing1_es6.ts, 34, 1))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 12))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 25))
>foo1 : Symbol(foo1, Decl(parameterInitializersForwardReferencing1_es6.ts, 36, 12))

Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
}

function f4 (foo, bar = foo) {
>f4 : (foo: any, bar?: string) => string
>f4 : (foo: any, bar?: any) => any
>foo : any
>bar : any
>foo : any
>bar : string
>foo : string

return bar
>bar : string
>bar : any
}

function f5 (a = a) {
Expand Down Expand Up @@ -92,3 +92,9 @@ class Foo {
>x : number
}

function f8(foo1: string, bar = foo1) { }
>f8 : (foo1: string, bar?: string) => void
>foo1 : string
>bar : string
>foo1 : string

Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}

function f8(foo1: string, bar = foo1) { }
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ function f7({[foo]: bar}: any[]) {
class Foo {
constructor(public x = 12, public y = x) {}
}

function f8(foo1: string, bar = foo1) { }