Fixed infinite #clowntown error loop

This commit is contained in:
Nick Lockwood
2015-05-14 11:53:22 -07:00
parent 766983f69b
commit 7c3070628a
2 changed files with 23 additions and 4 deletions

View File

@@ -13,10 +13,13 @@
'use strict';
var Promise = require('Promise');
var RCTSourceCode = require('NativeModules').SourceCode;
var NativeModules = require('NativeModules');
var SourceMapConsumer = require('SourceMap').SourceMapConsumer;
var SourceMapURL = require('./source-map-url');
var RCTSourceCode = NativeModules.SourceCode;
var RCTDataManager = NativeModules.DataManager;
function loadSourceMap(): Promise {
return fetchSourceMap()
.then(map => new SourceMapConsumer(map));
@@ -31,17 +34,31 @@ function fetchSourceMap(): Promise {
return Promise.reject(new Error('RCTSourceCode module is not available'));
}
if (!RCTDataManager) {
// Used internally by fetch
return Promise.reject(new Error('RCTDataManager module is not available'));
}
return new Promise(RCTSourceCode.getScriptText)
.then(extractSourceMapURL)
.then((url) => {
if (url === null) {
return Promise.reject(new Error('No source map URL found. May be running from bundled file.'));
}
return Promise.resolve(url);
})
.then(fetch)
.then(response => response.text())
}
function extractSourceMapURL({url, text, fullSourceMappingURL}): string {
function extractSourceMapURL({url, text, fullSourceMappingURL}): ?string {
if (fullSourceMappingURL) {
return fullSourceMappingURL;
}
var mapURL = SourceMapURL.getFrom(text);
if (!mapURL) {
return null;
}
var baseURL = url.match(/(.+:\/\/.*?)\//)[1];
return baseURL + mapURL;
}