Skip to content

Commit

Permalink
switch to @jridgewell/trace-mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Apr 21, 2022
1 parent 817f84b commit c6aa032
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
48 changes: 38 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -18,7 +18,7 @@
"/source-map-support.js"
],
"dependencies": {
"@cspotcode/source-map-consumer": "0.8.0"
"@jridgewell/trace-mapping": "0.3.9"
},
"devDependencies": {
"browserify": "^4.2.3",
Expand Down
10 changes: 9 additions & 1 deletion source-map-support.d.ts
Expand Up @@ -6,7 +6,15 @@
// Griffin Yourick <https://github.com/tough-griff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import { RawSourceMap } from '@cspotcode/source-map-consumer';
export interface RawSourceMap {
version: 3;
sources: string[];
names: string[];
sourceRoot?: string;
sourcesContent?: string[];
mappings: string;
file: string;
}

/**
* Output of retrieveSourceMap().
Expand Down
10 changes: 6 additions & 4 deletions source-map-support.js
@@ -1,4 +1,4 @@
var SourceMapConsumer = require('@cspotcode/source-map-consumer').SourceMapConsumer;
const { TraceMap, originalPositionFor, AnyMap } = require('@jridgewell/trace-mapping');
var path = require('path');
var util = require('util');

Expand Down Expand Up @@ -95,6 +95,7 @@ var sharedData = initializeSharedData({
fileContentsCache: {},

// Maps a file path to a source map for that file
/** @type {Record<string, {url: string, map: TraceMap}} */
sourceMapCache: {},

// Priority list of retrieve handlers
Expand Down Expand Up @@ -234,6 +235,7 @@ function retrieveSourceMapURL(source) {
// there is no source map. The map field may be either a string or the parsed
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
// constructor).
/** @type {(source: string) => import('./source-map-support').UrlAndMap | null} */
var retrieveSourceMap = handlerExec(sharedData.retrieveMapHandlers, sharedData.internalRetrieveMapHandlers);
sharedData.internalRetrieveMapHandlers.push(function(source) {
var sourceMappingURL = retrieveSourceMapURL(source);
Expand Down Expand Up @@ -270,7 +272,7 @@ function mapSourcePosition(position) {
if (urlAndMap) {
sourceMap = sharedData.sourceMapCache[position.source] = {
url: urlAndMap.url,
map: new SourceMapConsumer(urlAndMap.map)
map: new AnyMap(urlAndMap.map, urlAndMap.url)
};

// Load all sources stored inline with the source map into the file cache
Expand All @@ -293,8 +295,8 @@ function mapSourcePosition(position) {
}

// Resolve the source URL relative to the URL of the source map
if (sourceMap && sourceMap.map && typeof sourceMap.map.originalPositionFor === 'function') {
var originalPosition = sourceMap.map.originalPositionFor(position);
if (sourceMap && sourceMap.map) {
var originalPosition = originalPositionFor(sourceMap.map, position);

// Only return the original position if a matching line was found. If no
// matching line is found then we return position instead, which will cause
Expand Down

0 comments on commit c6aa032

Please sign in to comment.