Skip to content

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

@nicolo-ribaudo

Description

@nicolo-ribaudo

πŸ”Ž 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.

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions