expr()

in lib/parser.js [1790:2007]


  expr() {
    const begin = this.getIndex();
    const item = this.exprItem();
    let end = this.getIndex();
    if (this.is('.')) {
      return this.properties(item);
    }

    if (this.is('+')) {
      this.move();
      const right = this.expr();
      return {
        type: 'add',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is('-')) {
      this.move();
      const right = this.expr();
      return {
        type: 'subtract',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is('*')) {
      this.move();
      const right = this.expr();
      return {
        type: 'multi',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is('/')) {
      this.move();
      const right = this.expr();
      return {
        type: 'div',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.EQ)) {
      this.move();
      const right = this.expr();
      return {
        type: 'eq',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.NEQ)) {
      this.move();
      const right = this.expr();
      return {
        type: 'neq',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.GT)) {
      this.move();
      const right = this.expr();
      return {
        type: 'gt',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.GTE)) {
      this.move();
      const right = this.expr();
      return {
        type: 'gte',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.LTE)) {
      this.move();
      const right = this.expr();
      return {
        type: 'lte',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.LT)) {
      this.move();
      const right = this.expr();
      return {
        type: 'lt',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.AND)) {
      this.move();
      const right = this.expr();
      return {
        type: 'and',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.OR)) {
      this.move();
      const right = this.expr();
      return {
        type: 'or',
        left: item,
        right: right,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, right.tokenRange[1]]
      };
    }

    if (this.is(Tag.INCREMENT)) {
      this.move();
      return {
        type: 'increment',
        position: 'backend',
        expr: item,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, end]
      };
    }

    if (this.is(Tag.DECREMENT)) {
      this.move();
      return {
        type: 'decrement',
        position: 'backend',
        expr: item,
        loc: {
          start: item.loc.start,
          end: this.look.loc.end
        },
        tokenRange: [begin, end]
      };
    }
    item.tokenRange = [begin, end];
    return item;
  }