accept more case

This commit is contained in:
王文璐
2018-08-28 16:41:26 +08:00
parent d758075597
commit 8869f39c25
11 changed files with 99 additions and 18 deletions

View File

@@ -1196,12 +1196,12 @@ namespace ts {
// local types not visible outside the function body
: false;
}
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.FunctionScopedVariable) {
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) && lastLocation.initializer === originalLocation && result.valueDeclaration !== lastLocation) {
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && result.valueDeclaration !== lastLocation) {
useResult = false;
}
else {
else if (result.flags & SymbolFlags.FunctionScopedVariable) {
// parameters are visible only inside function body, parameter list and return type
// technically for parameter list case here we might mix parameters and variables declared in function,
// however it is detected separately when checking initializers of parameters

View File

@@ -3,9 +3,10 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(8,
tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(13,20): error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(21,18): error TS2372: Parameter 'a' cannot be referenced in its initializer.
tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(25,22): error TS2372: Parameter 'async' cannot be referenced in its initializer.
tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(29,15): error TS2448: Block-scoped variable 'foo' used before its declaration.
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts (5 errors) ====
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts (6 errors) ====
let foo: string = "";
function f1 (bar = foo) { // unexpected compiler error; works at runtime
@@ -42,4 +43,12 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts(25
~~~~~
!!! error TS2372: Parameter 'async' cannot be referenced in its initializer.
return async
}
}
function f7({[foo]: bar}: any[]) {
~~~
!!! error TS2448: Block-scoped variable 'foo' used before its declaration.
!!! related TS2728 tests/cases/conformance/functions/parameterInitializersForwardReferencing1.ts:30:9: 'foo' is declared here.
let foo: number = 2;
}

View File

@@ -25,7 +25,12 @@ function f5 (a = a) {
function f6 (async = async) {
return async
}
}
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
//// [parameterInitializersForwardReferencing1.js]
var foo = "";
@@ -59,3 +64,7 @@ function f6(async) {
if (async === void 0) { async = async; }
return async;
}
function f7(_a) {
var _b = foo, bar = _a[_b];
var foo = 2;
}

View File

@@ -65,3 +65,13 @@ function f6 (async = async) {
return async
>async : Symbol(async, Decl(parameterInitializersForwardReferencing1.ts, 24, 13))
}
function f7({[foo]: bar}: any[]) {
>f7 : Symbol(f7, Decl(parameterInitializersForwardReferencing1.ts, 26, 1))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1.ts, 29, 7))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1.ts, 28, 13))
let foo: number = 2;
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1.ts, 29, 7))
}

View File

@@ -71,3 +71,14 @@ function f6 (async = async) {
return async
>async : any
}
function f7({[foo]: bar}: any[]) {
>f7 : ({ [foo]: bar }: any[]) => void
>foo : number
>bar : any
let foo: number = 2;
>foo : number
>2 : 2
}

View File

@@ -11,7 +11,7 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
}
function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at runtime
var fooo: number = 2;
var foo: number = 2;
return bar(); // returns 1
}
@@ -33,4 +33,9 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
~~~~~
!!! error TS2372: Parameter 'async' cannot be referenced in its initializer.
return async
}
}
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}

View File

@@ -7,7 +7,7 @@ function f1 (bar = foo) { // unexpected compiler error; works at runtime
}
function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at runtime
var fooo: number = 2;
var foo: number = 2;
return bar(); // returns 1
}
@@ -25,7 +25,12 @@ function f5 (a = a) {
function f6 (async = async) {
return async
}
}
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}
//// [parameterInitializersForwardReferencing1_es6.js]
let foo = "";
@@ -34,7 +39,7 @@ function f1(bar = foo) {
return bar; // returns 1
}
function f2(bar = (baz = foo) => baz) {
var fooo = 2;
var foo = 2;
return bar(); // returns 1
}
function f3(bar = foo, foo = 2) {
@@ -49,3 +54,6 @@ function f5(a = a) {
function f6(async = async) {
return async;
}
function f7({ [foo]: bar }) {
let foo = 2;
}

View File

@@ -21,8 +21,8 @@ function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
>baz : Symbol(baz, Decl(parameterInitializersForwardReferencing1_es6.ts, 7, 20))
var fooo: number = 2;
>fooo : Symbol(fooo, Decl(parameterInitializersForwardReferencing1_es6.ts, 8, 7))
var foo: number = 2;
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 8, 7))
return bar(); // returns 1
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 7, 13))
@@ -65,3 +65,13 @@ function f6 (async = async) {
return async
>async : Symbol(async, Decl(parameterInitializersForwardReferencing1_es6.ts, 24, 13))
}
function f7({[foo]: bar}: any[]) {
>f7 : Symbol(f7, Decl(parameterInitializersForwardReferencing1_es6.ts, 26, 1))
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 28, 13))
let foo: number = 2;
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 29, 7))
}

View File

@@ -24,8 +24,8 @@ function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at
>foo : string
>baz : string
var fooo: number = 2;
>fooo : number
var foo: number = 2;
>foo : number
>2 : 2
return bar(); // returns 1
@@ -71,3 +71,14 @@ function f6 (async = async) {
return async
>async : any
}
function f7({[foo]: bar}: any[]) {
>f7 : ({ [foo]: bar }: any[]) => void
>foo : string
>bar : any
let foo: number = 2;
>foo : number
>2 : 2
}

View File

@@ -24,4 +24,8 @@ function f5 (a = a) {
function f6 (async = async) {
return async
}
}
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}

View File

@@ -8,7 +8,7 @@ function f1 (bar = foo) { // unexpected compiler error; works at runtime
}
function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at runtime
var fooo: number = 2;
var foo: number = 2;
return bar(); // returns 1
}
@@ -26,4 +26,8 @@ function f5 (a = a) {
function f6 (async = async) {
return async
}
}
function f7({[foo]: bar}: any[]) {
let foo: number = 2;
}