Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patbonecrusher/9b0218de518163fcb95f51c04c3664c5 to your computer and use it in GitHub Desktop.
Save patbonecrusher/9b0218de518163fcb95f51c04c3664c5 to your computer and use it in GitHub Desktop.

Set Up Babel — Working Example

We need alpha 7 version from Babel.

npm install --save-dev [email protected]
npm install --save-dev babel-plugin-transform-optional-chaining@^7.0.0-alpha.13.1

Create a .babelrc file in the project root:

{
  "plugins": ["transform-optional-chaining"]
}

Create an index.js to test the optional chaining operator.

var user = { name: 'Joe' }
var zip = user?.address?.zip
console.log(zip)

Then run it:

node_modules/.bin/babel-node index.js

Or transpile the code:

node_modules/.bin/babel index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment