fix(compiler): inherit param types when class has a constructor which takes no declared parameters and delegates up (#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 #29232
This commit is contained in:
parent
ce789b75a4
commit
00075647be
|
@ -23,6 +23,8 @@ export const DELEGATE_CTOR = /^function\s+\S+\(\)\s*{[\s\S]+\.apply\(this,\s*arg
|
||||||
export const INHERITED_CLASS = /^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{/;
|
export const INHERITED_CLASS = /^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{/;
|
||||||
export const INHERITED_CLASS_WITH_CTOR =
|
export const INHERITED_CLASS_WITH_CTOR =
|
||||||
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(/;
|
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(/;
|
||||||
|
export const INHERITED_CLASS_WITH_DELEGATE_CTOR =
|
||||||
|
/^class\s+[A-Za-z\d$_]*\s*extends\s+[^{]+{[\s\S]*constructor\s*\(\)\s*{\s+super\(\.\.\.arguments\)/;
|
||||||
|
|
||||||
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||||
private _reflect: any;
|
private _reflect: any;
|
||||||
|
@ -70,7 +72,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
|
||||||
// This also helps to work around for https://github.com/Microsoft/TypeScript/issues/12439
|
// This also helps to work around for https://github.com/Microsoft/TypeScript/issues/12439
|
||||||
// that sets 'design:paramtypes' to []
|
// that sets 'design:paramtypes' to []
|
||||||
// if a class inherits from another class but has no ctor declared itself.
|
// if a class inherits from another class but has no ctor declared itself.
|
||||||
if (DELEGATE_CTOR.exec(typeStr) ||
|
if (DELEGATE_CTOR.exec(typeStr) || INHERITED_CLASS_WITH_DELEGATE_CTOR.exec(typeStr) ||
|
||||||
(INHERITED_CLASS.exec(typeStr) && !INHERITED_CLASS_WITH_CTOR.exec(typeStr))) {
|
(INHERITED_CLASS.exec(typeStr) && !INHERITED_CLASS_WITH_CTOR.exec(typeStr))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue