From 3103258ca0fd2fb0fda0da1120d9cdf4baf0ca05 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Wed, 19 Jul 2017 10:57:56 -0700 Subject: [PATCH] BREAKING: Add regenerator-runtime on demand, based on the files Summary: Adding a Babel plugin that will analyze the file looking for any potential candidate to use `regenerator-runtime`, and if so, will inject dynamically the module. The module is injected per file, so we avoid polluting the global environment. The plugin is also able to inject the `require` call beforehand, so that the inliner can pick them and inline them. The Babel plugin is part of `react-native-babel-preset`, so as long as you are using this preset you are safe. If not, you should include the specific transformer into your list of plugins, as `react-native-babel-preset/transforms/transform-regenerator-runtime-insertion.js`. Reviewed By: davidaurelio Differential Revision: D5388655 fbshipit-source-id: dc403f3d5e2d807529eb8569a85c45fec36a6a3e --- Libraries/Core/InitializeCore.js | 9 --------- RNTester/js/ListExampleShared.js | 10 +++++----- babel-preset/package.json | 2 +- package.json | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Libraries/Core/InitializeCore.js b/Libraries/Core/InitializeCore.js index e5b65b59f..cadad7d47 100644 --- a/Libraries/Core/InitializeCore.js +++ b/Libraries/Core/InitializeCore.js @@ -138,15 +138,6 @@ defineProperty(global, 'Set', () => require('Set'), true); // ERROR: Event loop not supported. defineProperty(global, 'Promise', () => require('Promise')); -// Set up regenerator. -defineProperty(global, 'regeneratorRuntime', () => { - // The require just sets up the global, so make sure when we first - // invoke it the global does not exist - delete global.regeneratorRuntime; - require('regenerator-runtime/runtime'); - return global.regeneratorRuntime; -}); - // Set up timers const defineLazyTimer = name => { defineProperty(global, name, () => require('JSTimers')[name]); diff --git a/RNTester/js/ListExampleShared.js b/RNTester/js/ListExampleShared.js index 63a720262..1b7335f68 100644 --- a/RNTester/js/ListExampleShared.js +++ b/RNTester/js/ListExampleShared.js @@ -163,11 +163,11 @@ const THUMB_URLS = [ require('./Thumbnails/victory.png'), ]; -const LOREM_IPSUM = 'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix \ -civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id \ -integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem \ -vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud \ -modus, putant invidunt reprehendunt ne qui.'; +const LOREM_IPSUM = 'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix ' + + 'civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id ' + + 'integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem ' + + 'vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud ' + + 'modus, putant invidunt reprehendunt ne qui.'; /* eslint no-bitwise: 0 */ function hashCode(str: string): number { diff --git a/babel-preset/package.json b/babel-preset/package.json index f70959ab2..6ba484c52 100644 --- a/babel-preset/package.json +++ b/babel-preset/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-react-native", - "version": "2.0.0", + "version": "2.1.0", "description": "Babel preset for React Native applications", "main": "index.js", "repository": "https://github.com/facebook/react-native/tree/master/babel-preset", diff --git a/package.json b/package.json index f661d710d..4187cedaf 100644 --- a/package.json +++ b/package.json @@ -150,7 +150,7 @@ "babel-polyfill": "^6.20.0", "babel-preset-es2015-node": "^6.1.1", "babel-preset-fbjs": "^2.1.4", - "babel-preset-react-native": "^2.0.0", + "babel-preset-react-native": "^2.1.0", "babel-register": "^6.24.1", "babel-runtime": "^6.23.0", "babel-traverse": "^6.24.1",