source-map.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. export interface StartOfSourceMap {
  2. file?: string;
  3. sourceRoot?: string;
  4. }
  5. export interface RawSourceMap extends StartOfSourceMap {
  6. version: string;
  7. sources: string[];
  8. names: string[];
  9. sourcesContent?: string[];
  10. mappings: string;
  11. }
  12. export interface Position {
  13. line: number;
  14. column: number;
  15. }
  16. export interface LineRange extends Position {
  17. lastColumn: number;
  18. }
  19. export interface FindPosition extends Position {
  20. // SourceMapConsumer.GREATEST_LOWER_BOUND or SourceMapConsumer.LEAST_UPPER_BOUND
  21. bias?: number;
  22. }
  23. export interface SourceFindPosition extends FindPosition {
  24. source: string;
  25. }
  26. export interface MappedPosition extends Position {
  27. source: string;
  28. name?: string;
  29. }
  30. export interface MappingItem {
  31. source: string | null;
  32. generatedLine: number;
  33. generatedColumn: number;
  34. originalLine: number | null;
  35. originalColumn: number | null;
  36. name: string | null;
  37. }
  38. export class SourceMapConsumer {
  39. static GENERATED_ORDER: number;
  40. static ORIGINAL_ORDER: number;
  41. static GREATEST_LOWER_BOUND: number;
  42. static LEAST_UPPER_BOUND: number;
  43. constructor(rawSourceMap: RawSourceMap);
  44. readonly file: string | undefined | null;
  45. readonly sourceRoot: string | undefined | null;
  46. readonly sourcesContent: readonly string[] | null | undefined;
  47. readonly sources: readonly string[]
  48. computeColumnSpans(): void;
  49. originalPositionFor(generatedPosition: FindPosition): MappedPosition;
  50. generatedPositionFor(originalPosition: SourceFindPosition): LineRange;
  51. allGeneratedPositionsFor(originalPosition: MappedPosition): Position[];
  52. hasContentsOfAllSources(): boolean;
  53. sourceContentFor(source: string, returnNullOnMissing?: boolean): string | null;
  54. eachMapping(callback: (mapping: MappingItem) => void, context?: any, order?: number): void;
  55. }
  56. export interface Mapping {
  57. generated: Position;
  58. original?: Position | null;
  59. source?: string | null;
  60. name?: string | null;
  61. }
  62. export class SourceMapGenerator {
  63. constructor(startOfSourceMap?: StartOfSourceMap);
  64. static fromSourceMap(sourceMapConsumer: SourceMapConsumer, startOfSourceMap?: StartOfSourceMap): SourceMapGenerator;
  65. addMapping(mapping: Mapping): void;
  66. setSourceContent(sourceFile: string, sourceContent: string | null | undefined): void;
  67. applySourceMap(sourceMapConsumer: SourceMapConsumer, sourceFile?: string, sourceMapPath?: string): void;
  68. toString(): string;
  69. toJSON(): RawSourceMap;
  70. }
  71. export interface CodeWithSourceMap {
  72. code: string;
  73. map: SourceMapGenerator;
  74. }
  75. export class SourceNode {
  76. constructor();
  77. constructor(line: number, column: number, source: string);
  78. constructor(line: number, column: number, source: string, chunk?: string, name?: string);
  79. static fromStringWithSourceMap(code: string, sourceMapConsumer: SourceMapConsumer, relativePath?: string): SourceNode;
  80. add(chunk: string): void;
  81. prepend(chunk: string): void;
  82. setSourceContent(sourceFile: string, sourceContent: string): void;
  83. walk(fn: (chunk: string, mapping: MappedPosition) => void): void;
  84. walkSourceContents(fn: (file: string, content: string) => void): void;
  85. join(sep: string): SourceNode;
  86. replaceRight(pattern: string, replacement: string): SourceNode;
  87. toString(): string;
  88. toStringWithSourceMap(startOfSourceMap?: StartOfSourceMap): CodeWithSourceMap;
  89. }