Add Babel plugin "syntax-optional-chaining"


#1

Hi

I can’t get to make this Babel plugin to work: https://www.npmjs.com/package/babel-plugin-transform-optional-chaining

My .babelrc is farily simple:

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

Tried a lot of different configs based on what I saw in other topics, but I still have this kind of error:

=> Errors prevented startup:                  
   
   While processing files with ecmascript (for target web.browser):
   client/components/chapter/chapterEdit.js:208:41: Unexpected token (208:41)

Looks like the Meteor ecmascript package can’t parse that new feature even if I’m using a Babel plugin. Am I missing something?

Thanks!

Related but not mine: https://stackoverflow.com/questions/46340274/install-babel-optional-chaining-package-on-meteor


Babel 7 and Meteor
#2

Interesting package. Lodash’s _.get and _.result sort of do the same thing if that’s an ok substitute for you.


#3

By the way this package simply follows a stage-1 proposal for ecmascript: https://github.com/tc39/proposal-optional-chaining.

Thanks for pointing that out, but I can’t afford to remove Underscore from my project, so loading Lodash on top of it isn’t a solution…

Looks like .babelrc support for Meteor is meant to do just that, so I think I misunderstood something! :slight_smile:


#4

You could add it as an individual package and even add it to underscore with _.mixin :slight_smile: An option if you don’t figure out the babel issue.


#5

Unfortunately, this plugin is currently only supported in babel 7. I was tripped up by that just last week. I’m indeed looking forward to seeing this available in Meteor or any kind of javascript set up for that matter.


#6

Babel 7 is coming in Meteor 1.6, try updating to the release candidate and see if the plugin works there


#7

I’ll take another look this week-end, thanks! Is it anything more to do than npm installing the package & editing the .babelrc file?


#8

Just tried with Meteor 1.6-rc3, reinstalled the babel plugin, and I also tried to add this to package.json, but no luck:

"babel": {
  "plugins": ["syntax-optional-chaining"]
}

#9

Looks like Babel 7 has been shipped wit Meteor 1.6. Can’t upgrade for now, did anyone try it? https://github.com/meteor/meteor/pull/9090


#10

see https://stackoverflow.com/a/48121085/3748498