check modules when validating expression

This commit is contained in:
Bowen Tan 2022-01-27 14:08:10 +08:00
parent cc21a427e0
commit b874ca203d
3 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import {
ComponentType,
IAppModel,
IComponentModel,
ModuleId,
SlotName,
} from './IAppModel';
import { genComponent } from './utils';
@ -36,6 +37,10 @@ export class AppModel implements IAppModel {
return Object.values(this.componentMap);
}
get moduleIds(): ModuleId[] {
return this.allComponents.filter(c => c.type === 'core/v1/moduleContainer').map(c => c.properties.rawValue.id);
}
toSchema(): ComponentSchema[] {
this.schema = this.allComponents.map(c => {
return c.toSchema();

View File

@ -39,6 +39,7 @@ export type EventName = string & {
export interface IAppModel {
topComponents: IComponentModel[];
// modules: IModuleModel[];
moduleIds: ModuleId[];
// generated by traverse the tree. Component will be overwritten if its id is duplicated.
allComponents: IComponentModel[];
// all components, including orphan component

View File

@ -1,5 +1,5 @@
import { get, has } from 'lodash-es';
import { ComponentId } from '../../AppModel/IAppModel';
import { ComponentId, ModuleId } from '../../AppModel/IAppModel';
import {
PropertiesValidatorRule,
PropertiesValidateContext,
@ -97,8 +97,11 @@ class ExpressionValidatorRule implements PropertiesValidatorRule {
break;
}
}
} else if (appModel.moduleIds.includes(id as ModuleId)) {
// case 3: id is a module
// TODO: check module stateMap
} else {
// case 3: id doesn't exist
// case 4: id doesn't exist
results.push({
message: `Cannot find '${id}' in store or window.`,
componentId: component.id,