@jsenv/sourcemap 1.2.4 → 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 ADDED
@@ -0,0 +1,3 @@
1
+ # 1.2.3
2
+
3
+ - Improve code quality
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/sourcemap",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,7 +19,7 @@
19
19
  "test": "node --conditions=development ./scripts/test.mjs"
20
20
  },
21
21
  "dependencies": {
22
- "@jsenv/urls": "2.2.1",
22
+ "@jsenv/urls": "2.2.2",
23
23
  "magic-string": "0.30.5",
24
24
  "source-map-js": "1.0.2"
25
25
  }
package/scripts/test.mjs CHANGED
@@ -9,8 +9,5 @@ await executeTestPlan({
9
9
  },
10
10
  },
11
11
  },
12
- failFast: process.argv.includes("--workspace"),
13
- logShortForCompletedExecutions: true,
14
- logMergeForCompletedExecutions: process.argv.includes("--workspace"),
15
- githubCheckEnabled: false,
12
+ githubCheck: false,
16
13
  });
@@ -4,39 +4,33 @@ export const createMagicSource = (content) => {
4
4
  if (content === undefined) {
5
5
  throw new Error("content missing");
6
6
  }
7
- const mutations = [];
7
+ const magicString = new MagicString(content);
8
+ let touched = false;
9
+
8
10
  return {
9
11
  prepend: (string) => {
10
- mutations.push((magicString) => {
11
- magicString.prepend(string);
12
- });
12
+ touched = true;
13
+ magicString.prepend(string);
13
14
  },
14
15
  append: (string) => {
15
- mutations.push((magicString) => {
16
- magicString.append(string);
17
- });
16
+ touched = true;
17
+ magicString.append(string);
18
18
  },
19
19
  replace: ({ start, end, replacement }) => {
20
- mutations.push((magicString) => {
21
- magicString.overwrite(start, end, replacement);
22
- });
20
+ touched = true;
21
+ magicString.overwrite(start, end, replacement);
23
22
  },
24
23
  remove: ({ start, end }) => {
25
- mutations.push((magicString) => {
26
- magicString.remove(start, end);
27
- });
24
+ touched = true;
25
+ magicString.remove(start, end);
28
26
  },
29
27
  toContentAndSourcemap: ({ source } = {}) => {
30
- if (mutations.length === 0) {
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,