1
- // Type definitions for source-map 0.5
1
+ // Type definitions for source-map 0.7
2
2
// Project: https://github.com/mozilla/source-map
3
3
// Definitions by: Morten Houston Ludvigsen <https://github.com/MortenHoustonLudvigsen>,
4
- // Ron Buckton <https://github.com/rbuckton>
5
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
4
+ // Ron Buckton <https://github.com/rbuckton>,
5
+ // John Vilk <https://github.com/jvilk>
6
+ // Definitions: https://github.com/mozilla/source-map
6
7
export type SourceMapUrl = string ;
7
8
8
9
export interface StartOfSourceMap {
@@ -178,6 +179,11 @@ export interface SourceMapConsumer {
178
179
* `SourceMapConsumer.GENERATED_ORDER`.
179
180
*/
180
181
eachMapping ( callback : ( mapping : MappingItem ) => void , context ?: any , order ?: number ) : void ;
182
+ /**
183
+ * Free this source map consumer's associated wasm data that is manually-managed.
184
+ * Alternatively, you can use SourceMapConsumer.with to avoid needing to remember to call destroy.
185
+ */
186
+ destroy ( ) : void ;
181
187
}
182
188
183
189
export interface SourceMapConsumerConstructor {
@@ -188,17 +194,49 @@ export interface SourceMapConsumerConstructor {
188
194
GREATEST_LOWER_BOUND : number ;
189
195
LEAST_UPPER_BOUND : number ;
190
196
191
- new ( rawSourceMap : RawSourceMap , sourceMapUrl ?: SourceMapUrl ) : BasicSourceMapConsumer ;
192
- new ( rawSourceMap : RawIndexMap , sourceMapUrl ?: SourceMapUrl ) : IndexedSourceMapConsumer ;
193
- new ( rawSourceMap : RawSourceMap | RawIndexMap | string , sourceMapUrl ?: SourceMapUrl ) : BasicSourceMapConsumer | IndexedSourceMapConsumer ;
197
+ new ( rawSourceMap : RawSourceMap , sourceMapUrl ?: SourceMapUrl ) : Promise < BasicSourceMapConsumer > ;
198
+ new ( rawSourceMap : RawIndexMap , sourceMapUrl ?: SourceMapUrl ) : Promise < IndexedSourceMapConsumer > ;
199
+ new ( rawSourceMap : RawSourceMap | RawIndexMap | string , sourceMapUrl ?: SourceMapUrl ) : Promise < BasicSourceMapConsumer | IndexedSourceMapConsumer > ;
194
200
195
201
/**
196
202
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
197
203
*
198
204
* @param sourceMap
199
205
* The source map that will be consumed.
200
206
*/
201
- fromSourceMap ( sourceMap : SourceMapGenerator , sourceMapUrl ?: SourceMapUrl ) : BasicSourceMapConsumer ;
207
+ fromSourceMap ( sourceMap : SourceMapGenerator , sourceMapUrl ?: SourceMapUrl ) : Promise < BasicSourceMapConsumer > ;
208
+
209
+ /**
210
+ * Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl`
211
+ * (see the `SourceMapConsumer` constructor for details. Then, invoke the `async
212
+ * function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
213
+ * for `f` to complete, call `destroy` on the consumer, and return `f`'s return
214
+ * value.
215
+ *
216
+ * You must not use the consumer after `f` completes!
217
+ *
218
+ * By using `with`, you do not have to remember to manually call `destroy` on
219
+ * the consumer, since it will be called automatically once `f` completes.
220
+ *
221
+ * ```js
222
+ * const xSquared = await SourceMapConsumer.with(
223
+ * myRawSourceMap,
224
+ * null,
225
+ * async function (consumer) {
226
+ * // Use `consumer` inside here and don't worry about remembering
227
+ * // to call `destroy`.
228
+ *
229
+ * const x = await whatever(consumer);
230
+ * return x * x;
231
+ * }
232
+ * );
233
+ *
234
+ * // You may not use that `consumer` anymore out here; it has
235
+ * // been destroyed. But you can use `xSquared`.
236
+ * console.log(xSquared);
237
+ * ```
238
+ */
239
+ with < T > ( rawSourceMap : RawSourceMap | RawIndexMap | string , sourceMapUrl : SourceMapUrl | null | undefined , callback : ( consumer : BasicSourceMapConsumer | IndexedSourceMapConsumer ) => Promise < T > | T ) : Promise < T > ;
202
240
}
203
241
204
242
export const SourceMapConsumer : SourceMapConsumerConstructor ;
@@ -213,15 +251,15 @@ export interface BasicSourceMapConsumer extends SourceMapConsumer {
213
251
export interface BasicSourceMapConsumerConstructor {
214
252
prototype : BasicSourceMapConsumer ;
215
253
216
- new ( rawSourceMap : RawSourceMap | string ) : BasicSourceMapConsumer ;
254
+ new ( rawSourceMap : RawSourceMap | string ) : Promise < BasicSourceMapConsumer > ;
217
255
218
256
/**
219
257
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
220
258
*
221
259
* @param sourceMap
222
260
* The source map that will be consumed.
223
261
*/
224
- fromSourceMap ( sourceMap : SourceMapGenerator ) : BasicSourceMapConsumer ;
262
+ fromSourceMap ( sourceMap : SourceMapGenerator ) : Promise < BasicSourceMapConsumer > ;
225
263
}
226
264
227
265
export const BasicSourceMapConsumer : BasicSourceMapConsumerConstructor ;
@@ -233,7 +271,7 @@ export interface IndexedSourceMapConsumer extends SourceMapConsumer {
233
271
export interface IndexedSourceMapConsumerConstructor {
234
272
prototype : IndexedSourceMapConsumer ;
235
273
236
- new ( rawSourceMap : RawIndexMap | string ) : IndexedSourceMapConsumer ;
274
+ new ( rawSourceMap : RawIndexMap | string ) : Promise < IndexedSourceMapConsumer > ;
237
275
}
238
276
239
277
export const IndexedSourceMapConsumer : IndexedSourceMapConsumerConstructor ;
0 commit comments