babel-plugin-transform-class-constructor-call (deprecated)
Proposal Withdrawn: can be solved with decorators.
This plugin allows Babel to transform class constructors.
It basically allows to use the new.target feature on ES2015 classes:
{ thisx = x; thisy = y; } call { return x y; } let p1 = 1 2; // OKlet p2 = Point3 4; // OK
Example
Date example
The javascript Date works this way:
// You can get a Date instance using the new keywordlet now = ;console; // Prints '3'console; // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)' // You can get a string of the current date using Date as a function:let nowStr = Date;console; // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)'
It is currently possible to implement something like that using new.target (see example in proposal) and this new feature makes it available for ES2015 classes.
A date implementation could be:
{ // ... } call { let date = ; return date; } let now = ; // Get a Date instancelet nowStr = Date; // Use the 'call constructor()' part to get a string value of the current date
Installation
npm install --save-dev babel-plugin-transform-class-constructor-call
Usage
.babelrc
(Recommended)
Via .babelrc
Via CLI
babel --plugins transform-class-constructor-call script.js
Via Node API
;