From 79e9131fdab17d0afe4211b068a353b2bb5749b5 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Tue, 10 Oct 2017 11:22:33 +0300 Subject: [PATCH] Move require rename inside try/catch --- src/lib/locale/locales.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index d8bb937c95..2f5f2d8b0c 100644 --- a/src/lib/locale/locales.js +++ b/src/lib/locale/locales.js @@ -46,22 +46,23 @@ function chooseLocale(names) { } function loadLocale(name) { - var oldLocale = null, - // workaround for React Native 0.49+ - pretendingNotToRequire = require; + var oldLocale = null; // TODO: Find a better way to register and load all the locales in Node if (!locales[name] && (typeof module !== 'undefined') && module && module.exports) { oldLocale = globalLocale._abbr; try { - pretendingNotToRequire('moment/locale/' + name); + // workaround for React Native 0.49+ + var pretendingNotToRequireV1 = require; + pretendingNotToRequireV1('moment/locale/' + name); } catch (e) { // In the test environment, the external module 'moment' // can't be resolved because we're running inside it. // Fallback to using the old relative import try { - pretendingNotToRequire('./locale/' + name); + var pretendingNotToRequireV2 = require; + pretendingNotToRequireV2('./locale/' + name); } catch (e) { } }