@jridgewell/trace-mapping
Advanced tools
Comparing version 0.3.10 to 0.3.11
@@ -342,2 +342,6 @@ (function (global, factory) { | ||
/** | ||
* Retrieves the source content for a particular source, if its found. Returns null if not. | ||
*/ | ||
exports.sourceContentFor = void 0; | ||
/** | ||
* A helper that skips sorting of the input map's mappings array, which can be expensive for larger | ||
@@ -487,2 +491,11 @@ * maps. | ||
}; | ||
exports.sourceContentFor = (map, source) => { | ||
const { sources, resolvedSources, sourcesContent } = map; | ||
if (sourcesContent == null) | ||
return null; | ||
let index = sources.indexOf(source); | ||
if (index === -1) | ||
index = resolvedSources.indexOf(source); | ||
return index === -1 ? null : sourcesContent[index]; | ||
}; | ||
exports.presortedDecodedMap = (map, mapUrl) => { | ||
@@ -489,0 +502,0 @@ const clone = Object.assign({}, map); |
@@ -39,2 +39,6 @@ import type { SourceMapSegment } from './sourcemap-segment'; | ||
/** | ||
* Retrieves the source content for a particular source, if its found. Returns null if not. | ||
*/ | ||
export declare let sourceContentFor: (map: TraceMap, source: string) => string | null; | ||
/** | ||
* A helper that skips sorting of the input map's mappings array, which can be expensive for larger | ||
@@ -41,0 +45,0 @@ * maps. |
{ | ||
"name": "@jridgewell/trace-mapping", | ||
"version": "0.3.10", | ||
"version": "0.3.11", | ||
"description": "Trace the original position through a source map", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -20,3 +20,8 @@ # @jridgewell/trace-mapping | ||
```typescript | ||
import { TraceMap, originalPositionFor, generatedPositionFor } from '@jridgewell/trace-mapping'; | ||
import { | ||
TraceMap, | ||
originalPositionFor, | ||
generatedPositionFor, | ||
sourceContentFor, | ||
} from '@jridgewell/trace-mapping'; | ||
@@ -26,2 +31,3 @@ const tracer = new TraceMap({ | ||
sources: ['input.js'], | ||
sourcesContent: ['content of input.js'], | ||
names: ['foo'], | ||
@@ -40,2 +46,5 @@ mappings: 'KAyCIA', | ||
const content = sourceContentFor(tracer, traced.source); | ||
assert.strictEqual(content, 'content for input.js'); | ||
const generated = generatedPositionFor(tracer, { | ||
@@ -42,0 +51,0 @@ source: 'input.js', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
97112
1291
253