()
| 6065 | } |
| 6066 | |
| 6067 | func (p *Parser) isStartOfStatement() bool { |
| 6068 | switch p.token { |
| 6069 | // 'catch' and 'finally' do not actually indicate that the code is part of a statement, |
| 6070 | // however, we say they are here so that we may gracefully parse them and error later. |
| 6071 | case ast.KindAtToken, ast.KindSemicolonToken, ast.KindOpenBraceToken, ast.KindVarKeyword, ast.KindLetKeyword, |
| 6072 | ast.KindUsingKeyword, ast.KindFunctionKeyword, ast.KindClassKeyword, ast.KindEnumKeyword, ast.KindIfKeyword, |
| 6073 | ast.KindDoKeyword, ast.KindWhileKeyword, ast.KindForKeyword, ast.KindContinueKeyword, ast.KindBreakKeyword, |
| 6074 | ast.KindReturnKeyword, ast.KindWithKeyword, ast.KindSwitchKeyword, ast.KindThrowKeyword, ast.KindTryKeyword, |
| 6075 | ast.KindDebuggerKeyword, ast.KindCatchKeyword, ast.KindFinallyKeyword: |
| 6076 | return true |
| 6077 | case ast.KindImportKeyword: |
| 6078 | return p.isStartOfDeclaration() || p.isNextTokenOpenParenOrLessThanOrDot() |
| 6079 | case ast.KindConstKeyword, ast.KindExportKeyword: |
| 6080 | return p.isStartOfDeclaration() |
| 6081 | case ast.KindAsyncKeyword, ast.KindDeclareKeyword, ast.KindInterfaceKeyword, ast.KindModuleKeyword, ast.KindNamespaceKeyword, |
| 6082 | ast.KindTypeKeyword, ast.KindGlobalKeyword, ast.KindDeferKeyword: |
| 6083 | // When these don't start a declaration, they're an identifier in an expression statement |
| 6084 | return true |
| 6085 | case ast.KindAccessorKeyword, ast.KindPublicKeyword, ast.KindPrivateKeyword, ast.KindProtectedKeyword, ast.KindStaticKeyword, |
| 6086 | ast.KindReadonlyKeyword: |
| 6087 | // When these don't start a declaration, they may be the start of a class member if an identifier |
| 6088 | // immediately follows. Otherwise they're an identifier in an expression statement. |
| 6089 | return p.isStartOfDeclaration() || !p.lookAhead((*Parser).nextTokenIsIdentifierOrKeywordOnSameLine) |
| 6090 | |
| 6091 | default: |
| 6092 | return p.isStartOfExpression() |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | func (p *Parser) isStartOfDeclaration() bool { |
| 6097 | return p.lookAhead((*Parser).scanStartOfDeclaration) |
no test coverage detected