| 1 |
const { SourceMapConsumer, SourceMapGenerator } = require('..'); |
| 2 |
const assert = require('assert'); |
| 3 |
|
| 4 |
it('SourceMapGenerator', () => { |
| 5 |
const smg = new SourceMapGenerator({ |
| 6 |
file: 'output.js', |
| 7 |
sourceRoot: 'https://example.com/', |
| 8 |
}); |
| 9 |
|
| 10 |
smg.addMapping({ |
| 11 |
generated: { line: 1, column: 0 }, |
| 12 |
source: 'input.js', |
| 13 |
original: { line: 1, column: 0 }, |
| 14 |
name: 'foo', |
| 15 |
}); |
| 16 |
smg.setSourceContent('input.js', 'foobar'); |
| 17 |
|
| 18 |
assert.deepEqual(smg.toJSON(), { |
| 19 |
version: 3, |
| 20 |
file: 'output.js', |
| 21 |
sourceRoot: 'https://example.com/', |
| 22 |
names: ['foo'], |
| 23 |
sources: ['input.js'], |
| 24 |
sourcesContent: ['foobar'], |
| 25 |
mappings: 'AAAAA', |
| 26 |
}); |
| 27 |
|
| 28 |
assert.deepEqual(smg.toDecodedMap(), { |
| 29 |
version: 3, |
| 30 |
file: 'output.js', |
| 31 |
sourceRoot: 'https://example.com/', |
| 32 |
names: ['foo'], |
| 33 |
sources: ['input.js'], |
| 34 |
sourcesContent: ['foobar'], |
| 35 |
mappings: [[[0, 0, 0, 0, 0]]], |
| 36 |
}); |
| 37 |
}); |
| 38 |
|
| 39 |
it('SourceMapConsumer', () => { |
| 40 |
const smc = new SourceMapConsumer({ |
| 41 |
version: 3, |
| 42 |
file: 'output.js', |
| 43 |
sourceRoot: 'https://example.com/', |
| 44 |
names: ['foo'], |
| 45 |
sources: ['input.js'], |
| 46 |
sourcesContent: ['foobar'], |
| 47 |
mappings: 'AAAAA', |
| 48 |
}); |
| 49 |
|
| 50 |
assert.equal(smc.file, 'output.js'); |
| 51 |
assert.deepEqual(smc.names, ['foo']); |
| 52 |
assert.equal(smc.sourceRoot, 'https://example.com/'); |
| 53 |
assert.deepEqual(smc.sources, ['https://example.com/input.js']); |
| 54 |
assert.deepEqual(smc.sourcesContent, ['foobar']); |
| 55 |
|
| 56 |
assert.deepEqual(smc.originalPositionFor({ line: 1, column: 0 }), { |
| 57 |
source: 'https://example.com/input.js', |
| 58 |
line: 1, |
| 59 |
column: 0, |
| 60 |
name: 'foo', |
| 61 |
}); |
| 62 |
}); |