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

Function getDynamicIndentation

test/fixtures/snapshot/typescript.js:147359–147432  ·  view source on GitHub ↗
(node, nodeStartLine, indentation, delta)

Source from the content-addressed store, hash-verified

147357 }
147358 }
147359 function getDynamicIndentation(node, nodeStartLine, indentation, delta) {
147360 return {
147361 getIndentationForComment: function (kind, tokenIndentation, container) {
147362 switch (kind) {
147363 // preceding comment to the token that closes the indentation scope inherits the indentation from the scope
147364 // .. {
147365 // // comment
147366 // }
147367 case 19 /* SyntaxKind.CloseBraceToken */:
147368 case 23 /* SyntaxKind.CloseBracketToken */:
147369 case 21 /* SyntaxKind.CloseParenToken */:
147370 return indentation + getDelta(container);
147371 }
147372 return tokenIndentation !== -1 /* Constants.Unknown */ ? tokenIndentation : indentation;
147373 },
147374 // if list end token is LessThanToken '>' then its delta should be explicitly suppressed
147375 // so that LessThanToken as a binary operator can still be indented.
147376 // foo.then
147377 // <
147378 // number,
147379 // string,
147380 // >();
147381 // vs
147382 // var a = xValue
147383 // > yValue;
147384 getIndentationForToken: function (line, kind, container, suppressDelta) {
147385 return !suppressDelta && shouldAddDelta(line, kind, container) ? indentation + getDelta(container) : indentation;
147386 },
147387 getIndentation: function () { return indentation; },
147388 getDelta: getDelta,
147389 recomputeIndentation: function (lineAdded, parent) {
147390 if (formatting.SmartIndenter.shouldIndentChildNode(options, parent, node, sourceFile)) {
147391 indentation += lineAdded ? options.indentSize : -options.indentSize;
147392 delta = formatting.SmartIndenter.shouldIndentChildNode(options, node) ? options.indentSize : 0;
147393 }
147394 }
147395 };
147396 function shouldAddDelta(line, kind, container) {
147397 switch (kind) {
147398 // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent
147399 case 18 /* SyntaxKind.OpenBraceToken */:
147400 case 19 /* SyntaxKind.CloseBraceToken */:
147401 case 21 /* SyntaxKind.CloseParenToken */:
147402 case 91 /* SyntaxKind.ElseKeyword */:
147403 case 115 /* SyntaxKind.WhileKeyword */:
147404 case 59 /* SyntaxKind.AtToken */:
147405 return false;
147406 case 43 /* SyntaxKind.SlashToken */:
147407 case 31 /* SyntaxKind.GreaterThanToken */:
147408 switch (container.kind) {
147409 case 280 /* SyntaxKind.JsxOpeningElement */:
147410 case 281 /* SyntaxKind.JsxClosingElement */:
147411 case 279 /* SyntaxKind.JsxSelfClosingElement */:
147412 case 228 /* SyntaxKind.ExpressionWithTypeArguments */:
147413 return false;
147414 }
147415 break;
147416 case 22 /* SyntaxKind.OpenBracketToken */:

Callers 2

processNodeFunction · 0.85
processChildNodesFunction · 0.85

Calls 2

getDeltaFunction · 0.85
shouldAddDeltaFunction · 0.85

Tested by

no test coverage detected