MCPcopy
hub / github.com/mozilla/source-map / SourceMapConsumer

Class SourceMapConsumer

lib/source-map-consumer.js:17–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15const INTERNAL = Symbol("smcInternal");
16
17class SourceMapConsumer {
18 constructor(aSourceMap, aSourceMapURL) {
19 // If the constructor was called by super(), just return Promise<this>.
20 // Yes, this is a hack to retain the pre-existing API of the base-class
21 // constructor also being an async factory function.
22 if (aSourceMap == INTERNAL) {
23 return Promise.resolve(this);
24 }
25
26 return _factory(aSourceMap, aSourceMapURL);
27 }
28
29 static initialize(opts) {
30 readWasm.initialize(opts["lib/mappings.wasm"]);
31 }
32
33 static fromSourceMap(aSourceMap, aSourceMapURL) {
34 return _factoryBSM(aSourceMap, aSourceMapURL);
35 }
36
37 /**
38 * Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl`
39 * (see the `SourceMapConsumer` constructor for details. Then, invoke the `async
40 * function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
41 * for `f` to complete, call `destroy` on the consumer, and return `f`'s return
42 * value.
43 *
44 * You must not use the consumer after `f` completes!
45 *
46 * By using `with`, you do not have to remember to manually call `destroy` on
47 * the consumer, since it will be called automatically once `f` completes.
48 *
49 * ```js
50 * const xSquared = await SourceMapConsumer.with(
51 * myRawSourceMap,
52 * null,
53 * async function (consumer) {
54 * // Use `consumer` inside here and don't worry about remembering
55 * // to call `destroy`.
56 *
57 * const x = await whatever(consumer);
58 * return x * x;
59 * }
60 * );
61 *
62 * // You may not use that `consumer` anymore out here; it has
63 * // been destroyed. But you can use `xSquared`.
64 * console.log(xSquared);
65 * ```
66 */
67 static async with(rawSourceMap, sourceMapUrl, f) {
68 const consumer = await new SourceMapConsumer(rawSourceMap, sourceMapUrl);
69 try {
70 return await f(consumer);
71 } finally {
72 consumer.destroy();
73 }
74 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…