From aa4924513b95ee9249ab9f091ba746fe0d00bdde Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 9 Nov 2020 17:09:49 -0800 Subject: [PATCH] refactor(core): Cleanup circular dependency between ViewEngine and Ivy `ElementRef`. (#39621) `ElementRef` is declared in ViewEngine but it sub-classed in Ivy. This creates a circular dependency between ViewEngine `ElementRef` which needs to declare `__NG_ELEMENT_ID__` and ivy factory which needs to create it. The workaround used to be to pass the `ElementRef` through stack but that created a very convoluted code. This refactoring simply bundles the two files together and removes the stack workaround making the code simpler to follow. PR Close #39621 --- goldens/circular-deps/packages.json | 186 +++++++++--------- packages/core/src/linker/element_ref.ts | 37 +++- packages/core/src/linker/template_ref.ts | 2 +- .../core/src/linker/view_container_ref.ts | 2 +- packages/core/src/render3/component_ref.ts | 7 +- packages/core/src/render3/query.ts | 15 +- .../src/render3/view_engine_compatibility.ts | 55 ++---- .../view_engine_compatibility_prebound.ts | 5 +- .../test/render3/perf/ng_template/index.ts | 6 +- packages/core/test/render3/render_util.ts | 9 +- 10 files changed, 158 insertions(+), 166 deletions(-) diff --git a/goldens/circular-deps/packages.json b/goldens/circular-deps/packages.json index 8c26c0a489..2998cb1943 100644 --- a/goldens/circular-deps/packages.json +++ b/goldens/circular-deps/packages.json @@ -152,6 +152,93 @@ "packages/core/src/render3/definition.ts", "packages/core/src/metadata/ng_module.ts" ], + [ + "packages/core/src/application_ref.ts", + "packages/core/src/application_tokens.ts", + "packages/core/src/linker/component_factory.ts", + "packages/core/src/change_detection/change_detection.ts", + "packages/core/src/change_detection/change_detector_ref.ts", + "packages/core/src/render3/view_engine_compatibility.ts", + "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/view.ts", + "packages/core/src/di/injector.ts", + "packages/core/src/di/r3_injector.ts", + "packages/core/src/render3/definition.ts", + "packages/core/src/metadata/ng_module.ts" + ], + [ + "packages/core/src/application_ref.ts", + "packages/core/src/application_tokens.ts", + "packages/core/src/linker/component_factory.ts", + "packages/core/src/change_detection/change_detection.ts", + "packages/core/src/change_detection/change_detector_ref.ts", + "packages/core/src/render3/view_engine_compatibility.ts", + "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/view.ts", + "packages/core/src/metadata.ts", + "packages/core/src/di.ts", + "packages/core/src/di/index.ts", + "packages/core/src/di/injectable.ts", + "packages/core/src/di/jit/injectable.ts", + "packages/core/src/di/jit/environment.ts", + "packages/core/src/di/injector_compatibility.ts", + "packages/core/src/di/injector.ts", + "packages/core/src/di/r3_injector.ts", + "packages/core/src/render3/definition.ts", + "packages/core/src/metadata/ng_module.ts" + ], + [ + "packages/core/src/application_ref.ts", + "packages/core/src/application_tokens.ts", + "packages/core/src/linker/component_factory.ts", + "packages/core/src/change_detection/change_detection.ts", + "packages/core/src/change_detection/change_detector_ref.ts", + "packages/core/src/render3/view_engine_compatibility.ts", + "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/view.ts", + "packages/core/src/render3/interfaces/container.ts", + "packages/core/src/linker/view_ref.ts" + ], + [ + "packages/core/src/application_ref.ts", + "packages/core/src/application_tokens.ts", + "packages/core/src/linker/component_factory.ts", + "packages/core/src/change_detection/change_detection.ts", + "packages/core/src/change_detection/change_detector_ref.ts", + "packages/core/src/render3/view_engine_compatibility.ts", + "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/view.ts", + "packages/core/src/render3/interfaces/definition.ts", + "packages/core/src/core.ts", + "packages/core/src/metadata.ts", + "packages/core/src/di.ts", + "packages/core/src/di/index.ts", + "packages/core/src/di/injectable.ts", + "packages/core/src/di/jit/injectable.ts", + "packages/core/src/di/jit/environment.ts", + "packages/core/src/di/injector_compatibility.ts", + "packages/core/src/di/injector.ts", + "packages/core/src/di/r3_injector.ts", + "packages/core/src/render3/definition.ts", + "packages/core/src/metadata/ng_module.ts" + ], + [ + "packages/core/src/application_ref.ts", + "packages/core/src/application_tokens.ts", + "packages/core/src/linker/component_factory.ts", + "packages/core/src/change_detection/change_detection.ts", + "packages/core/src/change_detection/change_detector_ref.ts", + "packages/core/src/render3/view_engine_compatibility.ts", + "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/state.ts", + "packages/core/src/render3/assert.ts", + "packages/core/src/render3/definition.ts", + "packages/core/src/metadata/ng_module.ts" + ], [ "packages/core/src/application_ref.ts", "packages/core/src/application_tokens.ts", @@ -179,16 +266,6 @@ "packages/core/src/render3/definition.ts", "packages/core/src/metadata/ng_module.ts" ], - [ - "packages/core/src/application_ref.ts", - "packages/core/src/application_tokens.ts", - "packages/core/src/linker/component_factory.ts", - "packages/core/src/change_detection/change_detection.ts", - "packages/core/src/change_detection/change_detector_ref.ts", - "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/linker/template_ref.ts", - "packages/core/src/linker/view_ref.ts" - ], [ "packages/core/src/application_ref.ts", "packages/core/src/application_tokens.ts", @@ -202,81 +279,6 @@ "packages/core/src/render3/definition.ts", "packages/core/src/metadata/ng_module.ts" ], - [ - "packages/core/src/application_ref.ts", - "packages/core/src/application_tokens.ts", - "packages/core/src/linker/component_factory.ts", - "packages/core/src/change_detection/change_detection.ts", - "packages/core/src/change_detection/change_detector_ref.ts", - "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/render3/assert.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/metadata/ng_module.ts" - ], - [ - "packages/core/src/application_ref.ts", - "packages/core/src/application_tokens.ts", - "packages/core/src/linker/component_factory.ts", - "packages/core/src/change_detection/change_detection.ts", - "packages/core/src/change_detection/change_detector_ref.ts", - "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/render3/assert.ts", - "packages/core/src/render3/interfaces/container.ts", - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts", - "packages/core/src/di/injector.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/metadata/ng_module.ts" - ], - [ - "packages/core/src/application_ref.ts", - "packages/core/src/application_tokens.ts", - "packages/core/src/linker/component_factory.ts", - "packages/core/src/change_detection/change_detection.ts", - "packages/core/src/change_detection/change_detector_ref.ts", - "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/render3/assert.ts", - "packages/core/src/render3/interfaces/container.ts", - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts", - "packages/core/src/metadata.ts", - "packages/core/src/di.ts", - "packages/core/src/di/index.ts", - "packages/core/src/di/injectable.ts", - "packages/core/src/di/jit/injectable.ts", - "packages/core/src/di/jit/environment.ts", - "packages/core/src/di/injector_compatibility.ts", - "packages/core/src/di/injector.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/metadata/ng_module.ts" - ], - [ - "packages/core/src/application_ref.ts", - "packages/core/src/application_tokens.ts", - "packages/core/src/linker/component_factory.ts", - "packages/core/src/change_detection/change_detection.ts", - "packages/core/src/change_detection/change_detector_ref.ts", - "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/render3/assert.ts", - "packages/core/src/render3/interfaces/container.ts", - "packages/core/src/render3/interfaces/node.ts", - "packages/core/src/render3/interfaces/view.ts", - "packages/core/src/render3/interfaces/definition.ts", - "packages/core/src/core.ts", - "packages/core/src/metadata.ts", - "packages/core/src/di.ts", - "packages/core/src/di/index.ts", - "packages/core/src/di/injectable.ts", - "packages/core/src/di/jit/injectable.ts", - "packages/core/src/di/jit/environment.ts", - "packages/core/src/di/injector_compatibility.ts", - "packages/core/src/di/injector.ts", - "packages/core/src/di/r3_injector.ts", - "packages/core/src/render3/definition.ts", - "packages/core/src/metadata/ng_module.ts" - ], [ "packages/core/src/application_ref.ts", "packages/core/src/application_tokens.ts", @@ -867,7 +869,10 @@ [ "packages/core/src/change_detection/change_detector_ref.ts", "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/linker/template_ref.ts", + "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/view.ts", + "packages/core/src/render3/interfaces/container.ts", "packages/core/src/linker/view_ref.ts" ], [ @@ -929,6 +934,9 @@ ], [ "packages/core/src/linker/element_ref.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/renderer.ts", + "packages/core/src/render/api.ts", "packages/core/src/render3/view_engine_compatibility.ts" ], [ @@ -962,12 +970,12 @@ "packages/core/src/render3/jit/pipe.ts" ], [ - "packages/core/src/render/api.ts", - "packages/core/src/render3/view_engine_compatibility.ts" + "packages/core/src/render3/interfaces/container.ts", + "packages/core/src/render3/interfaces/node.ts", + "packages/core/src/render3/interfaces/view.ts" ], [ "packages/core/src/render3/interfaces/container.ts", - "packages/core/src/render3/interfaces/node.ts", "packages/core/src/render3/interfaces/view.ts" ], [ diff --git a/packages/core/src/linker/element_ref.ts b/packages/core/src/linker/element_ref.ts index b3b0821267..eb10908a09 100644 --- a/packages/core/src/linker/element_ref.ts +++ b/packages/core/src/linker/element_ref.ts @@ -6,9 +6,37 @@ * found in the LICENSE file at https://angular.io/license */ -import {injectElementRef as render3InjectElementRef} from '../render3/view_engine_compatibility'; +import {TNode} from '../render3/interfaces/node'; +import {RElement} from '../render3/interfaces/renderer'; +import {LView} from '../render3/interfaces/view'; +import {getCurrentTNode, getLView} from '../render3/state'; +import {getNativeByTNode} from '../render3/util/view_utils'; import {noop} from '../util/noop'; +/** + * Creates an ElementRef from the most recent node. + * + * @returns The ElementRef instance to use + */ +export function injectElementRef(): ElementRef { + return createElementRef(getCurrentTNode()!, getLView()); +} + +/** + * Creates an ElementRef given a node. + * + * @param tNode The node for which you'd like an ElementRef + * @param lView The view to which the node belongs + * @returns The ElementRef instance to use + */ +export function createElementRef(tNode: TNode, lView: LView): ElementRef { + return new ElementRef(getNativeByTNode(tNode, lView) as RElement); +} + +export const SWITCH_ELEMENT_REF_FACTORY__POST_R3__ = injectElementRef; +const SWITCH_ELEMENT_REF_FACTORY__PRE_R3__ = noop; +const SWITCH_ELEMENT_REF_FACTORY: typeof injectElementRef = SWITCH_ELEMENT_REF_FACTORY__PRE_R3__; + /** * A wrapper around a native element inside of a View. * @@ -56,10 +84,5 @@ export class ElementRef { * @internal * @nocollapse */ - static __NG_ELEMENT_ID__: () => ElementRef = () => SWITCH_ELEMENT_REF_FACTORY(ElementRef); + static __NG_ELEMENT_ID__: () => ElementRef = SWITCH_ELEMENT_REF_FACTORY; } - -export const SWITCH_ELEMENT_REF_FACTORY__POST_R3__ = render3InjectElementRef; -const SWITCH_ELEMENT_REF_FACTORY__PRE_R3__ = noop; -const SWITCH_ELEMENT_REF_FACTORY: typeof render3InjectElementRef = - SWITCH_ELEMENT_REF_FACTORY__PRE_R3__; diff --git a/packages/core/src/linker/template_ref.ts b/packages/core/src/linker/template_ref.ts index f027c28455..d1b99d2027 100644 --- a/packages/core/src/linker/template_ref.ts +++ b/packages/core/src/linker/template_ref.ts @@ -60,7 +60,7 @@ export abstract class TemplateRef { * @nocollapse */ static __NG_ELEMENT_ID__: - () => TemplateRef| null = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef) + () => TemplateRef| null = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef) } export const SWITCH_TEMPLATE_REF_FACTORY__POST_R3__ = render3InjectTemplateRef; diff --git a/packages/core/src/linker/view_container_ref.ts b/packages/core/src/linker/view_container_ref.ts index 17bf8f9f83..2985353abc 100644 --- a/packages/core/src/linker/view_container_ref.ts +++ b/packages/core/src/linker/view_container_ref.ts @@ -149,7 +149,7 @@ export abstract class ViewContainerRef { * @nocollapse */ static __NG_ELEMENT_ID__: - () => ViewContainerRef = () => SWITCH_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef, ElementRef) + () => ViewContainerRef = () => SWITCH_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef) } export const SWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__ = render3InjectViewContainerRef; diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index b9980d0176..473a3e83cc 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -13,7 +13,7 @@ import {InjectFlags} from '../di/interface/injector'; import {Type} from '../interface/type'; import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory'; import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver'; -import {ElementRef as viewEngine_ElementRef} from '../linker/element_ref'; +import {createElementRef, ElementRef as viewEngine_ElementRef} from '../linker/element_ref'; import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory'; import {RendererFactory2} from '../render/api'; import {Sanitizer} from '../sanitization/sanitizer'; @@ -35,7 +35,6 @@ import {enterView, leaveView} from './state'; import {setUpAttributes} from './util/attrs_utils'; import {defaultScheduler} from './util/misc_utils'; import {getTNode} from './util/view_utils'; -import {createElementRef} from './view_engine_compatibility'; import {RootViewRef, ViewRef} from './view_ref'; export class ComponentFactoryResolver extends viewEngine_ComponentFactoryResolver { @@ -219,8 +218,8 @@ export class ComponentFactory extends viewEngine_ComponentFactory { } return new ComponentRef( - this.componentType, component, - createElementRef(viewEngine_ElementRef, tElementNode, rootLView), rootLView, tElementNode); + this.componentType, component, createElementRef(tElementNode, rootLView), rootLView, + tElementNode); } } diff --git a/packages/core/src/render3/query.ts b/packages/core/src/render3/query.ts index 14046b0673..695da9ff7b 100644 --- a/packages/core/src/render3/query.ts +++ b/packages/core/src/render3/query.ts @@ -11,7 +11,7 @@ import {InjectionToken} from '../di/injection_token'; import {Type} from '../interface/type'; -import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; +import {createElementRef, ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; import {QueryList} from '../linker/query_list'; import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref'; import {ViewContainerRef} from '../linker/view_container_ref'; @@ -30,7 +30,7 @@ import {DECLARATION_LCONTAINER, LView, PARENT, QUERIES, TVIEW, TView} from './in import {assertTNodeType} from './node_assert'; import {getCurrentQueryIndex, getCurrentTNode, getLView, getTView, setCurrentQueryIndex} from './state'; import {isCreationMode} from './util/view_utils'; -import {createContainerRef, createElementRef, createTemplateRef} from './view_engine_compatibility'; +import {createContainerRef, createTemplateRef} from './view_engine_compatibility'; const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4; @@ -300,9 +300,9 @@ function getIdxOfMatchingSelector(tNode: TNode, selector: string): number|null { function createResultByTNodeType(tNode: TNode, currentView: LView): any { if (tNode.type & (TNodeType.AnyRNode | TNodeType.ElementContainer)) { - return createElementRef(ViewEngine_ElementRef, tNode, currentView); + return createElementRef(tNode, currentView); } else if (tNode.type & TNodeType.Container) { - return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, currentView); + return createTemplateRef(ViewEngine_TemplateRef, tNode, currentView); } return null; } @@ -323,14 +323,13 @@ function createResultForNode(lView: LView, tNode: TNode, matchingIdx: number, re function createSpecialToken(lView: LView, tNode: TNode, read: any): any { if (read === ViewEngine_ElementRef) { - return createElementRef(ViewEngine_ElementRef, tNode, lView); + return createElementRef(tNode, lView); } else if (read === ViewEngine_TemplateRef) { - return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, lView); + return createTemplateRef(ViewEngine_TemplateRef, tNode, lView); } else if (read === ViewContainerRef) { ngDevMode && assertTNodeType(tNode, TNodeType.AnyRNode | TNodeType.AnyContainer); return createContainerRef( - ViewContainerRef, ViewEngine_ElementRef, - tNode as TElementNode | TContainerNode | TElementContainerNode, lView); + ViewContainerRef, tNode as TElementNode | TContainerNode | TElementContainerNode, lView); } else { ngDevMode && throwError( diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index d2616be359..e4c9a60fd9 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -9,7 +9,7 @@ import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref'; import {Injector} from '../di/injector'; import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory'; -import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; +import {createElementRef, ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory'; import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref'; import {ViewContainerRef as ViewEngine_ViewContainerRef} from '../linker/view_container_ref'; @@ -36,35 +36,6 @@ import {ViewRef} from './view_ref'; -/** - * Creates an ElementRef from the most recent node. - * - * @returns The ElementRef instance to use - */ -export function injectElementRef(ElementRefToken: typeof ViewEngine_ElementRef): - ViewEngine_ElementRef { - return createElementRef(ElementRefToken, getCurrentTNode()!, getLView()); -} - -let R3ElementRef: {new (native: RElement|RComment): ViewEngine_ElementRef}; - -/** - * Creates an ElementRef given a node. - * - * @param ElementRefToken The ElementRef type - * @param tNode The node for which you'd like an ElementRef - * @param view The view to which the node belongs - * @returns The ElementRef instance to use - */ -export function createElementRef( - ElementRefToken: typeof ViewEngine_ElementRef, tNode: TNode, - view: LView): ViewEngine_ElementRef { - if (!R3ElementRef) { - R3ElementRef = class ElementRef extends ElementRefToken {}; - } - return new R3ElementRef(getNativeByTNode(tNode, view) as RElement); -} - let R3TemplateRef: { new (_declarationParentView: LView, hostTNode: TContainerNode, elementRef: ViewEngine_ElementRef): ViewEngine_TemplateRef @@ -75,10 +46,9 @@ let R3TemplateRef: { * * @returns The TemplateRef instance to use */ -export function injectTemplateRef( - TemplateRefToken: typeof ViewEngine_TemplateRef, - ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_TemplateRef|null { - return createTemplateRef(TemplateRefToken, ElementRefToken, getCurrentTNode()!, getLView()); +export function injectTemplateRef(TemplateRefToken: typeof ViewEngine_TemplateRef): + ViewEngine_TemplateRef|null { + return createTemplateRef(TemplateRefToken, getCurrentTNode()!, getLView()); } /** @@ -91,8 +61,8 @@ export function injectTemplateRef( * @returns The TemplateRef instance or null if we can't create a TemplateRef on a given node type */ export function createTemplateRef( - TemplateRefToken: typeof ViewEngine_TemplateRef, ElementRefToken: typeof ViewEngine_ElementRef, - hostTNode: TNode, hostView: LView): ViewEngine_TemplateRef|null { + TemplateRefToken: typeof ViewEngine_TemplateRef, hostTNode: TNode, + hostView: LView): ViewEngine_TemplateRef|null { if (!R3TemplateRef) { R3TemplateRef = class TemplateRef extends TemplateRefToken{ constructor( @@ -126,8 +96,7 @@ export function createTemplateRef( if (hostTNode.type & TNodeType.Container) { ngDevMode && assertDefined(hostTNode.tViews, 'TView must be allocated'); return new R3TemplateRef( - hostView, hostTNode as TContainerNode, - createElementRef(ElementRefToken, hostTNode, hostView)); + hostView, hostTNode as TContainerNode, createElementRef(hostTNode, hostView)); } else { return null; } @@ -145,11 +114,10 @@ let R3ViewContainerRef: { * * @returns The ViewContainerRef instance to use */ -export function injectViewContainerRef( - ViewContainerRefToken: typeof ViewEngine_ViewContainerRef, - ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_ViewContainerRef { +export function injectViewContainerRef(ViewContainerRefToken: typeof ViewEngine_ViewContainerRef): + ViewEngine_ViewContainerRef { const previousTNode = getCurrentTNode() as TElementNode | TElementContainerNode | TContainerNode; - return createContainerRef(ViewContainerRefToken, ElementRefToken, previousTNode, getLView()); + return createContainerRef(ViewContainerRefToken, previousTNode, getLView()); } /** @@ -163,7 +131,6 @@ export function injectViewContainerRef( */ export function createContainerRef( ViewContainerRefToken: typeof ViewEngine_ViewContainerRef, - ElementRefToken: typeof ViewEngine_ElementRef, hostTNode: TElementNode|TContainerNode|TElementContainerNode, hostView: LView): ViewEngine_ViewContainerRef { if (!R3ViewContainerRef) { @@ -176,7 +143,7 @@ export function createContainerRef( } get element(): ViewEngine_ElementRef { - return createElementRef(ElementRefToken, this._hostTNode, this._hostView); + return createElementRef(this._hostTNode, this._hostView); } get injector(): Injector { diff --git a/packages/core/src/render3/view_engine_compatibility_prebound.ts b/packages/core/src/render3/view_engine_compatibility_prebound.ts index ebdec19b6b..1234835af9 100644 --- a/packages/core/src/render3/view_engine_compatibility_prebound.ts +++ b/packages/core/src/render3/view_engine_compatibility_prebound.ts @@ -9,16 +9,13 @@ import {ChangeDetectorRef} from '../change_detection/change_detector_ref'; import {InjectFlags} from '../di/interface/injector'; -import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref'; import {throwProviderNotFoundError} from './errors'; - import {TNode} from './interfaces/node'; import {LView} from './interfaces/view'; import {createTemplateRef, injectChangeDetectorRef} from './view_engine_compatibility'; - /** * Retrieves `TemplateRef` instance from `Injector` when a local reference is placed on the * `` element. @@ -26,7 +23,7 @@ import {createTemplateRef, injectChangeDetectorRef} from './view_engine_compatib * @codeGenApi */ export function ɵɵtemplateRefExtractor(tNode: TNode, currentView: LView) { - return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, currentView); + return createTemplateRef(ViewEngine_TemplateRef, tNode, currentView); } diff --git a/packages/core/test/render3/perf/ng_template/index.ts b/packages/core/test/render3/perf/ng_template/index.ts index 50adf84370..eaedacf8a7 100644 --- a/packages/core/test/render3/perf/ng_template/index.ts +++ b/packages/core/test/render3/perf/ng_template/index.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {ElementRef, TemplateRef, ViewContainerRef} from '../../../../src/linker'; +import {TemplateRef, ViewContainerRef} from '../../../../src/linker'; import {ɵɵdefineDirective, ɵɵdirectiveInject, ɵɵtemplate} from '../../../../src/render3/index'; import {createLView, createTNode, createTView} from '../../../../src/render3/instructions/shared'; import {RenderFlags} from '../../../../src/render3/interfaces/definition'; @@ -21,7 +21,7 @@ class TemplateRefToken { * @nocollapse */ static __NG_ELEMENT_ID__(): TemplateRef|null { - return injectTemplateRef(TemplateRef, ElementRef); + return injectTemplateRef(TemplateRef); } } class ViewContainerRefToken { @@ -30,7 +30,7 @@ class ViewContainerRefToken { * @nocollapse */ static __NG_ELEMENT_ID__(): ViewContainerRef { - return injectViewContainerRef(ViewContainerRef, ElementRef); + return injectViewContainerRef(ViewContainerRef); } } diff --git a/packages/core/test/render3/render_util.ts b/packages/core/test/render3/render_util.ts index 4f44afc48b..bb6c0f0533 100644 --- a/packages/core/test/render3/render_util.ts +++ b/packages/core/test/render3/render_util.ts @@ -32,7 +32,7 @@ import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveT import {DirectiveDefList, DirectiveDefListOrFactory, DirectiveTypesOrFactory, HostBindingsFunction, PipeDef, PipeDefList, PipeDefListOrFactory, PipeTypesOrFactory} from '../../src/render3/interfaces/definition'; import {PlayerHandler} from '../../src/render3/interfaces/player'; import {domRendererFactory3, ProceduralRenderer3, RComment, RElement, Renderer3, RendererFactory3, RendererStyleFlags3, RNode, RText} from '../../src/render3/interfaces/renderer'; -import {HEADER_OFFSET, LView, LViewFlags, TVIEW, TViewType} from '../../src/render3/interfaces/view'; +import {LView, LViewFlags, TVIEW, TViewType} from '../../src/render3/interfaces/view'; import {destroyLView} from '../../src/render3/node_manipulation'; import {getRootView} from '../../src/render3/util/view_traversal_utils'; import {Sanitizer} from '../../src/sanitization/sanitizer'; @@ -452,10 +452,9 @@ export const text: RText = null as any as Text; * like injectElementRef() prematurely. */ export function enableIvyInjectableFactories() { - (ElementRef as any)[NG_ELEMENT_ID] = () => R3_ELEMENT_REF_FACTORY(ElementRef); - (TemplateRef as any)[NG_ELEMENT_ID] = () => R3_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef); - (ViewContainerRef as any)[NG_ELEMENT_ID] = () => - R3_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef, ElementRef); + (ElementRef as any)[NG_ELEMENT_ID] = () => R3_ELEMENT_REF_FACTORY(); + (TemplateRef as any)[NG_ELEMENT_ID] = () => R3_TEMPLATE_REF_FACTORY(TemplateRef); + (ViewContainerRef as any)[NG_ELEMENT_ID] = () => R3_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef); (ChangeDetectorRef as any)[NG_ELEMENT_ID] = () => R3_CHANGE_DETECTOR_REF_FACTORY(); (Renderer2 as any)[NG_ELEMENT_ID] = () => R3_RENDERER2_FACTORY(); }