From 1b9e99c22a24aade0b69ce4e1229c935f7da182c Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 14 Jun 2024 20:35:44 +0800 Subject: [PATCH] fix array check --- .../validator/expression-validator.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/schema/src/language-server/validator/expression-validator.ts b/packages/schema/src/language-server/validator/expression-validator.ts index ab6bc6f10..7f24f1f60 100644 --- a/packages/schema/src/language-server/validator/expression-validator.ts +++ b/packages/schema/src/language-server/validator/expression-validator.ts @@ -4,6 +4,7 @@ import { DataModelAttribute, Expression, ExpressionType, + isArrayExpr, isDataModel, isDataModelAttribute, isDataModelField, @@ -284,9 +285,18 @@ export default class ExpressionValidator implements AstValidator { return findUpAst(node, (n) => isDataModelAttribute(n) && n.decl.$refText === '@@validate'); } - private isNotModelFieldExpr(expr: Expression) { + private isNotModelFieldExpr(expr: Expression): boolean { return ( - isLiteralExpr(expr) || isEnumFieldReference(expr) || isNullExpr(expr) || this.isAuthOrAuthMemberAccess(expr) + // literal + isLiteralExpr(expr) || + // enum field + isEnumFieldReference(expr) || + // null + isNullExpr(expr) || + // `auth()` access + this.isAuthOrAuthMemberAccess(expr) || + // array + (isArrayExpr(expr) && expr.items.every((item) => this.isNotModelFieldExpr(item))) ); }