()
| 1458 | } |
| 1459 | |
| 1460 | parseBinaryExpression(): Node.Expression { |
| 1461 | const startToken = this.lookahead; |
| 1462 | |
| 1463 | let expr = this.inheritCoverGrammar(this.parseExponentiationExpression); |
| 1464 | |
| 1465 | const token = this.lookahead; |
| 1466 | let prec = this.binaryPrecedence(token); |
| 1467 | if (prec > 0) { |
| 1468 | this.nextToken(); |
| 1469 | |
| 1470 | this.context.isAssignmentTarget = false; |
| 1471 | this.context.isBindingElement = false; |
| 1472 | |
| 1473 | const markers = [startToken, this.lookahead]; |
| 1474 | let left = expr; |
| 1475 | let right = this.isolateCoverGrammar(this.parseExponentiationExpression); |
| 1476 | |
| 1477 | const stack = [left, token.value, right]; |
| 1478 | const precedences: number[] = [prec]; |
| 1479 | while (true) { |
| 1480 | prec = this.binaryPrecedence(this.lookahead); |
| 1481 | if (prec <= 0) { |
| 1482 | break; |
| 1483 | } |
| 1484 | |
| 1485 | // Reduce: make a binary expression from the three topmost entries. |
| 1486 | while ((stack.length > 2) && (prec <= precedences[precedences.length - 1])) { |
| 1487 | right = stack.pop(); |
| 1488 | const operator = stack.pop(); |
| 1489 | precedences.pop(); |
| 1490 | left = stack.pop(); |
| 1491 | markers.pop(); |
| 1492 | const node = this.startNode(markers[markers.length - 1]); |
| 1493 | stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right))); |
| 1494 | } |
| 1495 | |
| 1496 | // Shift. |
| 1497 | stack.push(this.nextToken().value); |
| 1498 | precedences.push(prec); |
| 1499 | markers.push(this.lookahead); |
| 1500 | stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression)); |
| 1501 | } |
| 1502 | |
| 1503 | // Final reduce to clean-up the stack. |
| 1504 | let i = stack.length - 1; |
| 1505 | expr = stack[i]; |
| 1506 | |
| 1507 | let lastMarker = markers.pop(); |
| 1508 | while (i > 1) { |
| 1509 | const marker = markers.pop(); |
| 1510 | const lastLineStart = lastMarker && lastMarker.lineStart; |
| 1511 | const node = this.startNode(marker, lastLineStart); |
| 1512 | const operator = stack[i - 1]; |
| 1513 | expr = this.finalize(node, new Node.BinaryExpression(operator, stack[i - 2], expr)); |
| 1514 | i -= 2; |
| 1515 | lastMarker = marker; |
| 1516 | } |
| 1517 | } |
nothing calls this directly
no test coverage detected