refactor(compiler): add type annotations to generated code

Adds explicit type annotations to the generated code so it's able to compile.
This commit is contained in:
Kristiyan Kostadinov
2026-03-13 12:30:14 +01:00
committed by Matthew Beck (Berry)
parent 419944b800
commit 40c0f53d8b
3 changed files with 21 additions and 5 deletions
+8 -2
View File
@@ -133,7 +133,7 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3CompiledExpre
function makeConditionalFactory(nonCtorExpr: o.Expression): o.ReadVarExpr {
const r = o.variable('__ngConditionalFactory__');
body.push(new o.DeclareVarStmt(r.name, o.NULL_EXPR, o.INFERRED_TYPE));
body.push(new o.DeclareVarStmt(r.name, o.NULL_EXPR, o.DYNAMIC_TYPE));
const ctorStmt =
ctorExpr !== null
? r.set(ctorExpr).toStmt()
@@ -188,7 +188,13 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): R3CompiledExpre
// There is a base factory variable so wrap its declaration along with the factory function into
// an IIFE.
factoryFn = o
.arrowFn([], [new o.DeclareVarStmt(baseFactoryVar.name!), new o.ReturnStatement(factoryFn)])
.arrowFn(
[],
[
new o.DeclareVarStmt(baseFactoryVar.name!, undefined, o.DYNAMIC_TYPE),
new o.ReturnStatement(factoryFn),
],
)
.callFn([], /* sourceSpan */ undefined, /* pure */ true);
}
@@ -246,7 +246,7 @@ function collectMessage(
// Sort the params for consistency with TemaplateDefinitionBuilder output.
messageOp.params = new Map([...messageOp.params.entries()].sort());
const mainVar = o.variable(job.pool.uniqueName(TRANSLATION_VAR_PREFIX));
const mainVar = o.variable(job.pool.uniqueName(TRANSLATION_VAR_PREFIX), o.DYNAMIC_TYPE);
// Closure Compiler requires const names to start with `MSG_` but disallows any other
// const to start with `MSG_`. We define a variable starting with `MSG_` just for the
// `goog.getMsg` call
@@ -342,7 +342,12 @@ function reifyCreateOperations(unit: CompilationUnit, ops: ir.OpList<ir.CreateOp
ir.OpList.replace<ir.CreateOp>(
op,
ir.createStatementOp(
new o.DeclareVarStmt(op.variable.name, op.initializer, undefined, o.StmtModifier.Final),
new o.DeclareVarStmt(
op.variable.name,
op.initializer,
o.DYNAMIC_TYPE,
o.StmtModifier.Final,
),
),
);
break;
@@ -693,7 +698,12 @@ function reifyUpdateOperations(unit: CompilationUnit, ops: ir.OpList<ir.UpdateOp
ir.OpList.replace<ir.UpdateOp>(
op,
ir.createStatementOp(
new o.DeclareVarStmt(op.variable.name, op.initializer, undefined, o.StmtModifier.Final),
new o.DeclareVarStmt(
op.variable.name,
op.initializer,
o.DYNAMIC_TYPE,
o.StmtModifier.Final,
),
),
);
break;