| [9af201e] | 1 | import buildSourceMapTree from './build-source-map-tree';
|
|---|
| 2 | import { traceMappings } from './source-map-tree';
|
|---|
| 3 | import SourceMap from './source-map';
|
|---|
| 4 |
|
|---|
| 5 | import type { SourceMapInput, SourceMapLoader, Options } from './types';
|
|---|
| 6 | export type {
|
|---|
| 7 | SourceMapSegment,
|
|---|
| 8 | EncodedSourceMap,
|
|---|
| 9 | EncodedSourceMap as RawSourceMap,
|
|---|
| 10 | DecodedSourceMap,
|
|---|
| 11 | SourceMapInput,
|
|---|
| 12 | SourceMapLoader,
|
|---|
| 13 | LoaderContext,
|
|---|
| 14 | Options,
|
|---|
| 15 | } from './types';
|
|---|
| 16 | export type { SourceMap };
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Traces through all the mappings in the root sourcemap, through the sources
|
|---|
| 20 | * (and their sourcemaps), all the way back to the original source location.
|
|---|
| 21 | *
|
|---|
| 22 | * `loader` will be called every time we encounter a source file. If it returns
|
|---|
| 23 | * a sourcemap, we will recurse into that sourcemap to continue the trace. If
|
|---|
| 24 | * it returns a falsey value, that source file is treated as an original,
|
|---|
| 25 | * unmodified source file.
|
|---|
| 26 | *
|
|---|
| 27 | * Pass `excludeContent` to exclude any self-containing source file content
|
|---|
| 28 | * from the output sourcemap.
|
|---|
| 29 | *
|
|---|
| 30 | * Pass `decodedMappings` to receive a SourceMap with decoded (instead of
|
|---|
| 31 | * VLQ encoded) mappings.
|
|---|
| 32 | */
|
|---|
| 33 | export default function remapping(
|
|---|
| 34 | input: SourceMapInput | SourceMapInput[],
|
|---|
| 35 | loader: SourceMapLoader,
|
|---|
| 36 | options?: boolean | Options,
|
|---|
| 37 | ): SourceMap {
|
|---|
| 38 | const opts =
|
|---|
| 39 | typeof options === 'object' ? options : { excludeContent: !!options, decodedMappings: false };
|
|---|
| 40 | const tree = buildSourceMapTree(input, loader);
|
|---|
| 41 | return new SourceMap(traceMappings(tree), opts);
|
|---|
| 42 | }
|
|---|