checkId()

in lib/semantic.js [1656:1698]


  checkId(id, env) {
    if (id.tag === Tag.VID) {
      return this.checkVid(id, env);
    }
    // 未定义变量检查
    const name = id.lexeme;
    if (env.local && env.local.hasDefined(name)) {
      // 是否在作用域链上定义过
      id.type = 'variable';
      return;
    }

    if (this.models.has(name)) {
      id.type = 'model';
      // model 类型
      return;
    }

    if (builtin.has(name)) {
      // alias 
      id.type = 'builtin_module';
      return;
    }

    if (this.dependencies.has(name)) {
      // alias 
      id.type = 'module';
      return;
    }

    if (this.enums.has(name)) {
      // alias 
      id.type = 'enum';
      return;
    }

    if (isTmpVariable(id.type)) {
      this.visitExpr(id, env);
      return;
    }
    
    this.error(`variable "${name}" undefined`, id);
  }