tc39/proposal-decorators

Prevent usage of context methods outside of initial decoration

Closed this issue · 3 comments

In the Babel transform users can currently capture and use addInitializer, setMetadata, and other functions outside of the context of the decorator they were passed into. This leads to odd/undefined behavior, such as being able to add an initializer at a later point in the lifecycle of decorator application, which exposes internal details about how and when decorators are applied and initializers are captured. Adding an assertion prevents any of this behavior so it is no longer an issue.

An assertion in the spec catches editorial errors; are you suggesting that these functions have some internal state, and throw exceptions once the "finished decorating" bit is set?

Correct, meant a runtime "assertion" (I'm used to using assert() helpers in TS so that's just the way I thought about it)

This has been updated in the latest version of the spec.