diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-10-13 10:37:19 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-10-13 10:37:19 +0800 |
| commit | e29b244aeab08ea36fb385c7beb2ad0560217039 (patch) | |
| tree | c66b744dc29573f1acc871862937a23f1b80e6bf /node_modules/source-map/README.md | |
| parent | 62c2881629e6413a8fec6d3dd092e4568e2a81dc (diff) | |
bump: @babel/cli 7.25.6 → 7.25.7, @babel/core 7.25.2 → 7.25.8, @babel/preset-env 7.25.4 → 7.25.8, postcss 8.4.41 → 8.4.47, swup 4.7.0 → 4.8.1
Diffstat (limited to 'node_modules/source-map/README.md')
| -rw-r--r-- | node_modules/source-map/README.md | 144 |
1 files changed, 32 insertions, 112 deletions
diff --git a/node_modules/source-map/README.md b/node_modules/source-map/README.md index 56e5ac3e..fea4beb1 100644 --- a/node_modules/source-map/README.md +++ b/node_modules/source-map/README.md @@ -2,8 +2,6 @@ [](https://travis-ci.org/mozilla/source-map) -[](https://coveralls.io/github/mozilla/source-map) - [](https://www.npmjs.com/package/source-map) This is a library to generate and consume the source map format @@ -17,12 +15,7 @@ This is a library to generate and consume the source map format ## Use on the Web - <script src="https://unpkg.com/source-map@0.7.3/dist/source-map.js"></script> - <script> - sourceMap.SourceMapConsumer.initialize({ - "lib/mappings.wasm": "https://unpkg.com/source-map@0.7.3/lib/mappings.wasm" - }); - </script> + <script src="https://raw.githubusercontent.com/mozilla/source-map/master/dist/source-map.min.js" defer></script> -------------------------------------------------------------------------------- @@ -39,10 +32,7 @@ This is a library to generate and consume the source map format - [With SourceMapGenerator (low level API)](#with-sourcemapgenerator-low-level-api) - [API](#api) - [SourceMapConsumer](#sourcemapconsumer) - - [SourceMapConsumer.initialize(options)](#sourcemapconsumerinitializeoptions) - [new SourceMapConsumer(rawSourceMap)](#new-sourcemapconsumerrawsourcemap) - - [SourceMapConsumer.with](#sourcemapconsumerwith) - - [SourceMapConsumer.prototype.destroy()](#sourcemapconsumerprototypedestroy) - [SourceMapConsumer.prototype.computeColumnSpans()](#sourcemapconsumerprototypecomputecolumnspans) - [SourceMapConsumer.prototype.originalPositionFor(generatedPosition)](#sourcemapconsumerprototypeoriginalpositionforgeneratedposition) - [SourceMapConsumer.prototype.generatedPositionFor(originalPosition)](#sourcemapconsumerprototypegeneratedpositionfororiginalposition) @@ -77,7 +67,7 @@ This is a library to generate and consume the source map format ### Consuming a source map ```js -const rawSourceMap = { +var rawSourceMap = { version: 3, file: 'min.js', names: ['bar', 'baz', 'n'], @@ -86,33 +76,30 @@ const rawSourceMap = { mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA' }; -const whatever = await SourceMapConsumer.with(rawSourceMap, null, consumer => { - - console.log(consumer.sources); - // [ 'http://example.com/www/js/one.js', - // 'http://example.com/www/js/two.js' ] - - console.log(consumer.originalPositionFor({ - line: 2, - column: 28 - })); - // { source: 'http://example.com/www/js/two.js', - // line: 2, - // column: 10, - // name: 'n' } - - console.log(consumer.generatedPositionFor({ - source: 'http://example.com/www/js/two.js', - line: 2, - column: 10 - })); - // { line: 2, column: 28 } - - consumer.eachMapping(function (m) { - // ... - }); - - return computeWhatever(); +var smc = new SourceMapConsumer(rawSourceMap); + +console.log(smc.sources); +// [ 'http://example.com/www/js/one.js', +// 'http://example.com/www/js/two.js' ] + +console.log(smc.originalPositionFor({ + line: 2, + column: 28 +})); +// { source: 'http://example.com/www/js/two.js', +// line: 2, +// column: 10, +// name: 'n' } + +console.log(smc.generatedPositionFor({ + source: 'http://example.com/www/js/two.js', + line: 2, + column: 10 +})); +// { line: 2, column: 28 } + +smc.eachMapping(function (m) { + // ... }); ``` @@ -195,27 +182,10 @@ const sourceMap = require("devtools/toolkit/sourcemap/source-map.js"); ### SourceMapConsumer -A `SourceMapConsumer` instance represents a parsed source map which we can query +A SourceMapConsumer instance represents a parsed source map which we can query for information about the original file positions by giving it a file position in the generated source. -#### SourceMapConsumer.initialize(options) - -When using `SourceMapConsumer` outside of node.js, for example on the Web, it -needs to know from what URL to load `lib/mappings.wasm`. You must inform it by -calling `initialize` before constructing any `SourceMapConsumer`s. - -The options object has the following properties: - -* `"lib/mappings.wasm"`: A `String` containing the URL of the - `lib/mappings.wasm` file, or an `ArrayBuffer` with the contents of `lib/mappings.wasm`. - -```js -sourceMap.SourceMapConsumer.initialize({ - "lib/mappings.wasm": "https://example.com/source-map/lib/mappings.wasm" -}); -``` - #### new SourceMapConsumer(rawSourceMap) The only parameter is the raw source map (either as a string which can be @@ -237,62 +207,10 @@ following attributes: * `file`: Optional. The generated filename this source map is associated with. -The promise of the constructed souce map consumer is returned. - -When the `SourceMapConsumer` will no longer be used anymore, you must call its -`destroy` method. - -```js -const consumer = await new sourceMap.SourceMapConsumer(rawSourceMapJsonData); -doStuffWith(consumer); -consumer.destroy(); -``` - -Alternatively, you can use `SourceMapConsumer.with` to avoid needing to remember -to call `destroy`. - -#### SourceMapConsumer.with - -Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl` -(see the `SourceMapConsumer` constructor for details. Then, invoke the `async -function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait -for `f` to complete, call `destroy` on the consumer, and return `f`'s return -value. - -You must not use the consumer after `f` completes! - -By using `with`, you do not have to remember to manually call `destroy` on -the consumer, since it will be called automatically once `f` completes. - ```js -const xSquared = await SourceMapConsumer.with( - myRawSourceMap, - null, - async function (consumer) { - // Use `consumer` inside here and don't worry about remembering - // to call `destroy`. - - const x = await whatever(consumer); - return x * x; - } -); - -// You may not use that `consumer` anymore out here; it has -// been destroyed. But you can use `xSquared`. -console.log(xSquared); +var consumer = new sourceMap.SourceMapConsumer(rawSourceMapJsonData); ``` -#### SourceMapConsumer.prototype.destroy() - -Free this source map consumer's associated wasm data that is manually-managed. - -```js -consumer.destroy(); -``` - -Alternatively, you can use `SourceMapConsumer.with` to avoid needing to remember -to call `destroy`. - #### SourceMapConsumer.prototype.computeColumnSpans() Compute the last column for each generated mapping. The last column is @@ -321,6 +239,7 @@ consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" }) // { line: 2, // column: 20, // lastColumn: Infinity } ] + ``` #### SourceMapConsumer.prototype.originalPositionFor(generatedPosition) @@ -660,8 +579,9 @@ Creates a SourceNode from generated code and a SourceMapConsumer. should be relative to. ```js -const consumer = await new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8")); -const node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), consumer); +var consumer = new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8")); +var node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), + consumer); ``` #### SourceNode.prototype.add(chunk) |
