Skip to content

Commit

Permalink
Add generator options to fromSourceMap (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Semirulnik <v7rulnik@gmail.com>
  • Loading branch information
ai and 7rulnik committed Mar 19, 2024
1 parent f0a16e5 commit 420748b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,18 @@ var generator = new sourceMap.SourceMapGenerator({
});
```

#### SourceMapGenerator.fromSourceMap(sourceMapConsumer)
#### SourceMapGenerator.fromSourceMap(sourceMapConsumer, sourceMapGeneratorOptions)

Creates a new `SourceMapGenerator` from an existing `SourceMapConsumer` instance.

* `sourceMapConsumer` The SourceMap.

* `sourceMapGeneratorOptions` options that will be passed to the SourceMapGenerator constructor which used under the hood.

```js
var generator = sourceMap.SourceMapGenerator.fromSourceMap(consumer);
var generator = sourceMap.SourceMapGenerator.fromSourceMap(consumer, {
ignoreInvalidMapping: true,
});
```

#### SourceMapGenerator.prototype.addMapping(mapping)
Expand Down
6 changes: 3 additions & 3 deletions lib/source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ SourceMapGenerator.prototype._version = 3;
* @param aSourceMapConsumer The SourceMap.
*/
SourceMapGenerator.fromSourceMap =
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) {
var sourceRoot = aSourceMapConsumer.sourceRoot;
var generator = new SourceMapGenerator({
var generator = new SourceMapGenerator(Object.assign(generatorOps || {}, {
file: aSourceMapConsumer.file,
sourceRoot: sourceRoot
});
}));
aSourceMapConsumer.eachMapping(function (mapping) {
var newMapping = {
generated: {
Expand Down

0 comments on commit 420748b

Please sign in to comment.