refactor(compiler): tighten type of `TemplateParser._console` (#36741)

This property can actually be `null` when called from the language-service.
This change allows us to remove the use of `!` to subvert the type system.

PR Close #36741
This commit is contained in:
Pete Bacon Darwin 2020-04-26 18:15:43 +01:00 committed by Andrew Kushnir
parent 7c8c41353b
commit 4172707346
2 changed files with 4 additions and 4 deletions

View File

@ -81,7 +81,7 @@ export class TemplateParser {
constructor(
private _config: CompilerConfig, private _reflector: CompileReflector,
private _exprParser: Parser, private _schemaRegistry: ElementSchemaRegistry,
private _htmlParser: HtmlParser, private _console: Console,
private _htmlParser: HtmlParser, private _console: Console|null,
public transforms: t.TemplateAstVisitor[]) {}
public get expressionParser() {
@ -100,7 +100,7 @@ export class TemplateParser {
const errors = result.errors!.filter(error => error.level === ParseErrorLevel.ERROR);
if (warnings.length > 0) {
this._console.warn(`Template parse warnings:\n${warnings.join('\n')}`);
this._console?.warn(`Template parse warnings:\n${warnings.join('\n')}`);
}
if (errors.length > 0) {

View File

@ -516,8 +516,8 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
const parser = new TemplateParser(
new CompilerConfig(), this.reflector, expressionParser, new DomElementSchemaRegistry(),
htmlParser,
null!, // console
[] // tranforms
null, // console
[] // tranforms
);
const htmlResult = htmlParser.parse(template.source, fileName, {
tokenizeExpansionForms: true,