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

Function getIfElseKeywords

test/fixtures/snapshot/typescript.js:135942–135964  ·  view source on GitHub ↗
(ifStatement, sourceFile)

Source from the content-addressed store, hash-verified

135940 return result;
135941 }
135942 function getIfElseKeywords(ifStatement, sourceFile) {
135943 var keywords = [];
135944 // Traverse upwards through all parent if-statements linked by their else-branches.
135945 while (ts.isIfStatement(ifStatement.parent) && ifStatement.parent.elseStatement === ifStatement) {
135946 ifStatement = ifStatement.parent;
135947 }
135948 // Now traverse back down through the else branches, aggregating if/else keywords of if-statements.
135949 while (true) {
135950 var children = ifStatement.getChildren(sourceFile);
135951 pushKeywordIf(keywords, children[0], 99 /* SyntaxKind.IfKeyword */);
135952 // Generally the 'else' keyword is second-to-last, so we traverse backwards.
135953 for (var i = children.length - 1; i >= 0; i--) {
135954 if (pushKeywordIf(keywords, children[i], 91 /* SyntaxKind.ElseKeyword */)) {
135955 break;
135956 }
135957 }
135958 if (!ifStatement.elseStatement || !ts.isIfStatement(ifStatement.elseStatement)) {
135959 break;
135960 }
135961 ifStatement = ifStatement.elseStatement;
135962 }
135963 return keywords;
135964 }
135965 /**
135966 * Whether or not a 'node' is preceded by a label of the given string.
135967 * Note: 'node' cannot be a SourceFile.

Callers 1

getIfElseOccurrencesFunction · 0.85

Calls 2

pushKeywordIfFunction · 0.85
getChildrenMethod · 0.80

Tested by

no test coverage detected