@drieam/class-default-properties
The plugin for transform properties of class which has parent class.
Table of Contents
Why need this
When we use Babel to support class properties.
Let's see the follow case:
class P {
value = 'value In P'
constructor(obj) {
Object.assign(this, obj)
}
}
class S extends P {
val = 'value in S'
}
console.log(new S({ val: 'cus' }).val)
Options
- condType (default: 'typeofUndefined') 'typeofUndefined' | 'in' | 'hasOwnProperty'
- 'typeofUndefined'
this.val = typeof this.val !== 'undefined' ? this.val : 'value in S' - 'in'
this.val = 'val' in this ? this.val : 'value in S' - 'hasOwnProperty'
this.val = this.hasOwnProperty('val') ? this.val : 'value in S'
Note
{
"plugins": [
// NOTE: the order is important
"class-properties-default-value",
"transform-class-properties"
]
}
This project is an extension of (babel-plugin-class-properties-default-value)[https://github.com/imcuttle/babel-plugin-class-properties-default-value]