From: Iskren Chernev Date: Tue, 10 Oct 2017 08:22:33 +0000 (+0300) Subject: Move require rename inside try/catch X-Git-Tag: 2.19.0~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4214%2Fhead;p=thirdparty%2Fmoment.git Move require rename inside try/catch --- diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index d8bb937c9..2f5f2d8b0 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) { } }