mirror of
https://github.com/unjs/unplugin.git
synced 2026-02-01 16:56:37 +00:00
fix: cleanup sources in transform map
close https://github.com/antfu/unplugin-vue-components/issues/138
This commit is contained in:
parent
676bdc5085
commit
17dd24a708
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user