@@ -137,6 +137,7 @@ export function AutoWired(target: Function) {
137
137
let existingInjectedParameters : number [ ] =
138
138
Reflect . getOwnMetadata ( "params_inject" , target ) || [ ] ;
139
139
let newConstructor ;
140
+ const _isClass = isClass ( target ) ;
140
141
if ( existingInjectedParameters . length > 0 ) {
141
142
existingInjectedParameters . reverse ( ) ;
142
143
const paramTypes : Array < any > =
@@ -149,14 +150,14 @@ export function AutoWired(target: Function) {
149
150
newArgs . push ( IoCContainer . get ( paramTypes [ index ] ) ) ;
150
151
}
151
152
}
152
- let ret = construct ( target , newArgs , ioc_wrapper , this ) ;
153
+ let ret = construct ( target , newArgs , ioc_wrapper , this , _isClass ) ;
153
154
return ret ;
154
155
} , target ) ;
155
156
}
156
157
else {
157
158
newConstructor = InjectorHanlder . decorateConstructor ( function ioc_wrapper ( ...args : any [ ] ) {
158
159
IoCContainer . assertInstantiable ( target ) ;
159
- let ret = construct ( target , args , ioc_wrapper , this ) ;
160
+ let ret = construct ( target , args , ioc_wrapper , this , _isClass ) ;
160
161
return ret ;
161
162
} , target ) ;
162
163
}
@@ -551,8 +552,12 @@ declare var Map: MapConstructor;
551
552
552
553
// Polyfill for Reflect.construct. Thanks to https://github.com/Mr0grog/newless
553
554
function isSyntaxSupported ( example ) {
554
- try { return ! ! Function ( "" , "'use strict';" + example ) ; }
555
- catch ( error ) { return false ; }
555
+ try { return ! ! Function ( "" , "'use strict';" + example ) ; }
556
+ catch ( error ) { return false ; }
557
+ }
558
+
559
+ function isClass ( v ) : boolean {
560
+ return typeof v === 'function' && / ^ \s * c l a s s \s + / . test ( v . toString ( ) ) ;
556
561
}
557
562
558
563
let _constructFunc = global [ 'Reflect' ] && global [ 'Reflect' ] . construct || ( function ( ) {
@@ -605,13 +610,13 @@ let _constructFunc = global['Reflect'] && global['Reflect'].construct || (functi
605
610
}
606
611
} ) ( ) ;
607
612
608
- construct = function ( constructor , args , target , _this ) {
609
- if ( Object [ 'setPrototypeOf' ] ) { //ES2015+
610
- let ret = _constructFunc ( constructor , args , target ) ;
613
+ construct = function ( target , args , constructor , _this , isClass ) {
614
+ if ( isClass ) { //ES2015+
615
+ let ret = _constructFunc ( target , args , constructor ) ;
611
616
// fix up the prototype so it matches the intended one, not one who's
612
617
// prototype is the intended one :P
613
618
Object [ 'setPrototypeOf' ] ( ret , target . prototype ) ;
614
619
return ret ;
615
620
}
616
- return constructor . apply ( _this , args ) ; //ES5
621
+ return target . apply ( _this , args ) ; //ES5
617
622
}
0 commit comments