GetNameTable returns a map of all names in the file to their positions. If the name appears more than once, the value is -1.
()
| 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. |
| 2718 | func (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 | |
| 2749 | func (node *SourceFile) IsBound() bool { |
| 2750 | return node.isBound.Load() |
no test coverage detected