@jsenv/sourcemap 1.2.3 → 1.2.5
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/CHANGELOG.md +3 -0
- package/package.json +3 -3
- package/scripts/test.mjs +1 -3
- package/src/magic_source.js +12 -18
package/CHANGELOG.md
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/sourcemap",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@jsenv/urls": "2.2.
|
|
23
|
-
"magic-string": "0.30.
|
|
22
|
+
"@jsenv/urls": "2.2.2",
|
|
23
|
+
"magic-string": "0.30.5",
|
|
24
24
|
"source-map-js": "1.0.2"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/scripts/test.mjs
CHANGED
package/src/magic_source.js
CHANGED
|
@@ -4,39 +4,33 @@ export const createMagicSource = (content) => {
|
|
|
4
4
|
if (content === undefined) {
|
|
5
5
|
throw new Error("content missing");
|
|
6
6
|
}
|
|
7
|
-
const
|
|
7
|
+
const magicString = new MagicString(content);
|
|
8
|
+
let touched = false;
|
|
9
|
+
|
|
8
10
|
return {
|
|
9
11
|
prepend: (string) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
12
|
+
touched = true;
|
|
13
|
+
magicString.prepend(string);
|
|
13
14
|
},
|
|
14
15
|
append: (string) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
16
|
+
touched = true;
|
|
17
|
+
magicString.append(string);
|
|
18
18
|
},
|
|
19
19
|
replace: ({ start, end, replacement }) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
20
|
+
touched = true;
|
|
21
|
+
magicString.overwrite(start, end, replacement);
|
|
23
22
|
},
|
|
24
23
|
remove: ({ start, end }) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
24
|
+
touched = true;
|
|
25
|
+
magicString.remove(start, end);
|
|
28
26
|
},
|
|
29
27
|
toContentAndSourcemap: ({ source } = {}) => {
|
|
30
|
-
if (
|
|
28
|
+
if (!touched) {
|
|
31
29
|
return {
|
|
32
30
|
content,
|
|
33
31
|
sourcemap: null,
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
|
-
const magicString = new MagicString(content);
|
|
37
|
-
mutations.forEach((mutation) => {
|
|
38
|
-
mutation(magicString);
|
|
39
|
-
});
|
|
40
34
|
const code = magicString.toString();
|
|
41
35
|
const map = magicString.generateMap({
|
|
42
36
|
hires: true,
|