-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathsource-map-cache.js
More file actions
60 lines (50 loc) · 1.56 KB
/
source-map-cache.js
File metadata and controls
60 lines (50 loc) · 1.56 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
60
'use strict';
const common = require('../common.js');
const assert = require('assert');
const fixtures = require('../../test/common/fixtures');
const bench = common.createBenchmark(
main,
{
operation: [
'findSourceMap-valid',
'findSourceMap-generated-source',
],
n: [1e5],
},
);
function main({ operation, n }) {
const Module = require('node:module');
Module.setSourceMapsSupport(true, {
generatedCode: true,
});
const validFileName = fixtures.path('test-runner/source-maps/line-lengths/index.js');
const fileNameKey = '/source-map/disk.js';
const generatedFileName = fixtures.path(fileNameKey);
const generatedFileContent = fixtures.readSync(fileNameKey, 'utf8');
const sourceMapUrl = generatedFileName.replace(/\.js$/, '.map');
const sourceWithGeneratedSourceMap =
`${generatedFileContent}\n//# sourceMappingURL=${sourceMapUrl}\n//# sourceURL=${generatedFileName}`;
const generatedExpectedUrl = `file://${generatedFileName}`;
let sourceMap;
switch (operation) {
case 'findSourceMap-valid':
require(validFileName);
bench.start();
for (let i = 0; i < n; i++) {
sourceMap = Module.findSourceMap(validFileName);
}
bench.end(n);
break;
case 'findSourceMap-generated-source':
eval(sourceWithGeneratedSourceMap);
bench.start();
for (let i = 0; i < n; i++) {
sourceMap = Module.findSourceMap(generatedExpectedUrl);
}
bench.end(n);
break;
default:
throw new Error(`Unknown operation: ${operation}`);
}
assert.ok(sourceMap);
}