0.0.2 • Published 5 years ago

babel-plugin-transform-lazy v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage

babel-plugin-transform-lazy

(WORKING IN PROGRESS, DO NOT USE) Allow swift-like lazy keyword before class properties.

Install

$ npm i babel-plugin-transform-lazy

Usage

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
  }
}

License

MIT