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

[Decorators] Missing error when calling addInitializer after that the decorator is done #57300

Open
nicolo-ribaudo opened this issue Feb 5, 2024 · 3 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@nicolo-ribaudo
Copy link

πŸ”Ž Search Terms

decorators addInitializer error

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried since Stage 3 decorators where implemented

⏯ Playground Link

https://www.typescriptlang.org/play?#code/DYUwLgBAhgJjCSA7AlmZVjIF4gE4DFcB7AWwEYAuCAERAGMjcoxGBhIxMEADzAG0ARLAQo0GbHgEBdANwBYAFCKAZgFdEdNBwgx6ZABQB9KlEQBPADQRN3KrQZMWudpx5gAlBADeiiNDhIqOiYOATE5BAAvNZg3AB0woFiIXjyCgC+iirqmsjaunQATEYm5laGhaVmnj4KfomiwRJhpAb6npEAfN7p7r7WHADORKBxwEQA5voCAILU1ACi1AJ9GVkKdMBQg4MQM979AAIFhUcFZP3KRERREGRpmUoKQA

πŸ’» Code

let addInitializerFrom1: DecoratorContext["addInitializer"];

function dec1(_: any, ctx: DecoratorContext) {
  addInitializerFrom1 = ctx.addInitializer;
}

function dec2(_: any, _2: any) {
  addInitializerFrom1(() => {})
  console.log("ADDED")
}

class A {
  @dec2
  @dec1
  foo = 1;
}

πŸ™ Actual behavior

The addInitializerFrom1 call should throw

πŸ™‚ Expected behavior

addInitializerFrom1 doesn't throw

Additional information about the issue

Spec: https://ci.tc39.es/preview/tc39/ecma262/sha/59003ed603d09485b957a0f579b46697f49a96a6/#sec-applydecoratorstoelementdefinition

After that dec1 is called, decorationState.[[Finished]] for the decorationState relative to dec1 is set to false and thus calling addInitializer should throw.

@nicolo-ribaudo
Copy link
Author

Oh there is an open issue about it in the decorators spec, hopefully it will be updated to match TS: tc39/proposal-decorators#500

@rbuckton
Copy link
Member

rbuckton commented Feb 9, 2024

Should this issue be closed? It seems like we'd want to adopt tc39/proposal-decorators#500 if that is approved at the next plenary session.

@nicolo-ribaudo
Copy link
Author

Oh right, I closed this assuming that TS already implements the proposed behavior but actually TS throws less than the current spec text and not as proposed in that PR.

@nicolo-ribaudo nicolo-ribaudo reopened this Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants