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

Method GetNameTable

internal/ast/ast.go:2718–2747  ·  view source on GitHub ↗

GetNameTable returns a map of all names in the file to their positions. If the name appears more than once, the value is -1.

()

Source from the content-addressed store, hash-verified

2716// GetNameTable returns a map of all names in the file to their positions.
2717// If the name appears more than once, the value is -1.
2718func (file *SourceFile) GetNameTable() map[string]int {
2719 file.nameTableOnce.Do(func() {
2720 nameTable := make(map[string]int, file.IdentifierCount)
2721
2722 var walk func(node *Node) bool
2723 walk = func(node *Node) bool {
2724 if IsIdentifier(node) && !IsTagName(node) && node.Text() != "" ||
2725 IsStringOrNumericLiteralLike(node) && literalIsName(node) ||
2726 IsPrivateIdentifier(node) {
2727 text := node.Text()
2728 if _, ok := nameTable[text]; ok {
2729 nameTable[text] = -1
2730 } else {
2731 nameTable[text] = node.Pos()
2732 }
2733 }
2734
2735 node.ForEachChild(walk)
2736 jsdocNodes := node.JSDoc(file)
2737 for _, jsdoc := range jsdocNodes {
2738 jsdoc.ForEachChild(walk)
2739 }
2740 return false
2741 }
2742 file.ForEachChild(walk)
2743
2744 file.nameTable = nameTable
2745 })
2746 return file.nameTable
2747}
2748
2749func (node *SourceFile) IsBound() bool {
2750 return node.isBound.Load()

Callers 2

searchForNameMethod · 0.80

Calls 11

ForEachChildMethod · 0.95
IsIdentifierFunction · 0.85
IsTagNameFunction · 0.85
literalIsNameFunction · 0.85
IsPrivateIdentifierFunction · 0.85
JSDocMethod · 0.80
TextMethod · 0.65
PosMethod · 0.65
ForEachChildMethod · 0.65
makeFunction · 0.50

Tested by

no test coverage detected