babel-plugin-transform-lazy

0.0.2 • Public • Published

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

Package Sidebar

Install

npm i babel-plugin-transform-lazy

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

3.9 kB

Total Files

5

Last publish

Collaborators

  • kael