From 76f5ee4cf80552efac75cc62707611e94b934148 Mon Sep 17 00:00:00 2001 From: eternalsky Date: Mon, 13 Feb 2023 10:09:10 +0800 Subject: [PATCH] feat: console the expression error --- modules/code-generator/src/generator/ProjectBuilder.ts | 2 +- modules/code-generator/src/utils/jsExpression.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/code-generator/src/generator/ProjectBuilder.ts b/modules/code-generator/src/generator/ProjectBuilder.ts index 040136057..6db81b0d7 100644 --- a/modules/code-generator/src/generator/ProjectBuilder.ts +++ b/modules/code-generator/src/generator/ProjectBuilder.ts @@ -328,7 +328,7 @@ export class ProjectBuilder implements IProjectBuilder { // template: this.template, inStrictMode: this.inStrictMode, tolerateEvalErrors: true, - evalErrorsHandler: '', + evalErrorsHandler: 'console.error(error)', ...this.extraContextData, ...extraContextData, }, diff --git a/modules/code-generator/src/utils/jsExpression.ts b/modules/code-generator/src/utils/jsExpression.ts index 25c7f47fd..08d2fafd8 100644 --- a/modules/code-generator/src/utils/jsExpression.ts +++ b/modules/code-generator/src/utils/jsExpression.ts @@ -79,7 +79,12 @@ function getBodyStatements(content: string) { throw new Error('Can not find Function Statement'); } -export function isJsCode(value: unknown): boolean { +/** + * 是否是广义上的 JSFunction + * @param value + * @returns + */ +export function isBroadJSFunction(value: unknown): boolean { return isJSExpressionFn(value) || isJSFunction(value); } @@ -117,7 +122,7 @@ export function generateFunction( isBindExpr: false, }, ) { - if (isJsCode(value)) { + if (isBroadJSFunction(value)) { const functionCfg = value as IPublicTypeJSFunction; const functionSource = getFunctionSource(functionCfg); if (config.isMember) {