()
| 5981 | } |
| 5982 | |
| 5983 | func (p *Parser) scanClassMemberStart() bool { |
| 5984 | idToken := ast.KindUnknown |
| 5985 | if p.token == ast.KindAtToken { |
| 5986 | return true |
| 5987 | } |
| 5988 | // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. |
| 5989 | for ast.IsModifierKind(p.token) { |
| 5990 | idToken = p.token |
| 5991 | // If the idToken is a class modifier (protected, private, public, and static), it is |
| 5992 | // certain that we are starting to parse class member. This allows better error recovery |
| 5993 | // Example: |
| 5994 | // public foo() ... // true |
| 5995 | // public @dec blah ... // true; we will then report an error later |
| 5996 | // export public ... // true; we will then report an error later |
| 5997 | if ast.IsClassMemberModifier(idToken) { |
| 5998 | return true |
| 5999 | } |
| 6000 | p.nextToken() |
| 6001 | } |
| 6002 | if p.token == ast.KindAsteriskToken { |
| 6003 | return true |
| 6004 | } |
| 6005 | // Try to get the first property-like token following all modifiers. |
| 6006 | // This can either be an identifier or the 'get' or 'set' keywords. |
| 6007 | if p.isLiteralPropertyName() { |
| 6008 | idToken = p.token |
| 6009 | p.nextToken() |
| 6010 | } |
| 6011 | // Index signatures and computed properties are class members; we can parse. |
| 6012 | if p.token == ast.KindOpenBracketToken { |
| 6013 | return true |
| 6014 | } |
| 6015 | // If we were able to get any potential identifier... |
| 6016 | if idToken != ast.KindUnknown { |
| 6017 | // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. |
| 6018 | if !ast.IsKeyword(idToken) || idToken == ast.KindSetKeyword || idToken == ast.KindGetKeyword { |
| 6019 | return true |
| 6020 | } |
| 6021 | // If it *is* a keyword, but not an accessor, check a little farther along |
| 6022 | // to see if it should actually be parsed as a class member. |
| 6023 | switch p.token { |
| 6024 | case ast.KindOpenParenToken, // Method declaration |
| 6025 | ast.KindLessThanToken, // Generic Method declaration |
| 6026 | ast.KindExclamationToken, // Non-null assertion on property name |
| 6027 | ast.KindColonToken, // Type Annotation for declaration |
| 6028 | ast.KindEqualsToken, // Initializer for declaration |
| 6029 | ast.KindQuestionToken: // Not valid, but permitted so that it gets caught later on. |
| 6030 | return true |
| 6031 | } |
| 6032 | // Covers |
| 6033 | // - Semicolons (declaration termination) |
| 6034 | // - Closing braces (end-of-class, must be declaration) |
| 6035 | // - End-of-files (not valid, but permitted so that it gets caught later on) |
| 6036 | // - Line-breaks (enabling *automatic semicolon insertion*) |
| 6037 | return p.canParseSemicolon() |
| 6038 | } |
| 6039 | return false |
| 6040 | } |
nothing calls this directly
no test coverage detected