From 87118b88f0e181cf7dd337076b617ac9d385360f Mon Sep 17 00:00:00 2001 From: liujuping Date: Mon, 12 Jun 2023 14:45:10 +0800 Subject: [PATCH] fix(render-core): fix when designMode is false & loop is null, isUseLoop should return true --- packages/renderer-core/jest.config.js | 1 + packages/renderer-core/src/utils/is-use-loop.ts | 8 ++++---- packages/renderer-core/tests/utils/is-use-loop.test.ts | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/renderer-core/jest.config.js b/packages/renderer-core/jest.config.js index e3267c517..1ea4204de 100644 --- a/packages/renderer-core/jest.config.js +++ b/packages/renderer-core/jest.config.js @@ -13,6 +13,7 @@ const jestConfig = { // testMatch: ['**/*/base.test.tsx'], // testMatch: ['**/utils/common.test.ts'], // testMatch: ['**/*/leaf.test.tsx'], + // testMatch: ['**/*/is-use-loop.test.ts'], transformIgnorePatterns: [ `/node_modules/(?!${esModules})/`, ], diff --git a/packages/renderer-core/src/utils/is-use-loop.ts b/packages/renderer-core/src/utils/is-use-loop.ts index 509450d94..b6d67a802 100644 --- a/packages/renderer-core/src/utils/is-use-loop.ts +++ b/packages/renderer-core/src/utils/is-use-loop.ts @@ -8,13 +8,13 @@ export default function isUseLoop(loop: null | any[] | IPublicTypeJSExpression, return true; } - if (!Array.isArray(loop)) { - return false; - } - if (!isDesignMode) { return true; } + if (!Array.isArray(loop)) { + return false; + } + return loop.length > 0; } diff --git a/packages/renderer-core/tests/utils/is-use-loop.test.ts b/packages/renderer-core/tests/utils/is-use-loop.test.ts index 5f502a2e5..b0a614f2e 100644 --- a/packages/renderer-core/tests/utils/is-use-loop.test.ts +++ b/packages/renderer-core/tests/utils/is-use-loop.test.ts @@ -5,6 +5,9 @@ describe('base test', () => { it('designMode is true', () => { expect(isUseLoop([], true)).toBeFalsy(); expect(isUseLoop([{}], true)).toBeTruthy(); + expect(isUseLoop(null, true)).toBeFalsy(); + expect(isUseLoop(undefined, true)).toBeFalsy(); + expect(isUseLoop(0, true)).toBeFalsy(); }); it('loop is expression', () => { @@ -21,5 +24,8 @@ describe('base test', () => { it('designMode is false', () => { expect(isUseLoop([], false)).toBeTruthy(); expect(isUseLoop([{}], false)).toBeTruthy(); + expect(isUseLoop(null, false)).toBeTruthy(); + expect(isUseLoop(undefined, false)).toBeTruthy(); + expect(isUseLoop(0, false)).toBeTruthy(); }); });