getExprVars()

in lib/generator.js [948:1051]


  getExprVars(ast) {
    let vars = [];
    if (ast.type === 'property_access') {
      vars.push({
        name: this.getName(ast),
        type: ast.id.inferred,
      });
    } else if (ast.type === 'object') {
      vars.concat(this.getObjectVars(ast));
    } else if (ast.type === 'variable') {
      vars.push({
        name: this.getName(ast),
        type: ast.inferred,
      });
    } else if (ast.type === 'virtualVariable') {
      vars.push({
        name: 'client',
        type: this.structName,
      });
    } else if (ast.type === 'decrement') {
      vars = vars.concat(this.getExprVars(ast.expr));
    } else if (ast.type === 'increment') {
      vars = vars.concat(this.getExprVars(ast.expr));
    } else if (ast.type === 'template_string') {
      for (let i = 0; i < ast.elements.length; i++) {
        const item = ast.elements[i];
        if (item.type === 'expr') {
          const expr = item.expr;
          vars = vars.concat(this.getExprVars(expr));
        }
      }
    } else if (ast.type === 'call') {
      for (let i = 0; i < ast.args.length; i++) {
        const expr = ast.args[i];
        vars = vars.concat(this.getExprVars(expr));
      }

      if(ast.left.type === 'instance_call') {

        if (_name(ast.left.id).indexOf('@') === 0) {
          vars.push({
            name: 'client',
            type: this.structName,
          });
        } else {
          const type = this.getModuleType(ast.left.id.moduleType);
          vars.push({
            name: _name(ast.left.id),
            type: type
          });
        }
      } else if(ast.left.type === 'method_call') {
        const name = _format(_name(ast.left.id));
        if (name.startsWith('$') && this.builtin[name]) {
          return vars;
        } 
        if (!ast.isStatic) {
          vars.push({
            name: 'client',
            type: this.structName,
          });
        }
      }
    } else if (ast.type === 'group') {
      vars = vars.concat(this.getExprVars(ast.expr));
    } else if (_isBinaryOp(ast.type)) {
      vars = vars.concat(this.getExprVars(ast.left));
      vars = vars.concat(this.getExprVars(ast.right));
    } else if (ast.type === 'construct') {
      for (let i = 0; i < ast.args.length; i++) {
        vars = vars.concat(this.getExprVars(ast.args[i]));
      }
    } else if (ast.type === 'construct_model' && ast.object) {
      vars = vars.concat(this.getObjectVars(ast.object));
    } else if (ast.type === 'not') {
      vars = vars.concat(this.getExprVars(ast.expr));
    } else if (ast.type === 'array') {
      for (let i = 0; i < ast.items.length; i++) {
        vars = vars.concat(this.getExprVars(ast.items[i]));
      }
    } else if (ast.type === 'map_access') {
      vars.push({
        name: this.getName(ast),
        type: {
          type: 'map', 
          keyType: { 
            type: 'basic', 
            name: 'string' 
          }, 
          valueType: ast.inferred 
        },
      });
    } else if (ast.type === 'array_access') {
      vars.push({
        name: this.getName(ast),
        type: { type: 'array', itemType: ast.inferred },
      });
    } else if (ast.type === 'super') {
      for (let i = 0; i < ast.args.length; i++) {
        vars = vars.concat(this.getExprVars(ast.args[i]));
      }
    }
    return vars;
  }