@jsenv/sourcemap 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/src/magic_source.js +15 -7
- package/src/sourcemap_composition_v3.js +36 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/sourcemap",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"./*": "./*"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@jridgewell/gen-mapping": "0.3.13",
|
|
17
|
+
"@jridgewell/trace-mapping": "0.3.31",
|
|
16
18
|
"@jsenv/urls": "2.9.10",
|
|
17
19
|
"magic-string": "1.0.0",
|
|
18
20
|
"source-map-js": "1.2.1"
|
package/src/magic_source.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import MagicString from "magic-string";
|
|
1
|
+
import { MagicString } from "magic-string";
|
|
2
2
|
|
|
3
3
|
export const createMagicSource = (content) => {
|
|
4
4
|
if (content === undefined) {
|
|
@@ -32,14 +32,22 @@ export const createMagicSource = (content) => {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
const code = magicString.toString();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
35
|
+
// The map is generated when first read, not here: a consumer that
|
|
36
|
+
// throws sourcemaps away (a build with sourcemaps "none") never reads
|
|
37
|
+
// it, and generating a high resolution map costs as much as the edit.
|
|
38
|
+
let map;
|
|
40
39
|
return {
|
|
41
40
|
content: code,
|
|
42
|
-
sourcemap
|
|
41
|
+
get sourcemap() {
|
|
42
|
+
if (map === undefined) {
|
|
43
|
+
map = magicString.generateMap({
|
|
44
|
+
hires: true,
|
|
45
|
+
includeContent: true,
|
|
46
|
+
source,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return map;
|
|
50
|
+
},
|
|
43
51
|
};
|
|
44
52
|
},
|
|
45
53
|
};
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* https://github.com/
|
|
2
|
+
* https://github.com/jridgewell/trace-mapping
|
|
3
|
+
* https://github.com/jridgewell/gen-mapping
|
|
4
|
+
*
|
|
5
|
+
* @jridgewell/* rather than source-map-js (still used by
|
|
6
|
+
* original_position.js): composing is the hot spot of a build with
|
|
7
|
+
* sourcemaps, and source-map-js sorts + binary searches its mappings on
|
|
8
|
+
* every lookup where trace-mapping walks them in order. On @jsenv/navi
|
|
9
|
+
* (3MB bundle, 18MB map) the build went from 11s to 4.6s for a map that is
|
|
10
|
+
* byte for byte the one source-map-js produced.
|
|
3
11
|
*/
|
|
4
12
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
import {
|
|
14
|
+
addMapping,
|
|
15
|
+
GenMapping,
|
|
16
|
+
toEncodedMap,
|
|
17
|
+
} from "@jridgewell/gen-mapping";
|
|
18
|
+
import {
|
|
19
|
+
eachMapping,
|
|
20
|
+
originalPositionFor,
|
|
21
|
+
TraceMap,
|
|
22
|
+
} from "@jridgewell/trace-mapping";
|
|
8
23
|
|
|
9
24
|
// "first" maps an intermediate content back to the true original source(s);
|
|
10
25
|
// "second" maps the final content back to that same intermediate content
|
|
@@ -24,10 +39,11 @@ export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
|
|
|
24
39
|
if (!secondSourcemap) {
|
|
25
40
|
return firstSourcemap;
|
|
26
41
|
}
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
42
|
+
const genMapping = new GenMapping();
|
|
43
|
+
const firstTraceMap = new TraceMap(firstSourcemap);
|
|
44
|
+
const secondTraceMap = new TraceMap(secondSourcemap);
|
|
45
|
+
eachMapping(
|
|
46
|
+
secondTraceMap,
|
|
31
47
|
({
|
|
32
48
|
generatedLine,
|
|
33
49
|
generatedColumn,
|
|
@@ -40,7 +56,7 @@ export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
|
|
|
40
56
|
// content) — nothing to chain through "first", leave unmapped.
|
|
41
57
|
return;
|
|
42
58
|
}
|
|
43
|
-
const original =
|
|
59
|
+
const original = originalPositionFor(firstTraceMap, {
|
|
44
60
|
line: originalLine,
|
|
45
61
|
column: originalColumn,
|
|
46
62
|
});
|
|
@@ -49,7 +65,10 @@ export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
|
|
|
49
65
|
// — leave unmapped rather than guessing.
|
|
50
66
|
return;
|
|
51
67
|
}
|
|
52
|
-
|
|
68
|
+
// addMapping, not maybeAddMapping: the latter drops mappings it
|
|
69
|
+
// considers redundant with the previous one, which shrinks the map
|
|
70
|
+
// but loses positions (a real fidelity change, to decide on its own).
|
|
71
|
+
addMapping(genMapping, {
|
|
53
72
|
generated: { line: generatedLine, column: generatedColumn },
|
|
54
73
|
original: { line: original.line, column: original.column },
|
|
55
74
|
source: original.source,
|
|
@@ -57,12 +76,16 @@ export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
|
|
|
57
76
|
});
|
|
58
77
|
},
|
|
59
78
|
);
|
|
60
|
-
const
|
|
61
|
-
const
|
|
79
|
+
const encodedMap = toEncodedMap(genMapping);
|
|
80
|
+
const sourcemap = {
|
|
81
|
+
version: 3,
|
|
82
|
+
sources: [...encodedMap.sources],
|
|
83
|
+
names: [...encodedMap.names],
|
|
84
|
+
mappings: encodedMap.mappings,
|
|
85
|
+
};
|
|
62
86
|
const sourcesContent = [];
|
|
63
87
|
const firstSourcesContent = firstSourcemap.sourcesContent;
|
|
64
88
|
sourcemap.sources.forEach((source) => {
|
|
65
|
-
sources.push(source);
|
|
66
89
|
if (firstSourcesContent) {
|
|
67
90
|
const firstSourceIndex = firstSourcemap.sources.indexOf(source);
|
|
68
91
|
if (firstSourceIndex > -1) {
|
|
@@ -72,7 +95,6 @@ export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
|
|
|
72
95
|
}
|
|
73
96
|
sourcesContent.push(null);
|
|
74
97
|
});
|
|
75
|
-
sourcemap.sources = sources;
|
|
76
98
|
sourcemap.sourcesContent = sourcesContent;
|
|
77
99
|
return sourcemap;
|
|
78
100
|
};
|