fix(ivy): handle overloaded constructors in ngtsc (#34590)
Currently ngtsc looks for the first `ConstructorDeclaration` when figuring out what the parameters are so that it can generate the DI instructions. The problem is that if a constructor has overloads, it'll have several `ConstructorDeclaration` members with a different number of parameters. These changes tweak the logic so it looks for the constructor implementation. PR Close #34590
This commit is contained in:
@ -192,6 +192,32 @@ runInEachFileSystem(os => {
|
||||
expect(jsContents).toContain('inject(Dep, 8)');
|
||||
});
|
||||
|
||||
it('should compile @Injectable with constructor overloads', () => {
|
||||
env.write('test.ts', `
|
||||
import {Injectable, Optional} from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
class Dep {}
|
||||
|
||||
@Injectable()
|
||||
class OptionalDep {}
|
||||
|
||||
@Injectable()
|
||||
class Service {
|
||||
constructor(dep: Dep);
|
||||
|
||||
constructor(dep: Dep, @Optional() optionalDep?: OptionalDep) {}
|
||||
}
|
||||
`);
|
||||
env.driveMain();
|
||||
const jsContents = env.getContents('test.js');
|
||||
|
||||
expect(jsContents)
|
||||
.toContain(
|
||||
`Service.ɵfac = function Service_Factory(t) { ` +
|
||||
`return new (t || Service)(i0.ɵɵinject(Dep), i0.ɵɵinject(OptionalDep, 8)); };`);
|
||||
});
|
||||
|
||||
it('should compile Directives without errors', () => {
|
||||
env.write('test.ts', `
|
||||
import {Directive} from '@angular/core';
|
||||
|
Reference in New Issue
Block a user