mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Matthew Beck (Berry)
parent
419944b800
commit
40c0f53d8b
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user