You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Partial support decorators when targeting ES3 #4681
Method/accessor decorators use defineProperty and getOwnPropertyDescriptor, which are not allowed in ES3. But class and property decorators don't use them. So class/property decorators can be allowed when targeting ES3.
It would be helpful. E.g. I must support old browsers and I use the property like methods instead of pure properties:
TypeScript does not emit, or depend on any polyfills. if you do for your code, and include polyfills you manage them separately. for helper code emitted by the compiler there is no dependency on any polyfills currently, nor this is intended.
__decorate helper will be emitted in every file that uses decorators. we try to keep any helper code as small as and as efficient as possible, since we are polluting user code.
Also we do not emit different versions of the helpers based on the target, to avoid breaking user code from an imported library built with a different target, but loaded first.
so a proposal for this should include the shape of the __decorate that does not use reduceRight, which will either be a for loop with a call to function, or a call to an additional helper function.
Personally, i would say the shape the helper is important, as again we emit it in every file. and since day 1, typescript strives to emit clean, idiomatic, JavaScript that would looks like the code you would write by hand if you were not using a compiler.
Koloto We initially did something similar, but simplified the __decorate helper when we decided to only support decorators for ES5+.
If we do decide to support ES3, we would likely support method decorators in the same fashion as property decorators (e.g. without the property descriptor).
If we do decide to support ES3, we would likely support method decorators in the same fashion as property decorators (e.g. without the property descriptor).
It would be great to support method decorators in ES3 also. Can I hope to see this feature in v1.6? :) I suppose, no. But support just class and property decorators in ES3 seems much easier. It would be a good start.
Decorators are now allowed when targeting ES3. In this case, all decorators on members of a class are treated in the same fashion as a decorator on a property declaration. A descriptor for the declaration will neither be provided to nor consumed by the __decorate helper in this case.
Decorators for ES5 and higher should be unaffected (although the actual emit for each decorator has changed slightly).
Activity
[-]Partially support decorators when targeting ES3[/-][+]Partial support decorators when targeting ES3[/+]mhegazy commentedon Sep 8, 2015
The problem is the
__decoratehelper uses ES5 features likereduceRight. so any proposal here would need to address that as well.xLama commentedon Sep 8, 2015
Mohamed Hegazy (@mhegazy)
reduceRight has a Polyfill
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight
mhegazy commentedon Sep 8, 2015
TypeScript does not emit, or depend on any polyfills. if you do for your code, and include polyfills you manage them separately. for helper code emitted by the compiler there is no dependency on any polyfills currently, nor this is intended.
__decoratehelper will be emitted in every file that uses decorators. we try to keep any helper code as small as and as efficient as possible, since we are polluting user code.Also we do not emit different versions of the helpers based on the target, to avoid breaking user code from an imported library built with a different target, but loaded first.
so a proposal for this should include the shape of the
__decoratethat does not usereduceRight, which will either be a for loop with a call to function, or a call to an additional helper function.Personally, i would say the shape the helper is important, as again we emit it in every file. and since day 1, typescript strives to emit clean, idiomatic, JavaScript that would looks like the code you would write by hand if you were not using a compiler.
Koloto commentedon Sep 9, 2015
Proposal for
__decoratehelper withoutreduceRight:This version is a bit shorter than the standard helper:)
Koloto commentedon Sep 10, 2015
More safe version (always returns the result, even if
decoratorsis an empty array):Mohamed Hegazy (@mhegazy) What do you think? Is it ok?
mhegazy commentedon Sep 10, 2015
Ron Buckton (@rbuckton) any comments?
rbuckton commentedon Sep 10, 2015
Koloto We initially did something similar, but simplified the
__decoratehelper when we decided to only support decorators for ES5+.If we do decide to support ES3, we would likely support method decorators in the same fashion as property decorators (e.g. without the property descriptor).
rbuckton commentedon Sep 10, 2015
I tweaked Koloto's version a bit to avoid repeated lookups on arguments.length and adjusted the return value:
rbuckton commentedon Sep 10, 2015
Further reduced:
Koloto commentedon Sep 10, 2015
Ron Buckton (@rbuckton)
It would be great to support method decorators in ES3 also. Can I hope to see this feature in v1.6? :) I suppose, no. But support just class and property decorators in ES3 seems much easier. It would be a good start.
rbuckton commentedon Oct 2, 2015
This should be addressed as of #4741.
Decorators are now allowed when targeting ES3. In this case, all decorators on members of a class are treated in the same fashion as a decorator on a property declaration. A descriptor for the declaration will neither be provided to nor consumed by the
__decoratehelper in this case.Decorators for ES5 and higher should be unaffected (although the actual emit for each decorator has changed slightly).