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

Function formatSpanWorker

test/fixtures/snapshot/typescript.js:147234–147937  ·  view source on GitHub ↗
(originalRange, enclosingNode, initialIndentation, delta, formattingScanner, _a, requestKind, rangeContainsError, sourceFile)

Source from the content-addressed store, hash-verified

147232 return formatting.getFormattingScanner(sourceFile.text, sourceFile.languageVariant, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end, function (scanner) { return formatSpanWorker(originalRange, enclosingNode, formatting.SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, formatContext.options), getOwnOrInheritedDelta(enclosingNode, formatContext.options, sourceFile), scanner, formatContext, requestKind, prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange), sourceFile); });
147233 }
147234 function formatSpanWorker(originalRange, enclosingNode, initialIndentation, delta, formattingScanner, _a, requestKind, rangeContainsError, sourceFile) {
147235 var _b;
147236 var options = _a.options, getRules = _a.getRules, host = _a.host;
147237 // formatting context is used by rules provider
147238 var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options);
147239 var previousRange;
147240 var previousParent;
147241 var previousRangeStartLine;
147242 var lastIndentedLine;
147243 var indentationOnLastIndentedLine = -1 /* Constants.Unknown */;
147244 var edits = [];
147245 formattingScanner.advance();
147246 if (formattingScanner.isOnToken()) {
147247 var startLine = sourceFile.getLineAndCharacterOfPosition(enclosingNode.getStart(sourceFile)).line;
147248 var undecoratedStartLine = startLine;
147249 if (enclosingNode.decorators) {
147250 undecoratedStartLine = sourceFile.getLineAndCharacterOfPosition(ts.getNonDecoratorTokenPosOfNode(enclosingNode, sourceFile)).line;
147251 }
147252 processNode(enclosingNode, enclosingNode, startLine, undecoratedStartLine, initialIndentation, delta);
147253 }
147254 if (!formattingScanner.isOnToken()) {
147255 var indentation = formatting.SmartIndenter.nodeWillIndentChild(options, enclosingNode, /*child*/ undefined, sourceFile, /*indentByDefault*/ false)
147256 ? initialIndentation + options.indentSize
147257 : initialIndentation;
147258 var leadingTrivia = formattingScanner.getCurrentLeadingTrivia();
147259 if (leadingTrivia) {
147260 indentTriviaItems(leadingTrivia, indentation, /*indentNextTokenOrTrivia*/ false, function (item) { return processRange(item, sourceFile.getLineAndCharacterOfPosition(item.pos), enclosingNode, enclosingNode, /*dynamicIndentation*/ undefined); });
147261 if (options.trimTrailingWhitespace !== false) {
147262 trimTrailingWhitespacesForRemainingRange(leadingTrivia);
147263 }
147264 }
147265 }
147266 if (previousRange && formattingScanner.getStartPos() >= originalRange.end) {
147267 var tokenInfo = formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
147268 formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
147269 undefined;
147270 if (tokenInfo) {
147271 var parent = ((_b = ts.findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)) === null || _b === void 0 ? void 0 : _b.parent) || previousParent;
147272 processPair(tokenInfo, sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line, parent, previousRange, previousRangeStartLine, previousParent, parent,
147273 /*dynamicIndentation*/ undefined);
147274 }
147275 }
147276 return edits;
147277 // local functions
147278 /** Tries to compute the indentation for a list element.
147279 * If list element is not in range then
147280 * function will pick its actual indentation
147281 * so it can be pushed downstream as inherited indentation.
147282 * If list element is in the range - its indentation will be equal
147283 * to inherited indentation from its predecessors.
147284 */
147285 function tryComputeIndentationForListItem(startPos, endPos, parentStartLine, range, inheritedIndentation) {
147286 if (ts.rangeOverlapsWithStartEnd(range, startPos, endPos) ||
147287 ts.rangeContainsStartEnd(range, startPos, endPos) /* Not to miss zero-range nodes e.g. JsxText */) {
147288 if (inheritedIndentation !== -1 /* Constants.Unknown */) {
147289 return inheritedIndentation;
147290 }
147291 }

Callers 2

formatSpanFunction · 0.85

Calls 6

processNodeFunction · 0.85
indentTriviaItemsFunction · 0.85
processRangeFunction · 0.85
processPairFunction · 0.85
advanceMethod · 0.80

Tested by

no test coverage detected