visitPropertyAccess()

in lib/generator.js [2380:2434]


  visitPropertyAccess(ast, level, env, expected) {
    assert.ok(ast.type === 'property_access' || ast.type === 'property');

    var id = _name(ast.id);

    if(ast.id.tag === Tag.VID){
      id = _vid(ast.id);
    }

    var expr = '';
    if (id === '__response') {
      expr += RESPONSE;
    } else if (id === '__request') {
      expr += REQUEST;
    } else {
      expr += _avoidReserveName(id);
    }
    var fieldType = '';
    var current = ast.id.inferred;
    var isMap = '';
    for (var i = 0; i < ast.propertyPath.length; i++) {
      const name = _name(ast.propertyPath[i]);
      if (current.type === 'model') {
        if (ast.inferred.type === 'array') {
          fieldType = `[]${this.getType(_name(ast.inferred.itemType), false)}`;
        } else {
          fieldType = ast.propertyPathTypes[i].name;
        }
        expr += `.${_format(name)}`;
      } else {
        fieldType = ast.propertyPathTypes[i].name;
        expr += `["${name}"]`;
      }
      if (current.type === 'map') {
        isMap = true;
      }
      current = ast.propertyPathTypes[i];
    }
    if (expected && expected.needCast === 'false') {
      this.emit(expr);

    } else if (expected && expected.pointer) {
      if (ast.id.inferred.type !== 'model' && !isMap && (DSL.util.isBasicType(fieldType) ||
        (current.type === 'array' && current.itemType.type === 'basic')) && !_isFilterType(fieldType)) {
        this.emit(`${_setExtendFunc(fieldType)}${expr})`);
      } else {
        this.emit(`${expr}`);
      }
    } else if ((ast.id.inferred.type === 'model' || isMap) && (DSL.util.isBasicType(fieldType) ||
      (current.type === 'array' && current.itemType.type === 'basic')) && !_isFilterType(fieldType)) {
      this.emit(`${_setValueFunc(fieldType)}${expr})`);
    } else {
      this.emit(expr);
    }
  }