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

Method parseRightSideOfDot

internal/parser/parser.go:2925–2970  ·  view source on GitHub ↗
(allowIdentifierNames bool, allowPrivateIdentifiers bool, allowUnicodeEscapeSequenceInIdentifierName bool)

Source from the content-addressed store, hash-verified

2923}
2924
2925func (p *Parser) parseRightSideOfDot(allowIdentifierNames bool, allowPrivateIdentifiers bool, allowUnicodeEscapeSequenceInIdentifierName bool) *ast.Node {
2926 // Technically a keyword is valid here as all identifiers and keywords are identifier names.
2927 // However, often we'll encounter this in error situations when the identifier or keyword
2928 // is actually starting another valid construct.
2929 //
2930 // So, we check for the following specific case:
2931 //
2932 // name.
2933 // identifierOrKeyword identifierNameOrKeyword
2934 //
2935 // Note: the newlines are important here. For example, if that above code
2936 // were rewritten into:
2937 //
2938 // name.identifierOrKeyword
2939 // identifierNameOrKeyword
2940 //
2941 // Then we would consider it valid. That's because ASI would take effect and
2942 // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword".
2943 // In the first case though, ASI will not take effect because there is not a
2944 // line terminator after the identifier or keyword.
2945 if p.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(p.token) && p.lookAhead((*Parser).nextTokenIsIdentifierOrKeywordOnSameLine) {
2946 // Report that we need an identifier. However, report it right after the dot,
2947 // and not on the next token. This is because the next token might actually
2948 // be an identifier and the error would be quite confusing.
2949 p.parseErrorAt(p.nodePos(), p.nodePos(), diagnostics.Identifier_expected)
2950 return p.createMissingIdentifier()
2951 }
2952 if p.token == ast.KindPrivateIdentifier {
2953 node := p.parsePrivateIdentifier()
2954 if allowPrivateIdentifiers {
2955 return node
2956 }
2957 p.parseErrorAt(p.nodePos(), p.nodePos(), diagnostics.Identifier_expected)
2958 return p.createMissingIdentifier()
2959 }
2960 if allowIdentifierNames {
2961 if allowUnicodeEscapeSequenceInIdentifierName {
2962 return p.parseIdentifierName()
2963 }
2964 return p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
2965 }
2966 saveHasAwaitIdentifier := p.statementHasAwaitIdentifier
2967 id := p.parseIdentifier()
2968 p.statementHasAwaitIdentifier = saveHasAwaitIdentifier
2969 return id
2970}
2971
2972func (p *Parser) newIdentifier(text string) *ast.Node {
2973 p.identifierCount++

Callers 4

parseEntityNameMethod · 0.95
parseJsxElementNameMethod · 0.95
parseSuperExpressionMethod · 0.95

Calls 10

hasPrecedingLineBreakMethod · 0.95
lookAheadMethod · 0.95
parseErrorAtMethod · 0.95
nodePosMethod · 0.95
parseIdentifierNameMethod · 0.95
parseIdentifierMethod · 0.95

Tested by

no test coverage detected