9ae52496c177e4c0305ae047541604d99d7e6a84379ddcd659a28f9725ba3169aae39994f600a6e85cb47fe6453918397ef6d5b686340ab428055a17442a95 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import type { SourceMapInput } from '@jridgewell/trace-mapping';
  2. import type { DecodedSourceMap, EncodedSourceMap, Pos, Mapping } from './types';
  3. export type { DecodedSourceMap, EncodedSourceMap, Mapping };
  4. export declare type Options = {
  5. file?: string | null;
  6. sourceRoot?: string | null;
  7. };
  8. /**
  9. * Provides the state to generate a sourcemap.
  10. */
  11. export declare class GenMapping {
  12. private _names;
  13. private _sources;
  14. private _sourcesContent;
  15. private _mappings;
  16. private _ignoreList;
  17. file: string | null | undefined;
  18. sourceRoot: string | null | undefined;
  19. constructor({ file, sourceRoot }?: Options);
  20. }
  21. /**
  22. * A low-level API to associate a generated position with an original source position. Line and
  23. * column here are 0-based, unlike `addMapping`.
  24. */
  25. export declare function addSegment(map: GenMapping, genLine: number, genColumn: number, source?: null, sourceLine?: null, sourceColumn?: null, name?: null, content?: null): void;
  26. export declare function addSegment(map: GenMapping, genLine: number, genColumn: number, source: string, sourceLine: number, sourceColumn: number, name?: null, content?: string | null): void;
  27. export declare function addSegment(map: GenMapping, genLine: number, genColumn: number, source: string, sourceLine: number, sourceColumn: number, name: string, content?: string | null): void;
  28. /**
  29. * A high-level API to associate a generated position with an original source position. Line is
  30. * 1-based, but column is 0-based, due to legacy behavior in `source-map` library.
  31. */
  32. export declare function addMapping(map: GenMapping, mapping: {
  33. generated: Pos;
  34. source?: null;
  35. original?: null;
  36. name?: null;
  37. content?: null;
  38. }): void;
  39. export declare function addMapping(map: GenMapping, mapping: {
  40. generated: Pos;
  41. source: string;
  42. original: Pos;
  43. name?: null;
  44. content?: string | null;
  45. }): void;
  46. export declare function addMapping(map: GenMapping, mapping: {
  47. generated: Pos;
  48. source: string;
  49. original: Pos;
  50. name: string;
  51. content?: string | null;
  52. }): void;
  53. /**
  54. * Same as `addSegment`, but will only add the segment if it generates useful information in the
  55. * resulting map. This only works correctly if segments are added **in order**, meaning you should
  56. * not add a segment with a lower generated line/column than one that came before.
  57. */
  58. export declare const maybeAddSegment: typeof addSegment;
  59. /**
  60. * Same as `addMapping`, but will only add the mapping if it generates useful information in the
  61. * resulting map. This only works correctly if mappings are added **in order**, meaning you should
  62. * not add a mapping with a lower generated line/column than one that came before.
  63. */
  64. export declare const maybeAddMapping: typeof addMapping;
  65. /**
  66. * Adds/removes the content of the source file to the source map.
  67. */
  68. export declare function setSourceContent(map: GenMapping, source: string, content: string | null): void;
  69. export declare function setIgnore(map: GenMapping, source: string, ignore?: boolean): void;
  70. /**
  71. * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
  72. * a sourcemap, or to JSON.stringify.
  73. */
  74. export declare function toDecodedMap(map: GenMapping): DecodedSourceMap;
  75. /**
  76. * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
  77. * a sourcemap, or to JSON.stringify.
  78. */
  79. export declare function toEncodedMap(map: GenMapping): EncodedSourceMap;
  80. /**
  81. * Constructs a new GenMapping, using the already present mappings of the input.
  82. */
  83. export declare function fromMap(input: SourceMapInput): GenMapping;
  84. /**
  85. * Returns an array of high-level mapping objects for every recorded segment, which could then be
  86. * passed to the `source-map` library.
  87. */
  88. export declare function allMappings(map: GenMapping): Mapping[];