Skip to content

Commit 837ddda

Browse files
Addressed CR feedback.
1 parent ba396ed commit 837ddda

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7124,35 +7124,4 @@ module ts {
71247124
}
71257125
}
71267126
}
7127-
7128-
// WARNING: This has the same semantics as the forEach family of functions,
7129-
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
7130-
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
7131-
7132-
return traverse(body);
7133-
7134-
function traverse(node: Node): T {
7135-
switch (node.kind) {
7136-
case SyntaxKind.ReturnStatement:
7137-
return visitor(node);
7138-
case SyntaxKind.Block:
7139-
case SyntaxKind.FunctionBlock:
7140-
case SyntaxKind.IfStatement:
7141-
case SyntaxKind.DoStatement:
7142-
case SyntaxKind.WhileStatement:
7143-
case SyntaxKind.ForStatement:
7144-
case SyntaxKind.ForInStatement:
7145-
case SyntaxKind.WithStatement:
7146-
case SyntaxKind.SwitchStatement:
7147-
case SyntaxKind.CaseClause:
7148-
case SyntaxKind.DefaultClause:
7149-
case SyntaxKind.LabelledStatement:
7150-
case SyntaxKind.TryStatement:
7151-
case SyntaxKind.TryBlock:
7152-
case SyntaxKind.CatchBlock:
7153-
case SyntaxKind.FinallyBlock:
7154-
return forEachChild(node, traverse);
7155-
}
7156-
}
7157-
}
71587127
}

src/compiler/parser.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,37 @@ module ts {
349349
}
350350
}
351351

352+
// Warning: This has the same semantics as the forEach family of functions,
353+
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
354+
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
355+
356+
return traverse(body);
357+
358+
function traverse(node: Node): T {
359+
switch (node.kind) {
360+
case SyntaxKind.ReturnStatement:
361+
return visitor(node);
362+
case SyntaxKind.Block:
363+
case SyntaxKind.FunctionBlock:
364+
case SyntaxKind.IfStatement:
365+
case SyntaxKind.DoStatement:
366+
case SyntaxKind.WhileStatement:
367+
case SyntaxKind.ForStatement:
368+
case SyntaxKind.ForInStatement:
369+
case SyntaxKind.WithStatement:
370+
case SyntaxKind.SwitchStatement:
371+
case SyntaxKind.CaseClause:
372+
case SyntaxKind.DefaultClause:
373+
case SyntaxKind.LabelledStatement:
374+
case SyntaxKind.TryStatement:
375+
case SyntaxKind.TryBlock:
376+
case SyntaxKind.CatchBlock:
377+
case SyntaxKind.FinallyBlock:
378+
return forEachChild(node, traverse);
379+
}
380+
}
381+
}
382+
352383
export function hasRestParameters(s: SignatureDeclaration): boolean {
353384
return s.parameters.length > 0 && (s.parameters[s.parameters.length - 1].flags & NodeFlags.Rest) !== 0;
354385
}

src/services/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,8 +2279,8 @@ module ts {
22792279
}
22802280

22812281
var keywords: Node[] = []
2282-
forEachReturnStatement(<Block>(<FunctionDeclaration>func).body, returnStmt => {
2283-
pushKeywordIf(keywords, returnStmt.getFirstToken(), SyntaxKind.ReturnKeyword);
2282+
forEachReturnStatement(<Block>(<FunctionDeclaration>func).body, returnStatement => {
2283+
pushKeywordIf(keywords, returnStatement.getFirstToken(), SyntaxKind.ReturnKeyword);
22842284
});
22852285

22862286
return map(keywords, keywordToReferenceEntry);

0 commit comments

Comments
 (0)