@@ -55,7 +55,7 @@ export function mapScopes(scopes: Promise<Scope>, frame: Frame) {
5555 ! sourceRecord . get ( "isPrettyPrinted" ) &&
5656 ! isGeneratedId ( frame . location . sourceId ) ;
5757
58- dispatch ( {
58+ await dispatch ( {
5959 type : "MAP_SCOPES" ,
6060 frame,
6161 [ PROMISE ] : ( async function ( ) {
@@ -88,7 +88,12 @@ async function buildMappedScopes(
8888 scopes : Scope ,
8989 sourceMaps : any ,
9090 client : any
91- ) : Promise < ?OriginalScope > {
91+ ) : Promise < ?{
92+ mappings: {
93+ [ string ] : string
94+ } ,
95+ scope : OriginalScope
96+ } > {
9297 const originalAstScopes = await getScopes ( frame . location ) ;
9398 const generatedAstScopes = await getScopes ( frame . generatedLocation ) ;
9499
@@ -102,42 +107,52 @@ async function buildMappedScopes(
102107 frame . this
103108 ) ;
104109
105- const mappedOriginalScopes = await Promise . all (
106- Array . from ( originalAstScopes , async item => {
107- const generatedBindings = { } ;
110+ const expressionLookup = { } ;
111+ const mappedOriginalScopes = [ ] ;
108112
109- await Promise . all (
110- Object . keys ( item . bindings ) . map ( async name => {
111- const binding = item . bindings [ name ] ;
113+ for ( const item of originalAstScopes ) {
114+ const generatedBindings = { } ;
112115
113- const result = await findGeneratedBinding (
114- sourceMaps ,
115- client ,
116- source ,
117- name ,
118- binding ,
119- generatedAstBindings
120- ) ;
116+ for ( const name of Object . keys ( item . bindings ) ) {
117+ const binding = item . bindings [ name ] ;
121118
122- if ( result ) {
123- generatedBindings [ name ] = result ;
124- }
125- } )
119+ const result = await findGeneratedBinding (
120+ sourceMaps ,
121+ client ,
122+ source ,
123+ name ,
124+ binding ,
125+ generatedAstBindings
126126 ) ;
127127
128- return {
129- ...item ,
130- generatedBindings
131- } ;
132- } )
133- ) ;
128+ if ( result ) {
129+ generatedBindings [ name ] = result . grip ;
130+
131+ if (
132+ binding . refs . length !== 0 &&
133+ // These are assigned depth-first, so we don't want shadowed
134+ // bindings in parent scopes overwriting the expression.
135+ ! Object . prototype . hasOwnProperty . call ( expressionLookup , name )
136+ ) {
137+ expressionLookup [ name ] = result . expression ;
138+ }
139+ }
140+ }
141+
142+ mappedOriginalScopes . push ( {
143+ ...item ,
144+ generatedBindings
145+ } ) ;
146+ }
134147
135148 const mappedGeneratedScopes = generateClientScope (
136149 scopes ,
137150 mappedOriginalScopes
138151 ) ;
139152
140- return isReliableScope ( mappedGeneratedScopes ) ? mappedGeneratedScopes : null ;
153+ return isReliableScope ( mappedGeneratedScopes )
154+ ? { mappings : expressionLookup , scope : mappedGeneratedScopes }
155+ : null ;
141156}
142157
143158/**
@@ -244,7 +259,10 @@ async function findGeneratedBinding(
244259 name : string ,
245260 originalBinding : BindingData ,
246261 generatedAstBindings : Array < GeneratedBindingLocation >
247- ) : Promise < ?BindingContents > {
262+ ) : Promise < ?{
263+ grip : BindingContents ,
264+ expression : string | null
265+ } > {
248266 // If there are no references to the implicits, then we have no way to
249267 // even attempt to map it back to the original since there is no location
250268 // data to use. Bail out instead of just showing it as unmapped.
@@ -275,7 +293,10 @@ async function findGeneratedBinding(
275293 } , null ) ;
276294
277295 if ( genContent && genContent . desc ) {
278- return genContent . desc ;
296+ return {
297+ grip : genContent . desc ,
298+ expression : genContent . expression
299+ } ;
279300 } else if ( genContent ) {
280301 // If there is no descriptor for 'this', then this is not the top-level
281302 // 'this' that the server gave us a binding for, and we can just ignore it.
@@ -287,17 +308,20 @@ async function findGeneratedBinding(
287308 // means that the server scope information didn't match the scope
288309 // information from the DevTools parsed scopes.
289310 return {
290- configurable : false ,
291- enumerable : true ,
292- writable : false ,
293- value : {
294- type : "unscoped" ,
295- unscoped : true ,
296-
297- // HACK: Until support for "unscoped" lands in devtools-reps,
298- // this will make these show as (unavailable).
299- missingArguments : true
300- }
311+ grip : {
312+ configurable : false ,
313+ enumerable : true ,
314+ writable : false ,
315+ value : {
316+ type : "unscoped" ,
317+ unscoped : true ,
318+
319+ // HACK: Until support for "unscoped" lands in devtools-reps,
320+ // this will make these show as (unavailable).
321+ missingArguments : true
322+ }
323+ } ,
324+ expression : null
301325 } ;
302326 }
303327
@@ -306,17 +330,20 @@ async function findGeneratedBinding(
306330 // of some scope, but the generated location is outside, leading
307331 // us to search for bindings that don't technically exist.
308332 return {
309- configurable : false ,
310- enumerable : true ,
311- writable : false ,
312- value : {
313- type : "unmapped" ,
314- unmapped : true ,
315-
316- // HACK: Until support for "unmapped" lands in devtools-reps,
317- // this will make these show as (unavailable).
318- missingArguments : true
319- }
333+ grip : {
334+ configurable : false ,
335+ enumerable : true ,
336+ writable : false ,
337+ value : {
338+ type : "unmapped" ,
339+ unmapped : true ,
340+
341+ // HACK: Until support for "unmapped" lands in devtools-reps,
342+ // this will make these show as (unavailable).
343+ missingArguments : true
344+ }
345+ } ,
346+ expression : null
320347 } ;
321348}
322349
0 commit comments