Tuesday 23 May 2017

Decorator on generator doesn't work


I'm trying to create a decorator for a generator function.
But there is some issue with the declaration.
What i'm doing wrong?

function  nothing (target, key, descriptor) {
  const fn = descriptor.value
  descriptor.value = function (...args) {
    fn.apply(this, args)
  }
}


class Test {
  @nothing
  *b(x) {
    const y = yield x
    return y + 1
  }
}

Error:

Unexpected token (36:8)
  34 | class Test {
  35 |   @nothing
> 36 |   *b(x) {
     |         ^
  37 |     const y = yield "a"
  38 |     return y + 1
  39 |   }

Example in babel online



via שלומי אמסלם

No comments:

Post a Comment