(WORKING IN PROGRESS, DO NOT USE) Allow swift-like lazy
keyword before class properties.
$ npm i babel-plugin-transform-lazy
class Foo {
lazy x = createX(this.bar)
constructor (bar) {
this.bar = bar
}
}
Out:
const X = Symbol('private:x')
class Foo {
constructor (bar) {
this.bar = bar
}
get x () {
if (X in this) {
return this[X]
}
const x = (() => createX(this.bar))()
this[X] = x
return x
}
set x (value) {
this[X] = value
}
}
MIT