source: imaps-frontend/node_modules/@jridgewell/source-map/README.md@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 4.3 KB
Line 
1# @jridgewell/source-map
2
3> Packages `@jridgewell/trace-mapping` and `@jridgewell/gen-mapping` into the familiar source-map API
4
5This isn't the full API, but it's the core functionality. This wraps
6[@jridgewell/trace-mapping][trace-mapping] and [@jridgewell/gen-mapping][gen-mapping]
7implementations.
8
9## Installation
10
11```sh
12npm install @jridgewell/source-map
13```
14
15## Usage
16
17TODO
18
19### SourceMapConsumer
20
21```typescript
22import { SourceMapConsumer } from '@jridgewell/source-map';
23const smc = new SourceMapConsumer({
24 version: 3,
25 names: ['foo'],
26 sources: ['input.js'],
27 mappings: 'AAAAA',
28});
29```
30
31#### SourceMapConsumer.fromSourceMap(mapGenerator[, mapUrl])
32
33Transforms a `SourceMapGenerator` into a `SourceMapConsumer`.
34
35```typescript
36const smg = new SourceMapGenerator();
37
38const smc = SourceMapConsumer.fromSourceMap(map);
39smc.originalPositionFor({ line: 1, column: 0 });
40```
41
42#### SourceMapConsumer.prototype.originalPositionFor(generatedPosition)
43
44```typescript
45const smc = new SourceMapConsumer(map);
46smc.originalPositionFor({ line: 1, column: 0 });
47```
48
49#### SourceMapConsumer.prototype.mappings
50
51```typescript
52const smc = new SourceMapConsumer(map);
53smc.mappings; // AAAA
54```
55
56#### SourceMapConsumer.prototype.allGeneratedPositionsFor(originalPosition)
57
58```typescript
59const smc = new SourceMapConsumer(map);
60smc.allGeneratedpositionsfor({ line: 1, column: 5, source: "baz.ts" });
61// [
62// { line: 2, column: 8 }
63// ]
64```
65
66#### SourceMapConsumer.prototype.eachMapping(callback[, context[, order]])
67
68> This implementation currently does not support the "order" parameter.
69> This function can only iterate in Generated order.
70
71```typescript
72const smc = new SourceMapConsumer(map);
73smc.eachMapping((mapping) => {
74// { source: 'baz.ts',
75// generatedLine: 4,
76// generatedColumn: 5,
77// originalLine: 4,
78// originalColumn: 5,
79// name: null }
80});
81```
82
83#### SourceMapConsumer.prototype.generatedPositionFor(originalPosition)
84
85```typescript
86const smc = new SourceMapConsumer(map);
87smc.generatedPositionFor({ line: 1, column: 5, source: "baz.ts" });
88// { line: 2, column: 8 }
89```
90
91#### SourceMapConsumer.prototype.hasContentsOfAllSources()
92
93```typescript
94const smc = new SourceMapConsumer(map);
95smc.hasContentsOfAllSources();
96// true
97```
98
99#### SourceMapConsumer.prototype.sourceContentFor(source[, returnNullOnMissing])
100
101```typescript
102const smc = new SourceMapConsumer(map);
103smc.generatedPositionFor("baz.ts");
104// "export default ..."
105```
106
107#### SourceMapConsumer.prototype.version
108
109Returns the source map's version
110
111### SourceMapGenerator
112
113```typescript
114import { SourceMapGenerator } from '@jridgewell/source-map';
115const smg = new SourceMapGenerator({
116 file: 'output.js',
117 sourceRoot: 'https://example.com/',
118});
119```
120
121#### SourceMapGenerator.fromSourceMap(map)
122
123Transform a `SourceMapConsumer` into a `SourceMapGenerator`.
124
125```typescript
126const smc = new SourceMapConsumer();
127const smg = SourceMapGenerator.fromSourceMap(smc);
128```
129
130#### SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile[, sourceMapPath]])
131
132> This method is not implemented yet
133
134#### SourceMapGenerator.prototype.addMapping(mapping)
135
136```typescript
137const smg = new SourceMapGenerator();
138smg.addMapping({
139 generated: { line: 1, column: 0 },
140 source: 'input.js',
141 original: { line: 1, column: 0 },
142 name: 'foo',
143});
144```
145
146#### SourceMapGenerator.prototype.setSourceContent(sourceFile, sourceContent)
147
148```typescript
149const smg = new SourceMapGenerator();
150smg.setSourceContent('input.js', 'foobar');
151```
152
153#### SourceMapGenerator.prototype.toJSON()
154
155```typescript
156const smg = new SourceMapGenerator();
157smg.toJSON(); // { version: 3, names: [], sources: [], mappings: '' }
158```
159
160#### SourceMapGenerator.prototype.toString()
161
162```typescript
163const smg = new SourceMapGenerator();
164smg.toJSON(); // "{version:3,names:[],sources:[],mappings:''}"
165```
166
167#### SourceMapGenerator.prototype.toDecodedMap()
168
169```typescript
170const smg = new SourceMapGenerator();
171smg.toDecodedMap(); // { version: 3, names: [], sources: [], mappings: [] }
172```
173
174## Known differences with other implementations
175
176This implementation has some differences with `source-map` and `source-map-js`.
177
178- `SourceMapConsumer.prototype.eachMapping()`
179 - Does not support the `order` argument
180- `SourceMapGenerator.prototype.applySourceMap()`
181 - Not implemented
182
183[trace-mapping]: https://github.com/jridgewell/trace-mapping/
184[gen-mapping]: https://github.com/jridgewell/gen-mapping/
Note: See TracBrowser for help on using the repository browser.