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

Include preset modules #11083

Merged
merged 13 commits into from Mar 16, 2020
Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jan 31, 2020

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

This PR introduces a new option for @babel/preset-env: bugfixes. When it is enabled,
Babel uses the plugins from @babel/preset-modules to replace "normal" plugins when possible.

@nicolo-ribaudo
Copy link
Member Author

Ready for review!

@hzoo
Copy link
Member

hzoo commented Feb 15, 2020

This is something we would want to at least move to defaulting to true in Babel 8, correct? And we are just waiting since we don't want to break anyone in case (minor version)

Copy link
Member

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is truly a herculean effort @nicolo-ribaudo. The ecosystem is in forever your debt.

Just a couple of questions/nits, nothing super blocking from me.

"transform-async-to-generator": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should transform-regenerator be here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes. We did it in the past,but had to revert it because regenerator doesn't support async functions with polyfilled promises.

I'd like to revisit it in Babel 8 somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. At least when bugfixes is enabled though, regenerator will never be included, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only included when targeting browsers not supporting generators (we don't use it for async functions).

It's unrelated to bugfixes: it isn't included because of the esmodules option.

"chrome": "55",
"edge": "15",
"firefox": "52",
"safari": "11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safari should be 10.1 / 10.3 here I think? Same as async-to-generator. I may have had references to Safari 11 in the plugin since that's what I had chosen to target, but the fix should work in all ES-Modules-supporting versions of Safari (10.1+ desktop / 10.3+ ios)

Edit: I keep thinking this list is "versions that are fixed by X", but it's actually "oldest version where this plugin is not needed", right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oldest version where this plugin is not needed

👍

@@ -0,0 +1,125 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo - meta-comment, more on the data format itself: do you think it might be easier to maintain this file if the data only specified which versions were actually affected by the bugfix plugins? For example, the edge function name plugin could just be listed as { "edge": "79" } rather than including the other browser versions which it doesn't have an effect on. A missing browser version could just be taken as "no change".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data is generated by the same script which generated the old data, so it's easier to generate all the targets 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! gotcha.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be interesting to create a rendered version based on the data on our website or something? Or just showcasing this in general in a more readable manner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like compat-table but with plugin names rather than ECMAScript features?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, then you could generate what @developit was saying allow about seeing the diff's or what was actually affected? Maybe we should add a simple readme to explain each json file

bugfixes: validateBoolOption(
TopLevelOptions.bugfixes,
opts.bugfixes,
false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall we'd said this would be enabled by default - I'm guessing this is false until Babel 8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍
This shouldn't technically be a breaking change, but it's safer to wait (Babel 8 will be released soonish anyway).

Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do this, will be a big win for everyone!

@@ -49,7 +49,20 @@ import transformTemplateLiterals from "@babel/plugin-transform-template-literals
import transformTypeofSymbol from "@babel/plugin-transform-typeof-symbol";
import transformUnicodeRegex from "@babel/plugin-transform-unicode-regex";

import bugfixAsyncArrowsInClass from "@babel/preset-modules/lib/plugins/transform-async-arrows-in-class";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We should export theses plugins from @babel/preset-modules instead of relying on internal file structures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to just move the plugin files inside @babel/preset-env in the future, if @developit is ok with that.

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Can you also update https://babeljs.io/docs/en/babel-preset-env#options ?

@nicolo-ribaudo nicolo-ribaudo force-pushed the include-preset-modules branch 2 times, most recently from 90a6848 to ecf47c9 Compare March 5, 2020 02:03
@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 Jun 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 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: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants