@jsenv/sourcemap 1.0.10 → 1.2.0
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 +5 -5
- package/scripts/test.mjs +5 -5
- package/src/error_stack_remap/detailed_message.js +6 -6
- package/src/error_stack_remap/install_error_stack_remapping.js +55 -55
- package/src/error_stack_remap/remap_call_site.js +77 -77
- package/src/error_stack_remap/remap_source_position.js +11 -11
- package/src/error_stack_remap/remap_stack.js +68 -68
- package/src/error_stack_remap/stringify_stack.js +5 -5
- package/src/magic_source.js +20 -20
- package/src/main.js +6 -6
- package/src/original_position.js +6 -6
- package/src/require_sourcemap.js +5 -5
- package/src/sourcemap_comment.js +55 -48
- package/src/sourcemap_composition_v3.js +37 -37
- package/src/sourcemap_converter.js +6 -6
- package/src/sourcemap_url_generator.js +9 -9
- package/tests/magic_source.xtest.mjs +7 -7
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DATA_URL } from "@jsenv/urls"
|
|
1
|
+
import { DATA_URL } from "@jsenv/urls";
|
|
2
2
|
|
|
3
|
-
import { SOURCEMAP } from "../sourcemap_comment.js"
|
|
4
|
-
import { createDetailedMessage } from "./detailed_message.js"
|
|
5
|
-
import { remapCallSite } from "./remap_call_site.js"
|
|
3
|
+
import { SOURCEMAP } from "../sourcemap_comment.js";
|
|
4
|
+
import { createDetailedMessage } from "./detailed_message.js";
|
|
5
|
+
import { remapCallSite } from "./remap_call_site.js";
|
|
6
6
|
|
|
7
7
|
export const remapStack = async ({
|
|
8
8
|
stack,
|
|
@@ -15,17 +15,17 @@ export const remapStack = async ({
|
|
|
15
15
|
const urlToSourcemapConsumer = memoizeByFirstArgStringValue(
|
|
16
16
|
async (stackTraceFileUrl) => {
|
|
17
17
|
if (stackTraceFileUrl.startsWith("node:")) {
|
|
18
|
-
return null
|
|
18
|
+
return null;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
try {
|
|
22
|
-
let text
|
|
22
|
+
let text;
|
|
23
23
|
try {
|
|
24
|
-
const fileResponse = await fetchFile(stackTraceFileUrl)
|
|
25
|
-
const { status } = fileResponse
|
|
24
|
+
const fileResponse = await fetchFile(stackTraceFileUrl);
|
|
25
|
+
const { status } = fileResponse;
|
|
26
26
|
if (status !== 200) {
|
|
27
27
|
if (status === 404) {
|
|
28
|
-
onFailure(`stack trace file not found at ${stackTraceFileUrl}`)
|
|
28
|
+
onFailure(`stack trace file not found at ${stackTraceFileUrl}`);
|
|
29
29
|
} else {
|
|
30
30
|
onFailure(
|
|
31
31
|
createDetailedMessage(
|
|
@@ -36,46 +36,46 @@ export const remapStack = async ({
|
|
|
36
36
|
["stack trace file"]: stackTraceFileUrl,
|
|
37
37
|
},
|
|
38
38
|
),
|
|
39
|
-
)
|
|
39
|
+
);
|
|
40
40
|
}
|
|
41
|
-
return null
|
|
41
|
+
return null;
|
|
42
42
|
}
|
|
43
|
-
text = await fileResponse.text()
|
|
43
|
+
text = await fileResponse.text();
|
|
44
44
|
} catch (e) {
|
|
45
45
|
onFailure(
|
|
46
46
|
createDetailedMessage(`error while fetching stack trace file.`, {
|
|
47
47
|
["fetch error stack"]: readErrorStack(e),
|
|
48
48
|
["stack trace file"]: stackTraceFileUrl,
|
|
49
49
|
}),
|
|
50
|
-
)
|
|
50
|
+
);
|
|
51
51
|
|
|
52
|
-
return null
|
|
52
|
+
return null;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const jsSourcemapComment = SOURCEMAP.readComment({
|
|
56
56
|
contentType: "text/javascript",
|
|
57
57
|
content: text,
|
|
58
|
-
})
|
|
58
|
+
});
|
|
59
59
|
if (!jsSourcemapComment) {
|
|
60
|
-
return null
|
|
60
|
+
return null;
|
|
61
61
|
}
|
|
62
|
-
const jsSourcemapUrl = jsSourcemapComment.specifier
|
|
63
|
-
let sourcemapUrl
|
|
64
|
-
let sourcemapString
|
|
62
|
+
const jsSourcemapUrl = jsSourcemapComment.specifier;
|
|
63
|
+
let sourcemapUrl;
|
|
64
|
+
let sourcemapString;
|
|
65
65
|
if (jsSourcemapUrl.startsWith("data:")) {
|
|
66
|
-
sourcemapUrl = stackTraceFileUrl
|
|
67
|
-
sourcemapString = DATA_URL.parse(jsSourcemapUrl, { as: "string" })
|
|
66
|
+
sourcemapUrl = stackTraceFileUrl;
|
|
67
|
+
sourcemapString = DATA_URL.parse(jsSourcemapUrl, { as: "string" });
|
|
68
68
|
} else {
|
|
69
69
|
sourcemapUrl = resolveFile(jsSourcemapUrl, stackTraceFileUrl, {
|
|
70
70
|
type: "source-map",
|
|
71
|
-
})
|
|
71
|
+
});
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
|
-
const sourcemapResponse = await fetchFile(sourcemapUrl)
|
|
75
|
-
const { status } = sourcemapResponse
|
|
74
|
+
const sourcemapResponse = await fetchFile(sourcemapUrl);
|
|
75
|
+
const { status } = sourcemapResponse;
|
|
76
76
|
if (status !== 200) {
|
|
77
77
|
if (status === 404) {
|
|
78
|
-
onFailure(`sourcemap file not found at ${sourcemapUrl}`)
|
|
78
|
+
onFailure(`sourcemap file not found at ${sourcemapUrl}`);
|
|
79
79
|
} else {
|
|
80
80
|
onFailure(
|
|
81
81
|
createDetailedMessage(
|
|
@@ -86,56 +86,56 @@ export const remapStack = async ({
|
|
|
86
86
|
["sourcemap url"]: sourcemapUrl,
|
|
87
87
|
},
|
|
88
88
|
),
|
|
89
|
-
)
|
|
89
|
+
);
|
|
90
90
|
}
|
|
91
|
-
return null
|
|
91
|
+
return null;
|
|
92
92
|
}
|
|
93
|
-
sourcemapString = await sourcemapResponse.text()
|
|
93
|
+
sourcemapString = await sourcemapResponse.text();
|
|
94
94
|
} catch (e) {
|
|
95
95
|
onFailure(
|
|
96
96
|
createDetailedMessage(`error while fetching sourcemap.`, {
|
|
97
97
|
["fetch error stack"]: readErrorStack(e),
|
|
98
98
|
["sourcemap url"]: sourcemapUrl,
|
|
99
99
|
}),
|
|
100
|
-
)
|
|
101
|
-
return null
|
|
100
|
+
);
|
|
101
|
+
return null;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
let sourceMap
|
|
105
|
+
let sourceMap;
|
|
106
106
|
try {
|
|
107
|
-
sourceMap = JSON.parse(sourcemapString)
|
|
107
|
+
sourceMap = JSON.parse(sourcemapString);
|
|
108
108
|
} catch (e) {
|
|
109
109
|
onFailure(
|
|
110
110
|
createDetailedMessage(`error while parsing sourcemap.`, {
|
|
111
111
|
["parse error stack"]: readErrorStack(e),
|
|
112
112
|
["sourcemap url"]: sourcemapUrl,
|
|
113
113
|
}),
|
|
114
|
-
)
|
|
115
|
-
return null
|
|
114
|
+
);
|
|
115
|
+
return null;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
let { sourcesContent } = sourceMap
|
|
118
|
+
let { sourcesContent } = sourceMap;
|
|
119
119
|
|
|
120
120
|
if (!sourcesContent) {
|
|
121
|
-
sourcesContent = []
|
|
122
|
-
sourceMap.sourcesContent = sourcesContent
|
|
121
|
+
sourcesContent = [];
|
|
122
|
+
sourceMap.sourcesContent = sourcesContent;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
let firstSourceMapSourceFailure = null
|
|
125
|
+
let firstSourceMapSourceFailure = null;
|
|
126
126
|
|
|
127
127
|
await Promise.all(
|
|
128
128
|
sourceMap.sources.map(async (source, index) => {
|
|
129
|
-
if (index in sourcesContent) return
|
|
129
|
+
if (index in sourcesContent) return;
|
|
130
130
|
|
|
131
131
|
const sourcemapSourceUrl = resolveFile(source, sourcemapUrl, {
|
|
132
132
|
type: "source",
|
|
133
|
-
})
|
|
133
|
+
});
|
|
134
134
|
try {
|
|
135
|
-
const sourceResponse = await fetchFile(sourcemapSourceUrl)
|
|
136
|
-
const { status } = sourceResponse
|
|
135
|
+
const sourceResponse = await fetchFile(sourcemapSourceUrl);
|
|
136
|
+
const { status } = sourceResponse;
|
|
137
137
|
if (status !== 200) {
|
|
138
|
-
if (firstSourceMapSourceFailure) return
|
|
138
|
+
if (firstSourceMapSourceFailure) return;
|
|
139
139
|
|
|
140
140
|
if (status === 404) {
|
|
141
141
|
firstSourceMapSourceFailure = createDetailedMessage(
|
|
@@ -144,8 +144,8 @@ export const remapStack = async ({
|
|
|
144
144
|
["sourcemap source url"]: sourcemapSourceUrl,
|
|
145
145
|
["sourcemap url"]: sourcemapUrl,
|
|
146
146
|
},
|
|
147
|
-
)
|
|
148
|
-
return
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
149
|
}
|
|
150
150
|
firstSourceMapSourceFailure = createDetailedMessage(
|
|
151
151
|
`unexpected response for sourcemap source.`,
|
|
@@ -155,14 +155,14 @@ export const remapStack = async ({
|
|
|
155
155
|
["sourcemap source url"]: sourcemapSourceUrl,
|
|
156
156
|
["sourcemap url"]: sourcemapUrl,
|
|
157
157
|
},
|
|
158
|
-
)
|
|
159
|
-
return
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
const sourceString = await sourceResponse.text()
|
|
163
|
-
sourcesContent[index] = sourceString
|
|
162
|
+
const sourceString = await sourceResponse.text();
|
|
163
|
+
sourcesContent[index] = sourceString;
|
|
164
164
|
} catch (e) {
|
|
165
|
-
if (firstSourceMapSourceFailure) return
|
|
165
|
+
if (firstSourceMapSourceFailure) return;
|
|
166
166
|
firstSourceMapSourceFailure = createDetailedMessage(
|
|
167
167
|
`error while fetching sourcemap source.`,
|
|
168
168
|
{
|
|
@@ -170,17 +170,17 @@ export const remapStack = async ({
|
|
|
170
170
|
["sourcemap source url"]: sourcemapSourceUrl,
|
|
171
171
|
["sourcemap url"]: sourcemapUrl,
|
|
172
172
|
},
|
|
173
|
-
)
|
|
173
|
+
);
|
|
174
174
|
}
|
|
175
175
|
}),
|
|
176
|
-
)
|
|
176
|
+
);
|
|
177
177
|
|
|
178
178
|
if (firstSourceMapSourceFailure) {
|
|
179
|
-
onFailure(firstSourceMapSourceFailure)
|
|
180
|
-
return null
|
|
179
|
+
onFailure(firstSourceMapSourceFailure);
|
|
180
|
+
return null;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
return new SourceMapConsumer(sourceMap)
|
|
183
|
+
return new SourceMapConsumer(sourceMap);
|
|
184
184
|
} catch (e) {
|
|
185
185
|
onFailure(
|
|
186
186
|
createDetailedMessage(
|
|
@@ -190,11 +190,11 @@ export const remapStack = async ({
|
|
|
190
190
|
["stack trace file"]: stackTraceFileUrl,
|
|
191
191
|
},
|
|
192
192
|
),
|
|
193
|
-
)
|
|
194
|
-
return null
|
|
193
|
+
);
|
|
194
|
+
return null;
|
|
195
195
|
}
|
|
196
196
|
},
|
|
197
|
-
)
|
|
197
|
+
);
|
|
198
198
|
const originalCallsites = await Promise.all(
|
|
199
199
|
stack.map((callSite) =>
|
|
200
200
|
remapCallSite(callSite, {
|
|
@@ -204,17 +204,17 @@ export const remapStack = async ({
|
|
|
204
204
|
onFailure,
|
|
205
205
|
}),
|
|
206
206
|
),
|
|
207
|
-
)
|
|
208
|
-
return originalCallsites
|
|
209
|
-
}
|
|
207
|
+
);
|
|
208
|
+
return originalCallsites;
|
|
209
|
+
};
|
|
210
210
|
|
|
211
211
|
const memoizeByFirstArgStringValue = (fn) => {
|
|
212
|
-
const stringValueCache = {}
|
|
212
|
+
const stringValueCache = {};
|
|
213
213
|
return (firstArgValue) => {
|
|
214
214
|
if (firstArgValue in stringValueCache)
|
|
215
|
-
return stringValueCache[firstArgValue]
|
|
216
|
-
const value = fn(firstArgValue)
|
|
217
|
-
stringValueCache[firstArgValue] = value
|
|
218
|
-
return value
|
|
219
|
-
}
|
|
220
|
-
}
|
|
215
|
+
return stringValueCache[firstArgValue];
|
|
216
|
+
const value = fn(firstArgValue);
|
|
217
|
+
stringValueCache[firstArgValue] = value;
|
|
218
|
+
return value;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export const stringifyStack = (stack, { error, indent }) => {
|
|
2
|
-
const name = error.name || "Error"
|
|
3
|
-
const message = error.message || ""
|
|
2
|
+
const name = error.name || "Error";
|
|
3
|
+
const message = error.message || "";
|
|
4
4
|
const stackString = stack
|
|
5
5
|
.map((callSite) => `\n${indent}at ${callSite}`)
|
|
6
|
-
.join("")
|
|
6
|
+
.join("");
|
|
7
7
|
|
|
8
|
-
return `${name}: ${message}${stackString}
|
|
9
|
-
}
|
|
8
|
+
return `${name}: ${message}${stackString}`;
|
|
9
|
+
};
|
package/src/magic_source.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
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) {
|
|
5
|
-
throw new Error("content missing")
|
|
5
|
+
throw new Error("content missing");
|
|
6
6
|
}
|
|
7
|
-
const mutations = []
|
|
7
|
+
const mutations = [];
|
|
8
8
|
return {
|
|
9
9
|
prepend: (string) => {
|
|
10
10
|
mutations.push((magicString) => {
|
|
11
|
-
magicString.prepend(string)
|
|
12
|
-
})
|
|
11
|
+
magicString.prepend(string);
|
|
12
|
+
});
|
|
13
13
|
},
|
|
14
14
|
append: (string) => {
|
|
15
15
|
mutations.push((magicString) => {
|
|
16
|
-
magicString.append(string)
|
|
17
|
-
})
|
|
16
|
+
magicString.append(string);
|
|
17
|
+
});
|
|
18
18
|
},
|
|
19
19
|
replace: ({ start, end, replacement }) => {
|
|
20
20
|
mutations.push((magicString) => {
|
|
21
|
-
magicString.overwrite(start, end, replacement)
|
|
22
|
-
})
|
|
21
|
+
magicString.overwrite(start, end, replacement);
|
|
22
|
+
});
|
|
23
23
|
},
|
|
24
24
|
remove: ({ start, end }) => {
|
|
25
25
|
mutations.push((magicString) => {
|
|
26
|
-
magicString.remove(start, end)
|
|
27
|
-
})
|
|
26
|
+
magicString.remove(start, end);
|
|
27
|
+
});
|
|
28
28
|
},
|
|
29
29
|
toContentAndSourcemap: ({ source } = {}) => {
|
|
30
30
|
if (mutations.length === 0) {
|
|
31
31
|
return {
|
|
32
32
|
content,
|
|
33
33
|
sourcemap: null,
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
}
|
|
36
|
-
const magicString = new MagicString(content)
|
|
36
|
+
const magicString = new MagicString(content);
|
|
37
37
|
mutations.forEach((mutation) => {
|
|
38
|
-
mutation(magicString)
|
|
39
|
-
})
|
|
40
|
-
const code = magicString.toString()
|
|
38
|
+
mutation(magicString);
|
|
39
|
+
});
|
|
40
|
+
const code = magicString.toString();
|
|
41
41
|
const map = magicString.generateMap({
|
|
42
42
|
hires: true,
|
|
43
43
|
includeContent: true,
|
|
44
44
|
source,
|
|
45
|
-
})
|
|
45
|
+
});
|
|
46
46
|
return {
|
|
47
47
|
content: code,
|
|
48
48
|
sourcemap: map,
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
51
|
+
};
|
|
52
|
+
};
|
package/src/main.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { createMagicSource } from "./magic_source.js"
|
|
2
|
-
export { composeTwoSourcemaps } from "./sourcemap_composition_v3.js"
|
|
1
|
+
export { createMagicSource } from "./magic_source.js";
|
|
2
|
+
export { composeTwoSourcemaps } from "./sourcemap_composition_v3.js";
|
|
3
3
|
|
|
4
|
-
export { getOriginalPosition } from "./original_position.js"
|
|
5
|
-
export { sourcemapConverter } from "./sourcemap_converter.js"
|
|
4
|
+
export { getOriginalPosition } from "./original_position.js";
|
|
5
|
+
export { sourcemapConverter } from "./sourcemap_converter.js";
|
|
6
6
|
export {
|
|
7
7
|
generateSourcemapFileUrl,
|
|
8
8
|
generateSourcemapDataUrl,
|
|
9
|
-
} from "./sourcemap_url_generator.js"
|
|
10
|
-
export { SOURCEMAP } from "./sourcemap_comment.js"
|
|
9
|
+
} from "./sourcemap_url_generator.js";
|
|
10
|
+
export { SOURCEMAP } from "./sourcemap_comment.js";
|
package/src/original_position.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { requireSourcemap } from "./require_sourcemap.js"
|
|
1
|
+
import { requireSourcemap } from "./require_sourcemap.js";
|
|
2
2
|
|
|
3
3
|
// https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
|
|
4
4
|
export const getOriginalPosition = ({ sourcemap, line, column, bias }) => {
|
|
5
|
-
const { SourceMapConsumer } = requireSourcemap()
|
|
5
|
+
const { SourceMapConsumer } = requireSourcemap();
|
|
6
6
|
|
|
7
|
-
const sourceMapConsumer = new SourceMapConsumer(sourcemap)
|
|
7
|
+
const sourceMapConsumer = new SourceMapConsumer(sourcemap);
|
|
8
8
|
const originalPosition = sourceMapConsumer.originalPositionFor({
|
|
9
9
|
line,
|
|
10
10
|
column,
|
|
11
11
|
bias,
|
|
12
|
-
})
|
|
13
|
-
return originalPosition
|
|
14
|
-
}
|
|
12
|
+
});
|
|
13
|
+
return originalPosition;
|
|
14
|
+
};
|
package/src/require_sourcemap.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createRequire } from "node:module"
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
|
|
3
|
-
const require = createRequire(import.meta.url)
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
4
|
// consider using https://github.com/7rulnik/source-map-js
|
|
5
5
|
|
|
6
6
|
export const requireSourcemap = () => {
|
|
7
|
-
const namespace = require("source-map-js")
|
|
8
|
-
return namespace
|
|
9
|
-
}
|
|
7
|
+
const namespace = require("source-map-js");
|
|
8
|
+
return namespace;
|
|
9
|
+
};
|
package/src/sourcemap_comment.js
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
export const SOURCEMAP = {
|
|
2
2
|
enabledOnContentType: (contentType) => {
|
|
3
|
-
return ["text/javascript", "text/css"].includes(contentType)
|
|
3
|
+
return ["text/javascript", "text/css"].includes(contentType);
|
|
4
4
|
},
|
|
5
5
|
|
|
6
6
|
readComment: ({ contentType, content }) => {
|
|
7
7
|
const read = {
|
|
8
8
|
"text/javascript": parseJavaScriptSourcemapComment,
|
|
9
9
|
"text/css": parseCssSourcemapComment,
|
|
10
|
-
}[contentType]
|
|
11
|
-
return read ? read(content) : null
|
|
10
|
+
}[contentType];
|
|
11
|
+
return read ? read(content) : null;
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
removeComment: ({ contentType, content }) => {
|
|
15
|
+
return SOURCEMAP.writeComment({ contentType, content, specifier: "" });
|
|
12
16
|
},
|
|
13
17
|
|
|
14
18
|
writeComment: ({ contentType, content, specifier }) => {
|
|
15
19
|
const write = {
|
|
16
20
|
"text/javascript": setJavaScriptSourceMappingUrl,
|
|
17
21
|
"text/css": setCssSourceMappingUrl,
|
|
18
|
-
}[contentType]
|
|
19
|
-
return write ? write(content, specifier) : content
|
|
22
|
+
}[contentType];
|
|
23
|
+
return write ? write(content, specifier) : content;
|
|
20
24
|
},
|
|
21
|
-
}
|
|
25
|
+
};
|
|
22
26
|
|
|
23
27
|
const parseJavaScriptSourcemapComment = (javaScriptSource) => {
|
|
24
|
-
let sourceMappingUrl
|
|
28
|
+
let sourceMappingUrl;
|
|
25
29
|
replaceSourceMappingUrl(
|
|
26
30
|
javaScriptSource,
|
|
27
31
|
javascriptSourceMappingUrlCommentRegexp,
|
|
28
32
|
(value) => {
|
|
29
|
-
sourceMappingUrl = value
|
|
33
|
+
sourceMappingUrl = value;
|
|
30
34
|
},
|
|
31
|
-
)
|
|
35
|
+
);
|
|
32
36
|
if (!sourceMappingUrl) {
|
|
33
|
-
return null
|
|
37
|
+
return null;
|
|
34
38
|
}
|
|
35
39
|
return {
|
|
36
40
|
type: "sourcemap_comment",
|
|
@@ -40,46 +44,46 @@ const parseJavaScriptSourcemapComment = (javaScriptSource) => {
|
|
|
40
44
|
// ${"//#"} is to avoid static analysis to think there is a sourceMappingUrl for this file
|
|
41
45
|
column: `${"//#"} sourceMappingURL=`.length + 1,
|
|
42
46
|
specifier: sourceMappingUrl,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
45
49
|
|
|
46
50
|
const setJavaScriptSourceMappingUrl = (
|
|
47
51
|
javaScriptSource,
|
|
48
52
|
sourceMappingFileUrl,
|
|
49
53
|
) => {
|
|
50
|
-
let replaced
|
|
54
|
+
let replaced;
|
|
51
55
|
const sourceAfterReplace = replaceSourceMappingUrl(
|
|
52
56
|
javaScriptSource,
|
|
53
57
|
javascriptSourceMappingUrlCommentRegexp,
|
|
54
58
|
() => {
|
|
55
|
-
replaced = true
|
|
59
|
+
replaced = true;
|
|
56
60
|
return sourceMappingFileUrl
|
|
57
61
|
? writeJavaScriptSourceMappingURL(sourceMappingFileUrl)
|
|
58
|
-
: ""
|
|
62
|
+
: "";
|
|
59
63
|
},
|
|
60
|
-
)
|
|
64
|
+
);
|
|
61
65
|
if (replaced) {
|
|
62
|
-
return sourceAfterReplace
|
|
66
|
+
return sourceAfterReplace;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
return sourceMappingFileUrl
|
|
66
70
|
? `${javaScriptSource}
|
|
67
71
|
${writeJavaScriptSourceMappingURL(sourceMappingFileUrl)}
|
|
68
72
|
`
|
|
69
|
-
: javaScriptSource
|
|
70
|
-
}
|
|
73
|
+
: javaScriptSource;
|
|
74
|
+
};
|
|
71
75
|
|
|
72
76
|
const parseCssSourcemapComment = (cssSource) => {
|
|
73
|
-
let sourceMappingUrl
|
|
77
|
+
let sourceMappingUrl;
|
|
74
78
|
replaceSourceMappingUrl(
|
|
75
79
|
cssSource,
|
|
76
80
|
cssSourceMappingUrlCommentRegExp,
|
|
77
81
|
(value) => {
|
|
78
|
-
sourceMappingUrl = value
|
|
82
|
+
sourceMappingUrl = value;
|
|
79
83
|
},
|
|
80
|
-
)
|
|
84
|
+
);
|
|
81
85
|
if (!sourceMappingUrl) {
|
|
82
|
-
return null
|
|
86
|
+
return null;
|
|
83
87
|
}
|
|
84
88
|
return {
|
|
85
89
|
type: "sourcemap_comment",
|
|
@@ -89,55 +93,58 @@ const parseCssSourcemapComment = (cssSource) => {
|
|
|
89
93
|
// ${"//*#"} is to avoid static analysis to think there is a sourceMappingUrl for this file
|
|
90
94
|
column: `${"//*#"} sourceMappingURL=`.length + 1,
|
|
91
95
|
specifier: sourceMappingUrl,
|
|
92
|
-
}
|
|
93
|
-
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
94
98
|
|
|
95
99
|
const setCssSourceMappingUrl = (cssSource, sourceMappingFileUrl) => {
|
|
96
|
-
let replaced
|
|
100
|
+
let replaced;
|
|
97
101
|
const sourceAfterReplace = replaceSourceMappingUrl(
|
|
98
102
|
cssSource,
|
|
99
103
|
cssSourceMappingUrlCommentRegExp,
|
|
100
104
|
() => {
|
|
101
|
-
replaced = true
|
|
105
|
+
replaced = true;
|
|
102
106
|
return sourceMappingFileUrl
|
|
103
107
|
? writeCssSourceMappingUrl(sourceMappingFileUrl)
|
|
104
|
-
: ""
|
|
108
|
+
: "";
|
|
105
109
|
},
|
|
106
|
-
)
|
|
110
|
+
);
|
|
107
111
|
if (replaced) {
|
|
108
|
-
return sourceAfterReplace
|
|
112
|
+
return sourceAfterReplace;
|
|
109
113
|
}
|
|
110
114
|
return sourceMappingFileUrl
|
|
111
115
|
? `${cssSource}
|
|
112
116
|
${writeCssSourceMappingUrl(sourceMappingFileUrl)}
|
|
113
117
|
`
|
|
114
|
-
: cssSource
|
|
115
|
-
}
|
|
118
|
+
: cssSource;
|
|
119
|
+
};
|
|
116
120
|
|
|
117
121
|
const javascriptSourceMappingUrlCommentRegexp =
|
|
118
|
-
/\/\/ ?# ?sourceMappingURL=([^\s'"]+)/g
|
|
122
|
+
/\/\/ ?# ?sourceMappingURL=([^\s'"]+)/g;
|
|
119
123
|
const cssSourceMappingUrlCommentRegExp =
|
|
120
|
-
/\/\*# ?sourceMappingURL=([^\s'"]+) \*\//g
|
|
124
|
+
/\/\*# ?sourceMappingURL=([^\s'"]+) \*\//g;
|
|
121
125
|
|
|
122
126
|
// ${"//#"} is to avoid a parser thinking there is a sourceMappingUrl for this file
|
|
123
|
-
const writeJavaScriptSourceMappingURL = (value) =>
|
|
124
|
-
`${"//#"} sourceMappingURL=${value}
|
|
125
|
-
|
|
127
|
+
const writeJavaScriptSourceMappingURL = (value) => {
|
|
128
|
+
return `${"//#"} sourceMappingURL=${value}`;
|
|
129
|
+
};
|
|
130
|
+
const writeCssSourceMappingUrl = (value) => {
|
|
131
|
+
return `/*# sourceMappingURL=${value} */`;
|
|
132
|
+
};
|
|
126
133
|
|
|
127
134
|
const replaceSourceMappingUrl = (source, regexp, callback) => {
|
|
128
|
-
let lastSourceMappingUrl
|
|
129
|
-
let matchSourceMappingUrl
|
|
135
|
+
let lastSourceMappingUrl;
|
|
136
|
+
let matchSourceMappingUrl;
|
|
130
137
|
while ((matchSourceMappingUrl = regexp.exec(source))) {
|
|
131
|
-
lastSourceMappingUrl = matchSourceMappingUrl
|
|
138
|
+
lastSourceMappingUrl = matchSourceMappingUrl;
|
|
132
139
|
}
|
|
133
140
|
if (lastSourceMappingUrl) {
|
|
134
|
-
const index = lastSourceMappingUrl.index
|
|
135
|
-
const before = source.slice(0, index)
|
|
136
|
-
const after = source.slice(index)
|
|
141
|
+
const index = lastSourceMappingUrl.index;
|
|
142
|
+
const before = source.slice(0, index);
|
|
143
|
+
const after = source.slice(index);
|
|
137
144
|
const mappedAfter = after.replace(regexp, (match, firstGroup) => {
|
|
138
|
-
return callback(firstGroup)
|
|
139
|
-
})
|
|
140
|
-
return `${before}${mappedAfter}
|
|
145
|
+
return callback(firstGroup);
|
|
146
|
+
});
|
|
147
|
+
return `${before}${mappedAfter}`;
|
|
141
148
|
}
|
|
142
|
-
return source
|
|
143
|
-
}
|
|
149
|
+
return source;
|
|
150
|
+
};
|