New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: don't mutate InputTarget's passed to @babel/helper-compilation-targets #11648
fix: don't mutate InputTarget's passed to @babel/helper-compilation-targets #11648
Conversation
7bf0302
to
d637bfa
Compare
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 7bf0302:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/23208/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4446b99:
|
Babel 7.10.0 [introduced a change that mutates the `targets` object passed into [`@babel/helper-compilation-targets`](babel/babel#11500). Since [ember-cli caches the value of `config/targets.js` on the Project](https://github.com/ember-cli/ember-cli/blob/master/lib/models/project.js#L271-L289), that means any subsequent calls to ember-cli-babel would lose `@babel/preset-env` options defined in `targets` if the ember-cli babel was included again anywhere else in the tree (which it usually is due to addons depending on ember-cli-babel). This would sometimes result in a `regeneratorRuntime is not defined` error for addons like Ember Concurrency that use ECMAScript features like generator functions or async functions, because the addon would not be compiled against the appropriate `browsers` list (or other `@babel/preset-env` options) because `@babel/helper-compilation-targets` mutated it away. This would happen usually in development or test, if [limiting the targets used in development](https://www.rwjblue.com/2017/10/30/async-await-configuration-adventure/#limit-targets-locally), which has been the [default in Ember CLI for a while now](ember-cli/ember-cli@7798114). As a workaround, we can copy the `targets` object before passing it to `@babel/helper-compilation-targets` as a workaround until the regression is [fixed upstream in babel](babel/babel#11648).
…argets If `@babel/helper-compilation-targets` is called directly, as it is in the [Ember-CLI babel](https://github.com/babel/ember-cli-babel/blob/6f76f405b9dd2a48cce394c4826dd50847f74282/index.js#L543-L545) and [Vue CLI](https://github.com/vuejs/vue-cli/blob/c8cecffedbf7b19cf930bb2821b5c352bc716a67/packages/%40vue/babel-preset-app/index.js#L17) integrations, we don't want to mutate the input passed in. At least in Ember CLI, babel could be called multiple times. So, on subsequent passes all `browsers` and `esmodules` info would be lost (and losing the `browsers` info affects the output in negative ways). Copying the object before dropping keys allows callers not have to worry about babel mutating the object they pass in. Switching to a more functional approach makes it easier for babel to not worry about what consumers are passing in. Dropping the `browser` property was introduced in: babel#11500 Dropping the `esmodules` property was introduced in babel#11124 Discussion about dropping the `esmodules` property: babel#11124 (comment)
d637bfa
to
4446b99
Compare
@fivetanley thanks! |
If
@babel/helper-compilation-targets
is called directly, as it is in the Ember-CLI babel and VueCLI integrations, we don't want to mutate the input passed in as the caller may want to cache the value in the build layer. At least in Ember CLI, babel could be called multiple times. So, on subsequent passes all
browsers
andesmodules
info would be lost (and losing thebrowsers
info affects the output in negative ways). Copying the object before dropping keys allows callers not have to worry about babel mutating the object they pass in. Switching to a more functional approach makes it easier to reason about and makes it easier for babel to not worry about what consumers do with the object they pass in.Dropping the
browser
property was introduced in: #11500Dropping the
esmodules
property was introduced in #11124Discussion about dropping the
esmodules
property: #11124 (comment)