fix: cleanup sources in transform map

close https://github.com/antfu/unplugin-vue-components/issues/138
This commit is contained in:
Anthony Fu 2021-09-16 08:56:25 +08:00
parent 676bdc5085
commit 17dd24a708

View File

@ -19,7 +19,23 @@ export default async function transform (this: LoaderContext<any>, source: strin
if (res == null) {
callback(null, source, map)
} else if (typeof res !== 'string') {
callback(null, res.code, map == null ? map : (res.map || map))
// only pass sourcemap when sourcemap is provided upstream
const newMap = map == null ? map : (res.map || map)
// clean up nullish sources produced by magic-string
if (newMap && Array.isArray(newMap.sources)) {
const excluded: number[] = []
newMap.sources = newMap.sources.filter((i:any, idx:number) => {
if (i == null) {
excluded.push(idx)
return false
}
return true
})
newMap.sources = newMap.sources.filter((_: any, idx: number) => {
return !excluded.includes(idx)
})
}
callback(null, res.code, newMap)
} else {
callback(null, res, map)
}