From 60b05cae9ededbff538a7fce6c59520399077264 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Fri, 21 Sep 2018 16:05:10 -0700 Subject: [PATCH] Use babel runtime instead of relying on global babelHelpers and regenerator (#198) Summary: **Summary** The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app. This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package. This will solve issues like this https://github.com/facebook/react-native/issues/20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before. **Test plan** - Updated tests so they all pass. - Tested that it actually works by applying the changes locally in an RN app. - Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global. - Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file). Pull Request resolved: https://github.com/facebook/metro/pull/198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225 --- jest/preprocessor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest/preprocessor.js b/jest/preprocessor.js index 245ed984cbf386..30e6d5620b3e90 100644 --- a/jest/preprocessor.js +++ b/jest/preprocessor.js @@ -52,6 +52,7 @@ module.exports = { options: { ast: true, // needed for open source (?) https://github.com/facebook/react-native/commit/f8d6b97140cffe8d18b2558f94570c8d1b410d5c#r28647044 dev: true, + disableBabelRuntime: true, inlineRequires: true, minify: false, platform: '',