From 280f528dc3a85fd714340726b84ef24a5b51a873 Mon Sep 17 00:00:00 2001 From: hkaikai <617760820@qq.com> Date: Fri, 1 Dec 2023 20:08:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixed=20the=20problem=20t?= =?UTF-8?q?hat=20rawSourceMap=20may=20be=20a=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed the problem that rawSourceMap may be a string, causing the coverage plug-in to report an error ✅ Closes: #32 --- src/loader/webpack5-istanbul-loader.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/loader/webpack5-istanbul-loader.ts b/src/loader/webpack5-istanbul-loader.ts index 2d21da7..6410ffe 100644 --- a/src/loader/webpack5-istanbul-loader.ts +++ b/src/loader/webpack5-istanbul-loader.ts @@ -25,7 +25,8 @@ type RawSourceMap = { names?: string[]; }; -function sanitizeSourceMap(rawSourceMap: RawSourceMap): RawSourceMap { +function sanitizeSourceMap(rawSourceMap: RawSourceMap | string): RawSourceMap { + if (typeof rawSourceMap === 'string') return JSON.parse(rawSourceMap); const { sourcesContent, ...sourceMap } = rawSourceMap ?? {}; // JSON parse/stringify trick required for istanbul to accept the SourceMap