tc39 / proposal-extractors

Extractors for ECMAScript
http://tc39.es/proposal-extractors/
MIT License
200 stars 3 forks source link

Can this be an extension of decorators instead? #9

Closed trusktr closed 5 months ago

trusktr commented 11 months ago
let @Foo x = y

or similar, leaving the implementation to decorator authors (perhaps also providing decorator primitives for authors to use)?

rbuckton commented 5 months ago

No, decorators are intended to be declarative and apply only once during declaration instantiation. Extractors are intended to be evaluated as part of normal evaluation, such as during any function call or during each successive iteration of a for loop.

For example,

class C {
  m(@Foo x) { }
}

would run once when C is defined, and could be used to describe metadata about the x parameter of C's m method.

However,

class C {
  m(Foo(x, y)) { }
}

would run every type m is called as part of destructuring the first argument.