@jsenv/sourcemap 1.0.3 → 1.0.4
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/sourcemap",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@jsenv/urls": "1.2.7",
|
|
23
23
|
"magic-string": "0.26.2",
|
|
24
|
-
"source-map": "0.
|
|
24
|
+
"source-map-js": "1.0.2"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -16,13 +16,12 @@ export const remapCallSite = async (
|
|
|
16
16
|
const line = callSite.getLineNumber()
|
|
17
17
|
const column = callSite.getColumnNumber() - 1
|
|
18
18
|
const originalPosition = await remapSourcePosition({
|
|
19
|
-
source,
|
|
19
|
+
url: resolveFile(source),
|
|
20
20
|
line,
|
|
21
21
|
column,
|
|
22
22
|
resolveFile,
|
|
23
23
|
urlToSourcemapConsumer,
|
|
24
24
|
readErrorStack,
|
|
25
|
-
onFailure,
|
|
26
25
|
})
|
|
27
26
|
|
|
28
27
|
const callSiteClone = cloneCallSite(callSite)
|
|
@@ -194,12 +193,11 @@ const remapEvalOrigin = async (
|
|
|
194
193
|
const line = Number(topLevelEvalMatch[3])
|
|
195
194
|
const column = topLevelEvalMatch[4] - 1
|
|
196
195
|
const originalPosition = await remapSourcePosition({
|
|
197
|
-
source,
|
|
196
|
+
url: resolveFile(source),
|
|
198
197
|
line,
|
|
199
198
|
column,
|
|
200
199
|
resolveFile,
|
|
201
200
|
urlToSourcemapConsumer,
|
|
202
|
-
onFailure,
|
|
203
201
|
})
|
|
204
202
|
return `eval at ${topLevelEvalMatch[1]} (${originalPosition.source}:${
|
|
205
203
|
originalPosition.line
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { createDetailedMessage } from "./detailed_message.js"
|
|
2
2
|
|
|
3
3
|
export const remapSourcePosition = async ({
|
|
4
|
-
|
|
4
|
+
url,
|
|
5
5
|
line,
|
|
6
6
|
column,
|
|
7
7
|
resolveFile,
|
|
8
8
|
urlToSourcemapConsumer,
|
|
9
|
-
readErrorStack,
|
|
10
|
-
onFailure,
|
|
9
|
+
readErrorStack = (e) => e.stack,
|
|
11
10
|
}) => {
|
|
12
|
-
const position = {
|
|
13
|
-
|
|
14
|
-
const url = sourceToUrl(source, { resolveFile })
|
|
15
|
-
if (!url) return position
|
|
16
|
-
|
|
11
|
+
const position = { url, line, column }
|
|
17
12
|
const sourceMapConsumer = await urlToSourcemapConsumer(url)
|
|
18
13
|
|
|
19
|
-
if (!sourceMapConsumer)
|
|
14
|
+
if (!sourceMapConsumer) {
|
|
15
|
+
return position
|
|
16
|
+
}
|
|
20
17
|
|
|
21
18
|
try {
|
|
22
19
|
const originalPosition = sourceMapConsumer.originalPositionFor(position)
|
|
@@ -27,18 +24,19 @@ export const remapSourcePosition = async ({
|
|
|
27
24
|
// better to give a precise location in the compiled file than a vague
|
|
28
25
|
// location in the original file.
|
|
29
26
|
const originalSource = originalPosition.source
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
if (originalSource === null) {
|
|
28
|
+
return position
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
url: resolveFile(originalSource, url),
|
|
32
|
+
line: originalPosition.line,
|
|
33
|
+
column: originalPosition.column,
|
|
34
|
+
}
|
|
37
35
|
} catch (e) {
|
|
38
|
-
|
|
36
|
+
console.warn(
|
|
39
37
|
createDetailedMessage(`error while remapping position.`, {
|
|
40
38
|
["error stack"]: readErrorStack(e),
|
|
41
|
-
["
|
|
39
|
+
["url"]: url,
|
|
42
40
|
["line"]: line,
|
|
43
41
|
["column"]: column,
|
|
44
42
|
}),
|
|
@@ -46,61 +44,3 @@ export const remapSourcePosition = async ({
|
|
|
46
44
|
return position
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
const sourceToUrl = (source, { resolveFile }) => {
|
|
51
|
-
if (startsWithScheme(source)) {
|
|
52
|
-
return source
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// linux filesystem path
|
|
56
|
-
if (source[0] === "/") {
|
|
57
|
-
return resolveFile(source)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// be careful, due to babel or something like that we might receive paths like
|
|
61
|
-
// C:/directory/file.js (without backslashes we would expect on windows)
|
|
62
|
-
// In that case we consider C: is the signe we are on windows
|
|
63
|
-
// And I avoid to rely on process.platform === "win32" because this file might be executed in chrome
|
|
64
|
-
if (startsWithWindowsDriveLetter(source)) {
|
|
65
|
-
return windowsFilePathToUrl(source)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// I don't think we will ever encounter relative file in the stack trace
|
|
69
|
-
// but if it ever happens we are safe :)
|
|
70
|
-
if (source.slice(0, 2) === "./" || source.slice(0, 3) === "../") {
|
|
71
|
-
return resolveFile(source)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// we have received a "bare specifier" for the source
|
|
75
|
-
// it happens for internal/process/task_queues.js for instance
|
|
76
|
-
// if we do return resolveFile(source) it will be converted to
|
|
77
|
-
// file:///C:/project-directory/internal/process/task_queues.js in node
|
|
78
|
-
// and
|
|
79
|
-
// http://domain.com/internal/process/task_queues.js
|
|
80
|
-
// but the file will certainly be a 404
|
|
81
|
-
// and if not it won't be the right file anyway
|
|
82
|
-
// for now we assume "bare specifier" in the stack trace
|
|
83
|
-
// are internal files that are pointless to try to remap
|
|
84
|
-
return null
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const startsWithScheme = (string) => {
|
|
88
|
-
return /^[a-zA-Z]{2,}:/.test(string)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const startsWithWindowsDriveLetter = (string) => {
|
|
92
|
-
const firstChar = string[0]
|
|
93
|
-
if (!/[a-zA-Z]/.test(firstChar)) return false
|
|
94
|
-
|
|
95
|
-
const secondChar = string[1]
|
|
96
|
-
if (secondChar !== ":") return false
|
|
97
|
-
|
|
98
|
-
return true
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const windowsFilePathToUrl = (windowsFilePath) => {
|
|
102
|
-
return `file:///${replaceBackSlashesWithSlashes(windowsFilePath)}`
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export const replaceBackSlashesWithSlashes = (string) =>
|
|
106
|
-
string.replace(/\\/g, "/")
|
package/src/original_position.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { requireSourcemap } from "./require_sourcemap.js"
|
|
2
2
|
|
|
3
3
|
// https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
|
|
4
|
-
export const getOriginalPosition =
|
|
5
|
-
sourcemap,
|
|
6
|
-
line,
|
|
7
|
-
column,
|
|
8
|
-
bias,
|
|
9
|
-
}) => {
|
|
4
|
+
export const getOriginalPosition = ({ sourcemap, line, column, bias }) => {
|
|
10
5
|
const { SourceMapConsumer } = requireSourcemap()
|
|
11
6
|
|
|
12
|
-
const sourceMapConsumer =
|
|
7
|
+
const sourceMapConsumer = new SourceMapConsumer(sourcemap)
|
|
13
8
|
const originalPosition = sourceMapConsumer.originalPositionFor({
|
|
14
9
|
line,
|
|
15
10
|
column,
|
package/src/require_sourcemap.js
CHANGED
|
@@ -6,7 +6,7 @@ import { requireSourcemap } from "./require_sourcemap.js"
|
|
|
6
6
|
|
|
7
7
|
const { SourceMapConsumer, SourceMapGenerator } = requireSourcemap()
|
|
8
8
|
|
|
9
|
-
export const composeTwoSourcemaps =
|
|
9
|
+
export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
|
|
10
10
|
if (!firstSourcemap && !secondSourcemap) {
|
|
11
11
|
return null
|
|
12
12
|
}
|
|
@@ -17,8 +17,8 @@ export const composeTwoSourcemaps = async (firstSourcemap, secondSourcemap) => {
|
|
|
17
17
|
return firstSourcemap
|
|
18
18
|
}
|
|
19
19
|
const sourcemapGenerator = new SourceMapGenerator()
|
|
20
|
-
const firstSourcemapConsumer =
|
|
21
|
-
const secondSourcemapConsumer =
|
|
20
|
+
const firstSourcemapConsumer = new SourceMapConsumer(firstSourcemap)
|
|
21
|
+
const secondSourcemapConsumer = new SourceMapConsumer(secondSourcemap)
|
|
22
22
|
const firstMappings = readMappings(firstSourcemapConsumer)
|
|
23
23
|
firstMappings.forEach((mapping) => {
|
|
24
24
|
sourcemapGenerator.addMapping(mapping)
|