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

Method getDeclarationName

internal/binder/binder.go:306–360  ·  view source on GitHub ↗

Should not be called on a declaration with a computed property name, unless it is a well known Symbol.

(node *ast.Node)

Source from the content-addressed store, hash-verified

304// Should not be called on a declaration with a computed property name,
305// unless it is a well known Symbol.
306func (b *Binder) getDeclarationName(node *ast.Node) string {
307 if ast.IsExportAssignment(node) {
308 return core.IfElse(node.AsExportAssignment().IsExportEquals, ast.InternalSymbolNameExportEquals, ast.InternalSymbolNameDefault)
309 }
310 name := ast.GetNameOfDeclaration(node)
311 if name != nil {
312 if ast.IsAmbientModule(node) {
313 moduleName := name.Text()
314 if ast.IsGlobalScopeAugmentation(node) {
315 return ast.InternalSymbolNameGlobal
316 }
317 return "\"" + moduleName + "\""
318 }
319 if ast.IsPrivateIdentifier(name) {
320 // containingClass exists because private names only allowed inside classes
321 containingClass := ast.GetContainingClass(node)
322 if containingClass == nil {
323 // we can get here in cases where there is already a parse error.
324 return ast.InternalSymbolNameMissing
325 }
326 return GetSymbolNameForPrivateIdentifier(containingClass.Symbol(), name.Text())
327 }
328 if ast.IsPropertyNameLiteral(name) || ast.IsJsxNamespacedName(name) {
329 return name.Text()
330 }
331 if ast.IsComputedPropertyName(name) {
332 nameExpression := name.Expression()
333 // treat computed property names where expression is string/numeric literal as just string/numeric literal
334 if ast.IsStringOrNumericLiteralLike(nameExpression) {
335 return nameExpression.Text()
336 }
337 if ast.IsSignedNumericLiteral(nameExpression) {
338 unaryExpression := nameExpression.AsPrefixUnaryExpression()
339 return scanner.TokenToString(unaryExpression.Operator) + unaryExpression.Operand.Text()
340 }
341 panic("Only computed properties with literal names have declaration names")
342 }
343 return ast.InternalSymbolNameMissing
344 }
345 switch node.Kind {
346 case ast.KindConstructor:
347 return ast.InternalSymbolNameConstructor
348 case ast.KindFunctionType, ast.KindCallSignature:
349 return ast.InternalSymbolNameCall
350 case ast.KindConstructorType, ast.KindConstructSignature:
351 return ast.InternalSymbolNameNew
352 case ast.KindIndexSignature:
353 return ast.InternalSymbolNameIndex
354 case ast.KindExportDeclaration:
355 return ast.InternalSymbolNameExportStar
356 case ast.KindSourceFile, ast.KindBinaryExpression:
357 return ast.InternalSymbolNameExportEquals
358 }
359 return ast.InternalSymbolNameMissing
360}
361
362func (b *Binder) getDisplayName(node *ast.Node) string {
363 nameNode := node.Name()

Callers 8

declareSymbolExMethod · 0.95
getDisplayNameMethod · 0.95
declareModuleMemberMethod · 0.95
bindExportDeclarationMethod · 0.95
bindExportAssignmentMethod · 0.95
bindTypeParameterMethod · 0.95

Calls 15

IsExportAssignmentFunction · 0.92
IfElseFunction · 0.92
GetNameOfDeclarationFunction · 0.92
IsAmbientModuleFunction · 0.92
IsPrivateIdentifierFunction · 0.92
GetContainingClassFunction · 0.92
IsPropertyNameLiteralFunction · 0.92
IsJsxNamespacedNameFunction · 0.92
IsComputedPropertyNameFunction · 0.92
IsSignedNumericLiteralFunction · 0.92

Tested by

no test coverage detected