市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

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