1 | # source-list-map
|
---|
2 |
|
---|
3 | ## API
|
---|
4 |
|
---|
5 | ### Example
|
---|
6 |
|
---|
7 | ``` js
|
---|
8 | var SourceListMap = require("source-list-map").SourceListMap;
|
---|
9 |
|
---|
10 | // Create a new map
|
---|
11 | var map = new SourceListMap();
|
---|
12 |
|
---|
13 | // Add generated code that is map line to line to some soure
|
---|
14 | map.add("Generated\ncode1\n", "source-code.js", "Orginal\nsource");
|
---|
15 |
|
---|
16 | // Add generated code that isn't mapped
|
---|
17 | map.add("Generated\ncode2\n");
|
---|
18 |
|
---|
19 | // Get SourceMap and generated source
|
---|
20 | map.toStringWithSourceMap({ file: "generated-code.js" });
|
---|
21 | // {
|
---|
22 | // source: 'Generated\ncode1\nGenerated\ncode2\n',
|
---|
23 | // map: {
|
---|
24 | // version: 3,
|
---|
25 | // file: 'generated-code.js',
|
---|
26 | // sources: [ 'source-code.js' ],
|
---|
27 | // sourcesContent: [ 'Orginal\nsource' ],
|
---|
28 | // mappings: 'AAAA;AACA;;;'
|
---|
29 | // }
|
---|
30 | // }
|
---|
31 |
|
---|
32 | // Convert existing SourceMap into SourceListMap
|
---|
33 | // (Only the first mapping per line is preserved)
|
---|
34 | var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
|
---|
35 | var map = fromStringWithSourceMap("Generated\ncode", { version: 3, ... });
|
---|
36 |
|
---|
37 | ```
|
---|
38 |
|
---|
39 | ### `new SourceListMap()`
|
---|
40 |
|
---|
41 | ### `SourceListMap.prototype.add`
|
---|
42 |
|
---|
43 | ``` js
|
---|
44 | SourceListMap.prototype.add(generatedCode: string)
|
---|
45 | SourceListMap.prototype.add(generatedCode: string, source: string, originalSource: string)
|
---|
46 | SourceListMap.prototype.add(sourceListMap: SourceListMap)
|
---|
47 | ```
|
---|
48 |
|
---|
49 | Append some stuff.
|
---|
50 |
|
---|
51 | ### `SourceListMap.prototype.prepend`
|
---|
52 |
|
---|
53 | ``` js
|
---|
54 | SourceListMap.prototype.prepend(generatedCode: string)
|
---|
55 | SourceListMap.prototype.prepend(generatedCode: string, source: string, originalSource: string)
|
---|
56 | SourceListMap.prototype.prepend(sourceListMap: SourceListMap)
|
---|
57 | ```
|
---|
58 |
|
---|
59 | Prepend some stuff.
|
---|
60 |
|
---|
61 | ### `SourceListMap.prototype.toString()`
|
---|
62 |
|
---|
63 | Get generated code.
|
---|
64 |
|
---|
65 | ### `SourceListMap.prototype.toStringWithSourceMap`
|
---|
66 |
|
---|
67 | ``` js
|
---|
68 | SourceListMap.prototype.toStringWithSourceMap(options: object)
|
---|
69 | ```
|
---|
70 |
|
---|
71 | Get generated code and SourceMap. `options` can contains `file` property which defines the `file` property of the SourceMap.
|
---|
72 |
|
---|
73 | ### `SourceListMap.prototype.mapGeneratedCode`
|
---|
74 |
|
---|
75 | ``` js
|
---|
76 | SourceListMap.prototype.mapGeneratedCode(fn: function) : SourceListMap
|
---|
77 | ```
|
---|
78 |
|
---|
79 | Applies `fn` to each generated code block (per line). The returned value is set as new generated code. Returns a new SourceListMap.
|
---|
80 |
|
---|
81 | Removing and adding lines is supported. The SourceMap complexity will increase when doing this.
|
---|
82 |
|
---|
83 | ## Test
|
---|
84 |
|
---|
85 | [![Build Status](https://travis-ci.org/webpack/source-list-map.svg)](https://travis-ci.org/webpack/source-list-map)
|
---|
86 |
|
---|
87 | ## License
|
---|
88 |
|
---|
89 | Copyright (c) 2017 JS Foundation
|
---|
90 |
|
---|
91 | MIT (http://www.opensource.org/licenses/mit-license.php) |
---|