vidThings()

in lib/parser.js [1543:1662]


  vidThings() {
    var vid = this.look;
    this.match(Tag.VID);

    // @id = xxx
    if (this.look.tag === '=') {
      this.move();
      var expr = this.expr();
      return {
        type: 'assign',
        left: {
          type: 'virtualVariable',
          vid: vid
        },
        expr: expr,
        loc: {
          start: vid.loc.start,
          end: this.lexer.loc()
        }
      };
    }

    // @vid.x = xxx, @id.x(), @id.x
    if (this.look.tag === '.') {
      const propertyPath = [];
      while (this.look.tag === '.') {
        this.move();
        var prop = this.look;
        this.match(Tag.ID);
        propertyPath.push(prop);
      }

      // id.x()
      if (this.look.tag === '(') {
        this.move();
        const args = this.args();
        this.match(')');
        // Module.staticCall() or module.instanceCall()
        return {
          type: 'call',
          left: {
            type: 'static_or_instance_call',
            id: vid,
            propertyPath: propertyPath
          },
          args: args,
          loc: {
            start: vid.loc.start,
            end: this.lexer.loc()
          },
        };
      }

      // id.x = xxx
      if (this.look.tag === '=') {
        this.move();
        let expr = this.expr();
        return {
          type: 'assign',
          left: {
            type: 'property',
            id: vid,
            propertyPath
          },
          expr: expr
        };
      }

      if (this.look.tag === '[') {
        this.move();
        let accessKey = this.expr();
        this.match(']');
        // @id.x[]
        return this.mapAccess({
          type: 'map_access',
          id: vid,
          propertyPath: propertyPath,
          accessKey: accessKey,
          loc: {
            start: vid.loc.start,
            end: this.lexer.loc()
          }
        });
      }

      // id.x
      return {
        type: 'property_access',
        id: vid,
        propertyPath: propertyPath,
        loc: {
          start: vid.loc.start,
          end: this.lexer.loc()
        }
      };
    }


    if (this.look.tag === '[') {
      this.move();
      let accessKey = this.expr();
      this.match(']');
      // @id.x[]
      return this.mapAccess({
        type: 'map_access',
        id: vid,
        accessKey: accessKey,
        loc: {
          start: vid.loc.start,
          end: this.lexer.loc()
        }
      });
    }

    return {
      type: 'virtualVariable',
      vid: vid,
      loc: vid.loc
    };
  }