mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler): replace any casts with precise types
- r3_factory: use `in` operator instead of `as any` property probing
in isDelegatedFactoryMetadata / isExpressionFactoryMetadata type guards
- r3_deferred_triggers: narrow assignment to
`DeferredBlockTriggers[typeof name]` instead of `as any`
- defer_resolve_targets / reify: drop unnecessary `as any` on
`op.trigger` — `DeferTriggerBase.kind` is present on all union members
- pipe_creation: replace double `as any` with `as {target?: ir.XrefId}`,
and reuse the already-narrowed `slotHandle` variable for the call
- extractor_merger: replace legacy `<any>console` guards with a proper
`typeof console !== 'undefined'` check
(cherry picked from commit 5d76720e06)
This commit is contained in:
committed by
Jessica Janiuk
parent
644455b29e
commit
cc84776f75
@@ -208,7 +208,7 @@ class _Visitor implements html.Visitor {
|
||||
if (!this._inI18nBlock) {
|
||||
if (isOpening) {
|
||||
// deprecated from v5 you should use <ng-container i18n> instead of i18n comments
|
||||
if (!i18nCommentsWarned && <any>console && <any>console.warn) {
|
||||
if (!i18nCommentsWarned && typeof console?.warn === 'function') {
|
||||
i18nCommentsWarned = true;
|
||||
const details = comment.sourceSpan.details ? `, ${comment.sourceSpan.details}` : '';
|
||||
// TODO(ocombe): use a log service once there is a public one available
|
||||
@@ -674,8 +674,7 @@ function _isClosingComment(n: html.Node): boolean {
|
||||
function _getI18nAttr(p: html.Element | html.Component): html.Attribute | null {
|
||||
return (
|
||||
(p.attrs.find((attr) => attr instanceof html.Attribute && attr.name === _I18N_ATTR) as
|
||||
| html.Attribute
|
||||
| undefined) || null
|
||||
html.Attribute | undefined) || null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -451,7 +451,10 @@ class OnTriggerParser {
|
||||
);
|
||||
}
|
||||
|
||||
private trackTrigger(name: keyof t.DeferredBlockTriggers, trigger: t.DeferredTrigger): void {
|
||||
private trackTrigger<Name extends keyof t.DeferredBlockTriggers>(
|
||||
name: Name,
|
||||
trigger: NonNullable<t.DeferredBlockTriggers[Name]>,
|
||||
): void {
|
||||
trackTrigger(name, this.triggers, this.errors, trigger);
|
||||
}
|
||||
|
||||
@@ -467,16 +470,16 @@ class OnTriggerParser {
|
||||
}
|
||||
|
||||
/** Adds a trigger to a map of triggers. */
|
||||
function trackTrigger(
|
||||
name: keyof t.DeferredBlockTriggers,
|
||||
function trackTrigger<Name extends keyof t.DeferredBlockTriggers>(
|
||||
name: Name,
|
||||
allTriggers: t.DeferredBlockTriggers,
|
||||
errors: ParseError[],
|
||||
trigger: t.DeferredTrigger,
|
||||
trigger: NonNullable<t.DeferredBlockTriggers[Name]>,
|
||||
) {
|
||||
if (allTriggers[name]) {
|
||||
errors.push(new ParseError(trigger.sourceSpan, `Duplicate "${name}" trigger is not allowed`));
|
||||
} else {
|
||||
allTriggers[name] = trigger as any;
|
||||
allTriggers[name] = trigger;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,7 @@ export interface R3ExpressionFactoryMetadata extends R3ConstructorFactoryMetadat
|
||||
}
|
||||
|
||||
export type R3FactoryMetadata =
|
||||
| R3ConstructorFactoryMetadata
|
||||
| R3DelegatedFnOrClassMetadata
|
||||
| R3ExpressionFactoryMetadata;
|
||||
R3ConstructorFactoryMetadata | R3DelegatedFnOrClassMetadata | R3ExpressionFactoryMetadata;
|
||||
|
||||
export interface R3DependencyMetadata {
|
||||
/**
|
||||
@@ -321,13 +319,13 @@ function createCtorDepType(dep: R3DependencyMetadata): o.LiteralMapExpr | null {
|
||||
export function isDelegatedFactoryMetadata(
|
||||
meta: R3FactoryMetadata,
|
||||
): meta is R3DelegatedFnOrClassMetadata {
|
||||
return (meta as any).delegateType !== undefined;
|
||||
return (meta as R3DelegatedFnOrClassMetadata).delegateType !== undefined;
|
||||
}
|
||||
|
||||
export function isExpressionFactoryMetadata(
|
||||
meta: R3FactoryMetadata,
|
||||
): meta is R3ExpressionFactoryMetadata {
|
||||
return (meta as any).expression !== undefined;
|
||||
return (meta as R3ExpressionFactoryMetadata).expression !== undefined;
|
||||
}
|
||||
|
||||
function getInjectFn(target: FactoryTarget): o.ExternalReference {
|
||||
|
||||
@@ -38,11 +38,11 @@ function processPipeBindingsInView(unit: CompilationUnit): void {
|
||||
}
|
||||
|
||||
// TODO: We can delete this cast and check once compatibility mode is removed.
|
||||
const slotHandle = (updateOp as any).target;
|
||||
const slotHandle = (updateOp as {target?: ir.XrefId}).target;
|
||||
if (slotHandle == undefined) {
|
||||
throw new Error(`AssertionError: expected slot handle to be assigned for pipe creation`);
|
||||
}
|
||||
addPipeToCreationBlock(unit, (updateOp as any).target, expr);
|
||||
addPipeToCreationBlock(unit, slotHandle, expr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user