Reputation: 31815
I've recently been trying the online Babel transpiling tool, and I've noticed that when transpiling a class to ES2015, it doesnt use javascript class and creates var _createClass = function () {...
boilerplate instead: Demo
Yet, the javascript class keyword has been added in ES2015. Source
The javascript class is used only when ticking ES2016.
Why is that?
Upvotes: 1
Views: 140
Reputation: 664548
I've noticed that when transpiling a class to ES2015, it doesnt use javascript class: https://babeljs.io/repl#?presets=es2015&…
You weren't transpiling to ES2015, you were transpiling from ES2015 to an older version. The ES2015 preset selects all the transformations that generate ES3/5 code for ES2015 stuff.
The javascript class is used only when ticking ES2016.
Yes, it keeps the class
syntax and other features from ES2015 when you only transpile the ES2016 (or higher) stuff.
Upvotes: 3
Reputation:
Yet, the javascript class keyword has been added in ES2015
Yes, the keyword was defined on ES2015 and class
was already a reserved word before that, but the actual implementation is a different story. As @AshKander mentions in they comment, the point of using babel with a specific target is to get that code to work on all browsers that support such target.
List of reserved keywords (present and future)
Upvotes: 0