* conditional operation * * condition ? truePart : falsePart * * Note: conditional operator is right-associative * * @return {Node} node * @private
(state)
| 752 | * @private |
| 753 | */ |
| 754 | function parseConditional (state) { |
| 755 | let node = parseLogicalOr(state) |
| 756 | |
| 757 | while (state.token === '?') { // eslint-disable-line no-unmodified-loop-condition |
| 758 | // set a conditional level, the range operator will be ignored as long |
| 759 | // as conditionalLevel === state.nestingLevel. |
| 760 | const prev = state.conditionalLevel |
| 761 | state.conditionalLevel = state.nestingLevel |
| 762 | getTokenSkipNewline(state) |
| 763 | |
| 764 | const condition = node |
| 765 | const trueExpr = parseAssignment(state) |
| 766 | |
| 767 | if (state.token !== ':') throw createSyntaxError(state, 'False part of conditional expression expected') |
| 768 | |
| 769 | state.conditionalLevel = null |
| 770 | getTokenSkipNewline(state) |
| 771 | |
| 772 | const falseExpr = parseAssignment(state) // Note: check for conditional operator again, right associativity |
| 773 | |
| 774 | node = new ConditionalNode(condition, trueExpr, falseExpr) |
| 775 | |
| 776 | // restore the previous conditional level |
| 777 | state.conditionalLevel = prev |
| 778 | } |
| 779 | |
| 780 | return node |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * logical or, 'x or y' |
no test coverage detected
searching dependent graphs…