From f83dfd6f5aabdfc1c5363fa8a7f7b8145c8fad92 Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 28 Jun 2019 13:14:47 +0200 Subject: [PATCH] fix(core): handle `undefined` meta in `injectArgs` (#31333) In the recent versions of the CLI we introduced a ctor downleveler tranformer for VE JIT builds based on the one found in tsickle, to fix the TDZ issue of `forwardRef`. However this caused a regression as the injector is not handling that a position `paramType` can be undefined. Which is bubbled down to https://github.com/angular/angular/blob/c6b29f4c6d23b1510db3434cb030203d5bdea119/packages/core/src/di/injector_compatibility.ts#L162 and will crash https://github.com/angular/angular/blob/c6b29f4c6d23b1510db3434cb030203d5bdea119/packages/core/src/di/injector_compatibility.ts#L174-L186 Fixes https://github.com/angular/angular-cli/issues/14888 PR Close #31333 --- .../core/src/reflection/reflection_capabilities.ts | 2 +- packages/core/test/reflection/reflector_spec.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/core/src/reflection/reflection_capabilities.ts b/packages/core/src/reflection/reflection_capabilities.ts index 799d4a4ecd..baadf9a404 100644 --- a/packages/core/src/reflection/reflection_capabilities.ts +++ b/packages/core/src/reflection/reflection_capabilities.ts @@ -64,7 +64,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities { // migration, but this can be revisited. if (typeof paramTypes === 'undefined') { result[i] = []; - } else if (paramTypes[i] != Object) { + } else if (paramTypes[i] && paramTypes[i] != Object) { result[i] = [paramTypes[i]]; } else { result[i] = []; diff --git a/packages/core/test/reflection/reflector_spec.ts b/packages/core/test/reflection/reflector_spec.ts index 25cb3d0725..ff07f8b1f6 100644 --- a/packages/core/test/reflection/reflector_spec.ts +++ b/packages/core/test/reflection/reflector_spec.ts @@ -109,6 +109,16 @@ class TestObj { class ForwardDep {} expect(reflector.parameters(Forward)).toEqual([[ForwardDep]]); }); + + it('should not return undefined types for downleveled types', () => { + class Dep {} + + class TestService { + constructor() {} + static ctorParameters = () => [{type: undefined, decorators: []}, {type: Dep}]; + } + expect(reflector.parameters(TestService)).toEqual([[], [Dep]]); + }); }); describe('propMetadata', () => {