Skip to content

Commit 16a7d67

Browse files
committed
fix: 解决 defaultPlatformStr 可能为空的问题
1 parent c1d0a64 commit 16a7d67

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/core/src/context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,10 @@ function mergePlatformItems<T = any>(source: CommentArray<CommentObject> | undef
642642
platformUsage[v.platformStr] = (platformUsage[v.platformStr] || 0) + 1
643643
})
644644
})
645-
const defaultPlatformStr = Object.keys(platformUsage).reduce((a, b) => platformUsage[a] > platformUsage[b] ? a : b)
645+
const usageKeys = Object.keys(platformUsage)
646+
const defaultPlatformStr = usageKeys.length
647+
? usageKeys.reduce((a, b) => (platformUsage[a] > platformUsage[b] ? a : b))
648+
: currentPlatform
646649

647650
// 为 result 添加 Symbol.for(`before:0`) 添加生成标识注释
648651
result[Symbol.for('before:0') as CommentSymbol] = [{

0 commit comments

Comments
 (0)