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

Function computeIndentation

test/fixtures/snapshot/typescript.js:147305–147334  ·  view source on GitHub ↗
(node, startLine, inheritedIndentation, parent, parentDynamicIndentation, effectiveParentStartLine)

Source from the content-addressed store, hash-verified

147303 return -1 /* Constants.Unknown */;
147304 }
147305 function computeIndentation(node, startLine, inheritedIndentation, parent, parentDynamicIndentation, effectiveParentStartLine) {
147306 var delta = formatting.SmartIndenter.shouldIndentChildNode(options, node) ? options.indentSize : 0;
147307 if (effectiveParentStartLine === startLine) {
147308 // if node is located on the same line with the parent
147309 // - inherit indentation from the parent
147310 // - push children if either parent of node itself has non-zero delta
147311 return {
147312 indentation: startLine === lastIndentedLine ? indentationOnLastIndentedLine : parentDynamicIndentation.getIndentation(),
147313 delta: Math.min(options.indentSize, parentDynamicIndentation.getDelta(node) + delta)
147314 };
147315 }
147316 else if (inheritedIndentation === -1 /* Constants.Unknown */) {
147317 if (node.kind === 20 /* SyntaxKind.OpenParenToken */ && startLine === lastIndentedLine) {
147318 // the is used for chaining methods formatting
147319 // - we need to get the indentation on last line and the delta of parent
147320 return { indentation: indentationOnLastIndentedLine, delta: parentDynamicIndentation.getDelta(node) };
147321 }
147322 else if (formatting.SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile) ||
147323 formatting.SmartIndenter.childIsUnindentedBranchOfConditionalExpression(parent, node, startLine, sourceFile) ||
147324 formatting.SmartIndenter.argumentStartsOnSameLineAsPreviousArgument(parent, node, startLine, sourceFile)) {
147325 return { indentation: parentDynamicIndentation.getIndentation(), delta: delta };
147326 }
147327 else {
147328 return { indentation: parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(node), delta: delta };
147329 }
147330 }
147331 else {
147332 return { indentation: inheritedIndentation, delta: delta };
147333 }
147334 }
147335 function getFirstNonDecoratorTokenOfNode(node) {
147336 if (node.modifiers && node.modifiers.length) {
147337 return node.modifiers[0].kind;

Callers 1

processChildNodeFunction · 0.85

Calls 1

minMethod · 0.45

Tested by

no test coverage detected