refactor(compiler): ensure compatibility with typescript strict flag (#30993)

As part of FW-1265, the `@angular/compiler` package is made compatible
with the TypeScript `--strict` flag. This already unveiled a few bugs,
so the strictness flag seems to help with increasing the overall code health.

Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
This commit is contained in:
Paul Gschwendtner
2019-06-14 09:28:04 +02:00
committed by Miško Hevery
parent 2200884e55
commit 012b535147
11 changed files with 28 additions and 25 deletions

View File

@ -177,7 +177,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
this._valueConverter = new ValueConverter(
constantPool, () => this.allocateDataSlot(),
(numSlots: number) => this.allocatePureFunctionSlots(numSlots),
(name, localName, slot, value: o.ReadVarExpr) => {
(name, localName, slot, value: o.Expression) => {
const pipeType = pipeTypeByName.get(name);
if (pipeType) {
this.pipes.add(pipeType);
@ -1517,7 +1517,7 @@ const SHARED_CONTEXT_KEY = '$$shared_ctx$$';
* declaration should always come before the local ref declaration.
*/
type BindingData = {
retrievalLevel: number; lhs: o.ReadVarExpr; declareLocalCallback?: DeclareLocalVarCallback;
retrievalLevel: number; lhs: o.Expression; declareLocalCallback?: DeclareLocalVarCallback;
declare: boolean;
priority: number;
localRef: boolean;
@ -1593,7 +1593,7 @@ export class BindingScope implements LocalResolver {
* @param declareLocalCallback The callback to invoke when declaring this local var
* @param localRef Whether or not this is a local ref
*/
set(retrievalLevel: number, name: string, lhs: o.ReadVarExpr,
set(retrievalLevel: number, name: string, lhs: o.Expression,
priority: number = DeclarationPriority.DEFAULT,
declareLocalCallback?: DeclareLocalVarCallback, localRef?: true): BindingScope {
if (this.map.has(name)) {
@ -1644,12 +1644,14 @@ export class BindingScope implements LocalResolver {
if (!this.map.has(bindingKey)) {
this.generateSharedContextVar(retrievalLevel);
}
return this.map.get(bindingKey) !.lhs;
// Shared context variables are always generated as "ReadVarExpr".
return this.map.get(bindingKey) !.lhs as o.ReadVarExpr;
}
getSharedContextName(retrievalLevel: number): o.ReadVarExpr|null {
const sharedCtxObj = this.map.get(SHARED_CONTEXT_KEY + retrievalLevel);
return sharedCtxObj && sharedCtxObj.declare ? sharedCtxObj.lhs : null;
// Shared context variables are always generated as "ReadVarExpr".
return sharedCtxObj && sharedCtxObj.declare ? sharedCtxObj.lhs as o.ReadVarExpr : null;
}
maybeGenerateSharedContextVar(value: BindingData) {