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

Function consumeTokenAndAdvanceScanner

test/fixtures/snapshot/typescript.js:147599–147647  ·  view source on GitHub ↗
(currentTokenInfo, parent, dynamicIndentation, container, isListEndToken)

Source from the content-addressed store, hash-verified

147597 }
147598 }
147599 function consumeTokenAndAdvanceScanner(currentTokenInfo, parent, dynamicIndentation, container, isListEndToken) {
147600 ts.Debug.assert(ts.rangeContainsRange(parent, currentTokenInfo.token));
147601 var lastTriviaWasNewLine = formattingScanner.lastTrailingTriviaWasNewLine();
147602 var indentToken = false;
147603 if (currentTokenInfo.leadingTrivia) {
147604 processTrivia(currentTokenInfo.leadingTrivia, parent, childContextNode, dynamicIndentation);
147605 }
147606 var lineAction = 0 /* LineAction.None */;
147607 var isTokenInRange = ts.rangeContainsRange(originalRange, currentTokenInfo.token);
147608 var tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos);
147609 if (isTokenInRange) {
147610 var rangeHasError = rangeContainsError(currentTokenInfo.token);
147611 // save previousRange since processRange will overwrite this value with current one
147612 var savePreviousRange = previousRange;
147613 lineAction = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation);
147614 // do not indent comments\token if token range overlaps with some error
147615 if (!rangeHasError) {
147616 if (lineAction === 0 /* LineAction.None */) {
147617 // indent token only if end line of previous range does not match start line of the token
147618 var prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line;
147619 indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
147620 }
147621 else {
147622 indentToken = lineAction === 1 /* LineAction.LineAdded */;
147623 }
147624 }
147625 }
147626 if (currentTokenInfo.trailingTrivia) {
147627 processTrivia(currentTokenInfo.trailingTrivia, parent, childContextNode, dynamicIndentation);
147628 }
147629 if (indentToken) {
147630 var tokenIndentation = (isTokenInRange && !rangeContainsError(currentTokenInfo.token)) ?
147631 dynamicIndentation.getIndentationForToken(tokenStart.line, currentTokenInfo.token.kind, container, !!isListEndToken) :
147632 -1 /* Constants.Unknown */;
147633 var indentNextTokenOrTrivia = true;
147634 if (currentTokenInfo.leadingTrivia) {
147635 var commentIndentation_1 = dynamicIndentation.getIndentationForComment(currentTokenInfo.token.kind, tokenIndentation, container);
147636 indentNextTokenOrTrivia = indentTriviaItems(currentTokenInfo.leadingTrivia, commentIndentation_1, indentNextTokenOrTrivia, function (item) { return insertIndentation(item.pos, commentIndentation_1, /*lineAdded*/ false); });
147637 }
147638 // indent token only if is it is in target range and does not overlap with any error ranges
147639 if (tokenIndentation !== -1 /* Constants.Unknown */ && indentNextTokenOrTrivia) {
147640 insertIndentation(currentTokenInfo.token.pos, tokenIndentation, lineAction === 1 /* LineAction.LineAdded */);
147641 lastIndentedLine = tokenStart.line;
147642 indentationOnLastIndentedLine = tokenIndentation;
147643 }
147644 }
147645 formattingScanner.advance();
147646 childContextNode = parent;
147647 }
147648 }
147649 function indentTriviaItems(trivia, commentIndentation, indentNextTokenOrTrivia, indentSingleLine) {
147650 for (var _i = 0, trivia_1 = trivia; _i < trivia_1.length; _i++) {

Callers 3

processNodeFunction · 0.85
processChildNodeFunction · 0.85
processChildNodesFunction · 0.85

Calls 6

processTriviaFunction · 0.85
processRangeFunction · 0.85
indentTriviaItemsFunction · 0.85
insertIndentationFunction · 0.85
assertMethod · 0.80
advanceMethod · 0.80

Tested by

no test coverage detected