mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler-cli): cleanup inferences (#49863)
With the ts compiler updates these inferences have been fixed. PR Close #49863
This commit is contained in:
committed by
Jessica Janiuk
parent
8f28f1999b
commit
2aa6d6d616
@@ -143,9 +143,8 @@ export function validateConstructorDependencies(
|
||||
} else if (deps.deps !== null) {
|
||||
return deps.deps;
|
||||
} else {
|
||||
// TODO(alxhub): this cast is necessary because the g3 typescript version doesn't narrow here.
|
||||
// There is at least one error.
|
||||
const error = (deps as {errors: ConstructorDepError[]}).errors[0];
|
||||
const error = deps.errors[0];
|
||||
throw createUnsuitableInjectionTokenError(clazz, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,15 +111,7 @@ export type TemplateDeclaration = InlineTemplateDeclaration|ExternalTemplateDecl
|
||||
|
||||
/** Determines the node to use for debugging purposes for the given TemplateDeclaration. */
|
||||
export function getTemplateDeclarationNodeForError(declaration: TemplateDeclaration): ts.Node {
|
||||
// TODO(zarend): Change this to if/else when that is compatible with g3. This uses a switch
|
||||
// because if/else fails to compile on g3. That is because g3 compiles this in non-strict mode
|
||||
// where type inference does not work correctly.
|
||||
switch (declaration.isInline) {
|
||||
case true:
|
||||
return declaration.expression;
|
||||
case false:
|
||||
return declaration.templateUrlExpression;
|
||||
}
|
||||
return declaration.isInline ? declaration.expression : declaration.templateUrlExpression;
|
||||
}
|
||||
|
||||
export interface ExtractTemplateOptions {
|
||||
@@ -199,9 +191,7 @@ export function extractTemplate(
|
||||
sourceMapping: {
|
||||
type: 'external',
|
||||
componentClass: node,
|
||||
// TODO(alxhub): TS in g3 is unable to make this inference on its own, so cast it here
|
||||
// until g3 is able to figure this out.
|
||||
node: (template as ExternalTemplateDeclaration).templateUrlExpression,
|
||||
node: template.templateUrlExpression,
|
||||
template: templateContent,
|
||||
templateUrl: template.resolvedTemplateUrl,
|
||||
},
|
||||
|
||||
@@ -61,10 +61,9 @@ export function makeTemplateDiagnostic(
|
||||
// For external temoplates, the HTML filename is used.
|
||||
const componentSf = mapping.componentClass.getSourceFile();
|
||||
const componentName = mapping.componentClass.name.text;
|
||||
// TODO(alxhub): remove cast when TS in g3 supports this narrowing.
|
||||
const fileName = mapping.type === 'indirect' ?
|
||||
`${componentSf.fileName} (${componentName} template)` :
|
||||
(mapping as ExternalTemplateSourceMapping).templateUrl;
|
||||
mapping.templateUrl;
|
||||
|
||||
let relatedInformation: ts.DiagnosticRelatedInformation[] = [];
|
||||
if (relatedMessages !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user