1- var SourceMapConsumer = require ( '@cspotcode/source-map-consumer' ) . SourceMapConsumer ;
1+ const { TraceMap , originalPositionFor , AnyMap } = require ( '@jridgewell/trace-mapping' ) ;
22var path = require ( 'path' ) ;
33var util = require ( 'util' ) ;
44
@@ -95,6 +95,7 @@ var sharedData = initializeSharedData({
9595 fileContentsCache : { } ,
9696
9797 // Maps a file path to a source map for that file
98+ /** @type {Record<string, {url: string, map: TraceMap} } */
9899 sourceMapCache : { } ,
99100
100101 // Priority list of retrieve handlers
@@ -234,6 +235,7 @@ function retrieveSourceMapURL(source) {
234235// there is no source map. The map field may be either a string or the parsed
235236// JSON object (ie, it must be a valid argument to the SourceMapConsumer
236237// constructor).
238+ /** @type {(source: string) => import('./source-map-support').UrlAndMap | null } */
237239var retrieveSourceMap = handlerExec ( sharedData . retrieveMapHandlers , sharedData . internalRetrieveMapHandlers ) ;
238240sharedData . internalRetrieveMapHandlers . push ( function ( source ) {
239241 var sourceMappingURL = retrieveSourceMapURL ( source ) ;
@@ -270,7 +272,7 @@ function mapSourcePosition(position) {
270272 if ( urlAndMap ) {
271273 sourceMap = sharedData . sourceMapCache [ position . source ] = {
272274 url : urlAndMap . url ,
273- map : new SourceMapConsumer ( urlAndMap . map )
275+ map : new AnyMap ( urlAndMap . map , urlAndMap . url )
274276 } ;
275277
276278 // Load all sources stored inline with the source map into the file cache
@@ -293,8 +295,8 @@ function mapSourcePosition(position) {
293295 }
294296
295297 // 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 ) ;
298300
299301 // Only return the original position if a matching line was found. If no
300302 // matching line is found then we return position instead, which will cause
0 commit comments