You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix transformer changing process.env.BABEL_ENV as a side-effect, transform tests non-determinism (#55557)
Summary:
Pull Request resolved: #55557
Currently, the RN Babel transformer that is used both by Metro and Jest, and the base transformer in Metro, set [`process.env.BABEL_ENV`](https://babeljs.io/docs/options?utm_source=chatgpt.com#envname) during transformation, presumably to ensure that Babel always uses the `development` configuration when multiple are configured.
It attempts to set it back in a `finally` block - but that's guarded in the old value being truthy, which was introduced as a fix in react/metro#446 - setting `process.env.BABEL_ENV = undefined` actually gives it the string value `'undefined'`.
However, the fix wasn't quite right, because it just leaves a previously-unset `BABEL_ENV` at its new value. So if `BABEL_ENV` is initially `undefined`, using the transformer sets it to `'development'`.
This has a knock-on effect on `react-native/babel-preset`, which sets `dev: true` on the preset if `BABEL_ENV` is `'development'`.
Changelog:
[General][Fixed] Fix Babel transformer changing `BABEL_ENV` as a side effect
Reviewed By: huntie
Differential Revision: D93328555
fbshipit-source-id: e47f51028e60efc1c346bea44d1d8f2af264ca60
function_createForOfIteratorHelperLoose(r,e){vart="undefined"!=typeofSymbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeofr.length){t&&(r=t);varo=0;returnfunction(){returno>=r.length ? {done: !0} : {done: !1,value: r[o++]};};}thrownewTypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}
Copy file name to clipboardExpand all lines: packages/react-native-babel-preset/src/__tests__/__fixtures__/output/hermes-stable-prod-no-import-export-transform.js
+5-11Lines changed: 5 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -25,11 +25,7 @@ import _classPrivateFieldLooseBase from "@babel/runtime/helpers/classPrivateFiel
function_createForOfIteratorHelperLoose(r,e){vart="undefined"!=typeofSymbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeofr.length){t&&(r=t);varo=0;returnfunction(){returno>=r.length ? {done: !0} : {done: !1,value: r[o++]};};}thrownewTypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}
0 commit comments