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.

115 lines
3.8 KiB

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