MCPcopy Create free account
hub / github.com/microsoft/typescript-go / processChildNode

Method processChildNode

internal/format/span.go:333–430  ·  view source on GitHub ↗
(
	node *ast.Node,
	indenter *dynamicIndenter,
	nodeStartLine int,
	undecoratedNodeStartLine int,
	child *ast.Node,
	inheritedIndentation int,
	parent *ast.Node,
	parentDynamicIndentation *dynamicIndenter,
	parentStartLine int,
	undecoratedParentStartLine int,
	isListItem bool,
	isFirstListItem bool,
)

Source from the content-addressed store, hash-verified

331}
332
333func (w *formatSpanWorker) processChildNode(
334 node *ast.Node,
335 indenter *dynamicIndenter,
336 nodeStartLine int,
337 undecoratedNodeStartLine int,
338 child *ast.Node,
339 inheritedIndentation int,
340 parent *ast.Node,
341 parentDynamicIndentation *dynamicIndenter,
342 parentStartLine int,
343 undecoratedParentStartLine int,
344 isListItem bool,
345 isFirstListItem bool,
346) int {
347 debug.Assert(!ast.NodeIsSynthesized(child))
348
349 if ast.NodeIsMissing(child) || isGrammarError(parent, child) || child.Flags&ast.NodeFlagsReparsed != 0 {
350 return inheritedIndentation
351 }
352
353 childStartPos := scanner.GetTokenPosOfNode(child, w.sourceFile, false)
354 childStartLine := scanner.GetECMALineOfPosition(w.sourceFile, childStartPos)
355
356 undecoratedChildStartLine := childStartLine
357 if ast.HasDecorators(child) {
358 undecoratedChildStartLine = scanner.GetECMALineOfPosition(w.sourceFile, getNonDecoratorTokenPosOfNode(child, w.sourceFile))
359 }
360
361 // if child is a list item - try to get its indentation, only if parent is within the original range.
362 childIndentationAmount := -1
363
364 if isListItem && parent.Loc.ContainedBy(w.originalRange) {
365 childIndentationAmount = w.tryComputeIndentationForListItem(childStartPos, child.End(), parentStartLine, w.originalRange, inheritedIndentation)
366 if childIndentationAmount != -1 {
367 inheritedIndentation = childIndentationAmount
368 }
369 }
370
371 // child node is outside the target range - do not dive inside
372 if !w.originalRange.Overlaps(child.Loc) {
373 if child.End() < w.originalRange.Pos() {
374 w.formattingScanner.skipToEndOf(&child.Loc)
375 }
376 return inheritedIndentation
377 }
378
379 if child.Loc.Len() == 0 {
380 return inheritedIndentation
381 }
382
383 for w.formattingScanner.isOnToken() && w.formattingScanner.getTokenFullStart() < w.originalRange.End() {
384 // proceed any parent tokens that are located prior to child.getStart()
385 tokenInfo := w.formattingScanner.readTokenInfo(node)
386 if tokenInfo.token.Loc.End() > w.originalRange.End() {
387 return inheritedIndentation
388 }
389 if tokenInfo.token.Loc.End() > childStartPos {
390 if tokenInfo.token.Loc.Pos() > childStartPos {

Callers 2

executeMethod · 0.95
processChildNodesMethod · 0.95

Calls 15

computeIndentationMethod · 0.95
processNodeMethod · 0.95
AssertFunction · 0.92
NodeIsSynthesizedFunction · 0.92
NodeIsMissingFunction · 0.92
GetTokenPosOfNodeFunction · 0.92
GetECMALineOfPositionFunction · 0.92
HasDecoratorsFunction · 0.92
IsTokenKindFunction · 0.92
isGrammarErrorFunction · 0.85

Tested by

no test coverage detected