Skip to content

Commit c6aa032

Browse files
committed
switch to @jridgewell/trace-mapping
1 parent 817f84b commit c6aa032

File tree

4 files changed

+54
-16
lines changed

4 files changed

+54
-16
lines changed

package-lock.json

Lines changed: 38 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"/source-map-support.js"
1919
],
2020
"dependencies": {
21-
"@cspotcode/source-map-consumer": "0.8.0"
21+
"@jridgewell/trace-mapping": "0.3.9"
2222
},
2323
"devDependencies": {
2424
"browserify": "^4.2.3",

source-map-support.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
// Griffin Yourick <https://github.com/tough-griff>
77
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
88

9-
import { RawSourceMap } from '@cspotcode/source-map-consumer';
9+
export interface RawSourceMap {
10+
version: 3;
11+
sources: string[];
12+
names: string[];
13+
sourceRoot?: string;
14+
sourcesContent?: string[];
15+
mappings: string;
16+
file: string;
17+
}
1018

1119
/**
1220
* Output of retrieveSourceMap().

source-map-support.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var SourceMapConsumer = require('@cspotcode/source-map-consumer').SourceMapConsumer;
1+
const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
22
var path = require('path');
33
var 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} */
237239
var retrieveSourceMap = handlerExec(sharedData.retrieveMapHandlers, sharedData.internalRetrieveMapHandlers);
238240
sharedData.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

Comments
 (0)