Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorating generator functions, impossible? #26

Closed
silkentrance opened this issue Mar 22, 2016 · 2 comments
Closed

Decorating generator functions, impossible? #26

silkentrance opened this issue Mar 22, 2016 · 2 comments

Comments

@silkentrance
Copy link

Just stumbled across this one

function decorator(target, attr, descriptor)
{
    return descriptor;
}


class Foo
{
    @decorator
    * gen() { yield 1; }
}

will result in the following error

SyntaxError: src/test.es: Unexpected token (xx:xx)
  xx |     @decorator
> xx |     *gen() { yield 1; }

Is this by design or can this be fixed?

Because, when doing this instead

class Foo
{
    @decorator
    async gen() {}
}

the decorator will be applied just fine.

And, by looking at the spec, in 14.3 it states that the GeneratorDefinition from 14.4 is a valid MethodDefinition.

And according to https://github.com/wycats/javascript-decorators#grammar PropertyDefinition refers to MethodDefinition.

@loganfsmyth
Copy link
Owner

This plugin doesn't have much in the way of control over this since it relies on Babylon. Feel free to file this on https://github.com/babel/babylon though, it's probably worth raising again. This was originally on purpose which can be seen in https://phabricator.babeljs.io/T2014 and then the spec was updated but it essentially got rolled into https://phabricator.babeljs.io/T2645. The overall updated spec has taken much longer than we originally expected, so maybe it's worth revisiting tweaking the parser for now to allow it.

@silkentrance
Copy link
Author

@loganfsmyth thanks you very much for the pointers.

Just as a reminder for myself: bug in babylon https://github.com/babel/babylon/blob/master/src/parser/expression.js#L709

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants