diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts index fff12fa2a78..07834d353df 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts @@ -259,7 +259,7 @@ export class PartialComponentLinkerVersion1 implements private createR3ComponentDeferMetadata(boundTarget: BoundTarget): R3ComponentDeferMetadata { const deferredBlocks = boundTarget.getDeferBlocks(); - const blocks = new Map(); + const blocks = new Map(); for (const block of deferredBlocks) { // TODO: leaving `deps` empty for now, to be implemented as one of the next steps. 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 7b48a556a04..1484f356dcd 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts @@ -1489,7 +1489,7 @@ export class ComponentDecoratorHandler implements 'Internal error: deferPerBlockDependencies must be present when compiling in PerBlock mode'); } - const blocks = new Map(); + const blocks = new Map(); for (const [block, dependencies] of perBlockDeps) { blocks.set( block, diff --git a/packages/compiler/src/constant_pool.ts b/packages/compiler/src/constant_pool.ts index 173222b66de..dbae2c314ab 100644 --- a/packages/compiler/src/constant_pool.ts +++ b/packages/compiler/src/constant_pool.ts @@ -198,9 +198,8 @@ export class ConstantPool { // TODO: useUniqueName(false) is necessary for naming compatibility with // TemplateDefinitionBuilder, but should be removed once Template Pipeline is the default. - getSharedFunctionReference( - fn: o.FunctionExpr|o.ArrowFunctionExpr, prefix: string, - useUniqueName: boolean = true): o.Expression { + getSharedFunctionReference(fn: o.Expression, prefix: string, useUniqueName: boolean = true): + o.Expression { const isArrow = fn instanceof o.ArrowFunctionExpr; for (const current of this.statements) { @@ -212,14 +211,18 @@ export class ConstantPool { // Function declarations are saved as function statements // so we compare them directly to the passed-in function. - if (!isArrow && current instanceof o.DeclareFunctionStmt && fn.isEquivalent(current)) { + if (!isArrow && current instanceof o.DeclareFunctionStmt && fn instanceof o.FunctionExpr && + fn.isEquivalent(current)) { return o.variable(current.name); } } // Otherwise declare the function. const name = useUniqueName ? this.uniqueName(prefix) : prefix; - this.statements.push(fn.toDeclStmt(name, o.StmtModifier.Final)); + this.statements.push( + fn instanceof o.FunctionExpr ? + fn.toDeclStmt(name, o.StmtModifier.Final) : + new o.DeclareVarStmt(name, fn, o.INFERRED_TYPE, o.StmtModifier.Final, fn.sourceSpan)); return o.variable(name); } diff --git a/packages/compiler/src/jit_compiler_facade.ts b/packages/compiler/src/jit_compiler_facade.ts index 9724463c960..21e659aa2ef 100644 --- a/packages/compiler/src/jit_compiler_facade.ts +++ b/packages/compiler/src/jit_compiler_facade.ts @@ -11,7 +11,7 @@ import {ConstantPool} from './constant_pool'; import {ChangeDetectionStrategy, HostBinding, HostListener, Input, Output, ViewEncapsulation} from './core'; import {compileInjectable} from './injectable_compiler_2'; import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './ml_parser/defaults'; -import {ArrowFunctionExpr, DeclareVarStmt, Expression, literal, LiteralExpr, Statement, StmtModifier, WrappedNodeExpr} from './output/output_ast'; +import {DeclareVarStmt, Expression, literal, LiteralExpr, Statement, StmtModifier, WrappedNodeExpr} from './output/output_ast'; import {JitEvaluator} from './output/output_jit'; import {ParseError, ParseSourceSpan, r3JitTypeSourceSpan} from './parse_util'; import {DeferredBlock} from './render3/r3_ast'; @@ -624,7 +624,7 @@ function createR3DependencyMetadata( function createR3ComponentDeferMetadata(boundTarget: BoundTarget): R3ComponentDeferMetadata { const deferredBlocks = boundTarget.getDeferBlocks(); - const blocks = new Map(); + const blocks = new Map(); for (const block of deferredBlocks) { // TODO: leaving dependency function empty in JIT mode for now, diff --git a/packages/compiler/src/render3/view/api.ts b/packages/compiler/src/render3/view/api.ts index db1df5fdcbe..6edf2da1723 100644 --- a/packages/compiler/src/render3/view/api.ts +++ b/packages/compiler/src/render3/view/api.ts @@ -296,10 +296,10 @@ export interface R3ComponentMetadata */ export type R3ComponentDeferMetadata = { mode: DeferBlockDepsEmitMode.PerBlock, - blocks: Map, + blocks: Map, }|{ mode: DeferBlockDepsEmitMode.PerComponent, - dependenciesFn: o.ArrowFunctionExpr | null, + dependenciesFn: o.Expression | null, }; /** diff --git a/packages/compiler/src/render3/view/compiler.ts b/packages/compiler/src/render3/view/compiler.ts index 8dc8d72b304..ac1916870b6 100644 --- a/packages/compiler/src/render3/view/compiler.ts +++ b/packages/compiler/src/render3/view/compiler.ts @@ -180,7 +180,7 @@ export function compileComponentFromMetadata( meta.defer.dependenciesFn !== null) { const fnName = `${templateTypeName}_DeferFn`; constantPool.statements.push( - meta.defer.dependenciesFn.toDeclStmt(fnName, o.StmtModifier.Final)); + new o.DeclareVarStmt(fnName, meta.defer.dependenciesFn, undefined, o.StmtModifier.Final)); allDeferrableDepsFn = o.variable(fnName); } diff --git a/packages/compiler/src/template/pipeline/ir/src/ops/create.ts b/packages/compiler/src/template/pipeline/ir/src/ops/create.ts index 4e9b451f5d7..ec597248164 100644 --- a/packages/compiler/src/template/pipeline/ir/src/ops/create.ts +++ b/packages/compiler/src/template/pipeline/ir/src/ops/create.ts @@ -836,7 +836,7 @@ export interface DeferOp extends Op, ConsumesSlotOpTrait { * per deferred block or one for the entire template. This field contains the function that * belongs specifically to the current deferred block. */ - ownResolverFn: o.ArrowFunctionExpr|null; + ownResolverFn: o.Expression|null; /** * After processing, the resolver function for the defer deps will be extracted to the constant @@ -848,7 +848,7 @@ export interface DeferOp extends Op, ConsumesSlotOpTrait { } export function createDeferOp( - xref: XrefId, main: XrefId, mainSlot: SlotHandle, ownResolverFn: o.ArrowFunctionExpr|null, + xref: XrefId, main: XrefId, mainSlot: SlotHandle, ownResolverFn: o.Expression|null, resolverFn: o.Expression|null, sourceSpan: ParseSourceSpan): DeferOp { return { kind: OpKind.Defer, diff --git a/packages/compiler/src/template/pipeline/src/ingest.ts b/packages/compiler/src/template/pipeline/src/ingest.ts index 65f8caaace6..b0f4f88416a 100644 --- a/packages/compiler/src/template/pipeline/src/ingest.ts +++ b/packages/compiler/src/template/pipeline/src/ingest.ts @@ -447,7 +447,7 @@ function ingestDeferView( } function ingestDeferBlock(unit: ViewCompilationUnit, deferBlock: t.DeferredBlock): void { - let ownResolverFn: o.ArrowFunctionExpr|null = null; + let ownResolverFn: o.Expression|null = null; if (unit.job.deferMeta.mode === DeferBlockDepsEmitMode.PerBlock) { if (!unit.job.deferMeta.blocks.has(deferBlock)) {