mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 21:09:09 -05:00
Document highlights on yield keywords highlight other occurrences in the same body
This commit is contained in:
@@ -78,6 +78,8 @@ namespace ts.DocumentHighlights {
|
||||
return useParent(node.parent, isAwaitExpression, getAsyncAndAwaitOccurrences);
|
||||
case SyntaxKind.AsyncKeyword:
|
||||
return highlightSpans(getAsyncAndAwaitOccurrences(node));
|
||||
case SyntaxKind.YieldKeyword:
|
||||
return highlightSpans(getYieldOccurrences(node));
|
||||
default:
|
||||
return isModifierKind(node.kind) && (isDeclaration(node.parent) || isVariableStatement(node.parent))
|
||||
? highlightSpans(getModifierOccurrences(node.kind, node.parent))
|
||||
@@ -170,7 +172,7 @@ namespace ts.DocumentHighlights {
|
||||
if (statement.kind === SyntaxKind.ContinueStatement) {
|
||||
return false;
|
||||
}
|
||||
// falls through
|
||||
// falls through
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForOfStatement:
|
||||
@@ -237,7 +239,7 @@ namespace ts.DocumentHighlights {
|
||||
}
|
||||
}
|
||||
|
||||
function pushKeywordIf(keywordList: Push<Node>, token: Node, ...expected: SyntaxKind[]): boolean {
|
||||
function pushKeywordIf(keywordList: Push<Node>, token: Node | undefined, ...expected: SyntaxKind[]): boolean {
|
||||
if (token && contains(expected, token.kind)) {
|
||||
keywordList.push(token);
|
||||
return true;
|
||||
@@ -384,18 +386,42 @@ namespace ts.DocumentHighlights {
|
||||
});
|
||||
}
|
||||
|
||||
forEachChild(func, aggregate);
|
||||
forEachChild(func, child => {
|
||||
traverseWithoutCrossingFunction(child, node => {
|
||||
if (isAwaitExpression(node)) {
|
||||
pushKeywordIf(keywords, node.getFirstToken(), SyntaxKind.AwaitKeyword);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
function aggregate(node: Node): void {
|
||||
if (isAwaitExpression(node)) {
|
||||
pushKeywordIf(keywords, node.getFirstToken()!, SyntaxKind.AwaitKeyword);
|
||||
}
|
||||
// Do not cross function boundaries.
|
||||
if (!isFunctionLike(node) && !isClassLike(node) && !isInterfaceDeclaration(node) && !isModuleDeclaration(node) && !isTypeAliasDeclaration(node) && !isTypeNode(node)) {
|
||||
forEachChild(node, aggregate);
|
||||
}
|
||||
function getYieldOccurrences(node: Node): Node[] | undefined {
|
||||
const func = getContainingFunction(node) as FunctionDeclaration;
|
||||
if (!func) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const keywords: Node[] = [];
|
||||
|
||||
forEachChild(func, child => {
|
||||
traverseWithoutCrossingFunction(child, node => {
|
||||
if (isYieldExpression(node)) {
|
||||
pushKeywordIf(keywords, node.getFirstToken(), SyntaxKind.YieldKeyword);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
// Do not cross function/class/interface/module/type boundaries.
|
||||
function traverseWithoutCrossingFunction(node: Node, cb: (node: Node) => void) {
|
||||
cb(node);
|
||||
if (!isFunctionLike(node) && !isClassLike(node) && !isInterfaceDeclaration(node) && !isModuleDeclaration(node) && !isTypeAliasDeclaration(node) && !isTypeNode(node)) {
|
||||
forEachChild(node, child => traverseWithoutCrossingFunction(child, cb));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user