1313'use strict' ;
1414
1515var Promise = require ( 'Promise' ) ;
16- var RCTSourceCode = require ( 'NativeModules' ) . SourceCode ;
16+ var NativeModules = require ( 'NativeModules' ) ;
1717var SourceMapConsumer = require ( 'SourceMap' ) . SourceMapConsumer ;
1818var SourceMapURL = require ( './source-map-url' ) ;
1919
20+ var RCTSourceCode = NativeModules . SourceCode ;
21+ var RCTDataManager = NativeModules . DataManager ;
22+
2023function loadSourceMap ( ) : Promise {
2124 return fetchSourceMap ( )
2225 . then ( map => new SourceMapConsumer ( map ) ) ;
@@ -31,17 +34,31 @@ function fetchSourceMap(): Promise {
3134 return Promise . reject ( new Error ( 'RCTSourceCode module is not available' ) ) ;
3235 }
3336
37+ if ( ! RCTDataManager ) {
38+ // Used internally by fetch
39+ return Promise . reject ( new Error ( 'RCTDataManager module is not available' ) ) ;
40+ }
41+
3442 return new Promise ( RCTSourceCode . getScriptText )
3543 . then ( extractSourceMapURL )
44+ . then ( ( url ) => {
45+ if ( url === null ) {
46+ return Promise . reject ( new Error ( 'No source map URL found. May be running from bundled file.' ) ) ;
47+ }
48+ return Promise . resolve ( url ) ;
49+ } )
3650 . then ( fetch )
3751 . then ( response => response . text ( ) )
3852}
3953
40- function extractSourceMapURL ( { url, text, fullSourceMappingURL} ) : string {
54+ function extractSourceMapURL ( { url, text, fullSourceMappingURL} ) : ? string {
4155 if ( fullSourceMappingURL ) {
4256 return fullSourceMappingURL ;
4357 }
4458 var mapURL = SourceMapURL . getFrom ( text ) ;
59+ if ( ! mapURL ) {
60+ return null ;
61+ }
4562 var baseURL = url . match ( / ( .+ : \/ \/ .* ?) \/ / ) [ 1 ] ;
4663 return baseURL + mapURL ;
4764}
0 commit comments