@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
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/sourcemap",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/jsenv/
|
|
8
|
-
"directory": "packages/utils"
|
|
7
|
+
"url": "https://github.com/jsenv/core",
|
|
8
|
+
"directory": "packages/independent/utils"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@jsenv/urls": "2.
|
|
23
|
-
"magic-string": "0.30.
|
|
22
|
+
"@jsenv/urls": "2.2.0",
|
|
23
|
+
"magic-string": "0.30.2",
|
|
24
24
|
"source-map-js": "1.0.2"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/scripts/test.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { executeTestPlan, nodeWorkerThread } from "@jsenv/
|
|
1
|
+
import { executeTestPlan, nodeWorkerThread } from "@jsenv/test";
|
|
2
2
|
|
|
3
3
|
await executeTestPlan({
|
|
4
4
|
rootDirectoryUrl: new URL("../", import.meta.url),
|
|
5
5
|
testPlan: {
|
|
6
6
|
"./tests/**/*.test.mjs": {
|
|
7
7
|
node: {
|
|
8
|
-
runtime: nodeWorkerThread,
|
|
8
|
+
runtime: nodeWorkerThread(),
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
failFast: process.argv.includes("--workspace"),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
13
|
+
logShortForCompletedExecutions: true,
|
|
14
|
+
logMergeForCompletedExecutions: process.argv.includes("--workspace"),
|
|
15
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// duplicated from @jsenv/log to avoid the dependency
|
|
2
2
|
export const createDetailedMessage = (message, details = {}) => {
|
|
3
|
-
let string = `${message}
|
|
3
|
+
let string = `${message}`;
|
|
4
4
|
|
|
5
5
|
Object.keys(details).forEach((key) => {
|
|
6
|
-
const value = details[key]
|
|
6
|
+
const value = details[key];
|
|
7
7
|
string += `
|
|
8
8
|
--- ${key} ---
|
|
9
9
|
${
|
|
@@ -11,8 +11,8 @@ export const createDetailedMessage = (message, details = {}) => {
|
|
|
11
11
|
? value.join(`
|
|
12
12
|
`)
|
|
13
13
|
: value
|
|
14
|
-
}
|
|
15
|
-
})
|
|
14
|
+
}`;
|
|
15
|
+
});
|
|
16
16
|
|
|
17
|
-
return string
|
|
18
|
-
}
|
|
17
|
+
return string;
|
|
18
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createDetailedMessage } from "./detailed_message.js"
|
|
2
|
-
import { remapStack } from "./remap_stack.js"
|
|
3
|
-
import { stringifyStack } from "./stringify_stack.js"
|
|
1
|
+
import { createDetailedMessage } from "./detailed_message.js";
|
|
2
|
+
import { remapStack } from "./remap_stack.js";
|
|
3
|
+
import { stringifyStack } from "./stringify_stack.js";
|
|
4
4
|
|
|
5
5
|
export const installErrorStackRemapping = ({
|
|
6
6
|
fetchFile,
|
|
@@ -9,52 +9,52 @@ export const installErrorStackRemapping = ({
|
|
|
9
9
|
indent = " ",
|
|
10
10
|
}) => {
|
|
11
11
|
if (typeof fetchFile !== "function") {
|
|
12
|
-
throw new TypeError(`fetchFile must be a function, got ${fetchFile}`)
|
|
12
|
+
throw new TypeError(`fetchFile must be a function, got ${fetchFile}`);
|
|
13
13
|
}
|
|
14
14
|
if (typeof SourceMapConsumer !== "function") {
|
|
15
15
|
throw new TypeError(
|
|
16
16
|
`sourceMapConsumer must be a function, got ${SourceMapConsumer}`,
|
|
17
|
-
)
|
|
17
|
+
);
|
|
18
18
|
}
|
|
19
19
|
if (typeof indent !== "string") {
|
|
20
|
-
throw new TypeError(`indent must be a string, got ${indent}`)
|
|
20
|
+
throw new TypeError(`indent must be a string, got ${indent}`);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const errorRemappingCache = new WeakMap()
|
|
24
|
-
const errorRemapFailureCallbackMap = new WeakMap()
|
|
23
|
+
const errorRemappingCache = new WeakMap();
|
|
24
|
+
const errorRemapFailureCallbackMap = new WeakMap();
|
|
25
25
|
|
|
26
|
-
let installed = false
|
|
27
|
-
const previousPrepareStackTrace = Error.prepareStackTrace
|
|
26
|
+
let installed = false;
|
|
27
|
+
const previousPrepareStackTrace = Error.prepareStackTrace;
|
|
28
28
|
const install = () => {
|
|
29
|
-
if (installed) return
|
|
30
|
-
installed = true
|
|
31
|
-
Error.prepareStackTrace = prepareStackTrace
|
|
32
|
-
}
|
|
29
|
+
if (installed) return;
|
|
30
|
+
installed = true;
|
|
31
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
32
|
+
};
|
|
33
33
|
|
|
34
34
|
const uninstall = () => {
|
|
35
|
-
if (!installed) return
|
|
36
|
-
installed = false
|
|
37
|
-
Error.prepareStackTrace = previousPrepareStackTrace
|
|
38
|
-
}
|
|
35
|
+
if (!installed) return;
|
|
36
|
+
installed = false;
|
|
37
|
+
Error.prepareStackTrace = previousPrepareStackTrace;
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
// ensure we do not use prepareStackTrace for thoose error
|
|
41
41
|
// otherwise we would recursively remap error stack
|
|
42
42
|
// and if the reason causing the failure is still here
|
|
43
43
|
// it would create an infinite loop
|
|
44
44
|
const readErrorStack = (error) => {
|
|
45
|
-
uninstall()
|
|
46
|
-
const stack = error.stack
|
|
47
|
-
install()
|
|
48
|
-
return stack
|
|
49
|
-
}
|
|
45
|
+
uninstall();
|
|
46
|
+
const stack = error.stack;
|
|
47
|
+
install();
|
|
48
|
+
return stack;
|
|
49
|
+
};
|
|
50
50
|
|
|
51
51
|
const prepareStackTrace = (error, stack) => {
|
|
52
52
|
const onFailure = (failureData) => {
|
|
53
|
-
const failureCallbackArray = errorRemapFailureCallbackMap.get(error)
|
|
53
|
+
const failureCallbackArray = errorRemapFailureCallbackMap.get(error);
|
|
54
54
|
if (failureCallbackArray) {
|
|
55
|
-
failureCallbackArray.forEach((callback) => callback(failureData))
|
|
55
|
+
failureCallbackArray.forEach((callback) => callback(failureData));
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
};
|
|
58
58
|
|
|
59
59
|
const stackRemappingPromise = remapStack({
|
|
60
60
|
stack,
|
|
@@ -65,77 +65,77 @@ export const installErrorStackRemapping = ({
|
|
|
65
65
|
readErrorStack,
|
|
66
66
|
indent,
|
|
67
67
|
onFailure,
|
|
68
|
-
})
|
|
69
|
-
errorRemappingCache.set(error, stackRemappingPromise)
|
|
68
|
+
});
|
|
69
|
+
errorRemappingCache.set(error, stackRemappingPromise);
|
|
70
70
|
|
|
71
|
-
return stringifyStack(stack, { error, indent })
|
|
72
|
-
}
|
|
71
|
+
return stringifyStack(stack, { error, indent });
|
|
72
|
+
};
|
|
73
73
|
|
|
74
74
|
const getErrorOriginalStackString = async (
|
|
75
75
|
error,
|
|
76
76
|
{
|
|
77
77
|
onFailure = (message) => {
|
|
78
|
-
console.warn(message)
|
|
78
|
+
console.warn(message);
|
|
79
79
|
},
|
|
80
80
|
} = {},
|
|
81
81
|
) => {
|
|
82
82
|
if (onFailure) {
|
|
83
|
-
const remapFailureCallbackArray = errorRemapFailureCallbackMap.get(error)
|
|
83
|
+
const remapFailureCallbackArray = errorRemapFailureCallbackMap.get(error);
|
|
84
84
|
if (remapFailureCallbackArray) {
|
|
85
85
|
errorRemapFailureCallbackMap.set(error, [
|
|
86
86
|
...remapFailureCallbackArray,
|
|
87
87
|
onFailure,
|
|
88
|
-
])
|
|
88
|
+
]);
|
|
89
89
|
} else {
|
|
90
|
-
errorRemapFailureCallbackMap.set(error, [onFailure])
|
|
90
|
+
errorRemapFailureCallbackMap.set(error, [onFailure]);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// ensure Error.prepareStackTrace gets triggered by reading error.stack now
|
|
95
|
-
const { stack } = error
|
|
96
|
-
const promise = errorRemappingCache.get(error)
|
|
95
|
+
const { stack } = error;
|
|
96
|
+
const promise = errorRemappingCache.get(error);
|
|
97
97
|
|
|
98
98
|
if (promise) {
|
|
99
99
|
try {
|
|
100
|
-
const originalCallsites = await promise
|
|
101
|
-
errorRemapFailureCallbackMap.get(error)
|
|
100
|
+
const originalCallsites = await promise;
|
|
101
|
+
errorRemapFailureCallbackMap.get(error);
|
|
102
102
|
|
|
103
|
-
const firstCall = originalCallsites[0]
|
|
103
|
+
const firstCall = originalCallsites[0];
|
|
104
104
|
if (firstCall) {
|
|
105
105
|
Object.assign(error, {
|
|
106
106
|
filename: firstCall.getFileName(),
|
|
107
107
|
lineno: firstCall.getLineNumber(),
|
|
108
108
|
columnno: firstCall.getColumnNumber(),
|
|
109
|
-
})
|
|
109
|
+
});
|
|
110
110
|
}
|
|
111
|
-
return stringifyStack(originalCallsites, { error, indent })
|
|
111
|
+
return stringifyStack(originalCallsites, { error, indent });
|
|
112
112
|
} catch (e) {
|
|
113
113
|
onFailure(
|
|
114
114
|
createDetailedMessage(`error while computing original stack.`, {
|
|
115
115
|
["stack from error while computing"]: readErrorStack(e),
|
|
116
116
|
["stack from error to remap"]: stack,
|
|
117
117
|
}),
|
|
118
|
-
)
|
|
119
|
-
return stack
|
|
118
|
+
);
|
|
119
|
+
return stack;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
return stack
|
|
124
|
-
}
|
|
123
|
+
return stack;
|
|
124
|
+
};
|
|
125
125
|
|
|
126
|
-
install()
|
|
126
|
+
install();
|
|
127
127
|
|
|
128
|
-
return { getErrorOriginalStackString, uninstall }
|
|
129
|
-
}
|
|
128
|
+
return { getErrorOriginalStackString, uninstall };
|
|
129
|
+
};
|
|
130
130
|
|
|
131
131
|
const memoizeFetch = (fetchUrl) => {
|
|
132
|
-
const urlCache = {}
|
|
132
|
+
const urlCache = {};
|
|
133
133
|
return async (url) => {
|
|
134
134
|
if (url in urlCache) {
|
|
135
|
-
return urlCache[url]
|
|
135
|
+
return urlCache[url];
|
|
136
136
|
}
|
|
137
|
-
const responsePromise = fetchUrl(url)
|
|
138
|
-
urlCache[url] = responsePromise
|
|
139
|
-
return responsePromise
|
|
140
|
-
}
|
|
141
|
-
}
|
|
137
|
+
const responsePromise = fetchUrl(url);
|
|
138
|
+
urlCache[url] = responsePromise;
|
|
139
|
+
return responsePromise;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { remapSourcePosition } from "./remap_source_position.js"
|
|
1
|
+
import { remapSourcePosition } from "./remap_source_position.js";
|
|
2
2
|
|
|
3
3
|
export const remapCallSite = async (
|
|
4
4
|
callSite,
|
|
5
5
|
{ urlToSourcemapConsumer, resolveFile, readErrorStack, onFailure },
|
|
6
6
|
) => {
|
|
7
7
|
if (callSite.isNative()) {
|
|
8
|
-
return callSite
|
|
8
|
+
return callSite;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// Most call sites will return the source file from getFileName(), but code
|
|
12
12
|
// passed to eval() ending in "//# sourceURL=..." will return the source file
|
|
13
13
|
// from getScriptNameOrSourceURL() instead
|
|
14
|
-
const source = callSite.getFileName() || callSite.getScriptNameOrSourceURL()
|
|
14
|
+
const source = callSite.getFileName() || callSite.getScriptNameOrSourceURL();
|
|
15
15
|
if (source) {
|
|
16
|
-
const line = callSite.getLineNumber()
|
|
17
|
-
const column = callSite.getColumnNumber() - 1
|
|
16
|
+
const line = callSite.getLineNumber();
|
|
17
|
+
const column = callSite.getColumnNumber() - 1;
|
|
18
18
|
const originalPosition = await remapSourcePosition({
|
|
19
19
|
url: resolveFile(source),
|
|
20
20
|
line,
|
|
@@ -22,50 +22,50 @@ export const remapCallSite = async (
|
|
|
22
22
|
resolveFile,
|
|
23
23
|
urlToSourcemapConsumer,
|
|
24
24
|
readErrorStack,
|
|
25
|
-
})
|
|
25
|
+
});
|
|
26
26
|
|
|
27
|
-
const callSiteClone = cloneCallSite(callSite)
|
|
27
|
+
const callSiteClone = cloneCallSite(callSite);
|
|
28
28
|
|
|
29
29
|
callSiteClone.getFunctionName = () =>
|
|
30
|
-
originalPosition.name || callSite.getFunctionName()
|
|
31
|
-
callSiteClone.getFileName = () => originalPosition.source
|
|
32
|
-
callSiteClone.getLineNumber = () => originalPosition.line
|
|
33
|
-
callSiteClone.getColumnNumber = () => originalPosition.column + 1
|
|
34
|
-
callSiteClone.getScriptNameOrSourceURL = () => originalPosition.source
|
|
30
|
+
originalPosition.name || callSite.getFunctionName();
|
|
31
|
+
callSiteClone.getFileName = () => originalPosition.source;
|
|
32
|
+
callSiteClone.getLineNumber = () => originalPosition.line;
|
|
33
|
+
callSiteClone.getColumnNumber = () => originalPosition.column + 1;
|
|
34
|
+
callSiteClone.getScriptNameOrSourceURL = () => originalPosition.source;
|
|
35
35
|
|
|
36
|
-
return callSiteClone
|
|
36
|
+
return callSiteClone;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Code called using eval() needs special handling
|
|
40
40
|
if (callSite.isEval()) {
|
|
41
|
-
const origin = callSite.getEvalOrigin()
|
|
41
|
+
const origin = callSite.getEvalOrigin();
|
|
42
42
|
if (origin) {
|
|
43
|
-
const callSiteClone = cloneCallSite(callSite)
|
|
43
|
+
const callSiteClone = cloneCallSite(callSite);
|
|
44
44
|
const originalEvalOrigin = await remapEvalOrigin(origin, {
|
|
45
45
|
resolveFile,
|
|
46
46
|
urlToSourcemapConsumer,
|
|
47
47
|
readErrorStack,
|
|
48
48
|
onFailure,
|
|
49
|
-
})
|
|
50
|
-
callSiteClone.getEvalOrigin = () => originalEvalOrigin
|
|
51
|
-
return callSiteClone
|
|
49
|
+
});
|
|
50
|
+
callSiteClone.getEvalOrigin = () => originalEvalOrigin;
|
|
51
|
+
return callSiteClone;
|
|
52
52
|
}
|
|
53
|
-
return callSite
|
|
53
|
+
return callSite;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// If we get here then we were unable to change the source position
|
|
57
|
-
return callSite
|
|
58
|
-
}
|
|
57
|
+
return callSite;
|
|
58
|
+
};
|
|
59
59
|
|
|
60
60
|
const cloneCallSite = (callSite) => {
|
|
61
|
-
const callSiteClone = {}
|
|
61
|
+
const callSiteClone = {};
|
|
62
62
|
methods.forEach((name) => {
|
|
63
|
-
callSiteClone[name] = () => callSite[name]()
|
|
64
|
-
})
|
|
65
|
-
callSiteClone.toString = () => callSiteToFunctionCall(callSiteClone)
|
|
63
|
+
callSiteClone[name] = () => callSite[name]();
|
|
64
|
+
});
|
|
65
|
+
callSiteClone.toString = () => callSiteToFunctionCall(callSiteClone);
|
|
66
66
|
|
|
67
|
-
return callSiteClone
|
|
68
|
-
}
|
|
67
|
+
return callSiteClone;
|
|
68
|
+
};
|
|
69
69
|
|
|
70
70
|
const methods = [
|
|
71
71
|
"getColumnNumber",
|
|
@@ -84,99 +84,99 @@ const methods = [
|
|
|
84
84
|
"isNative",
|
|
85
85
|
"isToplevel",
|
|
86
86
|
"toString",
|
|
87
|
-
]
|
|
87
|
+
];
|
|
88
88
|
|
|
89
89
|
const callSiteToFunctionCall = (callSite) => {
|
|
90
|
-
const fileLocation = callSiteToFileLocation(callSite)
|
|
91
|
-
const isConstructor = callSite.isConstructor()
|
|
92
|
-
const isMethodCall = !callSite.isToplevel() && !isConstructor
|
|
90
|
+
const fileLocation = callSiteToFileLocation(callSite);
|
|
91
|
+
const isConstructor = callSite.isConstructor();
|
|
92
|
+
const isMethodCall = !callSite.isToplevel() && !isConstructor;
|
|
93
93
|
|
|
94
94
|
if (isMethodCall) {
|
|
95
|
-
return `${callSiteToMethodCall(callSite)} (${fileLocation})
|
|
95
|
+
return `${callSiteToMethodCall(callSite)} (${fileLocation})`;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const functionName = callSite.getFunctionName()
|
|
98
|
+
const functionName = callSite.getFunctionName();
|
|
99
99
|
if (isConstructor) {
|
|
100
|
-
return `new ${functionName || "<anonymous>"} (${fileLocation})
|
|
100
|
+
return `new ${functionName || "<anonymous>"} (${fileLocation})`;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
if (functionName) {
|
|
104
|
-
return `${functionName} (${fileLocation})
|
|
104
|
+
return `${functionName} (${fileLocation})`;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
return `${fileLocation}
|
|
108
|
-
}
|
|
107
|
+
return `${fileLocation}`;
|
|
108
|
+
};
|
|
109
109
|
|
|
110
110
|
const callSiteToMethodCall = (callSite) => {
|
|
111
|
-
const functionName = callSite.getFunctionName()
|
|
112
|
-
const typeName = callSiteToType(callSite)
|
|
111
|
+
const functionName = callSite.getFunctionName();
|
|
112
|
+
const typeName = callSiteToType(callSite);
|
|
113
113
|
|
|
114
114
|
if (!functionName) {
|
|
115
|
-
return `${typeName}.<anonymous
|
|
115
|
+
return `${typeName}.<anonymous>`;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
const methodName = callSite.getMethodName()
|
|
119
|
-
const as = generateAs({ methodName, functionName })
|
|
118
|
+
const methodName = callSite.getMethodName();
|
|
119
|
+
const as = generateAs({ methodName, functionName });
|
|
120
120
|
|
|
121
121
|
if (typeName && !functionName.startsWith(typeName)) {
|
|
122
|
-
return `${typeName}.${functionName}${as}
|
|
122
|
+
return `${typeName}.${functionName}${as}`;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
return `${functionName}${as}
|
|
126
|
-
}
|
|
125
|
+
return `${functionName}${as}`;
|
|
126
|
+
};
|
|
127
127
|
|
|
128
128
|
const generateAs = ({ methodName, functionName }) => {
|
|
129
|
-
if (!methodName) return ""
|
|
129
|
+
if (!methodName) return "";
|
|
130
130
|
if (
|
|
131
131
|
functionName.indexOf(`.${methodName}`) ===
|
|
132
132
|
functionName.length - methodName.length - 1
|
|
133
133
|
)
|
|
134
|
-
return ""
|
|
135
|
-
return ` [as ${methodName}]
|
|
136
|
-
}
|
|
134
|
+
return "";
|
|
135
|
+
return ` [as ${methodName}]`;
|
|
136
|
+
};
|
|
137
137
|
|
|
138
138
|
const callSiteToType = (callSite) => {
|
|
139
|
-
const typeName = callSite.getTypeName()
|
|
139
|
+
const typeName = callSite.getTypeName();
|
|
140
140
|
// Fixes shim to be backward compatible with Node v0 to v4
|
|
141
141
|
if (typeName === "[object Object]") {
|
|
142
|
-
return "null"
|
|
142
|
+
return "null";
|
|
143
143
|
}
|
|
144
|
-
return typeName
|
|
145
|
-
}
|
|
144
|
+
return typeName;
|
|
145
|
+
};
|
|
146
146
|
|
|
147
147
|
const callSiteToFileLocation = (callSite) => {
|
|
148
|
-
if (callSite.isNative()) return "native"
|
|
148
|
+
if (callSite.isNative()) return "native";
|
|
149
149
|
|
|
150
|
-
const sourceFile = callSiteToSourceFile(callSite)
|
|
151
|
-
const lineNumber = callSite.getLineNumber()
|
|
150
|
+
const sourceFile = callSiteToSourceFile(callSite);
|
|
151
|
+
const lineNumber = callSite.getLineNumber();
|
|
152
152
|
if (lineNumber === null) {
|
|
153
|
-
return sourceFile
|
|
153
|
+
return sourceFile;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
const columnNumber = callSite.getColumnNumber()
|
|
156
|
+
const columnNumber = callSite.getColumnNumber();
|
|
157
157
|
if (!columnNumber) {
|
|
158
|
-
return `${sourceFile}:${lineNumber}
|
|
158
|
+
return `${sourceFile}:${lineNumber}`;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
return `${sourceFile}:${lineNumber}:${columnNumber}
|
|
162
|
-
}
|
|
161
|
+
return `${sourceFile}:${lineNumber}:${columnNumber}`;
|
|
162
|
+
};
|
|
163
163
|
|
|
164
164
|
const callSiteToSourceFile = (callSite) => {
|
|
165
|
-
const fileName = callSite.getScriptNameOrSourceURL()
|
|
165
|
+
const fileName = callSite.getScriptNameOrSourceURL();
|
|
166
166
|
|
|
167
167
|
if (fileName) {
|
|
168
|
-
return fileName
|
|
168
|
+
return fileName;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
// Source code does not originate from a file and is not native, but we
|
|
172
172
|
// can still get the source position inside the source string, e.g. in
|
|
173
173
|
// an eval string.
|
|
174
174
|
if (callSite.isEval()) {
|
|
175
|
-
return `${callSite.getEvalOrigin()}, <anonymous
|
|
175
|
+
return `${callSite.getEvalOrigin()}, <anonymous>`;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
return "<anonymous>"
|
|
179
|
-
}
|
|
178
|
+
return "<anonymous>";
|
|
179
|
+
};
|
|
180
180
|
|
|
181
181
|
// Parses code generated by FormatEvalOrigin(), a function inside V8:
|
|
182
182
|
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
|
|
@@ -187,34 +187,34 @@ const remapEvalOrigin = async (
|
|
|
187
187
|
// Most eval() calls are in this format
|
|
188
188
|
const topLevelEvalMatch = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(
|
|
189
189
|
origin,
|
|
190
|
-
)
|
|
190
|
+
);
|
|
191
191
|
if (topLevelEvalMatch) {
|
|
192
|
-
const source = topLevelEvalMatch[2]
|
|
193
|
-
const line = Number(topLevelEvalMatch[3])
|
|
194
|
-
const column = topLevelEvalMatch[4] - 1
|
|
192
|
+
const source = topLevelEvalMatch[2];
|
|
193
|
+
const line = Number(topLevelEvalMatch[3]);
|
|
194
|
+
const column = topLevelEvalMatch[4] - 1;
|
|
195
195
|
const originalPosition = await remapSourcePosition({
|
|
196
196
|
url: resolveFile(source),
|
|
197
197
|
line,
|
|
198
198
|
column,
|
|
199
199
|
resolveFile,
|
|
200
200
|
urlToSourcemapConsumer,
|
|
201
|
-
})
|
|
201
|
+
});
|
|
202
202
|
return `eval at ${topLevelEvalMatch[1]} (${originalPosition.source}:${
|
|
203
203
|
originalPosition.line
|
|
204
|
-
}:${originalPosition.column + 1})
|
|
204
|
+
}:${originalPosition.column + 1})`;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
// Parse nested eval() calls using recursion
|
|
208
|
-
const nestedEvalMatch = /^eval at ([^(]+) \((.+)\)$/.exec(origin)
|
|
208
|
+
const nestedEvalMatch = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
|
209
209
|
if (nestedEvalMatch) {
|
|
210
210
|
const originalEvalOrigin = await remapEvalOrigin(nestedEvalMatch[2], {
|
|
211
211
|
resolveFile,
|
|
212
212
|
urlToSourcemapConsumer,
|
|
213
213
|
onFailure,
|
|
214
|
-
})
|
|
215
|
-
return `eval at ${nestedEvalMatch[1]} (${originalEvalOrigin})
|
|
214
|
+
});
|
|
215
|
+
return `eval at ${nestedEvalMatch[1]} (${originalEvalOrigin})`;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// Make sure we still return useful information if we didn't find anything
|
|
219
|
-
return origin
|
|
220
|
-
}
|
|
219
|
+
return origin;
|
|
220
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createDetailedMessage } from "./detailed_message.js"
|
|
1
|
+
import { createDetailedMessage } from "./detailed_message.js";
|
|
2
2
|
|
|
3
3
|
export const remapSourcePosition = async ({
|
|
4
4
|
url,
|
|
@@ -8,30 +8,30 @@ export const remapSourcePosition = async ({
|
|
|
8
8
|
urlToSourcemapConsumer,
|
|
9
9
|
readErrorStack = (e) => e.stack,
|
|
10
10
|
}) => {
|
|
11
|
-
const position = { url, line, column }
|
|
12
|
-
const sourceMapConsumer = await urlToSourcemapConsumer(url)
|
|
11
|
+
const position = { url, line, column };
|
|
12
|
+
const sourceMapConsumer = await urlToSourcemapConsumer(url);
|
|
13
13
|
|
|
14
14
|
if (!sourceMapConsumer) {
|
|
15
|
-
return position
|
|
15
|
+
return position;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
|
-
const originalPosition = sourceMapConsumer.originalPositionFor(position)
|
|
19
|
+
const originalPosition = sourceMapConsumer.originalPositionFor(position);
|
|
20
20
|
|
|
21
21
|
// Only return the original position if a matching line was found. If no
|
|
22
22
|
// matching line is found then we return position instead, which will cause
|
|
23
23
|
// the stack trace to print the path and line for the compiled file. It is
|
|
24
24
|
// better to give a precise location in the compiled file than a vague
|
|
25
25
|
// location in the original file.
|
|
26
|
-
const originalSource = originalPosition.source
|
|
26
|
+
const originalSource = originalPosition.source;
|
|
27
27
|
if (originalSource === null) {
|
|
28
|
-
return position
|
|
28
|
+
return position;
|
|
29
29
|
}
|
|
30
30
|
return {
|
|
31
31
|
url: resolveFile(originalSource, url),
|
|
32
32
|
line: originalPosition.line,
|
|
33
33
|
column: originalPosition.column,
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
} catch (e) {
|
|
36
36
|
console.warn(
|
|
37
37
|
createDetailedMessage(`error while remapping position.`, {
|
|
@@ -40,7 +40,7 @@ export const remapSourcePosition = async ({
|
|
|
40
40
|
["line"]: line,
|
|
41
41
|
["column"]: column,
|
|
42
42
|
}),
|
|
43
|
-
)
|
|
44
|
-
return position
|
|
43
|
+
);
|
|
44
|
+
return position;
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
};
|