@jridgewell/trace-mapping
Advanced tools
Comparing version 0.3.7 to 0.3.8
@@ -338,2 +338,12 @@ (function (global, factory) { | ||
exports.presortedDecodedMap = void 0; | ||
/** | ||
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects | ||
* a sourcemap, or to JSON.stringify. | ||
*/ | ||
exports.decodedMap = void 0; | ||
/** | ||
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects | ||
* a sourcemap, or to JSON.stringify. | ||
*/ | ||
exports.encodedMap = void 0; | ||
class TraceMap { | ||
@@ -363,3 +373,3 @@ constructor(map, mapUrl) { | ||
this._encoded = mappings; | ||
this._decoded = sourcemapCodec.decode(mappings); | ||
this._decoded = undefined; | ||
} | ||
@@ -378,6 +388,11 @@ else { | ||
exports.decodedMappings = (map) => { | ||
return map._decoded; | ||
return (map._decoded || (map._decoded = sourcemapCodec.decode(map._encoded))); | ||
}; | ||
exports.traceSegment = (map, line, column) => { | ||
return traceOriginalSegment(map, line, column, GREATEST_LOWER_BOUND); | ||
const decoded = exports.decodedMappings(map); | ||
// It's common for parent source maps to have pointers to lines that have no | ||
// mapping (like a "//# sourceMappingURL=") at the end of the child file. | ||
if (line >= decoded.length) | ||
return null; | ||
return traceSegmentInternal(decoded[line], map._decodedMemo, line, column, GREATEST_LOWER_BOUND); | ||
}; | ||
@@ -390,3 +405,8 @@ exports.originalPositionFor = (map, { line, column, bias }) => { | ||
throw new Error(COL_GTR_EQ_ZERO); | ||
const segment = traceOriginalSegment(map, line, column, bias || GREATEST_LOWER_BOUND); | ||
const decoded = exports.decodedMappings(map); | ||
// It's common for parent source maps to have pointers to lines that have no | ||
// mapping (like a "//# sourceMappingURL=") at the end of the child file. | ||
if (line >= decoded.length) | ||
return INVALID_ORIGINAL_MAPPING; | ||
const segment = traceSegmentInternal(decoded[line], map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND); | ||
if (segment == null) | ||
@@ -416,3 +436,3 @@ return INVALID_ORIGINAL_MAPPING; | ||
return INVALID_GENERATED_MAPPING; | ||
const generated = (map._bySources || (map._bySources = buildBySources(map._decoded, (map._bySourceMemos = sources.map(memoizedState))))); | ||
const generated = (map._bySources || (map._bySources = buildBySources(exports.decodedMappings(map), (map._bySourceMemos = sources.map(memoizedState))))); | ||
const memos = map._bySourceMemos; | ||
@@ -431,3 +451,4 @@ const segments = generated[sourceIndex][line]; | ||
exports.eachMapping = (map, cb) => { | ||
const { _decoded: decoded, names, resolvedSources } = map; | ||
const decoded = exports.decodedMappings(map); | ||
const { names, resolvedSources } = map; | ||
for (let i = 0; i < decoded.length; i++) { | ||
@@ -468,22 +489,36 @@ const line = decoded[i]; | ||
}; | ||
function traceOriginalSegment(map, line, column, bias) { | ||
const decoded = map._decoded; | ||
// It's common for parent source maps to have pointers to lines that have no | ||
// mapping (like a "//# sourceMappingURL=") at the end of the child file. | ||
if (line >= decoded.length) | ||
return null; | ||
return traceSegmentInternal(decoded[line], map._decodedMemo, line, column, bias); | ||
exports.decodedMap = (map) => { | ||
return { | ||
version: 3, | ||
file: map.file, | ||
names: map.names, | ||
sourceRoot: map.sourceRoot, | ||
sources: map.sources, | ||
sourcesContent: map.sourcesContent, | ||
mappings: exports.decodedMappings(map), | ||
}; | ||
}; | ||
exports.encodedMap = (map) => { | ||
return { | ||
version: 3, | ||
file: map.file, | ||
names: map.names, | ||
sourceRoot: map.sourceRoot, | ||
sources: map.sources, | ||
sourcesContent: map.sourcesContent, | ||
mappings: exports.encodedMappings(map), | ||
}; | ||
}; | ||
})(); | ||
function traceSegmentInternal(segments, memo, line, column, bias) { | ||
let index = memoizedBinarySearch(segments, column, memo, line); | ||
if (found) { | ||
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index); | ||
} | ||
function traceSegmentInternal(segments, memo, line, column, bias) { | ||
let index = memoizedBinarySearch(segments, column, memo, line); | ||
if (found) { | ||
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index); | ||
} | ||
else if (bias === LEAST_UPPER_BOUND) | ||
index++; | ||
if (index === -1 || index === segments.length) | ||
return null; | ||
return segments[index]; | ||
} | ||
})(); | ||
else if (bias === LEAST_UPPER_BOUND) | ||
index++; | ||
if (index === -1 || index === segments.length) | ||
return null; | ||
return segments[index]; | ||
} | ||
@@ -490,0 +525,0 @@ exports.AnyMap = AnyMap; |
@@ -7,2 +7,2 @@ import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment'; | ||
}; | ||
export default function buildBySources(decoded: SourceMapSegment[][], memos: MemoState[]): Source[]; | ||
export default function buildBySources(decoded: readonly SourceMapSegment[][], memos: MemoState[]): Source[]; |
@@ -43,2 +43,14 @@ import type { SourceMapSegment } from './sourcemap-segment'; | ||
export declare let presortedDecodedMap: (map: DecodedSourceMap, mapUrl?: string) => TraceMap; | ||
/** | ||
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects | ||
* a sourcemap, or to JSON.stringify. | ||
*/ | ||
export declare let decodedMap: (map: TraceMap) => Omit<DecodedSourceMap, 'mappings'> & { | ||
mappings: readonly SourceMapSegment[][]; | ||
}; | ||
/** | ||
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects | ||
* a sourcemap, or to JSON.stringify. | ||
*/ | ||
export declare let encodedMap: (map: TraceMap) => EncodedSourceMap; | ||
export { AnyMap } from './any-map'; | ||
@@ -45,0 +57,0 @@ export declare class TraceMap implements SourceMap { |
{ | ||
"name": "@jridgewell/trace-mapping", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "Trace the original position through a source map", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
90725
1240