@@ -3,7 +3,10 @@ import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
3
3
import type { PluginContext , SourceMap , TransformPluginContext } from 'rollup'
4
4
import { normalizePath } from '@rollup/pluginutils'
5
5
import type { RawSourceMap } from 'source-map'
6
- import { SourceMapConsumer , SourceMapGenerator } from 'source-map'
6
+ import type { EncodedSourceMap as TraceEncodedSourceMap } from '@jridgewell/trace-mapping'
7
+ import { TraceMap , eachMapping } from '@jridgewell/trace-mapping'
8
+ import type { EncodedSourceMap as GenEncodedSourceMap } from '@jridgewell/gen-mapping'
9
+ import { addMapping , fromMap , toEncodedMap } from '@jridgewell/gen-mapping'
7
10
import { transformWithEsbuild } from 'vite'
8
11
import {
9
12
createDescriptor ,
@@ -158,13 +161,19 @@ export async function transformMain(
158
161
// of templateMap, we need to concatenate the two source maps.
159
162
let resolvedMap = options . sourceMap ? map : undefined
160
163
if ( resolvedMap && templateMap ) {
161
- const generator = SourceMapGenerator . fromSourceMap (
162
- new SourceMapConsumer ( map )
164
+ const gen = fromMap (
165
+ // version property of result.map is declared as string
166
+ // but actually it is `3`
167
+ map as Omit < RawSourceMap , 'version' > as TraceEncodedSourceMap
168
+ )
169
+ const tracer = new TraceMap (
170
+ // same above
171
+ templateMap as Omit < RawSourceMap , 'version' > as TraceEncodedSourceMap
163
172
)
164
173
const offset = ( scriptCode . match ( / \r ? \n / g) ?. length ?? 0 ) + 1
165
- const templateMapConsumer = new SourceMapConsumer ( templateMap )
166
- templateMapConsumer . eachMapping ( ( m ) => {
167
- generator . addMapping ( {
174
+ eachMapping ( tracer , ( m ) => {
175
+ if ( m . source == null ) return
176
+ addMapping ( gen , {
168
177
source : m . source ,
169
178
original : { line : m . originalLine , column : m . originalColumn } ,
170
179
generated : {
@@ -173,7 +182,12 @@ export async function transformMain(
173
182
}
174
183
} )
175
184
} )
176
- resolvedMap = ( generator as any ) . toJSON ( ) as RawSourceMap
185
+
186
+ // same above
187
+ resolvedMap = toEncodedMap ( gen ) as Omit <
188
+ GenEncodedSourceMap ,
189
+ 'version'
190
+ > as RawSourceMap
177
191
// if this is a template only update, we will be reusing a cached version
178
192
// of the main module compile result, which has outdated sourcesContent.
179
193
resolvedMap . sourcesContent = templateMap . sourcesContent
0 commit comments