From 7f8b0c5d69783e91792e5c952cf684079d33561d Mon Sep 17 00:00:00 2001 From: imsunhao Date: Fri, 17 Oct 2025 18:17:07 +0800 Subject: [PATCH] refactor(vtable): unify toBoxArray return type and simplify box tuple logic --- packages/vtable/src/tools/helper.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/vtable/src/tools/helper.ts b/packages/vtable/src/tools/helper.ts index 2b95700525..a6c184b11c 100644 --- a/packages/vtable/src/tools/helper.ts +++ b/packages/vtable/src/tools/helper.ts @@ -236,21 +236,22 @@ function getIgnoreCase(obj: any, name: string): any { return undefined; } -export function toBoxArray(obj: T | T[]): [T, T, T, T] { +type BoxTuple = [top: T, right: T, bottom: T, left: T]; +export function toBoxArray(obj: T | T[]): BoxTuple { if (!Array.isArray(obj)) { - return [obj /*top*/, obj /*right*/, obj /*bottom*/, obj /*left*/]; + return [obj, obj, obj, obj]; } if (obj.length === 3) { - return [obj[0] /*top*/, obj[1] /*right*/, obj[2] /*bottom*/, obj[1] /*left*/]; + return [obj[0], obj[1], obj[2], obj[1]]; } if (obj.length === 2) { - return [obj[0] /*top*/, obj[1] /*right*/, obj[0] /*bottom*/, obj[1] /*left*/]; + return [obj[0], obj[1], obj[0], obj[1]]; } if (obj.length === 1) { - return [obj[0] /*top*/, obj[0] /*right*/, obj[0] /*bottom*/, obj[0] /*left*/]; + return [obj[0], obj[0], obj[0], obj[0]]; } // return obj as [T, T, T, T];//原先这种返回方式,会造成修改引用问题 - return [obj[0] /*top*/, obj[1] /*right*/, obj[2] /*bottom*/, obj[3] /*left*/]; + return [obj[0], obj[1], obj[2], obj[3]]; } export { isNode, getChainSafe, applyChainSafe, getOrApply, getIgnoreCase, array };