Fix 9363: Object destructuring broken-variables are bound to the wrong object (#9383)

* Fix emit incorrect destructuring mapping in var declaration

* Add tests and baselines

* Add additional tests and baselines
This commit is contained in:
Yui
2016-06-28 13:33:11 -07:00
committed by GitHub
parent 50177b14d0
commit 29107e636b
5 changed files with 110 additions and 1 deletions

View File

@@ -4545,8 +4545,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}
write(";");
tempIndex++;
}
// Regardless of whether we will emit a var declaration for the binding pattern, we generate the temporary
// variable for the parameter (see: emitParameter)
tempIndex++;
}
else if (initializer) {
writeLine();

View File

@@ -0,0 +1,27 @@
//// [destructuringParameterDeclaration7ES5.ts]
interface ISomething {
foo: string,
bar: string
}
function foo({}, {foo, bar}: ISomething) {}
function baz([], {foo, bar}: ISomething) {}
function one([], {}) {}
function two([], [a, b, c]: number[]) {}
//// [destructuringParameterDeclaration7ES5.js]
function foo(_a, _b) {
var foo = _b.foo, bar = _b.bar;
}
function baz(_a, _b) {
var foo = _b.foo, bar = _b.bar;
}
function one(_a, _b) { }
function two(_a, _b) {
var a = _b[0], b = _b[1], c = _b[2];
}

View File

@@ -0,0 +1,33 @@
=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts ===
interface ISomething {
>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5.ts, 0, 0))
foo: string,
>foo : Symbol(ISomething.foo, Decl(destructuringParameterDeclaration7ES5.ts, 1, 22))
bar: string
>bar : Symbol(ISomething.bar, Decl(destructuringParameterDeclaration7ES5.ts, 2, 16))
}
function foo({}, {foo, bar}: ISomething) {}
>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5.ts, 4, 1))
>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5.ts, 6, 18))
>bar : Symbol(bar, Decl(destructuringParameterDeclaration7ES5.ts, 6, 22))
>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5.ts, 0, 0))
function baz([], {foo, bar}: ISomething) {}
>baz : Symbol(baz, Decl(destructuringParameterDeclaration7ES5.ts, 6, 43))
>foo : Symbol(foo, Decl(destructuringParameterDeclaration7ES5.ts, 8, 18))
>bar : Symbol(bar, Decl(destructuringParameterDeclaration7ES5.ts, 8, 22))
>ISomething : Symbol(ISomething, Decl(destructuringParameterDeclaration7ES5.ts, 0, 0))
function one([], {}) {}
>one : Symbol(one, Decl(destructuringParameterDeclaration7ES5.ts, 8, 43))
function two([], [a, b, c]: number[]) {}
>two : Symbol(two, Decl(destructuringParameterDeclaration7ES5.ts, 10, 23))
>a : Symbol(a, Decl(destructuringParameterDeclaration7ES5.ts, 12, 18))
>b : Symbol(b, Decl(destructuringParameterDeclaration7ES5.ts, 12, 20))
>c : Symbol(c, Decl(destructuringParameterDeclaration7ES5.ts, 12, 23))

View File

@@ -0,0 +1,33 @@
=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration7ES5.ts ===
interface ISomething {
>ISomething : ISomething
foo: string,
>foo : string
bar: string
>bar : string
}
function foo({}, {foo, bar}: ISomething) {}
>foo : ({}: {}, {foo, bar}: ISomething) => void
>foo : string
>bar : string
>ISomething : ISomething
function baz([], {foo, bar}: ISomething) {}
>baz : ([]: any[], {foo, bar}: ISomething) => void
>foo : string
>bar : string
>ISomething : ISomething
function one([], {}) {}
>one : ([]: any[], {}: {}) => void
function two([], [a, b, c]: number[]) {}
>two : ([]: any[], [a, b, c]: number[]) => void
>a : number
>b : number
>c : number

View File

@@ -0,0 +1,14 @@
// @target: es5
interface ISomething {
foo: string,
bar: string
}
function foo({}, {foo, bar}: ISomething) {}
function baz([], {foo, bar}: ISomething) {}
function one([], {}) {}
function two([], [a, b, c]: number[]) {}