visitPropertyAccess()

in lib/generator.js [1859:1880]


  visitPropertyAccess(ast, env = {}) {
    assert.ok(ast.type === 'property_access' || ast.type === 'property');
    var id = _snakeCase(_name(ast.id));
    if (ast.id.tag === Tag.VID) {
      id = `self.${_snakeCase(_vid(ast.id))}`;
    }
    var expr = _avoidKeywords(id);
    const prefix = env.left ? '[' : '.get(';
    const suffix = env.left ? ']' : ')';
    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 += `.${_avoidKeywords(_snakeCase(name))}`;
      } else {
        expr += `${prefix}"${name}"${suffix}`;
      }
      current = ast.propertyPathTypes[i];
    }
    this.emit(expr);
  }