Skip to content

Commit ed3ab96

Browse files
committed
Add tests for destructuring 'for...of'
1 parent 905f350 commit ed3ab96

15 files changed

Lines changed: 115 additions & 5 deletions

File tree

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10891,9 +10891,9 @@ module ts {
1089110891
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
1089210892
}
1089310893

10894-
function isUnknownIdentifier(location: Node, name: string): boolean {
10894+
function isUnknownIdentifier(location: Node, name: string, sourceFile: SourceFile): boolean {
1089510895
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
10896-
!hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name);
10896+
!hasProperty(getGeneratedNamesForSourceFile(sourceFile), name);
1089710897
}
1089810898

1089910899
function getBlockScopedVariableId(n: Identifier): number {

src/compiler/emitter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,10 +1639,12 @@ module ts {
16391639
}
16401640

16411641
if (root) {
1642+
currentSourceFile = root;
16421643
emit(root);
16431644
}
16441645
else {
16451646
forEach(host.getSourceFiles(), sourceFile => {
1647+
currentSourceFile = sourceFile;
16461648
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
16471649
emit(sourceFile);
16481650
}
@@ -1698,7 +1700,7 @@ module ts {
16981700

16991701
function isExistingName(location: Node, name: string) {
17001702
// check if resolver is aware of this name (if name was seen during the typecheck)
1701-
if (!resolver.isUnknownIdentifier(location, name)) {
1703+
if (!resolver.isUnknownIdentifier(location, name, currentSourceFile)) {
17021704
return true;
17031705
}
17041706

@@ -5191,7 +5193,6 @@ module ts {
51915193
}
51925194

51935195
function emitSourceFile(node: SourceFile) {
5194-
currentSourceFile = node;
51955196
// Start new file on new line
51965197
writeLine();
51975198
emitDetachedComments(node);

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ module ts {
12041204
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
12051205
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
12061206
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
1207-
isUnknownIdentifier(location: Node, name: string): boolean;
1207+
isUnknownIdentifier(location: Node, name: string, sourceFile: SourceFile): boolean;
12081208
getBlockScopedVariableId(node: Identifier): number;
12091209
}
12101210

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [ES5For-of26.ts]
2+
for (var [a = 0, b = 1] of [2, 3]) {
3+
a;
4+
b;
5+
}
6+
7+
//// [ES5For-of26.js]
8+
for (var _i = 0, _a = [2, 3]; _i < _a.length; _i++) {
9+
var _b = _a[_i], _c = _b[0], a = _c === void 0 ? 0 : _c, _d = _b[1], b = _d === void 0 ? 1 : _d;
10+
a;
11+
b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [ES5For-of27.ts]
2+
for (var {x: a = 0, y: b = 1} of [2, 3]) {
3+
a;
4+
b;
5+
}
6+
7+
//// [ES5For-of27.js]
8+
for (var _i = 0, _a = [2, 3]; _i < _a.length; _i++) {
9+
var _b = _a[_i], _c = _b.x, a = _c === void 0 ? 0 : _c, _d = _b.y, b = _d === void 0 ? 1 : _d;
10+
a;
11+
b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [ES5For-of28.ts]
2+
for (let [a = 0, b = 1] of [2, 3]) {
3+
a;
4+
b;
5+
}
6+
7+
//// [ES5For-of28.js]
8+
for (var _i = 0, _a = [2, 3]; _i < _a.length; _i++) {
9+
var _b = _a[_i], _c = _b[0], a = _c === void 0 ? 0 : _c, _d = _b[1], b = _d === void 0 ? 1 : _d;
10+
a;
11+
b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [ES5For-of29.ts]
2+
for (const {x: a = 0, y: b = 1} of [2, 3]) {
3+
a;
4+
b;
5+
}
6+
7+
//// [ES5For-of29.js]
8+
for (var _i = 0, _a = [2, 3]; _i < _a.length; _i++) {
9+
var _b = _a[_i], _c = _b.x, a = _c === void 0 ? 0 : _c, _d = _b.y, b = _d === void 0 ? 1 : _d;
10+
a;
11+
b;
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [ES5For-of30.ts]
2+
var a: string, b: number;
3+
var tuple: [number, string] = [2, "3"];
4+
for ([a = 1, b = ""] of tuple) {
5+
a;
6+
b;
7+
}
8+
9+
//// [ES5For-of30.js]
10+
var a, b;
11+
var tuple = [2, "3"];
12+
for (var _i = 0; _i < tuple.length; _i++) {
13+
_a = tuple[_i], _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? "" : _c;
14+
a;
15+
b;
16+
}
17+
var _a, _b, _c;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [ES5For-of31.ts]
2+
var a: string, b: number;
3+
4+
for ({ a: b = 1, b: a = ""} of []) {
5+
a;
6+
b;
7+
}
8+
9+
//// [ES5For-of31.js]
10+
var a, b;
11+
for (var _i = 0, _a = []; _i < _a.length; _i++) {
12+
_b = _a[_i], _c = _b.a, b = _c === void 0 ? 1 : _c, _d = _b.b, a = _d === void 0 ? "" : _d;
13+
a;
14+
b;
15+
}
16+
var _b, _c, _d;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for (var [a = 0, b = 1] of [2, 3]) {
2+
a;
3+
b;
4+
}

0 commit comments

Comments
 (0)