市场夺宝奇兵
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.

38 lines
1.3 KiB

  1. import { toDecodedMap, toEncodedMap } from '@jridgewell/gen-mapping';
  2. import type { GenMapping } from '@jridgewell/gen-mapping';
  3. import type { DecodedSourceMap, EncodedSourceMap, Options } from './types';
  4. /**
  5. * A SourceMap v3 compatible sourcemap, which only includes fields that were
  6. * provided to it.
  7. */
  8. export default class SourceMap {
  9. declare file?: string | null;
  10. declare mappings: EncodedSourceMap['mappings'] | DecodedSourceMap['mappings'];
  11. declare sourceRoot?: string;
  12. declare names: string[];
  13. declare sources: (string | null)[];
  14. declare sourcesContent?: (string | null)[];
  15. declare version: 3;
  16. declare ignoreList: number[] | undefined;
  17. constructor(map: GenMapping, options: Options) {
  18. const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
  19. this.version = out.version; // SourceMap spec says this should be first.
  20. this.file = out.file;
  21. this.mappings = out.mappings as SourceMap['mappings'];
  22. this.names = out.names as SourceMap['names'];
  23. this.ignoreList = out.ignoreList as SourceMap['ignoreList'];
  24. this.sourceRoot = out.sourceRoot;
  25. this.sources = out.sources as SourceMap['sources'];
  26. if (!options.excludeContent) {
  27. this.sourcesContent = out.sourcesContent as SourceMap['sourcesContent'];
  28. }
  29. }
  30. toString(): string {
  31. return JSON.stringify(this);
  32. }
  33. }