Skip to content

Commit c2c59b7

Browse files
committed
fix: fix the unit test failure problem caused by thisRequiredInJSE modification
1 parent 7e5a919 commit c2c59b7

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

packages/renderer-core/src/hoc/leaf.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
226226
nodeChildren: null,
227227
childrenInState: false,
228228
visible: !hidden,
229-
condition: __parseData(condition, scope),
229+
condition: __parseData?.(condition, scope),
230230
nodeCacheProps: {},
231231
nodeProps: {},
232232
};
@@ -396,7 +396,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
396396

397397
if (key === '___condition___') {
398398
const { condition = true } = this.leaf?.export(TransformStage.Render) || {};
399-
const conditionValue = __parseData(condition, scope);
399+
const conditionValue = __parseData?.(condition, scope);
400400
__debug(`key is ___condition___, change condition value to [${condition}]`);
401401
// 条件表达式改变
402402
this.setState({

packages/renderer-core/src/utils/common.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ export function forEach(targetObj: any, fn: any, context?: any) {
330330
Object.keys(targetObj).forEach((key) => fn.call(context, targetObj[key], key));
331331
}
332332

333-
export function parseData(schema: unknown, self: any, options: any): any {
333+
interface IParseOptions {
334+
thisRequiredInJSE?: boolean;
335+
}
336+
337+
export function parseData(schema: unknown, self: any, options: IParseOptions = {}): any {
334338
if (isJSExpression(schema)) {
335339
return parseExpression(schema, self, options.thisRequiredInJSE);
336340
} else if (isI18nData(schema)) {

packages/renderer-core/tests/hoc/leaf.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import '../utils/react-env-init';
55
import { leafWrapper } from '../../src/hoc/leaf';
66
import components from '../utils/components';
77
import Node from '../utils/node';
8+
import { parseData } from '../../src/utils';
89

910
let rerenderCount = 0;
1011

@@ -37,6 +38,9 @@ const baseRenderer: any = {
3738
}
3839
},
3940
documentId: '01'
41+
},
42+
__parseData (data, scope) {
43+
return parseData(data, scope, {});
4044
}
4145
}
4246

packages/renderer-core/tests/renderer/renderer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe('JSExpression', () => {
329329
],
330330
loop: {
331331
type: "JSExpression",
332-
value: "state.content"
332+
value: "this.state.content"
333333
},
334334
loopArgs: [
335335
"item",

0 commit comments

Comments
 (0)