Skip to content

Commit 3107aad

Browse files
committed
fix: 🐛 修复部分异常JSExpression返回值,减少Error
1 parent b36a5a0 commit 3107aad

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/datasource-engine/src/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ function isObject(obj: unknown) {
1818
}
1919

2020
export const transformExpression = (code: string, context: IDataSourceRuntimeContext) => {
21+
// 补充异常情况兼容性
22+
if (code === undefined) {
23+
return function () {};
24+
}
25+
if (code === '') {
26+
return function () { return ''; };
27+
}
2128
try {
2229
return new Function(`return (${code})`).call(context);
2330
} catch (error) {
@@ -26,6 +33,12 @@ export const transformExpression = (code: string, context: IDataSourceRuntimeCon
2633
};
2734

2835
export const transformFunction = (code: string, context: IDataSourceRuntimeContext) => {
36+
if (code === undefined) {
37+
return function () {};
38+
}
39+
if (code === '') {
40+
return function () { return ''; };
41+
}
2942
try {
3043
return new Function(`return (${code})`).call(context).bind(context);
3144
} catch (error) {

0 commit comments

Comments
 (0)