mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Added getOccs support for return keywords.
This commit is contained in:
parent
3f3dd29461
commit
fbb10cd6b3
@ -4394,37 +4394,6 @@ module ts {
|
||||
return voidType;
|
||||
}
|
||||
|
||||
// WARNING: This has the same semantics as the forEach family of functions,
|
||||
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
|
||||
function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
|
||||
|
||||
return traverse(body);
|
||||
|
||||
function traverse(node: Node): T {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ReturnStatement:
|
||||
return visitor(node);
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.FunctionBlock:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.WithStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.CaseClause:
|
||||
case SyntaxKind.DefaultClause:
|
||||
case SyntaxKind.LabelledStatement:
|
||||
case SyntaxKind.TryStatement:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
return forEachChild(node, traverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a set of types relating to every return expression relating to a function block.
|
||||
function checkAndAggregateReturnExpressionTypes(body: Block, contextualMapper?: TypeMapper): Type[] {
|
||||
var aggregatedTypes: Type[] = [];
|
||||
@ -7155,4 +7124,35 @@ module ts {
|
||||
|
||||
return checker;
|
||||
}
|
||||
|
||||
// WARNING: This has the same semantics as the forEach family of functions,
|
||||
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
|
||||
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
|
||||
|
||||
return traverse(body);
|
||||
|
||||
function traverse(node: Node): T {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ReturnStatement:
|
||||
return visitor(node);
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.FunctionBlock:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.WithStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.CaseClause:
|
||||
case SyntaxKind.DefaultClause:
|
||||
case SyntaxKind.LabelledStatement:
|
||||
case SyntaxKind.TryStatement:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
return forEachChild(node, traverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ module ts {
|
||||
LastFutureReservedWord = YieldKeyword,
|
||||
FirstTypeNode = TypeReference,
|
||||
LastTypeNode = ArrayType,
|
||||
FirstPunctuation= OpenBraceToken,
|
||||
FirstPunctuation = OpenBraceToken,
|
||||
LastPunctuation = CaretEqualsToken
|
||||
}
|
||||
|
||||
|
||||
@ -2174,6 +2174,11 @@ module ts {
|
||||
return getIfElseOccurrences(<IfStatement>node.parent);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ReturnKeyword:
|
||||
if (hasKind(node.parent, SyntaxKind.ReturnStatement)) {
|
||||
return getReturnOccurrences(<ReturnStatement>node.parent);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.TryKeyword:
|
||||
case SyntaxKind.CatchKeyword:
|
||||
case SyntaxKind.FinallyKeyword:
|
||||
@ -2261,6 +2266,25 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[]{
|
||||
var node: Node = returnStatement;
|
||||
while (!isAnyFunction(node) && node.parent) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
// If we didn't find a containing function with a block body, bail out.
|
||||
if (!(isAnyFunction(node) && hasKind((<FunctionDeclaration>node).body, SyntaxKind.FunctionBlock))) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var keywords: Node[] = []
|
||||
forEachReturnStatement(<Block>(<FunctionDeclaration>node).body, returnStmt => {
|
||||
pushKeywordIf(keywords, returnStmt.getFirstToken(), SyntaxKind.ReturnKeyword);
|
||||
});
|
||||
|
||||
return map(keywords, keywordToReferenceEntry);
|
||||
}
|
||||
|
||||
function getTryCatchFinallyOccurrences(tryStatement: TryStatement): ReferenceEntry[] {
|
||||
var keywords: Node[] = [];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user