Skip to content

Commit c73baa5

Browse files
authored
Merge pull request #321 from jvilk/typings-fix
Update source-map TypeScript typings to 0.7.0
2 parents 63b7486 + 7cc0c9d commit c73baa5

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"url": "http://github.com/mozilla/source-map.git"
4848
},
4949
"main": "./source-map.js",
50+
"types": "./source-map.d.ts",
5051
"files": [
5152
"source-map.js",
5253
"source-map.d.ts",

source-map.d.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Type definitions for source-map 0.5
1+
// Type definitions for source-map 0.7
22
// Project: https://github.com/mozilla/source-map
33
// 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
67
export type SourceMapUrl = string;
78

89
export interface StartOfSourceMap {
@@ -178,6 +179,11 @@ export interface SourceMapConsumer {
178179
* `SourceMapConsumer.GENERATED_ORDER`.
179180
*/
180181
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;
181187
}
182188

183189
export interface SourceMapConsumerConstructor {
@@ -188,17 +194,49 @@ export interface SourceMapConsumerConstructor {
188194
GREATEST_LOWER_BOUND: number;
189195
LEAST_UPPER_BOUND: number;
190196

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>;
194200

195201
/**
196202
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
197203
*
198204
* @param sourceMap
199205
* The source map that will be consumed.
200206
*/
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>;
202240
}
203241

204242
export const SourceMapConsumer: SourceMapConsumerConstructor;
@@ -213,15 +251,15 @@ export interface BasicSourceMapConsumer extends SourceMapConsumer {
213251
export interface BasicSourceMapConsumerConstructor {
214252
prototype: BasicSourceMapConsumer;
215253

216-
new (rawSourceMap: RawSourceMap | string): BasicSourceMapConsumer;
254+
new (rawSourceMap: RawSourceMap | string): Promise<BasicSourceMapConsumer>;
217255

218256
/**
219257
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
220258
*
221259
* @param sourceMap
222260
* The source map that will be consumed.
223261
*/
224-
fromSourceMap(sourceMap: SourceMapGenerator): BasicSourceMapConsumer;
262+
fromSourceMap(sourceMap: SourceMapGenerator): Promise<BasicSourceMapConsumer>;
225263
}
226264

227265
export const BasicSourceMapConsumer: BasicSourceMapConsumerConstructor;
@@ -233,7 +271,7 @@ export interface IndexedSourceMapConsumer extends SourceMapConsumer {
233271
export interface IndexedSourceMapConsumerConstructor {
234272
prototype: IndexedSourceMapConsumer;
235273

236-
new (rawSourceMap: RawIndexMap | string): IndexedSourceMapConsumer;
274+
new (rawSourceMap: RawIndexMap | string): Promise<IndexedSourceMapConsumer>;
237275
}
238276

239277
export const IndexedSourceMapConsumer: IndexedSourceMapConsumerConstructor;

0 commit comments

Comments
 (0)