Skip to content
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

Conversation

fivetanley
Copy link
Contributor

@fivetanley fivetanley commented May 29, 2020

Q                       A
Fixed Issues?
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link No
Any Dependency Changes? No
License MIT

If @babel/helper-compilation-targets is called directly, as it is in the Ember-CLI babel and Vue
CLI
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 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 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: #11500
Dropping the esmodules property was introduced in #11124

Discussion about dropping the esmodules property: #11124 (comment)

@fivetanley fivetanley force-pushed the dont-mutate-helper-compilation-target-input branch from 7bf0302 to d637bfa Compare May 29, 2020 22:35
@codesandbox-ci
Copy link

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:

Sandbox Source
thirsty-moser-xjb48 Configuration
strange-bush-zjevs Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented May 29, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/23208/

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 29, 2020

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:

Sandbox Source
magical-mendel-5fp51 Configuration
brave-lake-y30v3 Configuration

fivetanley added a commit to fivetanley/ember-cli-6to5 that referenced this pull request May 29, 2020
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).
@fivetanley fivetanley changed the title don't mutate InputTarget's passed to @babel/helper-compilation-targets fix: don't mutate InputTarget's passed to @babel/helper-compilation-targets May 30, 2020
…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)
@fivetanley fivetanley force-pushed the dont-mutate-helper-compilation-target-input branch from d637bfa to 4446b99 Compare May 30, 2020 00:22
@existentialism existentialism added pkg: preset-env PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels May 30, 2020
@existentialism existentialism merged commit 15d6da0 into babel:master May 30, 2020
@existentialism
Copy link
Member

@fivetanley thanks!

@fivetanley fivetanley deleted the dont-mutate-helper-compilation-target-input branch July 10, 2020 05:14
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: preset-env PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants