(isIdentifier bool, diagnosticMessage *diagnostics.Message, privateIdentifierDiagnosticMessage *diagnostics.Message)
| 5857 | } |
| 5858 | |
| 5859 | func (p *Parser) createIdentifierWithDiagnostic(isIdentifier bool, diagnosticMessage *diagnostics.Message, privateIdentifierDiagnosticMessage *diagnostics.Message) *ast.Node { |
| 5860 | if isIdentifier { |
| 5861 | var pos int |
| 5862 | if p.scanner.HasPrecedingJSDocLeadingAsterisks() { |
| 5863 | pos = p.scanner.TokenStart() |
| 5864 | } else { |
| 5865 | pos = p.nodePos() |
| 5866 | } |
| 5867 | text := p.scanner.TokenValue() |
| 5868 | p.nextTokenWithoutCheck() |
| 5869 | return p.finishNode(p.newIdentifier(p.internIdentifier(text)), pos) |
| 5870 | } |
| 5871 | if p.token == ast.KindPrivateIdentifier { |
| 5872 | if privateIdentifierDiagnosticMessage != nil { |
| 5873 | p.parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage) |
| 5874 | } else { |
| 5875 | p.parseErrorAtCurrentToken(diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies) |
| 5876 | } |
| 5877 | return p.createIdentifier(true /*isIdentifier*/) |
| 5878 | } |
| 5879 | // Only for end of file because the error gets reported incorrectly on embedded script tags. |
| 5880 | reportAtCurrentPosition := p.token == ast.KindEndOfFile |
| 5881 | if diagnosticMessage != nil { |
| 5882 | if reportAtCurrentPosition { |
| 5883 | pos := p.scanner.TokenFullStart() |
| 5884 | p.parseErrorAt(pos, pos, diagnosticMessage) |
| 5885 | } else { |
| 5886 | p.parseErrorAtCurrentToken(diagnosticMessage) |
| 5887 | } |
| 5888 | } else if isReservedWord(p.token) { |
| 5889 | if reportAtCurrentPosition { |
| 5890 | pos := p.scanner.TokenFullStart() |
| 5891 | p.parseErrorAt(pos, pos, diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, p.scanner.TokenText()) |
| 5892 | } else { |
| 5893 | p.parseErrorAtCurrentToken(diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, p.scanner.TokenText()) |
| 5894 | } |
| 5895 | } else { |
| 5896 | if reportAtCurrentPosition { |
| 5897 | pos := p.scanner.TokenFullStart() |
| 5898 | p.parseErrorAt(pos, pos, diagnostics.Identifier_expected) |
| 5899 | } else { |
| 5900 | p.parseErrorAtCurrentToken(diagnostics.Identifier_expected) |
| 5901 | } |
| 5902 | } |
| 5903 | return p.createMissingIdentifier() |
| 5904 | } |
| 5905 | |
| 5906 | func (p *Parser) internIdentifier(text string) string { |
| 5907 | if identifier, ok := p.identifiers[text]; ok { |
no test coverage detected