Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/decorators/auto-injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
isTransformDescriptor
} from "../providers/injection-token";
import {formatErrorCtor} from "../error-helpers";
import {__extends} from "tslib";

/**
* Class decorator factory that replaces the decorated class' constructor with
Expand All @@ -18,10 +19,16 @@ import {formatErrorCtor} from "../error-helpers";
function autoInjectable(): (target: constructor<any>) => any {
return function(target: constructor<any>): constructor<any> {
const paramInfo = getParamInfo(target);

return class extends target {
constructor(...args: any[]) {
super(
return (function(_super): any {
function extendedClazz(...args: any[]) {
const SuperProxy = new Proxy(_super, {
// target = Foo
apply(target, _, argumentsList) {
return new target(...argumentsList);
}
});
return SuperProxy.call(
null,
...args.concat(
paramInfo.slice(args.length).map((type, index) => {
try {
Expand Down Expand Up @@ -62,7 +69,9 @@ function autoInjectable(): (target: constructor<any>) => any {
)
);
}
};
__extends(extendedClazz, _super);
return extendedClazz;
})(target);
};
}

Expand Down