This repository was archived by the owner on Sep 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed
packages/devtools-source-map/src Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ const dispatcher = new WorkerDispatcher();
1717
1818const getOriginalURLs = dispatcher . task ( "getOriginalURLs" ) ;
1919const getGeneratedLocation = dispatcher . task ( "getGeneratedLocation" ) ;
20+ const getAllGeneratedLocations =
21+ dispatcher . task ( "getAllGeneratedLocations" ) ;
2022const getOriginalLocation = dispatcher . task ( "getOriginalLocation" ) ;
2123const getLocationScopes = dispatcher . task ( "getLocationScopes" ) ;
2224const getOriginalSourceText = dispatcher . task ( "getOriginalSourceText" ) ;
@@ -32,6 +34,7 @@ module.exports = {
3234 hasMappedSource,
3335 getOriginalURLs,
3436 getGeneratedLocation,
37+ getAllGeneratedLocations,
3538 getOriginalLocation,
3639 getLocationScopes,
3740 getOriginalSourceText,
Original file line number Diff line number Diff 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+
72100async function getOriginalLocation ( location : Location ) : Promise < Location > {
73101 if ( ! isGeneratedId ( location . sourceId ) ) {
74102 return location ;
@@ -144,6 +172,7 @@ function applySourceMap(
144172module . exports = {
145173 getOriginalURLs,
146174 getGeneratedLocation,
175+ getAllGeneratedLocations,
147176 getOriginalLocation,
148177 getOriginalSourceText,
149178 applySourceMap,
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ function trimUrlQuery(url: string): string {
4242const 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" ,
Original file line number Diff line number Diff line change 55const {
66 getOriginalURLs,
77 getGeneratedLocation,
8+ getAllGeneratedLocations,
89 getOriginalLocation,
910 getOriginalSourceText,
1011 getLocationScopes,
@@ -21,6 +22,7 @@ const { workerUtils: { workerHandler }} = require("devtools-utils");
2122self . onmessage = workerHandler ( {
2223 getOriginalURLs,
2324 getGeneratedLocation,
25+ getAllGeneratedLocations,
2426 getOriginalLocation,
2527 getLocationScopes,
2628 getOriginalSourceText,
You can’t perform that action at this time.
0 commit comments