()
| 1291 | } |
| 1292 | |
| 1293 | func (p *Parser) parseForOrForInOrForOfStatement() *ast.Node { |
| 1294 | pos := p.nodePos() |
| 1295 | jsdoc := p.jsdocScannerInfo() |
| 1296 | p.parseExpected(ast.KindForKeyword) |
| 1297 | awaitToken := p.parseOptionalToken(ast.KindAwaitKeyword) |
| 1298 | p.parseExpected(ast.KindOpenParenToken) |
| 1299 | var initializer *ast.ForInitializer |
| 1300 | if p.token != ast.KindSemicolonToken { |
| 1301 | if p.token == ast.KindVarKeyword || p.token == ast.KindLetKeyword || p.token == ast.KindConstKeyword || |
| 1302 | p.token == ast.KindUsingKeyword && p.lookAhead((*Parser).nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLineDisallowOf) || |
| 1303 | // this one is meant to allow of |
| 1304 | p.token == ast.KindAwaitKeyword && p.lookAhead((*Parser).nextIsUsingKeywordThenBindingIdentifierOrStartOfObjectDestructuringOnSameLine) { |
| 1305 | initializer = p.parseVariableDeclarationList(true /*inForStatementInitializer*/) |
| 1306 | } else { |
| 1307 | initializer = doInContext(p, ast.NodeFlagsDisallowInContext, true, (*Parser).parseExpression) |
| 1308 | } |
| 1309 | } |
| 1310 | var result *ast.Statement |
| 1311 | switch { |
| 1312 | case awaitToken != nil && p.parseExpected(ast.KindOfKeyword) || awaitToken == nil && p.parseOptional(ast.KindOfKeyword): |
| 1313 | expression := doInContext(p, ast.NodeFlagsDisallowInContext, false, (*Parser).parseAssignmentExpressionOrHigher) |
| 1314 | p.parseExpected(ast.KindCloseParenToken) |
| 1315 | result = p.factory.NewForInOrOfStatement(ast.KindForOfStatement, awaitToken, initializer, expression, p.parseStatement()) |
| 1316 | case p.parseOptional(ast.KindInKeyword): |
| 1317 | expression := p.parseExpressionAllowIn() |
| 1318 | p.parseExpected(ast.KindCloseParenToken) |
| 1319 | result = p.factory.NewForInOrOfStatement(ast.KindForInStatement, nil /*awaitToken*/, initializer, expression, p.parseStatement()) |
| 1320 | default: |
| 1321 | p.parseExpected(ast.KindSemicolonToken) |
| 1322 | var condition *ast.Expression |
| 1323 | if p.token != ast.KindSemicolonToken && p.token != ast.KindCloseParenToken { |
| 1324 | condition = p.parseExpressionAllowIn() |
| 1325 | } |
| 1326 | p.parseExpected(ast.KindSemicolonToken) |
| 1327 | var incrementor *ast.Expression |
| 1328 | if p.token != ast.KindCloseParenToken { |
| 1329 | incrementor = p.parseExpressionAllowIn() |
| 1330 | } |
| 1331 | p.parseExpected(ast.KindCloseParenToken) |
| 1332 | result = p.factory.NewForStatement(initializer, condition, incrementor, p.parseStatement()) |
| 1333 | } |
| 1334 | p.finishNode(result, pos) |
| 1335 | p.withJSDoc(result, jsdoc) |
| 1336 | return result |
| 1337 | } |
| 1338 | |
| 1339 | func (p *Parser) parseBreakStatement() *ast.Node { |
| 1340 | pos := p.nodePos() |
no test coverage detected