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

Decorator expression evaluation order (not descriptor processing order) #28

Open
loganfsmyth opened this issue Jul 22, 2015 · 1 comment

Comments

@loganfsmyth
Copy link

@sebmck wanted me to verify this over here first, since the spec desugaring examples imply it, but it's non-obvious and Babel currently doesn't seem to follow the implied behavior. I originally noticed this over in #20 but it's separate.

Decorator functions are applied to descriptors bottom-up and are thought of as wrappers. My question is about the order of evaluation of the decorator expression themselves. Are they also meant to be evaluated bottom-up, or top-down? In Python for example, while decorators are applied bottom-up, the expressions are evaluated top-down. To demonstrate:

function fn(arg){
  console.log('evaluated', arg);
  return function(){
    console.log('called', arg)
  };
}


class Example {
  @fn(1)
  @fn(2)
  method(){}
}

would the expected output be

evaluated 1
evaluated 2
called 2
called 1

or

evaluated 2
evaluated 1
called 2
called 1

Babel's current implementation results in #2, which is the opposite of Python's behavior, and also the opposite of the desugared examples, e.g.

fn(1)(fn(2)(...))

which will execute fn(1) first, but will call the result of fn(2) first.

@silkentrance
Copy link

+1 for this from me, the order by which the decorators are applied is important and should be bottom up as @loganfsmyth did implement in the interim legacy decorators plugin, which I think should be the basis for any future work.

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