Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit b6819f6

Browse files
loganfsmythjasonLaster
authored andcommitted
Expose the consumer's 'allGeneratedPositionsFor' method in the worker (#1014)
* Expose the consumer's 'allGeneratedPositionsFor' method in the worker. * Ensure that .mjs files are detected as JS.
1 parent 2f09a0f commit b6819f6

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

packages/devtools-source-map/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const dispatcher = new WorkerDispatcher();
1717

1818
const getOriginalURLs = dispatcher.task("getOriginalURLs");
1919
const getGeneratedLocation = dispatcher.task("getGeneratedLocation");
20+
const getAllGeneratedLocations =
21+
dispatcher.task("getAllGeneratedLocations");
2022
const getOriginalLocation = dispatcher.task("getOriginalLocation");
2123
const getLocationScopes = dispatcher.task("getLocationScopes");
2224
const getOriginalSourceText = dispatcher.task("getOriginalSourceText");
@@ -32,6 +34,7 @@ module.exports = {
3234
hasMappedSource,
3335
getOriginalURLs,
3436
getGeneratedLocation,
37+
getAllGeneratedLocations,
3538
getOriginalLocation,
3639
getLocationScopes,
3740
getOriginalSourceText,

packages/devtools-source-map/src/source-map.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ async function getGeneratedLocation(
6969
};
7070
}
7171

72+
async function getAllGeneratedLocations(
73+
location: Location,
74+
originalSource: Source
75+
): Promise<Array<Location>> {
76+
if (!isOriginalId(location.sourceId)) {
77+
return [];
78+
}
79+
80+
const generatedSourceId = originalToGeneratedId(location.sourceId);
81+
const map = await getSourceMap(generatedSourceId);
82+
if (!map) {
83+
return [];
84+
}
85+
86+
const positions = map.allGeneratedPositionsFor({
87+
source: originalSource.url,
88+
line: location.line,
89+
column: location.column == null ? 0 : location.column,
90+
bias: SourceMapConsumer.LEAST_UPPER_BOUND
91+
});
92+
93+
return positions.map(({ line, column }) => ({
94+
sourceId: generatedSourceId,
95+
line,
96+
column
97+
}));
98+
}
99+
72100
async function getOriginalLocation(location: Location): Promise<Location> {
73101
if (!isGeneratedId(location.sourceId)) {
74102
return location;
@@ -144,6 +172,7 @@ function applySourceMap(
144172
module.exports = {
145173
getOriginalURLs,
146174
getGeneratedLocation,
175+
getAllGeneratedLocations,
147176
getOriginalLocation,
148177
getOriginalSourceText,
149178
applySourceMap,

packages/devtools-source-map/src/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function trimUrlQuery(url: string): string {
4242
const contentMap = {
4343
"js": "text/javascript",
4444
"jsm": "text/javascript",
45+
"mjs": "text/javascript",
4546
"ts": "text/typescript",
4647
"tsx": "text/typescript-jsx",
4748
"jsx": "text/jsx",

packages/devtools-source-map/src/worker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const {
66
getOriginalURLs,
77
getGeneratedLocation,
8+
getAllGeneratedLocations,
89
getOriginalLocation,
910
getOriginalSourceText,
1011
getLocationScopes,
@@ -21,6 +22,7 @@ const { workerUtils: { workerHandler }} = require("devtools-utils");
2122
self.onmessage = workerHandler({
2223
getOriginalURLs,
2324
getGeneratedLocation,
25+
getAllGeneratedLocations,
2426
getOriginalLocation,
2527
getLocationScopes,
2628
getOriginalSourceText,

0 commit comments

Comments
 (0)