fix: fix the unit test failure problem caused by thisRequiredInJSE modification

This commit is contained in:
liujuping 2022-06-24 16:01:43 +08:00 committed by 刘菊萍(絮黎)
parent 7e5a919f93
commit c2c59b7ff7
4 changed files with 12 additions and 4 deletions

View File

@ -226,7 +226,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
nodeChildren: null,
childrenInState: false,
visible: !hidden,
condition: __parseData(condition, scope),
condition: __parseData?.(condition, scope),
nodeCacheProps: {},
nodeProps: {},
};
@ -396,7 +396,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
if (key === '___condition___') {
const { condition = true } = this.leaf?.export(TransformStage.Render) || {};
const conditionValue = __parseData(condition, scope);
const conditionValue = __parseData?.(condition, scope);
__debug(`key is ___condition___, change condition value to [${condition}]`);
// 条件表达式改变
this.setState({

View File

@ -330,7 +330,11 @@ export function forEach(targetObj: any, fn: any, context?: any) {
Object.keys(targetObj).forEach((key) => fn.call(context, targetObj[key], key));
}
export function parseData(schema: unknown, self: any, options: any): any {
interface IParseOptions {
thisRequiredInJSE?: boolean;
}
export function parseData(schema: unknown, self: any, options: IParseOptions = {}): any {
if (isJSExpression(schema)) {
return parseExpression(schema, self, options.thisRequiredInJSE);
} else if (isI18nData(schema)) {

View File

@ -5,6 +5,7 @@ import '../utils/react-env-init';
import { leafWrapper } from '../../src/hoc/leaf';
import components from '../utils/components';
import Node from '../utils/node';
import { parseData } from '../../src/utils';
let rerenderCount = 0;
@ -37,6 +38,9 @@ const baseRenderer: any = {
}
},
documentId: '01'
},
__parseData (data, scope) {
return parseData(data, scope, {});
}
}

View File

@ -329,7 +329,7 @@ describe('JSExpression', () => {
],
loop: {
type: "JSExpression",
value: "state.content"
value: "this.state.content"
},
loopArgs: [
"item",