Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Unable to decorate generator functions #13

Closed
silkentrance opened this issue Mar 23, 2016 · 6 comments
Closed

Unable to decorate generator functions #13

silkentrance opened this issue Mar 23, 2016 · 6 comments

Comments

@silkentrance
Copy link

With the latest babylon@6.7.0 I am unable to decorate generator functions, i.e.

class Foo
{
    @deco
    * gen() {}
}

will result in an unexpected error.

Here, it will fail if isGenerator is true.

I am currently working on a patch for this and will report back.

RATIONALE

According to 14.3/14.4 of the ECMAScript specification, a GeneratorMethod (14.4) is a valid MethodDefinition (14.3). And in the decorator specification also states that it can be used with a MethodDefinition and makes no limitations whatsoever.

@silkentrance
Copy link
Author

@loganfsmyth It seems that Parser#parseDecorator() will swallow up the asterisk and parse everything until after the method's name, or rather what it considers to be a call expression, i.e. @decorator * gen() seems to be parsed as a single expression here, which it is not.

And since Parser#parseDecorator() calls upon Parser#parseMaybeAssign() I am quite unsure how to proceed further as this is being used all over the place.

Perhaps a little help from you guys?

@silkentrance
Copy link
Author

For reference: @jayphelps proposed a different production for decorators here:
wycats/javascript-decorators#23 (comment)

@loganfsmyth
Copy link
Member

Yeah I have no idea what the expectation was. When I originally directed you here I thought that the spec had already been updated to cover this. If it hasn't, I'm not sure there is much we can do until there's an official spec decision.

@silkentrance silkentrance changed the title Unable to decorator generator functions Unable to decorate generator functions Mar 23, 2016
@silkentrance
Copy link
Author

@loganfsmyth well, you seem to be the go-to guy in all aspects, so I thought that maybe you can call upon someone to also have a look into this, so maybe with the help of @wycats this can then be sorted out, chiming in the guys who implemented babylon and fixing the issues as the spec gets updated...
while I continue to figure out how the code works... 😁

@machty
Copy link

machty commented May 5, 2017

I'd love to be able to experiment with this syntax for ember-concurrency.com

Ember.Object.extend({
    @restartableTask
    *doStuff() {
      // ..
    }
})

but I'm running into this same issue. While there are probably a handful of things that need to be settled about decorators, @wycats tells me the above syntax is uncontroversial; would it be possible to sneak in a fix just for the above (without having to wait for a brand new plugin)?

@hzoo
Copy link
Member

hzoo commented Jun 22, 2017

This is handled by #587 and will be in the next beta release which should be 7.0.0-beta.15 (soon)

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

No branches or pull requests

5 participants