1
+ // Type definitions for source-map 0.5
2
+ // Project: https://github.com/mozilla/source-map
3
+ // Definitions by: Morten Houston Ludvigsen <https://github.com/MortenHoustonLudvigsen>,
4
+ // Ron Buckton <https://github.com/rbuckton>
5
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
1
6
export interface StartOfSourceMap {
2
7
file ?: string ;
3
8
sourceRoot ?: string ;
9
+ skipValidation ?: boolean ;
4
10
}
5
11
6
- export interface RawSourceMap extends StartOfSourceMap {
7
- version : string ;
12
+ export interface RawSourceMap {
13
+ version : number ;
8
14
sources : string [ ] ;
9
15
names : string [ ] ;
16
+ sourceRoot ?: string ;
10
17
sourcesContent ?: string [ ] ;
11
18
mappings : string ;
19
+ file : string ;
12
20
}
13
21
14
- export interface Position {
15
- line : number ;
16
- column : number ;
22
+ export interface RawIndexMap extends StartOfSourceMap {
23
+ version : number ;
24
+ sections : RawSection [ ] ;
17
25
}
18
26
19
- export interface LineRange extends Position {
20
- lastColumn : number ;
27
+ export interface RawSection {
28
+ offset : Position ;
29
+ map : RawSourceMap ;
21
30
}
22
31
23
- export interface FindPosition extends Position {
24
- // SourceMapConsumer.GREATEST_LOWER_BOUND or SourceMapConsumer.LEAST_UPPER_BOUND
25
- bias ? : number ;
32
+ export interface Position {
33
+ line : number ;
34
+ column : number ;
26
35
}
27
36
28
- export interface SourceFindPosition extends FindPosition {
29
- source : string ;
37
+ export interface NullablePosition {
38
+ line : number | null ;
39
+ column : number | null ;
40
+ lastColumn : number | null ;
30
41
}
31
42
32
- export interface MappedPosition extends Position {
43
+ export interface MappedPosition {
33
44
source : string ;
45
+ line : number ;
46
+ column : number ;
34
47
name ?: string ;
35
48
}
36
49
50
+ export interface NullableMappedPosition {
51
+ source : string | null ;
52
+ line : number | null ;
53
+ column : number | null ;
54
+ name : string | null ;
55
+ }
56
+
37
57
export interface MappingItem {
38
58
source : string ;
39
59
generatedLine : number ;
@@ -43,56 +63,267 @@ export interface MappingItem {
43
63
name : string ;
44
64
}
45
65
46
- export class SourceMapConsumer {
47
- static GENERATED_ORDER : number ;
48
- static ORIGINAL_ORDER : number ;
66
+ export interface Mapping {
67
+ generated : Position ;
68
+ original : Position ;
69
+ source : string ;
70
+ name ?: string ;
71
+ }
49
72
50
- static GREATEST_LOWER_BOUND : number ;
51
- static LEAST_UPPER_BOUND : number ;
73
+ export interface CodeWithSourceMap {
74
+ code : string ;
75
+ map : SourceMapGenerator ;
76
+ }
52
77
53
- constructor ( rawSourceMap : RawSourceMap ) ;
78
+ export interface SourceMapConsumer {
79
+ /**
80
+ * Compute the last column for each generated mapping. The last column is
81
+ * inclusive.
82
+ */
54
83
computeColumnSpans ( ) : void ;
55
- originalPositionFor ( generatedPosition : FindPosition ) : MappedPosition ;
56
- generatedPositionFor ( originalPosition : SourceFindPosition ) : LineRange ;
57
- allGeneratedPositionsFor ( originalPosition : MappedPosition ) : Position [ ] ;
84
+
85
+ /**
86
+ * Returns the original source, line, and column information for the generated
87
+ * source's line and column positions provided. The only argument is an object
88
+ * with the following properties:
89
+ *
90
+ * - line: The line number in the generated source.
91
+ * - column: The column number in the generated source.
92
+ * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
93
+ * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
94
+ * closest element that is smaller than or greater than the one we are
95
+ * searching for, respectively, if the exact element cannot be found.
96
+ * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
97
+ *
98
+ * and an object is returned with the following properties:
99
+ *
100
+ * - source: The original source file, or null.
101
+ * - line: The line number in the original source, or null.
102
+ * - column: The column number in the original source, or null.
103
+ * - name: The original identifier, or null.
104
+ */
105
+ originalPositionFor ( generatedPosition : Position & { bias ?: number } ) : NullableMappedPosition ;
106
+
107
+ /**
108
+ * Returns the generated line and column information for the original source,
109
+ * line, and column positions provided. The only argument is an object with
110
+ * the following properties:
111
+ *
112
+ * - source: The filename of the original source.
113
+ * - line: The line number in the original source.
114
+ * - column: The column number in the original source.
115
+ * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
116
+ * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
117
+ * closest element that is smaller than or greater than the one we are
118
+ * searching for, respectively, if the exact element cannot be found.
119
+ * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
120
+ *
121
+ * and an object is returned with the following properties:
122
+ *
123
+ * - line: The line number in the generated source, or null.
124
+ * - column: The column number in the generated source, or null.
125
+ */
126
+ generatedPositionFor ( originalPosition : MappedPosition & { bias ?: number } ) : NullablePosition ;
127
+
128
+ /**
129
+ * Returns all generated line and column information for the original source,
130
+ * line, and column provided. If no column is provided, returns all mappings
131
+ * corresponding to a either the line we are searching for or the next
132
+ * closest line that has any mappings. Otherwise, returns all mappings
133
+ * corresponding to the given line and either the column we are searching for
134
+ * or the next closest column that has any offsets.
135
+ *
136
+ * The only argument is an object with the following properties:
137
+ *
138
+ * - source: The filename of the original source.
139
+ * - line: The line number in the original source.
140
+ * - column: Optional. the column number in the original source.
141
+ *
142
+ * and an array of objects is returned, each with the following properties:
143
+ *
144
+ * - line: The line number in the generated source, or null.
145
+ * - column: The column number in the generated source, or null.
146
+ */
147
+ allGeneratedPositionsFor ( originalPosition : MappedPosition ) : NullablePosition [ ] ;
148
+
149
+ /**
150
+ * Return true if we have the source content for every source in the source
151
+ * map, false otherwise.
152
+ */
58
153
hasContentsOfAllSources ( ) : boolean ;
59
- sourceContentFor ( source : string , returnNullOnMissing ?: boolean ) : string ;
154
+
155
+ /**
156
+ * Returns the original source content. The only argument is the url of the
157
+ * original source file. Returns null if no original source content is
158
+ * available.
159
+ */
160
+ sourceContentFor ( source : string , returnNullOnMissing ?: boolean ) : string | null ;
161
+
162
+ /**
163
+ * Iterate over each mapping between an original source/line/column and a
164
+ * generated line/column in this source map.
165
+ *
166
+ * @param callback
167
+ * The function that is called with each mapping.
168
+ * @param context
169
+ * Optional. If specified, this object will be the value of `this` every
170
+ * time that `aCallback` is called.
171
+ * @param order
172
+ * Either `SourceMapConsumer.GENERATED_ORDER` or
173
+ * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
174
+ * iterate over the mappings sorted by the generated file's line/column
175
+ * order or the original's source/line/column order, respectively. Defaults to
176
+ * `SourceMapConsumer.GENERATED_ORDER`.
177
+ */
60
178
eachMapping ( callback : ( mapping : MappingItem ) => void , context ?: any , order ?: number ) : void ;
61
179
}
62
180
63
- export interface Mapping {
64
- generated : Position ;
65
- original : Position ;
66
- source : string ;
67
- name ?: string ;
181
+ export interface SourceMapConsumerConstructor {
182
+ prototype : SourceMapConsumer ;
183
+
184
+ GENERATED_ORDER : number ;
185
+ ORIGINAL_ORDER : number ;
186
+ GREATEST_LOWER_BOUND : number ;
187
+ LEAST_UPPER_BOUND : number ;
188
+
189
+ new ( rawSourceMap : RawSourceMap ) : BasicSourceMapConsumer ;
190
+ new ( rawSourceMap : RawIndexMap ) : IndexedSourceMapConsumer ;
191
+ new ( rawSourceMap : RawSourceMap | RawIndexMap | string ) : BasicSourceMapConsumer | IndexedSourceMapConsumer ;
192
+
193
+ /**
194
+ * Create a BasicSourceMapConsumer from a SourceMapGenerator.
195
+ *
196
+ * @param sourceMap
197
+ * The source map that will be consumed.
198
+ */
199
+ fromSourceMap ( sourceMap : SourceMapGenerator ) : BasicSourceMapConsumer ;
200
+ }
201
+
202
+ export const SourceMapConsumer : SourceMapConsumerConstructor ;
203
+
204
+ export interface BasicSourceMapConsumer extends SourceMapConsumer {
205
+ file : string ;
206
+ sourceRoot : string ;
207
+ sources : string [ ] ;
208
+ sourcesContent : string [ ] ;
209
+ }
210
+
211
+ export interface BasicSourceMapConsumerConstructor {
212
+ prototype : BasicSourceMapConsumer ;
213
+
214
+ new ( rawSourceMap : RawSourceMap | string ) : BasicSourceMapConsumer ;
215
+
216
+ /**
217
+ * Create a BasicSourceMapConsumer from a SourceMapGenerator.
218
+ *
219
+ * @param sourceMap
220
+ * The source map that will be consumed.
221
+ */
222
+ fromSourceMap ( sourceMap : SourceMapGenerator ) : BasicSourceMapConsumer ;
223
+ }
224
+
225
+ export const BasicSourceMapConsumer : BasicSourceMapConsumerConstructor ;
226
+
227
+ export interface IndexedSourceMapConsumer extends SourceMapConsumer {
228
+ sources : string [ ] ;
68
229
}
69
230
231
+ export interface IndexedSourceMapConsumerConstructor {
232
+ prototype : IndexedSourceMapConsumer ;
233
+
234
+ new ( rawSourceMap : RawIndexMap | string ) : IndexedSourceMapConsumer ;
235
+ }
236
+
237
+ export const IndexedSourceMapConsumer : IndexedSourceMapConsumerConstructor ;
238
+
70
239
export class SourceMapGenerator {
71
240
constructor ( startOfSourceMap ?: StartOfSourceMap ) ;
241
+
242
+ /**
243
+ * Creates a new SourceMapGenerator based on a SourceMapConsumer
244
+ *
245
+ * @param sourceMapConsumer The SourceMap.
246
+ */
72
247
static fromSourceMap ( sourceMapConsumer : SourceMapConsumer ) : SourceMapGenerator ;
248
+
249
+ /**
250
+ * Add a single mapping from original source line and column to the generated
251
+ * source's line and column for this source map being created. The mapping
252
+ * object should have the following properties:
253
+ *
254
+ * - generated: An object with the generated line and column positions.
255
+ * - original: An object with the original line and column positions.
256
+ * - source: The original source file (relative to the sourceRoot).
257
+ * - name: An optional original token name for this mapping.
258
+ */
73
259
addMapping ( mapping : Mapping ) : void ;
260
+
261
+ /**
262
+ * Set the source content for a source file.
263
+ */
74
264
setSourceContent ( sourceFile : string , sourceContent : string ) : void ;
265
+
266
+ /**
267
+ * Applies the mappings of a sub-source-map for a specific source file to the
268
+ * source map being generated. Each mapping to the supplied source file is
269
+ * rewritten using the supplied source map. Note: The resolution for the
270
+ * resulting mappings is the minimium of this map and the supplied map.
271
+ *
272
+ * @param sourceMapConsumer The source map to be applied.
273
+ * @param sourceFile Optional. The filename of the source file.
274
+ * If omitted, SourceMapConsumer's file property will be used.
275
+ * @param sourceMapPath Optional. The dirname of the path to the source map
276
+ * to be applied. If relative, it is relative to the SourceMapConsumer.
277
+ * This parameter is needed when the two source maps aren't in the same
278
+ * directory, and the source map to be applied contains relative source
279
+ * paths. If so, those relative source paths need to be rewritten
280
+ * relative to the SourceMapGenerator.
281
+ */
75
282
applySourceMap ( sourceMapConsumer : SourceMapConsumer , sourceFile ?: string , sourceMapPath ?: string ) : void ;
283
+
76
284
toString ( ) : string ;
77
- }
78
285
79
- export interface CodeWithSourceMap {
80
- code : string ;
81
- map : SourceMapGenerator ;
286
+ toJSON ( ) : RawSourceMap ;
82
287
}
83
288
84
289
export class SourceNode {
290
+ children : SourceNode [ ] ;
291
+ sourceContents : any ;
292
+ line : number ;
293
+ column : number ;
294
+ source : string ;
295
+ name : string ;
296
+
85
297
constructor ( ) ;
86
- constructor ( line : number , column : number , source : string ) ;
87
- constructor ( line : number , column : number , source : string , chunk ?: string , name ?: string ) ;
88
- static fromStringWithSourceMap ( code : string , sourceMapConsumer : SourceMapConsumer , relativePath ?: string ) : SourceNode ;
89
- add ( chunk : string ) : void ;
90
- prepend ( chunk : string ) : void ;
298
+ constructor (
299
+ line : number | null ,
300
+ column : number | null ,
301
+ source : string | null ,
302
+ chunks ?: Array < ( string | SourceNode ) > | SourceNode | string ,
303
+ name ?: string
304
+ ) ;
305
+
306
+ static fromStringWithSourceMap (
307
+ code : string ,
308
+ sourceMapConsumer : SourceMapConsumer ,
309
+ relativePath ?: string
310
+ ) : SourceNode ;
311
+
312
+ add ( chunk : Array < ( string | SourceNode ) > | SourceNode | string ) : SourceNode ;
313
+
314
+ prepend ( chunk : Array < ( string | SourceNode ) > | SourceNode | string ) : SourceNode ;
315
+
91
316
setSourceContent ( sourceFile : string , sourceContent : string ) : void ;
317
+
92
318
walk ( fn : ( chunk : string , mapping : MappedPosition ) => void ) : void ;
319
+
93
320
walkSourceContents ( fn : ( file : string , content : string ) => void ) : void ;
321
+
94
322
join ( sep : string ) : SourceNode ;
323
+
95
324
replaceRight ( pattern : string , replacement : string ) : SourceNode ;
325
+
96
326
toString ( ) : string ;
327
+
97
328
toStringWithSourceMap ( startOfSourceMap ?: StartOfSourceMap ) : CodeWithSourceMap ;
98
329
}
0 commit comments