MCPcopy Index your code
hub / github.com/microsoft/typescript-go / hasTrailingComma

Method hasTrailingComma

internal/printer/printer.go:4770–4842  ·  view source on GitHub ↗
(parentNode *ast.Node, children *ast.NodeList)

Source from the content-addressed store, hash-verified

4768}
4769
4770func (p *Printer) hasTrailingComma(parentNode *ast.Node, children *ast.NodeList) bool {
4771 // NodeList.HasTrailingComma() is unreliable on transformed nodes as some nodes may have been removed. In the event
4772 // we believe we may need to emit a trailing comma, we must first look to the respective node list on the original
4773 // node first.
4774 if !children.HasTrailingComma() {
4775 return false
4776 }
4777
4778 originalParent := p.emitContext.MostOriginal(parentNode)
4779 if originalParent == parentNode {
4780 // if this node is the original node, we can trust the result
4781 return true
4782 }
4783
4784 if originalParent.Kind != parentNode.Kind {
4785 // if the original node is some other kind of node, we cannot correlate the list
4786 return false
4787 }
4788
4789 // find the respective node list on the original parent
4790 originalList := children
4791 switch originalParent.Kind {
4792 case ast.KindObjectLiteralExpression:
4793 originalList = originalParent.PropertyList()
4794 case ast.KindArrayLiteralExpression:
4795 originalList = originalParent.ElementList()
4796 case ast.KindCallExpression, ast.KindNewExpression:
4797 switch children {
4798 case parentNode.TypeArgumentList():
4799 originalList = originalParent.TypeArgumentList()
4800 case parentNode.ArgumentList():
4801 originalList = originalParent.ArgumentList()
4802 }
4803 case ast.KindConstructor,
4804 ast.KindMethodDeclaration,
4805 ast.KindGetAccessor,
4806 ast.KindSetAccessor,
4807 ast.KindFunctionDeclaration,
4808 ast.KindFunctionExpression,
4809 ast.KindArrowFunction,
4810 ast.KindFunctionType,
4811 ast.KindConstructorType,
4812 ast.KindCallSignature,
4813 ast.KindConstructSignature:
4814 switch children {
4815 case parentNode.TypeParameterList():
4816 originalList = originalParent.TypeParameterList()
4817 case parentNode.ParameterList():
4818 originalList = originalParent.ParameterList()
4819 }
4820 case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration:
4821 switch children {
4822 case parentNode.TypeParameterList():
4823 originalList = originalParent.TypeParameterList()
4824 }
4825 case ast.KindObjectBindingPattern, ast.KindArrayBindingPattern:
4826 switch children {
4827 case parentNode.ElementList():

Callers 1

emitListRangeMethod · 0.95

Calls 9

HasTrailingCommaMethod · 0.80
MostOriginalMethod · 0.80
PropertyListMethod · 0.80
ElementListMethod · 0.80
TypeArgumentListMethod · 0.80
ArgumentListMethod · 0.80
TypeParameterListMethod · 0.80
ParameterListMethod · 0.80
AsImportAttributesMethod · 0.80

Tested by

no test coverage detected