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

Add optional-chaining and nullish-coalescing to preset-env #10811

Merged
merged 9 commits into from Jan 10, 2020

Conversation

@Druotic
Copy link
Contributor

Druotic commented Dec 4, 2019

Q                       A
Fixed Issues? Fixes #10809
Patch: Bug Fix? N
Major: Breaking Change? N
Minor: New Feature? Y
Tests Added + Pass? Y
Documentation PR Link
Any Dependency Changes?
License MIT
@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Dec 4, 2019

@Druotic Could you also add nullish coalescing? 🙏

(@JLHwung you were right 😂)

@@ -299,6 +299,10 @@
"opera": "53",
"electron": "3.1"
},
"proposal-optional-chaining": {

This comment has been minimized.

Copy link
@JLHwung

JLHwung Dec 4, 2019

Contributor

We should also add a plugin syntax map to the pluginSyntaxMap

const pluginSyntaxMap = new Map([

So that if babel is configured with

{
  "presets": [
     ["@babel/env", { "targets": { "browserslist": "chrome 80" } }]
   ]
}

Babel would not transform them at all since it gets native support.

By doing so it means we need to add @babel/syntax-proposal-optional-chaining as dependencies, too.

This comment has been minimized.

Copy link
@Druotic

Druotic Dec 4, 2019

Author Contributor

Added - hopefully I did that correctly. Being new to this project - I must admit, I don't fully understand all of the machinery here, so assume the worst 😂

Thanks for the quick feedback, as well 👍

This comment has been minimized.

Copy link
@Druotic

Druotic Dec 4, 2019

Author Contributor

Hmm, am I correct in assuming I should also add the syntax plugin to the notIncludedPlugins in babel-present-env-standalone?

This comment has been minimized.

Copy link
@JLHwung

JLHwung Dec 4, 2019

Contributor

You are doing great! And we should also add the syntax plugin to preset-env/src/available-plugins.

@Druotic

This comment has been minimized.

Copy link
Contributor Author

Druotic commented Dec 4, 2019

Alright - should be good for a re-review. I combined the other PR (nullish coalescing) into this one and assumed the same pattern was necessary.

@nicolo-ribaudo nicolo-ribaudo changed the title Add support for optional-chaining (stage 4) in present-env Add optional-chaining and nullish-coalescing in present-env Dec 4, 2019
@nicolo-ribaudo nicolo-ribaudo changed the title Add optional-chaining and nullish-coalescing in present-env Add optional-chaining and nullish-coalescing to present-env Dec 4, 2019
"transform-named-capturing-groups-regex": "RegExp named capture groups",
"transform-member-expression-literals": "Object/array literal extensions / Reserved words as property names",
"transform-property-literals": "Object/array literal extensions / Reserved words as property names",
"transform-reserved-words": "Miscellaneous / Unreserved words",
"proposal-nullish-coalescing-operator": "nullish coalescing operator (??)",

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Dec 4, 2019

Member

Can you keep this alphabetically ordered?

This comment has been minimized.

Copy link
@kaicataldo

kaicataldo Dec 4, 2019

Member

Not a blocker for this PR, but would be nice if we can enforce this with ESLint, even if it's just enabling the rule using comments for this object.

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Dec 5, 2019

Member

Yeah that would be cool! But let's do it in a separate PR.

This comment has been minimized.

Copy link
@Druotic

Druotic Dec 5, 2019

Author Contributor

Oops - I didn't see this reply until after making the changes. I selectively added the sort-keys rule to a few files which resulted in some noise/sorting of existing keys. It's in a separate commit for easy review. If it's too much, I can pull it out into another PR.

This comment has been minimized.

Copy link
@JLHwung

JLHwung Dec 5, 2019

Contributor

It's still okay to review since the changes are related to a few files.

["proposal-unicode-property-regex", null],
["proposal-json-strings", "syntax-json-strings"],
["proposal-nullish-coalescing-operator", "syntax-nullish-coalescing-operator"],

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Dec 4, 2019

Member

Also here

@JLHwung
JLHwung approved these changes Dec 5, 2019
Copy link
Contributor

JLHwung left a comment

Thanks!

@JLHwung
JLHwung approved these changes Dec 5, 2019
@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Dec 5, 2019

@Druotic FYI, we will merge this PR when we are ready for the next minor release (it could take a while)

@LarsDenBakker

This comment has been minimized.

Copy link

LarsDenBakker commented Dec 5, 2019

I think a lot of people are eagerly awaiting this, any chance of doing this soonish? :)

@@ -3,12 +3,15 @@

const proposalPlugins = {};

// Please keep these in alphabetical order!

This comment has been minimized.

Copy link
@msholty-fd

msholty-fd Dec 5, 2019

If you want to enforce these tuples being in alphabetical order, you could use /* eslint sort-keys: "error" */ like you do in available-plugins.js, and create an object representing these plugins where the order will be enforced.

Then you could transform it for the new Map():

const pluginSyntaxObject = {
  "proposal-async-generator-functions": "syntax-async-generators",
  "proposal-json-strings": "syntax-json-strings",
  "proposal-nullish-coalescing-operator": "syntax-nullish-coalescing-operator",
  "proposal-object-rest-spread": "syntax-object-rest-spread",
  "proposal-optional-catch-binding": "syntax-optional-catch-binding",
  "proposal-optional-chaining": "syntax-optional-chaining",
  "proposal-unicode-property-regex": null,
}

const pluginSyntaxMap = new Map(Object.entries(pluginSyntaxMap))

This comment has been minimized.

Copy link
@Druotic

Druotic Dec 5, 2019

Author Contributor

Good call - updated. I also resolved new conflicts with master.

@Druotic Druotic changed the title Add optional-chaining and nullish-coalescing to present-env Add optional-chaining and nullish-coalescing to preset-env Dec 5, 2019
@JLHwung

This comment has been minimized.

Copy link
Contributor

JLHwung commented Dec 5, 2019

Note that if you really want to test on the new language features, you can always enable these features before preset-env supports them:

Install via yarn or npm

yarn add --dev @babel/plugin-proposal-nullish-coalescing-operator @babel/plugin-proposal-optional-chaining

Add these plugins to your babel config

{
  "presets": ["@babel/preset-env"],
  "plugins": [
    "@babel/plugin-proposal-nullish-coalescing-operator",
    "@babel/plugin-proposal-optional-chaining"
  ]
}
@JLHwung JLHwung changed the base branch from master to feat-7.8/preset-env Dec 5, 2019

module.exports = { proposalPlugins, pluginSyntaxMap };
const pluginSyntaxMap = new Map(Object.entries(pluginSyntaxObject));

This comment has been minimized.

Copy link
@JLHwung

JLHwung Dec 5, 2019

Contributor

Unfortunately Object.entries is not supported in Node 6 (behind a flag), could you add a todo item and restore it to Map constructor? We can apply this change on Babel 8.

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Dec 5, 2019

Member

Or maybe someone could write a feature request in the eslint repo to make sort-keys work with the Map and Set constructors ☺️

This comment has been minimized.

Copy link
@msholty-fd

msholty-fd Dec 5, 2019

Sorry for that confusion! I wasn't aware of the Object.entries limitation.

This comment has been minimized.

Copy link
@JLHwung

JLHwung Dec 5, 2019

Contributor

@msholty-fd I didn't realize it before I read the CI error. The discussion above is still constructive that we have new eslint rules idea.

@JLHwung JLHwung changed the base branch from feat-7.8/preset-env to master Dec 5, 2019
@nicolo-ribaudo nicolo-ribaudo force-pushed the Druotic:optional-chaining-present-env branch from 8d6d00c to 8f7a9a3 Jan 10, 2020
@nicolo-ribaudo nicolo-ribaudo force-pushed the Druotic:optional-chaining-present-env branch from 98edd87 to 773067a Jan 10, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit 80aa7dc into babel:master Jan 10, 2020
3 of 5 checks passed
3 of 5 checks passed
build (13.x)
Details
Travis CI - Pull Request Build Errored
Details
test262 Workflow: test262
Details
build-standalone Workflow: build-standalone
Details
e2e Workflow: e2e
Details
bennypowers added a commit to open-wc/open-wc that referenced this pull request Jan 15, 2020
babel/babel#10811 was merged and released in babel 7.8.0
bennypowers added a commit to open-wc/open-wc that referenced this pull request Jan 15, 2020
babel/babel#10811 was merged and released in 
babel 7.8.0
bennypowers added a commit to open-wc/open-wc that referenced this pull request Jan 15, 2020
babel/babel#10811 was merged and released in 
babel 7.8.0
bennypowers added a commit to open-wc/open-wc that referenced this pull request Jan 15, 2020
babel/babel#10811 was merged and released in 
babel 7.8.0
LarsDenBakker added a commit to open-wc/open-wc that referenced this pull request Feb 2, 2020
LarsDenBakker added a commit to open-wc/open-wc that referenced this pull request Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.