Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[critical] Move require rename inside try/catch #4214

Merged
merged 1 commit into from Oct 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/lib/locale/locales.js
Expand Up @@ -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) { }
}

Expand Down