-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
…erator (#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 facebook/react-native#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: #198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,14 @@ const reactDisplayName = [ | |
const reactJsxSource = [require('@babel/plugin-transform-react-jsx-source')]; | ||
const symbolMember = [require('../transforms/transform-symbol-member')]; | ||
|
||
const babelRuntime = [ | ||
require('@babel/plugin-transform-runtime'), | ||
{ | ||
helpers: true, | ||
regenerator: true, | ||
}, | ||
]; | ||
|
||
const getPreset = (src, options) => { | ||
const isNull = src == null; | ||
const hasClass = isNull || src.indexOf('class') !== -1; | ||
|
@@ -135,6 +143,10 @@ const getPreset = (src, options) => { | |
extraPlugins.push(reactJsxSource); | ||
} | ||
|
||
if (!options || !options.disableBabelRuntime) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rafeca
Contributor
|
||
extraPlugins.push(babelRuntime); | ||
} | ||
|
||
return { | ||
comments: false, | ||
compact: true, | ||
|
@rafeca What do you think about using https://jest-bot.github.io/jest/docs/configuration.html#unmockedmodulepathpatterns-array-string instead of disabling babel runtime?