Skip to content

Commit 169cfb5

Browse files
janicduplessisFacebook Github Bot 9
authored andcommitted
Remove the need for allowTopLevelThis in transform-es2015-modules-commonjs
Summary: This make the transform behave closer to the standard for modules. This removes the few places that a top level this was used to refer to the global space. It also clean up the usage of `GLOBAL` to use `global` instead as this is what is used everywhere else in the code base. We still define `GLOBAL` for compatibility with other modules. **Test plan** Clear the packager cache to make sure the transforms run again. (node ./local-cli/cli.js start --reset-cache). Run the Movies example (UIExplorer is broken atm) and make sure there are no errors. Closes #6255 Differential Revision: D3037227 Pulled By: mkonicek fb-gh-sync-id: bcf1350ae7a6e92c77d3a87fc9d6e42eb93cb9b9 fbshipit-source-id: bcf1350ae7a6e92c77d3a87fc9d6e42eb93cb9b9
1 parent 373537b commit 169cfb5

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
require('regenerator/runtime');
2626

2727
if (typeof GLOBAL === 'undefined') {
28-
global.GLOBAL = this;
28+
global.GLOBAL = global;
2929
}
3030

3131
if (typeof window === 'undefined') {
32-
global.window = GLOBAL;
32+
global.window = global;
3333
}
3434

3535
function setUpConsole() {
@@ -53,7 +53,7 @@ function setUpConsole() {
5353
* For more info on that particular case, see:
5454
* https://github.com/facebook/react-native/issues/934
5555
*/
56-
function polyfillGlobal(name, newValue, scope = GLOBAL) {
56+
function polyfillGlobal(name, newValue, scope = global) {
5757
var descriptor = Object.getOwnPropertyDescriptor(scope, name) || {
5858
// jest for some bad reasons runs the polyfill code multiple times. In jest
5959
// environment, XmlHttpRequest doesn't exist so getOwnPropertyDescriptor
@@ -70,7 +70,7 @@ function polyfillGlobal(name, newValue, scope = GLOBAL) {
7070
Object.defineProperty(scope, name, {...descriptor, value: newValue});
7171
}
7272

73-
function polyfillLazyGlobal(name, valueFn, scope = GLOBAL) {
73+
function polyfillLazyGlobal(name, valueFn, scope = global) {
7474
if (scope[name] !== undefined) {
7575
const descriptor = Object.getOwnPropertyDescriptor(scope, name);
7676
const backupName = `original${name[0].toUpperCase()}${name.substr(1)}`;
@@ -96,7 +96,7 @@ function polyfillLazyGlobal(name, valueFn, scope = GLOBAL) {
9696
/**
9797
* Polyfill a module if it is not already defined in `scope`.
9898
*/
99-
function polyfillIfNeeded(name, polyfill, scope = GLOBAL, descriptor = {}) {
99+
function polyfillIfNeeded(name, polyfill, scope = global, descriptor = {}) {
100100
if (scope[name] === undefined) {
101101
Object.defineProperty(scope, name, {...descriptor, value: polyfill});
102102
}
@@ -141,8 +141,8 @@ function setUpTimers() {
141141
}
142142

143143
function setUpAlert() {
144-
if (!GLOBAL.alert) {
145-
GLOBAL.alert = function(text) {
144+
if (!global.alert) {
145+
global.alert = function(text) {
146146
// Require Alert on demand. Requiring it too early can lead to issues
147147
// with things like Platform not being fully initialized.
148148
require('Alert').alert('Alert', '' + text);
@@ -169,12 +169,12 @@ function setUpXHR() {
169169
}
170170

171171
function setUpGeolocation() {
172-
polyfillIfNeeded('navigator', {}, GLOBAL, {
172+
polyfillIfNeeded('navigator', {}, global, {
173173
writable: true,
174174
enumerable: true,
175175
configurable: true,
176176
});
177-
polyfillLazyGlobal('geolocation', () => require('Geolocation'), GLOBAL.navigator);
177+
polyfillLazyGlobal('geolocation', () => require('Geolocation'), global.navigator);
178178
}
179179

180180
function setUpMapAndSet() {
@@ -185,7 +185,7 @@ function setUpMapAndSet() {
185185
}
186186

187187
function setUpProduct() {
188-
Object.defineProperty(GLOBAL.navigator, 'product', {value: 'ReactNative'});
188+
Object.defineProperty(global.navigator, 'product', {value: 'ReactNative'});
189189
}
190190

191191
function setUpWebSockets() {
@@ -200,13 +200,13 @@ function setUpProfile() {
200200
}
201201

202202
function setUpProcess() {
203-
GLOBAL.process = GLOBAL.process || {};
204-
GLOBAL.process.env = GLOBAL.process.env || {};
205-
if (!GLOBAL.process.env.NODE_ENV) {
206-
GLOBAL.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
203+
global.process = global.process || {};
204+
global.process.env = global.process.env || {};
205+
if (!global.process.env.NODE_ENV) {
206+
global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
207207
}
208208

209-
polyfillLazyGlobal('platform', () => require('Platform').OS, GLOBAL.process);
209+
polyfillLazyGlobal('platform', () => require('Platform').OS, global.process);
210210
}
211211

212212
function setUpDevTools() {

Libraries/Utilities/ErrorUtils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
*
99
* @providesModule ErrorUtils
1010
*/
11-
/* eslint-disable consistent-this, global-strict */
12-
13-
var GLOBAL = this;
11+
/* eslint-disable strict */
1412

1513
/**
1614
* The particular require runtime that we are using looks for a global
@@ -24,4 +22,4 @@ var GLOBAL = this;
2422
* that use it aren't just using a global variable, so simply export the global
2523
* variable here. ErrorUtils is originally defined in a file named error-guard.js.
2624
*/
27-
module.exports = GLOBAL.ErrorUtils;
25+
module.exports = global.ErrorUtils;

Libraries/Utilities/Systrace.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type RelayProfiler = {
2323
): void,
2424
};
2525

26-
var GLOBAL = GLOBAL || this;
2726
var TRACE_TAG_REACT_APPS = 1 << 17;
2827
var TRACE_TAG_JSC_CALLS = 1 << 27;
2928

0 commit comments

Comments
 (0)