From f93376241582ff98b5d9bc0434a0190b416e70d5 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 16 Jun 2022 11:53:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E5=A4=8D=E6=9D=82=E5=86=99=E6=B3=95=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=AD=A3=E7=A1=AE=E8=BF=94=E5=9B=9E=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/utils/isPureVariable.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/amis-core/src/utils/isPureVariable.ts b/packages/amis-core/src/utils/isPureVariable.ts index e06d2fd45..d5332b46f 100644 --- a/packages/amis-core/src/utils/isPureVariable.ts +++ b/packages/amis-core/src/utils/isPureVariable.ts @@ -1,5 +1,15 @@ +import {parse} from 'amis-formula'; + export function isPureVariable(path?: any): path is string { - return typeof path === 'string' - ? /^\$(?:((?:\w+\:)?[a-z0-9_.][a-z0-9_.\[\]]*)|{[^}{]+})$/i.test(path) - : false; + if (typeof path === 'string') { + try { + const ast = parse(path); + // 只有一个成员说明是纯表达式模式 + return ast.body.length === 1; + } catch (err) { + return false; + } + } + + return false; }