1
- var SourceMapConsumer = require ( '@cspotcode/source-map-consumer' ) . SourceMapConsumer ;
1
+ const { TraceMap , originalPositionFor , AnyMap } = require ( '@jridgewell/trace-mapping' ) ;
2
2
var path = require ( 'path' ) ;
3
3
var util = require ( 'util' ) ;
4
4
@@ -95,6 +95,7 @@ var sharedData = initializeSharedData({
95
95
fileContentsCache : { } ,
96
96
97
97
// Maps a file path to a source map for that file
98
+ /** @type {Record<string, {url: string, map: TraceMap} } */
98
99
sourceMapCache : { } ,
99
100
100
101
// Priority list of retrieve handlers
@@ -234,6 +235,7 @@ function retrieveSourceMapURL(source) {
234
235
// there is no source map. The map field may be either a string or the parsed
235
236
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
236
237
// constructor).
238
+ /** @type {(source: string) => import('./source-map-support').UrlAndMap | null } */
237
239
var retrieveSourceMap = handlerExec ( sharedData . retrieveMapHandlers , sharedData . internalRetrieveMapHandlers ) ;
238
240
sharedData . internalRetrieveMapHandlers . push ( function ( source ) {
239
241
var sourceMappingURL = retrieveSourceMapURL ( source ) ;
@@ -270,7 +272,7 @@ function mapSourcePosition(position) {
270
272
if ( urlAndMap ) {
271
273
sourceMap = sharedData . sourceMapCache [ position . source ] = {
272
274
url : urlAndMap . url ,
273
- map : new SourceMapConsumer ( urlAndMap . map )
275
+ map : new AnyMap ( urlAndMap . map , urlAndMap . url )
274
276
} ;
275
277
276
278
// Load all sources stored inline with the source map into the file cache
@@ -293,8 +295,8 @@ function mapSourcePosition(position) {
293
295
}
294
296
295
297
// Resolve the source URL relative to the URL of the source map
296
- if ( sourceMap && sourceMap . map && typeof sourceMap . map . originalPositionFor === 'function' ) {
297
- var originalPosition = sourceMap . map . originalPositionFor ( position ) ;
298
+ if ( sourceMap && sourceMap . map ) {
299
+ var originalPosition = originalPositionFor ( sourceMap . map , position ) ;
298
300
299
301
// Only return the original position if a matching line was found. If no
300
302
// matching line is found then we return position instead, which will cause
0 commit comments