order of applied class/constr-param decorators different than in tsc
See original GitHub issueWhen I compile
@ClassDec()
export class Decoratee {
constructor(@ParamDec() param: string) {}
}
with tsc I end up with (I replaced some tslib
calls with what they will be replaced with):
let Decoratee = class Decoratee {
constructor(param) { }
};
Decoratee = tslib_1.__decorate([
ClassDec(),
ParamDec(),
Reflect.metadata("design:paramtypes", [String])
], TokenService);
tslib then will call these three decorators on Decoratee
, starting with the last one (Reflect.metadata
), then alls ParamDec, and finally
ClassDec`.
Using this plugin, I get something like this, with the order being differently:
var _dec, _dec2, _class;
var Decoratee = (
_dec = (0, ClassDec)(),
_dec2 = Reflect.metadata("design:paramtypes", [String]),
_dec(
_class = _dec2(
_class = function Decoratee(param) {}
) || _class
) || _class
);
(0, ParamDec)()(Decoratee, undefined, 0);
Compiling this with babel will in some cases have different results, if libraries/frameworks rely on a consistent order. I do not know, if the order is defined in the metadata proposal, did not find anything so far. I think you mentioned this issue also at the bottom of README.md
. Specifically in the Angular DI, the @Injectable
decorator expects all @Inject
s inside the constructor parameter to already have been applied.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Awesome! I’d like to see the output code, and we should add some tests. Anyway, if you can build up something with a PR it would be cool 👍
By the way, this also resolves #22, I guess because we now put the new decorator on the class itself and this in return leads to the
Reflect.metadata
decorator being created.