From 4bde40f7c21615e5619aee2b09a7fa44bdb90287 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 10 Apr 2019 13:27:17 +0200 Subject: [PATCH] fix(core): don't include a local `EventListener` in typings (#29809) With dts bundles, `core.d.ts` will include an `EventListener` class as it's used in https://github.com/angular/angular/blob/303eae918d997070a36b523ddc97e018f622c258/packages/core/src/debug/debug_node.ts#L32 This will conflict with the DOM EventListener, as anything in `core.d.ts` which is using the DOM EventListener will fallback in using the one defined in the same module and hence build will fail because their implementation is different. With this change, we rename the local `EventListener` to `DebugEventListener`, the later one is non exported. Fixes #29806 PR Close #29809 --- packages/core/src/core.ts | 2 +- packages/core/src/debug/debug_node.ts | 11 +++++++---- packages/core/src/view/services.ts | 4 ++-- tools/public_api_guard/core/core.d.ts | 8 +++++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index e49543bd34..a21cfa7bfc 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -22,7 +22,7 @@ export {APP_INITIALIZER, ApplicationInitStatus} from './application_init'; export * from './zone'; export * from './render'; export * from './linker'; -export {DebugElement, DebugNode, asNativeElements, getDebugNode, Predicate} from './debug/debug_node'; +export {DebugElement, DebugEventListener, DebugNode, asNativeElements, getDebugNode, Predicate} from './debug/debug_node'; export {GetTestability, Testability, TestabilityRegistry, setTestabilityGetter} from './testability/testability'; export * from './change_detection'; export * from './platform_core_providers'; diff --git a/packages/core/src/debug/debug_node.ts b/packages/core/src/debug/debug_node.ts index 7e2a3210ee..12f4c1c245 100644 --- a/packages/core/src/debug/debug_node.ts +++ b/packages/core/src/debug/debug_node.ts @@ -21,7 +21,10 @@ import {getComponentViewByIndex, getNativeByTNode, isComponent, isLContainer} fr import {assertDomNode} from '../util/assert'; import {DebugContext} from '../view/index'; -export class EventListener { +/** + * @publicApi + */ +export class DebugEventListener { constructor(public name: string, public callback: Function) {} } @@ -29,7 +32,7 @@ export class EventListener { * @publicApi */ export interface DebugNode { - readonly listeners: EventListener[]; + readonly listeners: DebugEventListener[]; readonly parent: DebugElement|null; readonly nativeNode: any; readonly injector: Injector; @@ -39,7 +42,7 @@ export interface DebugNode { readonly providerTokens: any[]; } export class DebugNode__PRE_R3__ { - readonly listeners: EventListener[] = []; + readonly listeners: DebugEventListener[] = []; readonly parent: DebugElement|null = null; readonly nativeNode: any; private readonly _debugContext: DebugContext; @@ -219,7 +222,7 @@ class DebugNode__POST_R3__ implements DebugNode { } get context(): any { return getContext(this.nativeNode as Element); } - get listeners(): EventListener[] { + get listeners(): DebugEventListener[] { return getListeners(this.nativeNode as Element).filter(isBrowserEvents); } diff --git a/packages/core/src/view/services.ts b/packages/core/src/view/services.ts index 02302ba35e..8c705f378e 100644 --- a/packages/core/src/view/services.ts +++ b/packages/core/src/view/services.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {DebugElement__PRE_R3__, DebugNode__PRE_R3__, EventListener, getDebugNode, indexDebugNode, removeDebugNodeFromIndex} from '../debug/debug_node'; +import {DebugElement__PRE_R3__, DebugEventListener, DebugNode__PRE_R3__, getDebugNode, indexDebugNode, removeDebugNodeFromIndex} from '../debug/debug_node'; import {Injector} from '../di'; import {InjectableType} from '../di/injectable'; import {getInjectableDef, ɵɵInjectableDef} from '../di/interface/defs'; @@ -827,7 +827,7 @@ export class DebugRenderer2 implements Renderer2 { if (typeof target !== 'string') { const debugEl = getDebugNode(target); if (debugEl) { - debugEl.listeners.push(new EventListener(eventName, callback)); + debugEl.listeners.push(new DebugEventListener(eventName, callback)); } } diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index 74f2fd5e9b..cb31ced994 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -224,11 +224,17 @@ export declare const DebugElement: { new (...args: any[]): DebugElement; }; +export declare class DebugEventListener { + callback: Function; + name: string; + constructor(name: string, callback: Function); +} + export interface DebugNode { readonly componentInstance: any; readonly context: any; readonly injector: Injector; - readonly listeners: EventListener[]; + readonly listeners: DebugEventListener[]; readonly nativeNode: any; readonly parent: DebugElement | null; readonly providerTokens: any[];