@@ -15,12 +15,12 @@ const AssetServer = require('../AssetServer');
15
15
const getPlatformExtension = require ( '../node-haste' ) . getPlatformExtension ;
16
16
const Bundler = require ( '../Bundler' ) ;
17
17
const MultipartResponse = require ( './MultipartResponse' ) ;
18
- const SourceMapConsumer = require ( 'source-map' ) . SourceMapConsumer ;
19
18
20
19
const declareOpts = require ( '../lib/declareOpts' ) ;
21
20
const defaults = require ( '../../defaults' ) ;
22
21
const mime = require ( 'mime-types' ) ;
23
22
const path = require ( 'path' ) ;
23
+ const symbolicate = require ( './symbolicate' ) ;
24
24
const terminal = require ( '../lib/terminal' ) ;
25
25
const url = require ( 'url' ) ;
26
26
@@ -34,6 +34,7 @@ import type Bundle from '../Bundler/Bundle';
34
34
import type { Reporter } from '../lib/reporting' ;
35
35
import type { GetTransformOptions } from '../Bundler' ;
36
36
import type GlobalTransformCache from '../lib/GlobalTransformCache' ;
37
+ import type { SourceMap , Symbolicate } from './symbolicate' ;
37
38
38
39
const {
39
40
createActionStartEntry,
@@ -201,6 +202,7 @@ class Server {
201
202
_debouncedFileChangeHandler: ( filePath : string ) => mixed ;
202
203
_hmrFileChangeListener: ( type : string , filePath : string ) => mixed ;
203
204
_reporter: Reporter ;
205
+ _symbolicateInWorker: Symbolicate ;
204
206
205
207
constructor ( options : Options ) {
206
208
this . _opts = {
@@ -281,6 +283,8 @@ class Server {
281
283
}
282
284
this . _informChangeWatchers ( ) ;
283
285
} , 50 ) ;
286
+
287
+ this . _symbolicateInWorker = symbolicate . createWorker ( ) ;
284
288
}
285
289
286
290
end ( ) : mixed {
@@ -802,45 +806,27 @@ class Server {
802
806
803
807
// In case of multiple bundles / HMR, some stack frames can have
804
808
// different URLs from others
805
- const urlIndexes = { } ;
806
- const uniqueUrls = [ ] ;
809
+ const urls = new Set ( ) ;
807
810
stack . forEach ( frame => {
808
811
const sourceUrl = frame . file ;
809
812
// Skip `/debuggerWorker.js` which drives remote debugging because it
810
813
// does not need to symbolication.
811
814
// Skip anything except http(s), because there is no support for that yet
812
- if ( ! urlIndexes . hasOwnProperty ( sourceUrl ) &&
815
+ if ( ! urls . has ( sourceUrl ) &&
813
816
! sourceUrl . endsWith ( '/debuggerWorker.js' ) &&
814
817
sourceUrl . startsWith ( 'http' ) ) {
815
- urlIndexes [ sourceUrl ] = uniqueUrls . length ;
816
- uniqueUrls . push ( sourceUrl ) ;
818
+ urls . add ( sourceUrl ) ;
817
819
}
818
820
} ) ;
819
821
820
- const sourceMaps = uniqueUrls . map (
821
- sourceUrl => this . _sourceMapForURL ( sourceUrl )
822
- ) ;
823
- return Promise . all ( sourceMaps ) . then ( consumers => {
824
- return stack . map ( frame => {
825
- const sourceUrl = frame . file ;
826
- if ( ! urlIndexes . hasOwnProperty ( sourceUrl ) ) {
827
- return frame ;
828
- }
829
- const idx = urlIndexes [ sourceUrl ] ;
830
- const consumer = consumers [ idx ] ;
831
- const original = consumer . originalPositionFor ( {
832
- line : frame . lineNumber ,
833
- column : frame . column ,
834
- } ) ;
835
- if ( ! original ) {
836
- return frame ;
837
- }
838
- return Object . assign ( { } , frame , {
839
- file : original . source ,
840
- lineNumber : original . line ,
841
- column : original . column ,
842
- } ) ;
843
- } ) ;
822
+ const mapPromises =
823
+ Array . from ( urls . values ( ) ) . map ( this . _sourceMapForURL , this ) ;
824
+
825
+ debug ( 'Getting source maps for symbolication' ) ;
826
+ return Promise . all ( mapPromises ) . then ( maps => {
827
+ debug ( 'Sending stacks and maps to symbolication worker' ) ;
828
+ const urlsToMaps = zip ( urls . values ( ) , maps ) ;
829
+ return this . _symbolicateInWorker ( stack , urlsToMaps ) ;
844
830
} ) ;
845
831
} ) . then (
846
832
stack => {
@@ -858,16 +844,13 @@ class Server {
858
844
) ;
859
845
}
860
846
861
- _sourceMapForURL ( reqUrl : string ) : Promise < SourceMapConsumer > {
847
+ _sourceMapForURL ( reqUrl : string ) : Promise < SourceMap > {
862
848
const options = this . _getOptionsFromUrl ( reqUrl ) ;
863
849
const building = this . _useCachedOrUpdateOrCreateBundle ( options ) ;
864
- return building . then ( p => {
865
- const sourceMap = p . getSourceMap ( {
866
- minify : options . minify ,
867
- dev : options . dev ,
868
- } ) ;
869
- return new SourceMapConsumer ( sourceMap ) ;
870
- } ) ;
850
+ return building . then ( p => p . getSourceMap ( {
851
+ minify : options . minify ,
852
+ dev : options . dev ,
853
+ } ) ) ;
871
854
}
872
855
873
856
_handleError ( res : ServerResponse , bundleID : string , error : {
@@ -990,4 +973,16 @@ function contentsEqual(array: Array<mixed>, set: Set<mixed>): boolean {
990
973
return array . length === set . size && array . every ( set . has , set ) ;
991
974
}
992
975
976
+ function * zip < X , Y > (xs: Iterable< X > , ys: Iterable< Y > ): Iterable< [ X , Y ] > {
977
+ //$FlowIssue #9324959
978
+ const ysIter : Iterator < Y > = ys [ Symbol . iterator ] ( ) ;
979
+ for ( const x of xs ) {
980
+ const y = ysIter . next ( ) ;
981
+ if ( y . done ) {
982
+ return ;
983
+ }
984
+ yield [ x , y . value ] ;
985
+ }
986
+ }
987
+
993
988
module . exports = Server ;
0 commit comments