calculatePropertyType()

in lib/semantic.js [2629:2678]


  calculatePropertyType(ast, env) {
    const type = this.getVariableType(ast.id, env);

    if(!ast.id.inferred) {
      ast.id.inferred = type;
    }

    if(!ast.propertyPathTypes) {
      ast.propertyPathTypes = new Array(ast.propertyPath.length);
    }
    
    if (type.type === 'model' || type.type === 'map') {
      let current = type;
      for (let i = 0; i < ast.propertyPath.length; i++) {
        let prop = ast.propertyPath[i];
        current = this.getPropertyType(current, prop.lexeme);
        ast.propertyPathTypes[i] = current;
      }

      return current;
    }
    
    if (this.enums.has(ast.id.lexeme)) {
      return _enum(ast.id.lexeme);
    }

    if (this.models.has(ast.id.lexeme)) {
      return _basic('class');
    }

    if(builtin.get(ast.id.lexeme)) {
      const builtinModel = builtin.get(ast.id.lexeme);
      if(builtinModel.type === 'model') {
        return _model(ast.id.lexeme);
      }
    }
  

    if (this.dependencies.has(ast.id.lexeme)) {
      const checker = this.dependencies.get(ast.id.lexeme);
      const [ mainType ] = ast.propertyPath;
      if (checker.enums.has(mainType.lexeme)) {
        return _enum(mainType.lexeme, ast.id.lexeme);
      }
      return _basic('class');
    }

    console.log(ast);
    throw new Error('unknown type');
  }