properties()

in lib/parser.js [1456:1528]


  properties(id){
    const propertyPath = [];
    while (this.look.tag === '.') {
      this.move();
      var prop = this.look;
      this.matchID();
      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: id,
          propertyPath: propertyPath
        },
        args: args,
        loc: {
          start: id.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: id,
        propertyPath: propertyPath,
        accessKey: accessKey,
        loc: {
          start: id.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,
          propertyPath
        },
        expr: expr
      };
    }

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