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

Function createToken

internal/ast/ast.go:2805–2836  ·  view source on GitHub ↗

`kind` should be a token kind.

(kind Kind, file *SourceFile, pos, end int, flags TokenFlags)

Source from the content-addressed store, hash-verified

2803
2804// `kind` should be a token kind.
2805func createToken(kind Kind, file *SourceFile, pos, end int, flags TokenFlags) *Node {
2806 if file.tokenFactory == nil {
2807 file.tokenFactory = NewNodeFactory(NodeFactoryHooks{})
2808 }
2809 text := file.text[pos:end]
2810 switch kind {
2811 case KindNumericLiteral:
2812 return file.tokenFactory.NewNumericLiteral(text, flags)
2813 case KindBigIntLiteral:
2814 return file.tokenFactory.NewBigIntLiteral(text, flags)
2815 case KindStringLiteral:
2816 return file.tokenFactory.NewStringLiteral(text, flags)
2817 case KindJsxText, KindJsxTextAllWhiteSpaces:
2818 return file.tokenFactory.NewJsxText(text, kind == KindJsxTextAllWhiteSpaces)
2819 case KindRegularExpressionLiteral:
2820 return file.tokenFactory.NewRegularExpressionLiteral(text, flags)
2821 case KindNoSubstitutionTemplateLiteral:
2822 return file.tokenFactory.NewNoSubstitutionTemplateLiteral(text, flags)
2823 case KindTemplateHead:
2824 return file.tokenFactory.NewTemplateHead(text, "" /*rawText*/, flags)
2825 case KindTemplateMiddle:
2826 return file.tokenFactory.NewTemplateMiddle(text, "" /*rawText*/, flags)
2827 case KindTemplateTail:
2828 return file.tokenFactory.NewTemplateTail(text, "" /*rawText*/, flags)
2829 case KindIdentifier:
2830 return file.tokenFactory.NewIdentifier(text)
2831 case KindPrivateIdentifier:
2832 return file.tokenFactory.NewPrivateIdentifier(text)
2833 default: // Punctuation and keywords
2834 return file.tokenFactory.NewToken(kind)
2835 }
2836}
2837
2838func (node *SourceFile) GetDeclarationMap() map[string][]*Node {
2839 node.declarationMapMu.Lock()

Callers 1

GetOrCreateTokenMethod · 0.70

Calls 13

NewNumericLiteralMethod · 0.80
NewBigIntLiteralMethod · 0.80
NewStringLiteralMethod · 0.80
NewJsxTextMethod · 0.80
NewTemplateHeadMethod · 0.80
NewTemplateMiddleMethod · 0.80
NewTemplateTailMethod · 0.80
NewIdentifierMethod · 0.80
NewPrivateIdentifierMethod · 0.80
NewTokenMethod · 0.80

Tested by

no test coverage detected