From cbf1800f46ce73a27b93e6a9ccb382d3936debb9 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 8 Jan 2018 15:42:30 -0800 Subject: [PATCH] Ensure visitor visits the awaitModifier of a ForOfStatement --- src/compiler/visitor.ts | 2 +- .../cases/fourslash/extractMethod_forAwait.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/extractMethod_forAwait.ts diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 0b40e20a7b7c1..2d678eb0effcb 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -622,7 +622,7 @@ namespace ts { case SyntaxKind.ForOfStatement: return updateForOf(node, - (node).awaitModifier, + visitNode((node).awaitModifier, visitor, isToken), visitNode((node).initializer, visitor, isForInitializer), visitNode((node).expression, visitor, isExpression), visitNode((node).statement, visitor, isStatement, liftToBlock)); diff --git a/tests/cases/fourslash/extractMethod_forAwait.ts b/tests/cases/fourslash/extractMethod_forAwait.ts new file mode 100644 index 0000000000000..238c5875a0d85 --- /dev/null +++ b/tests/cases/fourslash/extractMethod_forAwait.ts @@ -0,0 +1,25 @@ +/// + +////async function f(xs: AsyncIterable) { +//// /*a*/for await (const x of xs) { +//// x * 2; +//// }/*b*/ +////} + +goTo.select('a', 'b') +edit.applyRefactor({ + refactorName: "Extract Symbol", + actionName: "function_scope_1", + actionDescription: "Extract to function in global scope", + newContent: +`async function f(xs: AsyncIterable) { + /*RENAME*/newFunction(xs); +} + +function newFunction(xs: any) { + for await (const x of xs) { + x * 2; + } +} +` +});