diff --git a/packages/compiler/src/aot/static_reflector.ts b/packages/compiler/src/aot/static_reflector.ts index 3e67872937..d699cd6210 100644 --- a/packages/compiler/src/aot/static_reflector.ts +++ b/packages/compiler/src/aot/static_reflector.ts @@ -132,7 +132,7 @@ export class StaticReflector implements CompileReflector { public tryAnnotations(type: StaticSymbol): any[] { const originalRecorder = this.errorRecorder; - this.errorRecorder = (error: any, fileName: string) => {}; + this.errorRecorder = (error: any, fileName?: string) => {}; try { return this.annotations(type); } finally { @@ -429,7 +429,7 @@ export class StaticReflector implements CompileReflector { */ private trySimplify(context: StaticSymbol, value: any): any { const originalRecorder = this.errorRecorder; - this.errorRecorder = (error: any, fileName: string) => {}; + this.errorRecorder = (error: any, fileName?: string) => {}; const result = this.simplify(context, value); this.errorRecorder = originalRecorder; return result; diff --git a/packages/compiler/src/constant_pool.ts b/packages/compiler/src/constant_pool.ts index e0124efa9f..ff88cbca79 100644 --- a/packages/compiler/src/constant_pool.ts +++ b/packages/compiler/src/constant_pool.ts @@ -273,11 +273,11 @@ class KeyVisitor implements o.ExpressionVisitor { visitCommaExpr = invalid; } -function invalid(arg: o.Expression | o.Statement): never { +function invalid(this: o.ExpressionVisitor, arg: o.Expression | o.Statement): never { throw new Error( `Invalid state: Visitor ${this.constructor.name} doesn't handle ${arg.constructor.name}`); } function isVariable(e: o.Expression): e is o.ReadVarExpr { return e instanceof o.ReadVarExpr; -} \ No newline at end of file +} diff --git a/packages/compiler/src/jit_compiler_facade.ts b/packages/compiler/src/jit_compiler_facade.ts index c14a4680bf..9255851376 100644 --- a/packages/compiler/src/jit_compiler_facade.ts +++ b/packages/compiler/src/jit_compiler_facade.ts @@ -210,7 +210,7 @@ const USE_FACTORY = Object.keys({useFactory: null})[0]; const USE_VALUE = Object.keys({useValue: null})[0]; const USE_EXISTING = Object.keys({useExisting: null})[0]; -const wrapReference = function(value: Type): R3Reference { +const wrapReference = function(value: any): R3Reference { const wrapped = new WrappedNodeExpr(value); return {value: wrapped, type: wrapped}; }; diff --git a/packages/compiler/src/metadata_resolver.ts b/packages/compiler/src/metadata_resolver.ts index 5f98425f8f..6c2f2d6fff 100644 --- a/packages/compiler/src/metadata_resolver.ts +++ b/packages/compiler/src/metadata_resolver.ts @@ -83,7 +83,7 @@ export class CompileMetadataResolver { private _createProxyClass(baseType: any, name: string): cpl.ProxyClass { let delegate: any = null; - const proxyClass: cpl.ProxyClass = function() { + const proxyClass: cpl.ProxyClass = function(this: unknown) { if (!delegate) { throw new Error( `Illegal state: Class ${name} for type ${stringify(baseType)} is not compiled yet!`); diff --git a/packages/compiler/src/ml_parser/ast.ts b/packages/compiler/src/ml_parser/ast.ts index a94d7c02b1..2eb23de344 100644 --- a/packages/compiler/src/ml_parser/ast.ts +++ b/packages/compiler/src/ml_parser/ast.ts @@ -112,7 +112,7 @@ export class RecursiveVisitor implements Visitor { if (children) results.push(visitAll(t, children, context)); } cb(visit); - return [].concat.apply([], results); + return Array.prototype.concat.apply([], results); } } @@ -149,4 +149,4 @@ export function findNode(nodes: Node[], position: number): HtmlAstPath { visitAll(visitor, nodes); return new AstPath(path, position); -} \ No newline at end of file +} diff --git a/packages/compiler/src/output/output_interpreter.ts b/packages/compiler/src/output/output_interpreter.ts index 7f63f7bb6c..9f25155809 100644 --- a/packages/compiler/src/output/output_interpreter.ts +++ b/packages/compiler/src/output/output_interpreter.ts @@ -38,8 +38,8 @@ class _ExecutionContext { exports: string[] = []; constructor( - public parent: _ExecutionContext|null, public instance: any, public className: string|null, - public vars: Map) {} + public parent: _ExecutionContext|null, public instance: Object|null, + public className: string|null, public vars: Map) {} createChildWihtLocalVars(): _ExecutionContext { return new _ExecutionContext(this, this.instance, this.className, new Map()); @@ -79,9 +79,9 @@ function createDynamicClass( const ctorParamNames = _classStmt.constructorMethod.params.map(param => param.name); // Note: use `function` instead of arrow function to capture `this` - const ctor = function(...args: any[]) { + const ctor = function(this: Object, ...args: any[]) { const instanceCtx = new _ExecutionContext(_ctx, this, _classStmt.name, _ctx.vars); - _classStmt.fields.forEach((field) => { this[field.name] = undefined; }); + _classStmt.fields.forEach((field) => { (this as any)[field.name] = undefined; }); _executeFunctionStatements( ctorParamNames, args, _classStmt.constructorMethod.body, instanceCtx, _visitor); }; @@ -125,7 +125,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor { if (ast.builtin != null) { switch (ast.builtin) { case o.BuiltinVar.Super: - return ctx.instance.__proto__; + return Object.getPrototypeOf(ctx.instance); case o.BuiltinVar.This: return ctx.instance; case o.BuiltinVar.CatchError: @@ -188,7 +188,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor { const args = this.visitAllExpressions(stmt.args, ctx); const fnExpr = stmt.fn; if (fnExpr instanceof o.ReadVarExpr && fnExpr.builtin === o.BuiltinVar.Super) { - ctx.instance.constructor.prototype.constructor.apply(ctx.instance, args); + ctx.instance !.constructor.prototype.constructor.apply(ctx.instance, args); return null; } else { const fn = stmt.fn.visitExpression(this, ctx); diff --git a/packages/compiler/src/render3/view/i18n/meta.ts b/packages/compiler/src/render3/view/i18n/meta.ts index 1c2ec9b39a..e798d9a8b9 100644 --- a/packages/compiler/src/render3/view/i18n/meta.ts +++ b/packages/compiler/src/render3/view/i18n/meta.ts @@ -15,7 +15,7 @@ import {ParseTreeResult} from '../../../ml_parser/parser'; import {I18N_ATTR, I18N_ATTR_PREFIX, I18nMeta, hasI18nAttrs, icuFromI18nMessage, metaFromI18nMessage, parseI18nMeta} from './util'; -function setI18nRefs(html: html.Node & {i18n: i18n.AST}, i18n: i18n.Node) { +function setI18nRefs(html: html.Node & {i18n?: i18n.AST}, i18n: i18n.Node) { html.i18n = i18n; } @@ -128,4 +128,4 @@ export function processI18nMeta( new I18nMetaVisitor(interpolationConfig, /* keepI18nAttrs */ false), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors); -} \ No newline at end of file +} diff --git a/packages/compiler/src/render3/view/i18n/util.ts b/packages/compiler/src/render3/view/i18n/util.ts index c700c1beb8..970c40be6d 100644 --- a/packages/compiler/src/render3/view/i18n/util.ts +++ b/packages/compiler/src/render3/view/i18n/util.ts @@ -165,7 +165,8 @@ export function assembleBoundTextPlaceholders( meta instanceof i18n.Message ? meta.nodes.find(node => node instanceof i18n.Container) : meta; if (node) { (node as i18n.Container) - .children.filter((child: i18n.Node) => child instanceof i18n.Placeholder) + .children + .filter((child: i18n.Node): child is i18n.Placeholder => child instanceof i18n.Placeholder) .forEach((child: i18n.Placeholder, idx: number) => { const content = wrapI18nPlaceholder(startIdx + idx, contextId); updatePlaceholderMap(placeholders, child.name, content); diff --git a/packages/compiler/src/render3/view/template.ts b/packages/compiler/src/render3/view/template.ts index 12dec412a2..7ed51f60b3 100644 --- a/packages/compiler/src/render3/view/template.ts +++ b/packages/compiler/src/render3/view/template.ts @@ -177,7 +177,7 @@ export class TemplateDefinitionBuilder implements t.Visitor, 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) { diff --git a/packages/compiler/src/render3/view/util.ts b/packages/compiler/src/render3/view/util.ts index 068d09d487..84b9d323bc 100644 --- a/packages/compiler/src/render3/view/util.ts +++ b/packages/compiler/src/render3/view/util.ts @@ -62,14 +62,14 @@ export function temporaryAllocator(statements: o.Statement[], name: string): () } -export function unsupported(feature: string): never { +export function unsupported(this: void|Function, feature: string): never { if (this) { throw new Error(`Builder ${this.constructor.name} doesn't support ${feature} yet`); } throw new Error(`Feature ${feature} is not supported yet`); } -export function invalid(arg: o.Expression | o.Statement | t.Node): never { +export function invalid(this: t.Visitor, arg: o.Expression | o.Statement | t.Node): never { throw new Error( `Invalid state: Visitor ${this.constructor.name} doesn't handle ${arg.constructor.name}`); } diff --git a/packages/compiler/src/template_parser/template_ast.ts b/packages/compiler/src/template_parser/template_ast.ts index 7f6672c55b..4041aedd72 100644 --- a/packages/compiler/src/template_parser/template_ast.ts +++ b/packages/compiler/src/template_parser/template_ast.ts @@ -359,7 +359,7 @@ export class RecursiveTemplateAstVisitor extends NullTemplateVisitor implements if (children && children.length) results.push(templateVisitAll(t, children, context)); } cb(visit); - return [].concat.apply([], results); + return Array.prototype.concat.apply([], results); } }