Skip to content

Commit 5b45db7

Browse files
committed
PR Feedback
1 parent afaa139 commit 5b45db7

2 files changed

Lines changed: 49 additions & 28 deletions

File tree

src/compiler/transformers/es2017.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,34 @@ namespace ts {
8686
}
8787

8888
function asyncBodyVisitor(node: Node): VisitResult<Node> {
89-
switch (node.kind) {
90-
case SyntaxKind.VariableStatement:
91-
return visitVariableStatementInAsyncBody(<VariableStatement>node);
92-
case SyntaxKind.ForStatement:
93-
return visitForStatementInAsyncBody(<ForStatement>node);
94-
case SyntaxKind.ForInStatement:
95-
return visitForInStatementInAsyncBody(<ForInStatement>node);
96-
case SyntaxKind.ForOfStatement:
97-
return visitForOfStatementInAsyncBody(<ForOfStatement>node);
98-
case SyntaxKind.CatchClause:
99-
return visitCatchClauseInAsyncBody(<CatchClause>node);
100-
case SyntaxKind.Block:
101-
case SyntaxKind.SwitchStatement:
102-
case SyntaxKind.CaseBlock:
103-
case SyntaxKind.CaseClause:
104-
case SyntaxKind.DefaultClause:
105-
case SyntaxKind.TryStatement:
106-
case SyntaxKind.DoStatement:
107-
case SyntaxKind.WhileStatement:
108-
case SyntaxKind.IfStatement:
109-
case SyntaxKind.WithStatement:
110-
case SyntaxKind.LabeledStatement:
111-
return visitEachChild(node, asyncBodyVisitor, context);
89+
if (isNodeWithPossibleHoistedDeclaration(node)) {
90+
switch (node.kind) {
91+
case SyntaxKind.VariableStatement:
92+
return visitVariableStatementInAsyncBody(node);
93+
case SyntaxKind.ForStatement:
94+
return visitForStatementInAsyncBody(node);
95+
case SyntaxKind.ForInStatement:
96+
return visitForInStatementInAsyncBody(node);
97+
case SyntaxKind.ForOfStatement:
98+
return visitForOfStatementInAsyncBody(node);
99+
case SyntaxKind.CatchClause:
100+
return visitCatchClauseInAsyncBody(node);
101+
case SyntaxKind.Block:
102+
case SyntaxKind.SwitchStatement:
103+
case SyntaxKind.CaseBlock:
104+
case SyntaxKind.CaseClause:
105+
case SyntaxKind.DefaultClause:
106+
case SyntaxKind.TryStatement:
107+
case SyntaxKind.DoStatement:
108+
case SyntaxKind.WhileStatement:
109+
case SyntaxKind.IfStatement:
110+
case SyntaxKind.WithStatement:
111+
case SyntaxKind.LabeledStatement:
112+
return visitEachChild(node, asyncBodyVisitor, context);
113+
default:
114+
return Debug.assertNever(node, "Unhandled node.");
115+
}
112116
}
113-
Debug.assert(!isNodeWithPossibleVarDeclaration(node), "Unhandled node.");
114117
return visitor(node);
115118
}
116119

src/compiler/utilities.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,14 +1761,32 @@ namespace ts {
17611761
return getAssignmentTargetKind(node) !== AssignmentKind.None;
17621762
}
17631763

1764+
export type NodeWithPossibleHoistedDeclaration =
1765+
| Block
1766+
| VariableStatement
1767+
| WithStatement
1768+
| IfStatement
1769+
| SwitchStatement
1770+
| CaseBlock
1771+
| CaseClause
1772+
| DefaultClause
1773+
| LabeledStatement
1774+
| ForStatement
1775+
| ForInStatement
1776+
| ForOfStatement
1777+
| DoStatement
1778+
| WhileStatement
1779+
| TryStatement
1780+
| CatchClause;
1781+
17641782
/**
1765-
* Indicates whether a node could contain embedded statements that share the same `var`
1766-
* declaration scope as its parent.
1783+
* Indicates whether a node could contain a `var` VariableDeclarationList that contributes to
1784+
* the same `var` declaration scope as the node's parent.
17671785
*/
1768-
export function isNodeWithPossibleVarDeclaration(node: Node) {
1786+
export function isNodeWithPossibleHoistedDeclaration(node: Node): node is NodeWithPossibleHoistedDeclaration {
17691787
switch (node.kind) {
1770-
case SyntaxKind.SourceFile:
17711788
case SyntaxKind.Block:
1789+
case SyntaxKind.VariableStatement:
17721790
case SyntaxKind.WithStatement:
17731791
case SyntaxKind.IfStatement:
17741792
case SyntaxKind.SwitchStatement:

0 commit comments

Comments
 (0)