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

Function GetPropertyNameForPropertyNameNode

internal/ast/utilities.go:3141–3161  ·  view source on GitHub ↗
(name *Node)

Source from the content-addressed store, hash-verified

3139}
3140
3141func GetPropertyNameForPropertyNameNode(name *Node) string {
3142 switch name.Kind {
3143 case KindIdentifier, KindPrivateIdentifier, KindStringLiteral, KindNoSubstitutionTemplateLiteral,
3144 KindNumericLiteral, KindBigIntLiteral, KindJsxNamespacedName:
3145 return name.Text()
3146 case KindComputedPropertyName:
3147 nameExpression := name.Expression()
3148 if IsStringOrNumericLiteralLike(nameExpression) {
3149 return nameExpression.Text()
3150 }
3151 if IsSignedNumericLiteral(nameExpression) {
3152 text := nameExpression.AsPrefixUnaryExpression().Operand.Text()
3153 if nameExpression.AsPrefixUnaryExpression().Operator == KindMinusToken {
3154 text = "-" + text
3155 }
3156 return text
3157 }
3158 return InternalSymbolNameMissing
3159 }
3160 panic("Unhandled case in getPropertyNameForPropertyNameNode")
3161}
3162
3163func IsPartOfTypeOnlyImportOrExportDeclaration(node *Node) bool {
3164 return FindAncestor(node, IsTypeOnlyImportOrExportDeclaration) != nil

Calls 6

IsSignedNumericLiteralFunction · 0.85
panicFunction · 0.85
ExpressionMethod · 0.80
TextMethod · 0.65

Tested by

no test coverage detected