visitConstructModel()

in lib/semantic.js [2286:2341]


  visitConstructModel(ast, env) {
    
    const aliasId = ast.aliasId.lexeme;
    if (this.dependencies.has(aliasId)) {
      ast.aliasId.isModule = true;
      const checker = this.dependencies.get(aliasId);
      const modelId = ast.propertyPath.map((item) => {
        return item.lexeme;
      }).join('.');
      const model = checker.models.get(modelId);
      if (!model) {
        this.error(`the model "${modelId}" is undefined in module "${aliasId}"`, ast.propertyPath[0]);
      }
      ast.aliasId.isException = model.isException;

      this.usedExternModel.get(aliasId).add(modelId);
      this.checkConstructModelFields(ast, model, `${modelId}`, env);
      return;
    }

    if (builtin.has(aliasId)) {
      const model = builtin.get(aliasId);
      assert.ok(model.type === 'model');
      ast.aliasId.isModel = true;
      this.checkConstructModelFields(ast, model, aliasId, env);
      return;
    }

    if (this.models.has(aliasId)) {
      const model = this.models.get(aliasId);
      ast.aliasId.isModel = true;
      ast.aliasId.isException = model.isException;
      if (ast.propertyPath.length === 0) {
        this.checkConstructModelFields(ast, model, aliasId, env);
        return;
      }

      const fullPath = [aliasId, ...ast.propertyPath.map((item) => {
        return item.lexeme;
      })];

      for (let i = 1; i < fullPath.length; i++) {
        const subModelName = fullPath.slice(0, i + 1).join('.');
        if (!this.models.has(subModelName)) {
          this.error(`the model "${subModelName}" is undefined`, ast.propertyPath[i]);
        }
      }

      const modelName = fullPath.join('.');
      const subModel = this.models.get(modelName);
      this.checkConstructModelFields(ast, subModel, modelName, env);
      return;
    }
    
    this.error(`expected "${aliasId}" is module or model`, ast.aliasId);
  }