source-maps-existing.js
1.99 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var test = require('tap').test;
var pack = require('../');
var convert = require('convert-source-map');
var parse = require('parse-base64vlq-mappings');
var foo = {
version: 3,
file: 'foo.js',
sourceRoot: '',
sources: [ 'foo.coffee' ],
names: [],
mappings: ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',
sourcesContent: [ 'console.log(require \'./bar.js\')\n' ] };
test('pack one file with source file field and existing sourcemap', function (t) {
t.plan(7);
var mapComment = convert.fromObject(foo).toComment();
var fooMappings = parse(foo.mappings);
var p = pack();
var src = '';
p.on('data', function (buf) { src += buf });
p.on('end', function () {
var sm = convert.fromSource(src).toObject();
var mappings = parse(sm.mappings);
var remainingMaps = src.match(convert.commentRegex);
// remove map for _prelude.js
mappings.shift();
var fstMap = mappings[0];
var fstFooMap = fooMappings[0];
var lstMap = mappings.pop();
var lstFooMap = fooMappings.pop();
t.deepEqual(fstMap.original, fstFooMap.original, 'first original mappings are same');
t.deepEqual(lstMap.original, lstFooMap.original, 'last original mappings are same');
t.equal(fstMap.generated.column, fstFooMap.generated.column, 'first generated columns are same');
t.equal(lstMap.generated.column, lstFooMap.generated.column, 'last generated columns are same');
t.equal(fstMap.generated.line, fstFooMap.generated.line + 1, 'first generated line is offset by 1');
t.equal(lstMap.generated.line, lstFooMap.generated.line + 1, 'last generated line is offset by 1');
t.equal(remainingMaps.length, 1, 'removes orinal source maps');
});
p.end(JSON.stringify([
{
id: 'xyz',
source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + mapComment,
sourceFile: 'foo.js'
}
]));
});