From 01ce70c06c2d7a3a71d62fe01639638918f53641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Thu, 24 Nov 2022 19:24:59 +0800 Subject: [PATCH] fix: make isJSExpression more robust --- packages/types/src/value-type.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/types/src/value-type.ts b/packages/types/src/value-type.ts index 933e9a698..a266cb9f3 100644 --- a/packages/types/src/value-type.ts +++ b/packages/types/src/value-type.ts @@ -128,8 +128,18 @@ export interface CompositeObject { [key: string]: CompositeValue; } +/** + * 为了避免把 { type: 'JSExpression', extType: 'function' } 误判为表达式,故增加如下逻辑。 + * + * 引擎中关于函数的表达: + * 开源版本:{ type: 'JSFunction', source: '', value: '' } + * 内部版本:{ type: 'JSExpression', source: '', value: '', extType: 'function' } + * 能力是对标的,不过开源的 react-renderer 只认识第一种,而内部只识别第二种(包括 Java 代码、RE)。 + * @param data + * @returns + */ export function isJSExpression(data: any): data is JSExpression { - return data && data.type === 'JSExpression'; + return data && data.type === 'JSExpression' && data.extType !== 'function'; } export function isJSFunction(x: any): x is JSFunction {