Skip to content

Commit

Permalink
fix(core): handle invalid constructor parameters in partial factory d…
Browse files Browse the repository at this point in the history
…eclarations (#43619)

This commit fixes an oversight in the JIT compilation of partial factory
declarations, where the literal `'invalid'` was not accounted for
(unlike the AOT linker).

Fixes #43609

PR Close #43619
  • Loading branch information
JoostK authored and dylhunn committed Oct 1, 2021
1 parent 75f74de commit b4b4410
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/compiler/src/compiler_facade_interface.ts
Expand Up @@ -241,7 +241,7 @@ export interface R3FactoryDefMetadataFacade {

export interface R3DeclareFactoryFacade {
type: Type;
deps: R3DeclareDependencyMetadataFacade[]|null;
deps: R3DeclareDependencyMetadataFacade[]|'invalid'|null;
target: FactoryTarget;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/compiler/src/jit_compiler_facade.ts
Expand Up @@ -241,7 +241,8 @@ export class CompilerFacadeImpl implements CompilerFacade {
type: wrapReference(meta.type),
internalType: new WrappedNodeExpr(meta.type),
typeArgumentCount: 0,
deps: meta.deps && meta.deps.map(convertR3DeclareDependencyMetadata),
deps: Array.isArray(meta.deps) ? meta.deps.map(convertR3DeclareDependencyMetadata) :
meta.deps,
target: meta.target,
});
return this.jitExpression(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/compiler/compiler_facade_interface.ts
Expand Up @@ -241,7 +241,7 @@ export interface R3FactoryDefMetadataFacade {

export interface R3DeclareFactoryFacade {
type: Type;
deps: R3DeclareDependencyMetadataFacade[]|null;
deps: R3DeclareDependencyMetadataFacade[]|'invalid'|null;
target: FactoryTarget;
}

Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/render3/jit/declare_factory_spec.ts
Expand Up @@ -36,6 +36,11 @@ describe('Factory declaration jit compilation', () => {
expect(instance).toBeInstanceOf(ChildClass);
expect(instance.testClass).toBeInstanceOf(TestClass);
});

it('should compile a factory declaration with an invalid dependency', () => {
const factory = InvalidDepsClass.ɵfac as Function;
expect(() => factory()).toThrowError(/not compatible/);
});
});

class TestClass {
Expand All @@ -56,6 +61,11 @@ class ChildClass extends DependingClass {
ɵɵngDeclareFactory({type: ChildClass, deps: null, target: ɵɵFactoryTarget.Injectable});
}

class InvalidDepsClass {
static ɵfac = ɵɵngDeclareFactory(
{type: InvalidDepsClass, deps: 'invalid', target: ɵɵFactoryTarget.Injectable});
}

class TestInjector {
static ɵinj = ɵɵdefineInjector({
providers: [TestClass, DependingClass, ChildClass],
Expand Down

0 comments on commit b4b4410

Please sign in to comment.