Don't assume the SourceCode native module exists

Reviewed By: yungsters

Differential Revision: D7185837

fbshipit-source-id: e8efc22ac0af092dbc1fdf616b0b3f111390dd5d
This commit is contained in:
Andrew Chen (Eng) 2018-03-07 18:34:55 -08:00 committed by Facebook Github Bot
parent 596bcb6d84
commit 8cdc7d3e02
2 changed files with 2 additions and 2 deletions

View File

@ -25,7 +25,7 @@ type DevServerInfo = {
*/
function getDevServer(): DevServerInfo {
if (_cachedDevServerURL === undefined) {
const match = SourceCode.scriptURL && SourceCode.scriptURL.match(/^https?:\/\/.*?\//);
const match = SourceCode && SourceCode.scriptURL && SourceCode.scriptURL.match(/^https?:\/\/.*?\//);
_cachedDevServerURL = match ? match[0] : null;
}

View File

@ -92,7 +92,7 @@ if (!sourceCode) {
const NativeModules = require('NativeModules');
sourceCode = NativeModules && NativeModules.SourceCode;
}
_sourceCodeScriptURL = sourceCode.scriptURL;
_sourceCodeScriptURL = sourceCode && sourceCode.scriptURL;
module.exports = resolveAssetSource;
module.exports.pickScale = AssetSourceResolver.pickScale;