From a2975c7507c3d226cf1c5b274501ff1c4b5b5a34 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 7 Jun 2021 21:02:10 +0200 Subject: [PATCH] refactor(platform-browser): ensure compatibility with noImplicitOverride (#42512) Adds the `override` keyword to the `platform-browser` sources to ensure compatibility with `noImplicitOverride`. PR Close #42512 --- .../animations/src/animation_renderer.ts | 7 ++++--- .../animations/test/animation_renderer_spec.ts | 18 +++++++++--------- .../platform-browser/src/dom/dom_renderer.ts | 12 ++++++------ .../src/dom/shared_styles_host.ts | 2 +- .../test/dom/events/event_manager_spec.ts | 4 ++-- .../test/testing_public_spec.ts | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/platform-browser/animations/src/animation_renderer.ts b/packages/platform-browser/animations/src/animation_renderer.ts index a7f6adffa6..7ba2d7fc7e 100644 --- a/packages/platform-browser/animations/src/animation_renderer.ts +++ b/packages/platform-browser/animations/src/animation_renderer.ts @@ -241,7 +241,7 @@ export class AnimationRenderer extends BaseAnimationRenderer implements Renderer this.namespaceId = namespaceId; } - setProperty(el: any, name: string, value: any): void { + override setProperty(el: any, name: string, value: any): void { if (name.charAt(0) == ANIMATION_PREFIX) { if (name.charAt(1) == '.' && name == DISABLE_ANIMATIONS_FLAG) { value = value === undefined ? true : !!value; @@ -254,8 +254,9 @@ export class AnimationRenderer extends BaseAnimationRenderer implements Renderer } } - listen(target: 'window'|'document'|'body'|any, eventName: string, callback: (event: any) => any): - () => void { + override listen( + target: 'window'|'document'|'body'|any, eventName: string, + callback: (event: any) => any): () => void { if (eventName.charAt(0) == ANIMATION_PREFIX) { const element = resolveElementFromTarget(target); let name = eventName.substr(1); diff --git a/packages/platform-browser/animations/test/animation_renderer_spec.ts b/packages/platform-browser/animations/test/animation_renderer_spec.ts index 75bc50de60..2cc9c74aaf 100644 --- a/packages/platform-browser/animations/test/animation_renderer_spec.ts +++ b/packages/platform-browser/animations/test/animation_renderer_spec.ts @@ -368,26 +368,26 @@ class MockAnimationEngine extends InjectableAnimationEngine { data.push(args); } - registerTrigger( + override registerTrigger( componentId: string, namespaceId: string, hostElement: any, name: string, metadata: AnimationTriggerMetadata): void { this.triggers.push(metadata); } - onInsert(namespaceId: string, element: any): void { + override onInsert(namespaceId: string, element: any): void { this._capture('onInsert', [element]); } - onRemove(namespaceId: string, element: any, domFn: () => any): void { + override onRemove(namespaceId: string, element: any, domFn: () => any): void { this._capture('onRemove', [element]); } - process(namespaceId: string, element: any, property: string, value: any): boolean { + override process(namespaceId: string, element: any, property: string, value: any): boolean { this._capture('setProperty', [element, property, value]); return true; } - listen( + override listen( namespaceId: string, element: any, eventName: string, eventPhase: string, callback: (event: any) => any): () => void { // we don't capture the callback here since the renderer wraps it in a zone @@ -395,21 +395,21 @@ class MockAnimationEngine extends InjectableAnimationEngine { return () => {}; } - flush() {} + override flush() {} - destroy(namespaceId: string) {} + override destroy(namespaceId: string) {} } @Injectable() class ExtendedAnimationRendererFactory extends AnimationRendererFactory { public log: string[] = []; - begin() { + override begin() { super.begin(); this.log.push('begin'); } - end() { + override end() { super.end(); this.log.push('end'); } diff --git a/packages/platform-browser/src/dom/dom_renderer.ts b/packages/platform-browser/src/dom/dom_renderer.ts index 31f85be2cd..02db420b5f 100644 --- a/packages/platform-browser/src/dom/dom_renderer.ts +++ b/packages/platform-browser/src/dom/dom_renderer.ts @@ -304,7 +304,7 @@ class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 { super.setAttribute(element, this.hostAttr, ''); } - createElement(parent: any, name: string): Element { + override createElement(parent: any, name: string): Element { const el = super.createElement(parent, name); super.setAttribute(el, this.contentAttr, ''); return el; @@ -332,20 +332,20 @@ class ShadowDomRenderer extends DefaultDomRenderer2 { return node === this.hostEl ? this.shadowRoot : node; } - destroy() { + override destroy() { this.sharedStylesHost.removeHost(this.shadowRoot); } - appendChild(parent: any, newChild: any): void { + override appendChild(parent: any, newChild: any): void { return super.appendChild(this.nodeOrShadowRoot(parent), newChild); } - insertBefore(parent: any, newChild: any, refChild: any): void { + override insertBefore(parent: any, newChild: any, refChild: any): void { return super.insertBefore(this.nodeOrShadowRoot(parent), newChild, refChild); } - removeChild(parent: any, oldChild: any): void { + override removeChild(parent: any, oldChild: any): void { return super.removeChild(this.nodeOrShadowRoot(parent), oldChild); } - parentNode(node: any): any { + override parentNode(node: any): any { return this.nodeOrShadowRoot(super.parentNode(this.nodeOrShadowRoot(node))); } } diff --git a/packages/platform-browser/src/dom/shared_styles_host.ts b/packages/platform-browser/src/dom/shared_styles_host.ts index f82ee229c0..9a85ad5f29 100644 --- a/packages/platform-browser/src/dom/shared_styles_host.ts +++ b/packages/platform-browser/src/dom/shared_styles_host.ts @@ -64,7 +64,7 @@ export class DomSharedStylesHost extends SharedStylesHost implements OnDestroy { this._hostNodes.delete(hostNode); } - onStylesAdded(additions: Set): void { + override onStylesAdded(additions: Set): void { this._hostNodes.forEach((styleNodes, hostNode) => { this._addStylesToHost(additions, hostNode, styleNodes); }); diff --git a/packages/platform-browser/test/dom/events/event_manager_spec.ts b/packages/platform-browser/test/dom/events/event_manager_spec.ts index 24014ffb7c..00277372b8 100644 --- a/packages/platform-browser/test/dom/events/event_manager_spec.ts +++ b/packages/platform-browser/test/dom/events/event_manager_spec.ts @@ -526,10 +526,10 @@ class FakeNgZone extends NgZone { constructor() { super({enableLongStackTrace: false, shouldCoalesceEventChangeDetection: true}); } - run(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T { + override run(fn: (...args: any[]) => T, applyThis?: any, applyArgs?: any[]): T { return fn(); } - runOutsideAngular(fn: Function) { + override runOutsideAngular(fn: Function) { return fn(); } } diff --git a/packages/platform-browser/test/testing_public_spec.ts b/packages/platform-browser/test/testing_public_spec.ts index 253507fbe3..b580fa01d8 100644 --- a/packages/platform-browser/test/testing_public_spec.ts +++ b/packages/platform-browser/test/testing_public_spec.ts @@ -70,7 +70,7 @@ class FancyService { } class MockFancyService extends FancyService { - value: string = 'mocked out value'; + override value: string = 'mocked out value'; } @Component({