Skip to content

Commit

Permalink
feat: Add optional chaining to the babel preset
Browse files Browse the repository at this point in the history
[Optional chaining](https://github.com/tc39/proposal-optional-chaining)
allows to chain potentially null components.

Instead of doing
```
if (window && window.location && window.location.protocol) {
  ssl = window.location.protocol
}
```
we could do
```
ssl = window?.location?.protocol
```

The spec is stage 1 only but [they seem to have reach consensus](tc39/proposal-optional-chaining#75 (comment))
and [the formal stage 2 decision should be in March](tc39/proposal-optional-chaining#76 (comment))

There should not be any compatibility break
  • Loading branch information
edas committed Feb 18, 2019
1 parent 9950024 commit 461ce42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/babel-preset-cozy-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@babel/helper-plugin-utils": "7.0.0",
"@babel/plugin-proposal-class-properties": "7.2.3",
"@babel/plugin-proposal-object-rest-spread": "7.2.0",
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/preset-env": "7.2.3",
"@babel/preset-react": "7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-cozy-app/basics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

module.exports = {
plugins: ['prettier'],
plugins: ['prettier', '@babel/plugin-proposal-optional-chaining'],
extends: ['eslint:recommended', 'eslint-config-prettier'],
parser: 'babel-eslint',
env: {
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-catch-binding" "^7.2.0"

"@babel/plugin-proposal-optional-chaining@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.2.0.tgz#ae454f4c21c6c2ce8cb2397dc332ae8b420c5441"
integrity sha512-ea3Q6edZC/55wEBVZAEz42v528VulyO0eir+7uky/sT4XRcdkWJcFi1aPtitTlwUzGnECWJNExWww1SStt+yWw==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-chaining" "^7.2.0"

"@babel/plugin-proposal-unicode-property-regex@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.2.0.tgz#abe7281fe46c95ddc143a65e5358647792039520"
Expand Down Expand Up @@ -436,6 +444,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-optional-chaining@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.2.0.tgz#a59d6ae8c167e7608eaa443fda9fa8fa6bf21dff"
integrity sha512-HtGCtvp5Uq/jH/WNUPkK6b7rufnCPLLlDAFN7cmACoIjaOOiXxUt3SswU5loHqrhtqTsa/WoLQ1OQ1AGuZqaWA==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-arrow-functions@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz#9aeafbe4d6ffc6563bf8f8372091628f00779550"
Expand Down

0 comments on commit 461ce42

Please sign in to comment.