Commit de59fcc
Fix transformer changing process.env.BABEL_ENV as a side-effect, transform tests non-determinism
Summary:
X-link: facebook/react-native#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 #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: e47f51028e60efc1c346bea44d1d8f2af264ca601 parent 1c2986d commit de59fcc
1 file changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
| |||
0 commit comments