visitAssign()

in lib/common_generator.js [86:134]


  visitAssign(ast, level) {
    var isCollection = false;
    var isBuilder = false;
    if (ast.left.type === 'id') {
      this.emit(`${_name(ast.left.id)}`, level);
    } else if (ast.left.type === 'property_assign' || ast.left.type === 'property') {
      var id = _name(ast.left.id);
      if (id === '__request') {
        id = 'request_';
      }
      this.emit(`${id}`, level);
      for (var i = 0; i < ast.left.propertyPath.length; i++) {
        if ((i === ast.left.propertyPath.length - 1 && ast.left.propertyPathTypes[i - 1] && ast.left.propertyPathTypes[i - 1].type === 'map') ||
          (ast.left.id.inferred && ast.left.id.inferred.type === 'map')) {
          this.emit(`.put("${_name(ast.left.propertyPath[i])}", `);
          isCollection = true;
        } else {
          this.emit(` = ${id}.toBuilder().${_name(ast.left.propertyPath[i])}(`);
          isBuilder = true;
        }
      }
    } else if (ast.left.type === 'virtualVariable') {
      this.emit(`this.${_name(ast.left.vid).substr(1)}`, level);
    } else if (ast.left.type === 'variable') {
      this.emit(`${_name(ast.left.id)}`, level);
    } else if (ast.left.type === 'map_access') {
      isCollection = true;
      this.visitMapAccess(ast.left, false, level);
    } else if (ast.left.type === 'array_access') {
      isCollection = true;
      this.visitArrayAccess(ast.left, false, level);
    } else {
      throw new Error('unimpelemented');
    }
    if (!isCollection && !isBuilder) {
      this.emit(' = ');
    }
    this.visitExpr(ast.expr, level);
    if (isCollection) {
      this.emit(')');
    }
    if (isBuilder) {
      this.emit(').build()');
    }
    if (ast.expr.type === 'call' && ast.expr.isAsync) {
      this.emit(`.join()`);
    }
    this.emit(';\n');
  }