visitPropertyAccess()

in lib/generator.js [1566:1589]


  visitPropertyAccess(ast) {
    assert.ok(ast.type === 'property_access' || ast.type === 'property');
    var id = _name(ast.id);
    if (ast.id.tag === Tag.VID) {
      id = `this->${_vid(ast.id)}`;
    }

    var expr = `$${_avoidKeywords(id)}`;

    var current = ast.id.inferred;
    for (var i = 0; i < ast.propertyPath.length; i++) {
      var name = _name(ast.propertyPath[i]);
      if (current.type === 'model') {
        expr += `->${name}`;
      } else {
        if(!expr.startsWith('@')) {
          expr = `@${expr}`;
        }
        expr += `['${name}']`;
      }
      current = ast.propertyPathTypes[i];
    }
    this.emit(expr);
  }