Skip to content
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

Fix missing visit of expression in for..of #11132

Merged
merged 1 commit into from
Sep 25, 2016
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/transformers/es6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ namespace ts {
// Note also that because an extra statement is needed to assign to the LHS,
// for-of bodies are always emitted as blocks.

const expression = node.expression;
const expression = visitNode(node.expression, visitor, isExpression);
const initializer = node.initializer;
const statements: Statement[] = [];

Expand Down Expand Up @@ -2014,7 +2014,7 @@ namespace ts {
case SyntaxKind.ForOfStatement:
const initializer = (<ForStatement | ForInStatement | ForOfStatement>node).initializer;
if (initializer && initializer.kind === SyntaxKind.VariableDeclarationList) {
loopInitializer = <VariableDeclarationList>(<ForStatement | ForInStatement | ForOfStatement>node).initializer;
loopInitializer = <VariableDeclarationList>initializer;
}
break;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/forOfTransformsExpression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [forOfTransformsExpression.ts]
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {

}

//// [forOfTransformsExpression.js]
// https://github.com/Microsoft/TypeScript/issues/11024
var items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var _i = 0, _a = items.sort(function (a, b) { return a.name.localeCompare(b.name); }); _i < _a.length; _i++) {
var item = _a[_i];
}
25 changes: 25 additions & 0 deletions tests/baselines/reference/forOfTransformsExpression.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/compiler/forOfTransformsExpression.ts ===
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
>items : Symbol(items, Decl(forOfTransformsExpression.ts, 1, 3))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 29))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 44))

for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {
>item : Symbol(item, Decl(forOfTransformsExpression.ts, 2, 8))
>items.sort : Symbol(Array.sort, Decl(lib.d.ts, --, --))
>items : Symbol(items, Decl(forOfTransformsExpression.ts, 1, 3))
>sort : Symbol(Array.sort, Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(forOfTransformsExpression.ts, 2, 29))
>b : Symbol(b, Decl(forOfTransformsExpression.ts, 2, 31))
>a.name.localeCompare : Symbol(String.localeCompare, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>a.name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>a : Symbol(a, Decl(forOfTransformsExpression.ts, 2, 29))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>localeCompare : Symbol(String.localeCompare, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>b.name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))
>b : Symbol(b, Decl(forOfTransformsExpression.ts, 2, 31))
>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14))

}
35 changes: 35 additions & 0 deletions tests/baselines/reference/forOfTransformsExpression.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== tests/cases/compiler/forOfTransformsExpression.ts ===
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
>items : { name: string; }[]
>[{ name: "A" }, { name: "C" }, { name: "B" }] : { name: string; }[]
>{ name: "A" } : { name: string; }
>name : string
>"A" : "A"
>{ name: "C" } : { name: string; }
>name : string
>"C" : "C"
>{ name: "B" } : { name: string; }
>name : string
>"B" : "B"

for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {
>item : { name: string; }
>items.sort((a, b) => a.name.localeCompare(b.name)) : { name: string; }[]
>items.sort : (compareFn?: (a: { name: string; }, b: { name: string; }) => number) => { name: string; }[]
>items : { name: string; }[]
>sort : (compareFn?: (a: { name: string; }, b: { name: string; }) => number) => { name: string; }[]
>(a, b) => a.name.localeCompare(b.name) : (a: { name: string; }, b: { name: string; }) => number
>a : { name: string; }
>b : { name: string; }
>a.name.localeCompare(b.name) : number
>a.name.localeCompare : { (that: string): number; (that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; }
>a.name : string
>a : { name: string; }
>name : string
>localeCompare : { (that: string): number; (that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; }
>b.name : string
>b : { name: string; }
>name : string

}
5 changes: 5 additions & 0 deletions tests/cases/compiler/forOfTransformsExpression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://github.com/Microsoft/TypeScript/issues/11024
let items = [{ name: "A" }, { name: "C" }, { name: "B" }];
for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) {

}