MCPcopy Create free account
hub / github.com/nodejs/node / getHighlightSpans

Function getHighlightSpans

test/fixtures/snapshot/typescript.js:135581–135640  ·  view source on GitHub ↗
(node, sourceFile)

Source from the content-addressed store, hash-verified

135579 return highlightSpans && [{ fileName: sourceFile.fileName, highlightSpans: highlightSpans }];
135580 }
135581 function getHighlightSpans(node, sourceFile) {
135582 switch (node.kind) {
135583 case 99 /* SyntaxKind.IfKeyword */:
135584 case 91 /* SyntaxKind.ElseKeyword */:
135585 return ts.isIfStatement(node.parent) ? getIfElseOccurrences(node.parent, sourceFile) : undefined;
135586 case 105 /* SyntaxKind.ReturnKeyword */:
135587 return useParent(node.parent, ts.isReturnStatement, getReturnOccurrences);
135588 case 109 /* SyntaxKind.ThrowKeyword */:
135589 return useParent(node.parent, ts.isThrowStatement, getThrowOccurrences);
135590 case 111 /* SyntaxKind.TryKeyword */:
135591 case 83 /* SyntaxKind.CatchKeyword */:
135592 case 96 /* SyntaxKind.FinallyKeyword */:
135593 var tryStatement = node.kind === 83 /* SyntaxKind.CatchKeyword */ ? node.parent.parent : node.parent;
135594 return useParent(tryStatement, ts.isTryStatement, getTryCatchFinallyOccurrences);
135595 case 107 /* SyntaxKind.SwitchKeyword */:
135596 return useParent(node.parent, ts.isSwitchStatement, getSwitchCaseDefaultOccurrences);
135597 case 82 /* SyntaxKind.CaseKeyword */:
135598 case 88 /* SyntaxKind.DefaultKeyword */: {
135599 if (ts.isDefaultClause(node.parent) || ts.isCaseClause(node.parent)) {
135600 return useParent(node.parent.parent.parent, ts.isSwitchStatement, getSwitchCaseDefaultOccurrences);
135601 }
135602 return undefined;
135603 }
135604 case 81 /* SyntaxKind.BreakKeyword */:
135605 case 86 /* SyntaxKind.ContinueKeyword */:
135606 return useParent(node.parent, ts.isBreakOrContinueStatement, getBreakOrContinueStatementOccurrences);
135607 case 97 /* SyntaxKind.ForKeyword */:
135608 case 115 /* SyntaxKind.WhileKeyword */:
135609 case 90 /* SyntaxKind.DoKeyword */:
135610 return useParent(node.parent, function (n) { return ts.isIterationStatement(n, /*lookInLabeledStatements*/ true); }, getLoopBreakContinueOccurrences);
135611 case 134 /* SyntaxKind.ConstructorKeyword */:
135612 return getFromAllDeclarations(ts.isConstructorDeclaration, [134 /* SyntaxKind.ConstructorKeyword */]);
135613 case 136 /* SyntaxKind.GetKeyword */:
135614 case 149 /* SyntaxKind.SetKeyword */:
135615 return getFromAllDeclarations(ts.isAccessor, [136 /* SyntaxKind.GetKeyword */, 149 /* SyntaxKind.SetKeyword */]);
135616 case 132 /* SyntaxKind.AwaitKeyword */:
135617 return useParent(node.parent, ts.isAwaitExpression, getAsyncAndAwaitOccurrences);
135618 case 131 /* SyntaxKind.AsyncKeyword */:
135619 return highlightSpans(getAsyncAndAwaitOccurrences(node));
135620 case 125 /* SyntaxKind.YieldKeyword */:
135621 return highlightSpans(getYieldOccurrences(node));
135622 case 101 /* SyntaxKind.InKeyword */:
135623 return undefined;
135624 default:
135625 return ts.isModifierKind(node.kind) && (ts.isDeclaration(node.parent) || ts.isVariableStatement(node.parent))
135626 ? highlightSpans(getModifierOccurrences(node.kind, node.parent))
135627 : undefined;
135628 }
135629 function getFromAllDeclarations(nodeTest, keywords) {
135630 return useParent(node.parent, nodeTest, function (decl) { return ts.mapDefined(decl.symbol.declarations, function (d) {
135631 return nodeTest(d) ? ts.find(d.getChildren(sourceFile), function (c) { return ts.contains(keywords, c.kind); }) : undefined;
135632 }); });
135633 }
135634 function useParent(node, nodeTest, getNodes) {
135635 return nodeTest(node) ? highlightSpans(getNodes(node, sourceFile)) : undefined;
135636 }
135637 function highlightSpans(nodes) {
135638 return nodes && nodes.map(function (node) { return getHighlightSpanForNode(node, sourceFile); });

Callers 1

Calls 7

getIfElseOccurrencesFunction · 0.85
useParentFunction · 0.85
getFromAllDeclarationsFunction · 0.85
highlightSpansFunction · 0.85
getYieldOccurrencesFunction · 0.85
getModifierOccurrencesFunction · 0.85

Tested by

no test coverage detected