Skip to content

Commit 0007564

Browse files
bolumhevery
authored andcommitted
fix(compiler): inherit param types when class has a constructor which takes no declared parameters and delegates up (angular#29232)
In ReflectionCapabilities, when checking for own parameters of a type, inherit the types properly for classes that do have a constructor, but the constructor takes no declared parameters and just delegates to super(...arguments). This removes the need to declare trivial constructors in such classes to make them work properly in JIT mode. Without this, DI fails and injectables are undefined. PR Close angular#29232
1 parent ce789b7 commit 0007564

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/core/src/reflection/reflection_capabilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const DELEGATE_CTOR = /^function\s+\S+\(\)\s*{[\s\S]+\.apply\(this,\s*arg
2323
export const INHERITED_CLASS = /^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{/;
2424
export const INHERITED_CLASS_WITH_CTOR =
2525
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(/;
26+
export const INHERITED_CLASS_WITH_DELEGATE_CTOR =
27+
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(\)\s*{\s+super\(\.\.\.arguments\)/;
2628

2729
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
2830
private _reflect: any;
@@ -70,7 +72,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
7072
// This also helps to work around for https://github.com/Microsoft/TypeScript/issues/12439
7173
// that sets 'design:paramtypes' to []
7274
// if a class inherits from another class but has no ctor declared itself.
73-
if (DELEGATE_CTOR.exec(typeStr) ||
75+
if (DELEGATE_CTOR.exec(typeStr) || INHERITED_CLASS_WITH_DELEGATE_CTOR.exec(typeStr) ||
7476
(INHERITED_CLASS.exec(typeStr) && !INHERITED_CLASS_WITH_CTOR.exec(typeStr))) {
7577
return null;
7678
}

0 commit comments

Comments
 (0)