diff --git a/packages/compiler-cli/src/ngtsc/annotations/common/src/factory.ts b/packages/compiler-cli/src/ngtsc/annotations/common/src/factory.ts index b73e470641f6ca..8ecd6d320c590d 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/common/src/factory.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/common/src/factory.ts @@ -14,10 +14,22 @@ export type CompileFactoryFn = (metadata: R3FactoryMetadata) => CompileResult; export function compileNgFactoryDefField(metadata: R3FactoryMetadata): CompileResult { const res = compileFactoryFunction(metadata); - return {name: 'ɵfac', initializer: res.expression, statements: res.statements, type: res.type}; + return { + name: 'ɵfac', + initializer: res.expression, + statements: res.statements, + type: res.type, + deferrableImports: null + }; } export function compileDeclareFactory(metadata: R3FactoryMetadata): CompileResult { const res = compileDeclareFactoryFunction(metadata); - return {name: 'ɵfac', initializer: res.expression, statements: res.statements, type: res.type}; + return { + name: 'ɵfac', + initializer: res.expression, + statements: res.statements, + type: res.type, + deferrableImports: null + }; } diff --git a/packages/compiler-cli/src/ngtsc/annotations/common/src/input_transforms.ts b/packages/compiler-cli/src/ngtsc/annotations/common/src/input_transforms.ts index f1bfd81e284889..42d09546788799 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/common/src/input_transforms.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/common/src/input_transforms.ts @@ -22,7 +22,8 @@ export function compileInputTransformFields(inputs: ClassPropertyMapping): CompileResult[] { + deferrableImports: Set|null): CompileResult[] { const statements = def.statements; if (metadataStmt !== null) { statements.push(metadataStmt); diff --git a/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts b/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts index 849315b083fa2e..3251accd7324a1 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts @@ -1032,7 +1032,8 @@ export class ComponentDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileDeclareClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵcmp', inputTransformFields); + return compileResults( + fac, def, classMetadata, 'ɵcmp', inputTransformFields, null /* deferrableImports */); } compileLocal( @@ -1055,7 +1056,8 @@ export class ComponentDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵcmp', inputTransformFields); + return compileResults( + fac, def, classMetadata, 'ɵcmp', inputTransformFields, null /* deferrableImports */); } /** diff --git a/packages/compiler-cli/src/ngtsc/annotations/directive/src/handler.ts b/packages/compiler-cli/src/ngtsc/annotations/directive/src/handler.ts index 7ba9991ea0fb11..901518cd619426 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/directive/src/handler.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/directive/src/handler.ts @@ -214,7 +214,8 @@ export class DirectiveDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵdir', inputTransformFields); + return compileResults( + fac, def, classMetadata, 'ɵdir', inputTransformFields, null /* deferrableImports */); } compilePartial( @@ -227,7 +228,8 @@ export class DirectiveDecoratorHandler implements compileDeclareClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵdir', inputTransformFields); + return compileResults( + fac, def, classMetadata, 'ɵdir', inputTransformFields, null /* deferrableImports */); } compileLocal( @@ -239,7 +241,8 @@ export class DirectiveDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵdir', inputTransformFields); + return compileResults( + fac, def, classMetadata, 'ɵdir', inputTransformFields, null /* deferrableImports */); } /** diff --git a/packages/compiler-cli/src/ngtsc/annotations/ng_module/src/handler.ts b/packages/compiler-cli/src/ngtsc/annotations/ng_module/src/handler.ts index f81314e41989f0..12d1d6d1354251 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/ng_module/src/handler.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/ng_module/src/handler.ts @@ -779,12 +779,14 @@ export class NgModuleDecoratorHandler implements initializer: ngModuleDef.expression, statements: ngModuleDef.statements, type: ngModuleDef.type, + deferrableImports: null, }, { name: 'ɵinj', initializer: injectorDef.expression, statements: injectorDef.statements, type: injectorDef.type, + deferrableImports: null, }, ]; return res; diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts b/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts index 1e6fb4e7d73bc1..2c9e35b3eb72a5 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts @@ -156,8 +156,13 @@ export class InjectableDecoratorHandler implements if (ɵprov === undefined) { // Only add a new ɵprov if there is not one already const res = compileInjectableFn(analysis.meta); - results.push( - {name: 'ɵprov', initializer: res.expression, statements: res.statements, type: res.type}); + results.push({ + name: 'ɵprov', + initializer: res.expression, + statements: res.statements, + type: res.type, + deferrableImports: null + }); } return results; diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts b/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts index 57379d47322683..1bd4c4a868ef52 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts @@ -185,7 +185,7 @@ export class PipeDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵpipe', null); + return compileResults(fac, def, classMetadata, 'ɵpipe', null, null /* deferrableImports */); } compilePartial(node: ClassDeclaration, analysis: Readonly): CompileResult[] { @@ -194,7 +194,7 @@ export class PipeDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileDeclareClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵpipe', null); + return compileResults(fac, def, classMetadata, 'ɵpipe', null, null /* deferrableImports */); } compileLocal(node: ClassDeclaration, analysis: Readonly): CompileResult[] { @@ -203,6 +203,6 @@ export class PipeDecoratorHandler implements const classMetadata = analysis.classMetadata !== null ? compileClassMetadata(analysis.classMetadata).toStmt() : null; - return compileResults(fac, def, classMetadata, 'ɵpipe', null); + return compileResults(fac, def, classMetadata, 'ɵpipe', null, null /* deferrableImports */); } } diff --git a/packages/compiler-cli/src/ngtsc/transform/src/api.ts b/packages/compiler-cli/src/ngtsc/transform/src/api.ts index 18be10e1705bde..8bec70c4272ba8 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/api.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/api.ts @@ -248,7 +248,7 @@ export interface CompileResult { initializer: Expression|null; statements: Statement[]; type: Type; - deferrableImports?: Set; + deferrableImports: Set|null; } export interface ResolveResult { diff --git a/packages/compiler-cli/src/ngtsc/transform/src/transform.ts b/packages/compiler-cli/src/ngtsc/transform/src/transform.ts index 66ff1cb1330037..aa652227a6baaf 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/transform.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/transform.ts @@ -74,7 +74,7 @@ class IvyCompilationVisitor extends Visitor { // so that we can pass it to the transform visitor that will drop // corresponding regular import declarations. for (const classResult of result) { - if (classResult.deferrableImports && classResult.deferrableImports.size > 0) { + if (classResult.deferrableImports !== null && classResult.deferrableImports.size > 0) { classResult.deferrableImports.forEach( importDecl => this.deferrableImports.add(importDecl)); }