forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin-memory-sourcemaps.js
More file actions
29 lines (28 loc) · 907 Bytes
/
in-memory-sourcemaps.js
File metadata and controls
29 lines (28 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const assert = require('node:assert');
const path = require('node:path');
const { SourceMapConsumer } = require('source-map');
const rollup = require('../../dist/rollup');
const { loader } = require('../utils.js');
describe('in-memory sourcemaps', () => {
it('generates an in-memory sourcemap', async () => {
const bundle = await rollup.rollup({
input: 'main',
plugins: [loader({ main: `console.log( 42 );` })]
});
const {
output: [generated]
} = await bundle.generate({
format: 'cjs',
sourcemap: true,
sourcemapFile: path.resolve('bundle.js')
});
const smc = await new SourceMapConsumer(generated.map);
const locator = (await import('locate-character')).getLocator(generated.code, {
offsetLine: 1
});
const loc = smc.originalPositionFor(locator('42')); // 42
assert.equal(loc.source, 'main');
assert.equal(loc.line, 1);
assert.equal(loc.column, 13);
});
});