mirror of https://github.com/status-im/metro.git
Use `this` rather than `global` in prelude
Summary: in new-style builds, the prelude is not wrapped into an IIFE, so `global` is not available. Since the bundle as a whole is not running in strict mode, we can access the global object with `this`. Reviewed By: jeanlauliac Differential Revision: D5051731 fbshipit-source-id: 4003b5e57ba8626e38e68e92d5778c2c59ca69a5
This commit is contained in:
parent
020b619125
commit
73ce956838
|
@ -97,6 +97,6 @@ function* concat<T>(...iterables: Array<Iterable<T>>): Iterable<T> {
|
|||
function prelude(optimize) {
|
||||
return virtualModule(
|
||||
`var __DEV__=${String(!optimize)},` +
|
||||
'__BUNDLE_START_TIME__=global.nativePerformanceNow?global.nativePerformanceNow():Date.now();'
|
||||
'__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ describe('build setup', () => {
|
|||
dependencies: [],
|
||||
file: {
|
||||
code: 'var __DEV__=true,__BUNDLE_START_TIME__=' +
|
||||
'global.nativePerformanceNow?global.nativePerformanceNow():Date.now();',
|
||||
'this.nativePerformanceNow?nativePerformanceNow():Date.now();',
|
||||
path: '',
|
||||
type: 'script',
|
||||
},
|
||||
|
@ -43,7 +43,7 @@ describe('build setup', () => {
|
|||
const [prelude] = result.modules;
|
||||
expect(prelude.file.code)
|
||||
.toEqual('var __DEV__=false,__BUNDLE_START_TIME__=' +
|
||||
'global.nativePerformanceNow?global.nativePerformanceNow():Date.now();');
|
||||
'this.nativePerformanceNow?nativePerformanceNow():Date.now();');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue