From 739d745eb5a9338e30a2ca90b22650aac191368f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 9 Nov 2020 19:57:47 -0800 Subject: [PATCH] refactor(core): Cleanup circular dependency between ViewEngine and Ivy `ViewContainerRef`. (#39621) `ViewContainerRef` is declared in ViewEngine but it sub-classed in Ivy. This creates a circular dependency between ViewEngine `ViewContainerRef` which needs to declare `__NG_ELEMENT_ID__` and ivy factory which needs to create it. The workaround used to be to pass the `ViewContainerRef` 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 | 325 +++++++++--------- .../core/src/linker/view_container_ref.ts | 283 ++++++++++++++- packages/core/src/render3/query.ts | 6 +- .../src/render3/view_engine_compatibility.ts | 290 +--------------- .../bundling/forms/bundle.golden_symbols.json | 6 + .../router/bundle.golden_symbols.json | 6 + .../bundling/todo/bundle.golden_symbols.json | 6 + .../test/render3/perf/ng_template/index.ts | 5 +- packages/core/test/render3/render_util.ts | 2 +- 9 files changed, 460 insertions(+), 469 deletions(-) diff --git a/goldens/circular-deps/packages.json b/goldens/circular-deps/packages.json index 8a2bd85151..0046c2aa6d 100644 --- a/goldens/circular-deps/packages.json +++ b/goldens/circular-deps/packages.json @@ -147,19 +147,6 @@ "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/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/di/injector.ts", @@ -174,7 +161,6 @@ "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", @@ -196,7 +182,6 @@ "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", @@ -209,7 +194,6 @@ "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", @@ -233,7 +217,6 @@ "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", @@ -246,6 +229,124 @@ "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/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/render3/view_ref.ts", + "packages/core/src/linker/view_container_ref.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/di.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/di.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/di.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/instructions/shared.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/instructions/shared.ts", + "packages/core/src/error_handler.ts", + "packages/core/src/errors.ts", + "packages/core/src/view/types.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/instructions/shared.ts", + "packages/core/src/error_handler.ts", + "packages/core/src/errors.ts", + "packages/core/src/view/types.ts", "packages/core/src/linker/ng_module_factory.ts", "packages/core/src/di/injector.ts", "packages/core/src/di/r3_injector.ts", @@ -259,6 +360,12 @@ "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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/instructions/shared.ts", + "packages/core/src/error_handler.ts", + "packages/core/src/errors.ts", + "packages/core/src/view/types.ts", "packages/core/src/linker/ng_module_factory.ts", "packages/core/src/linker/component_factory_resolver.ts", "packages/core/src/di/injector.ts", @@ -273,68 +380,8 @@ "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/render3/instructions/shared.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/template_ref.ts", - "packages/core/src/render3/instructions/shared.ts", - "packages/core/src/error_handler.ts", - "packages/core/src/errors.ts", - "packages/core/src/view/types.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/template_ref.ts", - "packages/core/src/render3/instructions/shared.ts", - "packages/core/src/error_handler.ts", - "packages/core/src/errors.ts", - "packages/core/src/view/types.ts", + "packages/core/src/render3/view_ref.ts", "packages/core/src/linker/view_container_ref.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/template_ref.ts", "packages/core/src/render3/instructions/shared.ts", "packages/core/src/render3/definition.ts", "packages/core/src/metadata/ng_module.ts" @@ -346,51 +393,8 @@ "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/render3/instructions/shared.ts", - "packages/core/src/render3/di.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/template_ref.ts", - "packages/core/src/render3/instructions/shared.ts", - "packages/core/src/render3/di.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/template_ref.ts", - "packages/core/src/render3/instructions/shared.ts", - "packages/core/src/render3/di.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/template_ref.ts", + "packages/core/src/render3/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", "packages/core/src/render3/instructions/shared.ts", "packages/core/src/render3/instructions/lview_debug.ts", "packages/core/src/core.ts", @@ -406,16 +410,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/render3/view_ref.ts" - ], [ "packages/core/src/application_ref.ts", "packages/core/src/application_tokens.ts", @@ -851,39 +845,36 @@ "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/view_ref.ts", + "packages/core/src/linker/view_container_ref.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/instructions/shared.ts", + "packages/core/src/error_handler.ts", + "packages/core/src/errors.ts", + "packages/core/src/view/types.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/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/instructions/shared.ts", + "packages/core/src/error_handler.ts", + "packages/core/src/errors.ts", + "packages/core/src/view/types.ts", "packages/core/src/linker/ng_module_factory.ts", "packages/core/src/linker/component_factory_resolver.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/render3/instructions/shared.ts", - "packages/core/src/error_handler.ts", - "packages/core/src/errors.ts", - "packages/core/src/view/types.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/render3/instructions/shared.ts", - "packages/core/src/error_handler.ts", - "packages/core/src/errors.ts", - "packages/core/src/view/types.ts", - "packages/core/src/linker/view_container_ref.ts", - "packages/core/src/linker/component_factory.ts" - ], [ "packages/core/src/change_detection/change_detector_ref.ts", "packages/core/src/render3/view_engine_compatibility.ts" @@ -891,7 +882,6 @@ [ "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", @@ -900,7 +890,6 @@ [ "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/render3/view_ref.ts" ], [ @@ -962,8 +951,9 @@ "packages/core/src/error_handler.ts", "packages/core/src/errors.ts", "packages/core/src/view/types.ts", - "packages/core/src/linker/view_container_ref.ts", "packages/core/src/linker/template_ref.ts", + "packages/core/src/render3/view_ref.ts", + "packages/core/src/linker/view_container_ref.ts", "packages/core/src/render3/instructions/shared.ts" ], [ @@ -971,25 +961,20 @@ "packages/core/src/errors.ts", "packages/core/src/view/types.ts", "packages/core/src/linker/view_container_ref.ts", - "packages/core/src/render3/view_engine_compatibility.ts", - "packages/core/src/linker/template_ref.ts", "packages/core/src/render3/instructions/shared.ts" ], [ "packages/core/src/linker/component_factory_resolver.ts", "packages/core/src/linker/ng_module_factory.ts" ], - [ - "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" - ], [ "packages/core/src/linker/ng_module_factory_registration.ts", "packages/core/src/render3/ng_module_ref.ts" ], + [ + "packages/core/src/linker/view_container_ref.ts", + "packages/core/src/render3/view_ref.ts" + ], [ "packages/core/src/metadata/directives.ts", "packages/core/src/render3/jit/directive.ts" @@ -1008,6 +993,10 @@ "packages/core/src/metadata/directives.ts", "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", diff --git a/packages/core/src/linker/view_container_ref.ts b/packages/core/src/linker/view_container_ref.ts index 2985353abc..bec0e00e8d 100644 --- a/packages/core/src/linker/view_container_ref.ts +++ b/packages/core/src/linker/view_container_ref.ts @@ -7,16 +7,36 @@ */ import {Injector} from '../di/injector'; -import {injectViewContainerRef as render3InjectViewContainerRef} from '../render3/view_engine_compatibility'; +import {assertNodeInjector} from '../render3/assert'; +import {getParentInjectorLocation, NodeInjector} from '../render3/di'; +import {addToViewTree, createLContainer, createTNode} from '../render3/instructions/shared'; +import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE, VIEW_REFS} from '../render3/interfaces/container'; +import {NodeInjectorOffset} from '../render3/interfaces/injector'; +import {TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNodeType} from '../render3/interfaces/node'; +import {RComment, RElement} from '../render3/interfaces/renderer'; +import {isLContainer, isRootView} from '../render3/interfaces/type_checks'; +import {LView, PARENT, RENDERER, T_HOST, TVIEW} from '../render3/interfaces/view'; +import {assertTNodeType} from '../render3/node_assert'; +import {addViewToContainer, appendChild, destroyLView, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode} from '../render3/node_manipulation'; +import {getCurrentTNode, getLView} from '../render3/state'; +import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from '../render3/util/injector_utils'; +import {getNativeByTNode, unwrapRNode, viewAttachedToContainer} from '../render3/util/view_utils'; +import {ViewRef as R3ViewRef} from '../render3/view_ref'; +import {addToArray, removeFromArray} from '../util/array_utils'; +import {assertEqual, assertGreaterThan, assertLessThan} from '../util/assert'; import {noop} from '../util/noop'; - import {ComponentFactory, ComponentRef} from './component_factory'; -import {ElementRef} from './element_ref'; +import {createElementRef, ElementRef} from './element_ref'; import {NgModuleRef} from './ng_module_factory'; import {TemplateRef} from './template_ref'; import {EmbeddedViewRef, ViewRef} from './view_ref'; +export const SWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__ = injectViewContainerRef; +const SWITCH_VIEW_CONTAINER_REF_FACTORY__PRE_R3__ = noop as typeof injectViewContainerRef; +const SWITCH_VIEW_CONTAINER_REF_FACTORY: typeof injectViewContainerRef = + SWITCH_VIEW_CONTAINER_REF_FACTORY__PRE_R3__; + /** * Represents a container where one or more views can be attached to a component. * @@ -148,11 +168,256 @@ export abstract class ViewContainerRef { * @internal * @nocollapse */ - static __NG_ELEMENT_ID__: - () => ViewContainerRef = () => SWITCH_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef) + static __NG_ELEMENT_ID__: () => ViewContainerRef = SWITCH_VIEW_CONTAINER_REF_FACTORY; } -export const SWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__ = render3InjectViewContainerRef; -const SWITCH_VIEW_CONTAINER_REF_FACTORY__PRE_R3__ = noop; -const SWITCH_VIEW_CONTAINER_REF_FACTORY: typeof render3InjectViewContainerRef = - SWITCH_VIEW_CONTAINER_REF_FACTORY__PRE_R3__; +/** + * Creates a ViewContainerRef and stores it on the injector. Or, if the ViewContainerRef + * already exists, retrieves the existing ViewContainerRef. + * + * @returns The ViewContainerRef instance to use + */ +export function injectViewContainerRef(): ViewContainerRef { + const previousTNode = getCurrentTNode() as TElementNode | TElementContainerNode | TContainerNode; + return createContainerRef(previousTNode, getLView()); +} + +const VE_ViewContainerRef = ViewContainerRef; + +const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef { + constructor( + private _lContainer: LContainer, + private _hostTNode: TElementNode|TContainerNode|TElementContainerNode, + private _hostLView: LView) { + super(); + } + + get element(): ElementRef { + return createElementRef(this._hostTNode, this._hostLView); + } + + get injector(): Injector { + return new NodeInjector(this._hostTNode, this._hostLView); + } + + /** @deprecated No replacement */ + get parentInjector(): Injector { + const parentLocation = getParentInjectorLocation(this._hostTNode, this._hostLView); + if (hasParentInjector(parentLocation)) { + const parentView = getParentInjectorView(parentLocation, this._hostLView); + const injectorIndex = getParentInjectorIndex(parentLocation); + ngDevMode && assertNodeInjector(parentView, injectorIndex); + const parentTNode = + parentView[TVIEW].data[injectorIndex + NodeInjectorOffset.TNODE] as TElementNode; + return new NodeInjector(parentTNode, parentView); + } else { + return new NodeInjector(null, this._hostLView); + } + } + + clear(): void { + while (this.length > 0) { + this.remove(this.length - 1); + } + } + + get(index: number): ViewRef|null { + return this._lContainer[VIEW_REFS] !== null && this._lContainer[VIEW_REFS]![index] || null; + } + + get length(): number { + return this._lContainer.length - CONTAINER_HEADER_OFFSET; + } + + createEmbeddedView(templateRef: TemplateRef, context?: C, index?: number): + EmbeddedViewRef { + const viewRef = templateRef.createEmbeddedView(context || {}); + this.insert(viewRef, index); + return viewRef; + } + + createComponent( + componentFactory: ComponentFactory, index?: number|undefined, + injector?: Injector|undefined, projectableNodes?: any[][]|undefined, + ngModuleRef?: NgModuleRef|undefined): ComponentRef { + const contextInjector = injector || this.parentInjector; + if (!ngModuleRef && (componentFactory as any).ngModule == null && contextInjector) { + // DO NOT REFACTOR. The code here used to have a `value || undefined` expression + // which seems to cause internal google apps to fail. This is documented in the + // following internal bug issue: go/b/142967802 + const result = contextInjector.get(NgModuleRef, null); + if (result) { + ngModuleRef = result; + } + } + + const componentRef = + componentFactory.create(contextInjector, projectableNodes, undefined, ngModuleRef); + this.insert(componentRef.hostView, index); + return componentRef; + } + + insert(viewRef: ViewRef, index?: number): ViewRef { + const lView = (viewRef as R3ViewRef)._lView!; + const tView = lView[TVIEW]; + + if (ngDevMode && viewRef.destroyed) { + throw new Error('Cannot insert a destroyed View in a ViewContainer!'); + } + + this.allocateContainerIfNeeded(); + + if (viewAttachedToContainer(lView)) { + // If view is already attached, detach it first so we clean up references appropriately. + + const prevIdx = this.indexOf(viewRef); + + // A view might be attached either to this or a different container. The `prevIdx` for + // those cases will be: + // equal to -1 for views attached to this ViewContainerRef + // >= 0 for views attached to a different ViewContainerRef + if (prevIdx !== -1) { + this.detach(prevIdx); + } else { + const prevLContainer = lView[PARENT] as LContainer; + ngDevMode && + assertEqual( + isLContainer(prevLContainer), true, + 'An attached view should have its PARENT point to a container.'); + + + // We need to re-create a R3ViewContainerRef instance since those are not stored on + // LView (nor anywhere else). + const prevVCRef = new R3ViewContainerRef( + prevLContainer, prevLContainer[T_HOST] as TDirectiveHostNode, prevLContainer[PARENT]); + + prevVCRef.detach(prevVCRef.indexOf(viewRef)); + } + } + + // Logical operation of adding `LView` to `LContainer` + const adjustedIdx = this._adjustIndex(index); + const lContainer = this._lContainer; + insertView(tView, lView, lContainer, adjustedIdx); + + // Physical operation of adding the DOM nodes. + const beforeNode = getBeforeNodeForView(adjustedIdx, lContainer); + const renderer = lView[RENDERER]; + const parentRNode = nativeParentNode(renderer, lContainer[NATIVE] as RElement | RComment); + if (parentRNode !== null) { + addViewToContainer(tView, lContainer[T_HOST], renderer, lView, parentRNode, beforeNode); + } + + (viewRef as R3ViewRef).attachToViewContainerRef(this); + addToArray(lContainer[VIEW_REFS]!, adjustedIdx, viewRef); + + return viewRef; + } + + move(viewRef: ViewRef, newIndex: number): ViewRef { + if (ngDevMode && viewRef.destroyed) { + throw new Error('Cannot move a destroyed View in a ViewContainer!'); + } + return this.insert(viewRef, newIndex); + } + + indexOf(viewRef: ViewRef): number { + const viewRefsArr = this._lContainer[VIEW_REFS]; + return viewRefsArr !== null ? viewRefsArr.indexOf(viewRef) : -1; + } + + remove(index?: number): void { + this.allocateContainerIfNeeded(); + const adjustedIdx = this._adjustIndex(index, -1); + const detachedView = detachView(this._lContainer, adjustedIdx); + + if (detachedView) { + // Before destroying the view, remove it from the container's array of `ViewRef`s. + // This ensures the view container length is updated before calling + // `destroyLView`, which could recursively call view container methods that + // rely on an accurate container length. + // (e.g. a method on this view container being called by a child directive's OnDestroy + // lifecycle hook) + removeFromArray(this._lContainer[VIEW_REFS]!, adjustedIdx); + destroyLView(detachedView[TVIEW], detachedView); + } + } + + detach(index?: number): ViewRef|null { + this.allocateContainerIfNeeded(); + const adjustedIdx = this._adjustIndex(index, -1); + const view = detachView(this._lContainer, adjustedIdx); + + const wasDetached = view && removeFromArray(this._lContainer[VIEW_REFS]!, adjustedIdx) != null; + return wasDetached ? new R3ViewRef(view!) : null; + } + + private _adjustIndex(index?: number, shift: number = 0) { + if (index == null) { + return this.length + shift; + } + if (ngDevMode) { + assertGreaterThan(index, -1, `ViewRef index must be positive, got ${index}`); + // +1 because it's legal to insert at the end. + assertLessThan(index, this.length + 1 + shift, 'index'); + } + return index; + } + + private allocateContainerIfNeeded(): void { + if (this._lContainer[VIEW_REFS] === null) { + this._lContainer[VIEW_REFS] = []; + } + } +}; + +/** + * Creates a ViewContainerRef and stores it on the injector. + * + * @param ViewContainerRefToken The ViewContainerRef type + * @param ElementRefToken The ElementRef type + * @param hostTNode The node that is requesting a ViewContainerRef + * @param hostLView The view to which the node belongs + * @returns The ViewContainerRef instance to use + */ +export function createContainerRef( + hostTNode: TElementNode|TContainerNode|TElementContainerNode, + hostLView: LView): ViewContainerRef { + ngDevMode && assertTNodeType(hostTNode, TNodeType.AnyContainer | TNodeType.AnyRNode); + + let lContainer: LContainer; + const slotValue = hostLView[hostTNode.index]; + if (isLContainer(slotValue)) { + // If the host is a container, we don't need to create a new LContainer + lContainer = slotValue; + } else { + let commentNode: RComment; + // If the host is an element container, the native host element is guaranteed to be a + // comment and we can reuse that comment as anchor element for the new LContainer. + // The comment node in question is already part of the DOM structure so we don't need to append + // it again. + if (hostTNode.type & TNodeType.ElementContainer) { + commentNode = unwrapRNode(slotValue) as RComment; + } else { + // If the host is a regular element, we have to insert a comment node manually which will + // be used as an anchor when inserting elements. In this specific case we use low-level DOM + // manipulation to insert it. + const renderer = hostLView[RENDERER]; + ngDevMode && ngDevMode.rendererCreateComment++; + commentNode = renderer.createComment(ngDevMode ? 'container' : ''); + + const hostNative = getNativeByTNode(hostTNode, hostLView)!; + const parentOfHostNative = nativeParentNode(renderer, hostNative); + nativeInsertBefore( + renderer, parentOfHostNative!, commentNode, nativeNextSibling(renderer, hostNative), + false); + } + + hostLView[hostTNode.index] = lContainer = + createLContainer(slotValue, hostLView, commentNode, hostTNode); + + addToViewTree(hostLView, lContainer); + } + + return new R3ViewContainerRef(lContainer, hostTNode, hostLView); +} diff --git a/packages/core/src/render3/query.ts b/packages/core/src/render3/query.ts index 1fc9972621..89fa943ec3 100644 --- a/packages/core/src/render3/query.ts +++ b/packages/core/src/render3/query.ts @@ -14,10 +14,9 @@ import {Type} from '../interface/type'; import {createElementRef, ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; import {QueryList} from '../linker/query_list'; import {createTemplateRef, TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref'; -import {ViewContainerRef} from '../linker/view_container_ref'; +import {createContainerRef, ViewContainerRef} from '../linker/view_container_ref'; import {assertDefined, assertIndexInRange, throwError} from '../util/assert'; import {stringify} from '../util/stringify'; - import {assertFirstCreatePass, assertLContainer} from './assert'; import {getNodeInjectable, locateDirectiveOrProvider} from './di'; import {storeCleanupWithContext} from './instructions/shared'; @@ -30,7 +29,6 @@ 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} from './view_engine_compatibility'; const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4; @@ -329,7 +327,7 @@ function createSpecialToken(lView: LView, tNode: TNode, read: any): any { } else if (read === ViewContainerRef) { ngDevMode && assertTNodeType(tNode, TNodeType.AnyRNode | TNodeType.AnyContainer); return createContainerRef( - ViewContainerRef, tNode as TElementNode | TContainerNode | TElementContainerNode, lView); + 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 0ff6730a29..85eb4a7f3a 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -7,297 +7,17 @@ */ 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 {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'; -import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_ViewRef} from '../linker/view_ref'; import {Renderer2} from '../render/api'; -import {addToArray, removeFromArray} from '../util/array_utils'; -import {assertEqual, assertGreaterThan, assertLessThan} from '../util/assert'; - -import {assertNodeInjector} from './assert'; -import {getParentInjectorLocation, NodeInjector} from './di'; -import {addToViewTree, createLContainer} from './instructions/shared'; -import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE, VIEW_REFS} from './interfaces/container'; -import {NodeInjectorOffset} from './interfaces/injector'; -import {TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node'; -import {isProceduralRenderer, RComment, RElement} from './interfaces/renderer'; -import {isComponentHost, isLContainer, isLView} from './interfaces/type_checks'; -import {DECLARATION_COMPONENT_VIEW, LView, PARENT, RENDERER, T_HOST, TVIEW} from './interfaces/view'; -import {assertTNodeType} from './node_assert'; -import {addViewToContainer, destroyLView, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode} from './node_manipulation'; +import {TNode, TNodeType} from './interfaces/node'; +import {isProceduralRenderer} from './interfaces/renderer'; +import {isComponentHost, isLView} from './interfaces/type_checks'; +import {DECLARATION_COMPONENT_VIEW, LView, RENDERER} from './interfaces/view'; import {getCurrentTNode, getLView} from './state'; -import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './util/injector_utils'; -import {getComponentLViewByIndex, getNativeByTNode, unwrapRNode, viewAttachedToContainer} from './util/view_utils'; +import {getComponentLViewByIndex} from './util/view_utils'; import {ViewRef} from './view_ref'; -let R3ViewContainerRef: { - new ( - lContainer: LContainer, hostTNode: TElementNode|TContainerNode|TElementContainerNode, - hostView: LView): ViewEngine_ViewContainerRef -}; - -/** - * Creates a ViewContainerRef and stores it on the injector. Or, if the ViewContainerRef - * already exists, retrieves the existing ViewContainerRef. - * - * @returns The ViewContainerRef instance to use - */ -export function injectViewContainerRef(ViewContainerRefToken: typeof ViewEngine_ViewContainerRef): - ViewEngine_ViewContainerRef { - const previousTNode = getCurrentTNode() as TElementNode | TElementContainerNode | TContainerNode; - return createContainerRef(ViewContainerRefToken, previousTNode, getLView()); -} - -/** - * Creates a ViewContainerRef and stores it on the injector. - * - * @param ViewContainerRefToken The ViewContainerRef type - * @param ElementRefToken The ElementRef type - * @param hostTNode The node that is requesting a ViewContainerRef - * @param hostView The view to which the node belongs - * @returns The ViewContainerRef instance to use - */ -export function createContainerRef( - ViewContainerRefToken: typeof ViewEngine_ViewContainerRef, - hostTNode: TElementNode|TContainerNode|TElementContainerNode, - hostView: LView): ViewEngine_ViewContainerRef { - if (!R3ViewContainerRef) { - R3ViewContainerRef = class ViewContainerRef extends ViewContainerRefToken { - constructor( - private _lContainer: LContainer, - private _hostTNode: TElementNode|TContainerNode|TElementContainerNode, - private _hostView: LView) { - super(); - } - - get element(): ViewEngine_ElementRef { - return createElementRef(this._hostTNode, this._hostView); - } - - get injector(): Injector { - return new NodeInjector(this._hostTNode, this._hostView); - } - - /** @deprecated No replacement */ - get parentInjector(): Injector { - const parentLocation = getParentInjectorLocation(this._hostTNode, this._hostView); - if (hasParentInjector(parentLocation)) { - const parentView = getParentInjectorView(parentLocation, this._hostView); - const injectorIndex = getParentInjectorIndex(parentLocation); - ngDevMode && assertNodeInjector(parentView, injectorIndex); - const parentTNode = - parentView[TVIEW].data[injectorIndex + NodeInjectorOffset.TNODE] as TElementNode; - return new NodeInjector(parentTNode, parentView); - } else { - return new NodeInjector(null, this._hostView); - } - } - - clear(): void { - while (this.length > 0) { - this.remove(this.length - 1); - } - } - - get(index: number): viewEngine_ViewRef|null { - return this._lContainer[VIEW_REFS] !== null && this._lContainer[VIEW_REFS]![index] || null; - } - - get length(): number { - return this._lContainer.length - CONTAINER_HEADER_OFFSET; - } - - createEmbeddedView(templateRef: ViewEngine_TemplateRef, context?: C, index?: number): - viewEngine_EmbeddedViewRef { - const viewRef = templateRef.createEmbeddedView(context || {}); - this.insert(viewRef, index); - return viewRef; - } - - createComponent( - componentFactory: viewEngine_ComponentFactory, index?: number|undefined, - injector?: Injector|undefined, projectableNodes?: any[][]|undefined, - ngModuleRef?: viewEngine_NgModuleRef|undefined): viewEngine_ComponentRef { - const contextInjector = injector || this.parentInjector; - if (!ngModuleRef && (componentFactory as any).ngModule == null && contextInjector) { - // DO NOT REFACTOR. The code here used to have a `value || undefined` expression - // which seems to cause internal google apps to fail. This is documented in the - // following internal bug issue: go/b/142967802 - const result = contextInjector.get(viewEngine_NgModuleRef, null); - if (result) { - ngModuleRef = result; - } - } - - const componentRef = - componentFactory.create(contextInjector, projectableNodes, undefined, ngModuleRef); - this.insert(componentRef.hostView, index); - return componentRef; - } - - insert(viewRef: viewEngine_ViewRef, index?: number): viewEngine_ViewRef { - const lView = (viewRef as ViewRef)._lView!; - const tView = lView[TVIEW]; - - if (viewRef.destroyed) { - throw new Error('Cannot insert a destroyed View in a ViewContainer!'); - } - - this.allocateContainerIfNeeded(); - - if (viewAttachedToContainer(lView)) { - // If view is already attached, detach it first so we clean up references appropriately. - - const prevIdx = this.indexOf(viewRef); - - // A view might be attached either to this or a different container. The `prevIdx` for - // those cases will be: - // equal to -1 for views attached to this ViewContainerRef - // >= 0 for views attached to a different ViewContainerRef - if (prevIdx !== -1) { - this.detach(prevIdx); - } else { - const prevLContainer = lView[PARENT] as LContainer; - ngDevMode && - assertEqual( - isLContainer(prevLContainer), true, - 'An attached view should have its PARENT point to a container.'); - - - // We need to re-create a R3ViewContainerRef instance since those are not stored on - // LView (nor anywhere else). - const prevVCRef = new R3ViewContainerRef( - prevLContainer, prevLContainer[T_HOST] as TDirectiveHostNode, - prevLContainer[PARENT]); - - prevVCRef.detach(prevVCRef.indexOf(viewRef)); - } - } - - // Logical operation of adding `LView` to `LContainer` - const adjustedIdx = this._adjustIndex(index); - const lContainer = this._lContainer; - insertView(tView, lView, lContainer, adjustedIdx); - - // Physical operation of adding the DOM nodes. - const beforeNode = getBeforeNodeForView(adjustedIdx, lContainer); - const renderer = lView[RENDERER]; - const parentRNode = nativeParentNode(renderer, lContainer[NATIVE] as RElement | RComment); - if (parentRNode !== null) { - addViewToContainer(tView, lContainer[T_HOST], renderer, lView, parentRNode, beforeNode); - } - - (viewRef as ViewRef).attachToViewContainerRef(this); - addToArray(lContainer[VIEW_REFS]!, adjustedIdx, viewRef); - - return viewRef; - } - - move(viewRef: viewEngine_ViewRef, newIndex: number): viewEngine_ViewRef { - if (viewRef.destroyed) { - throw new Error('Cannot move a destroyed View in a ViewContainer!'); - } - return this.insert(viewRef, newIndex); - } - - indexOf(viewRef: viewEngine_ViewRef): number { - const viewRefsArr = this._lContainer[VIEW_REFS]; - return viewRefsArr !== null ? viewRefsArr.indexOf(viewRef) : -1; - } - - remove(index?: number): void { - this.allocateContainerIfNeeded(); - const adjustedIdx = this._adjustIndex(index, -1); - const detachedView = detachView(this._lContainer, adjustedIdx); - - if (detachedView) { - // Before destroying the view, remove it from the container's array of `ViewRef`s. - // This ensures the view container length is updated before calling - // `destroyLView`, which could recursively call view container methods that - // rely on an accurate container length. - // (e.g. a method on this view container being called by a child directive's OnDestroy - // lifecycle hook) - removeFromArray(this._lContainer[VIEW_REFS]!, adjustedIdx); - destroyLView(detachedView[TVIEW], detachedView); - } - } - - detach(index?: number): viewEngine_ViewRef|null { - this.allocateContainerIfNeeded(); - const adjustedIdx = this._adjustIndex(index, -1); - const view = detachView(this._lContainer, adjustedIdx); - - const wasDetached = - view && removeFromArray(this._lContainer[VIEW_REFS]!, adjustedIdx) != null; - return wasDetached ? new ViewRef(view!) : null; - } - - private _adjustIndex(index?: number, shift: number = 0) { - if (index == null) { - return this.length + shift; - } - if (ngDevMode) { - assertGreaterThan(index, -1, `ViewRef index must be positive, got ${index}`); - // +1 because it's legal to insert at the end. - assertLessThan(index, this.length + 1 + shift, 'index'); - } - return index; - } - - private allocateContainerIfNeeded(): void { - if (this._lContainer[VIEW_REFS] === null) { - this._lContainer[VIEW_REFS] = []; - } - } - }; - } - - ngDevMode && assertTNodeType(hostTNode, TNodeType.AnyContainer | TNodeType.AnyRNode); - - let lContainer: LContainer; - const slotValue = hostView[hostTNode.index]; - if (isLContainer(slotValue)) { - // If the host is a container, we don't need to create a new LContainer - lContainer = slotValue; - } else { - let commentNode: RComment; - // If the host is an element container, the native host element is guaranteed to be a - // comment and we can reuse that comment as anchor element for the new LContainer. - // The comment node in question is already part of the DOM structure so we don't need to append - // it again. - if (hostTNode.type & TNodeType.ElementContainer) { - commentNode = unwrapRNode(slotValue) as RComment; - } else { - // If the host is a regular element, we have to insert a comment node manually which will - // be used as an anchor when inserting elements. In this specific case we use low-level DOM - // manipulation to insert it. - const renderer = hostView[RENDERER]; - ngDevMode && ngDevMode.rendererCreateComment++; - commentNode = renderer.createComment(ngDevMode ? 'container' : ''); - - const hostNative = getNativeByTNode(hostTNode, hostView)!; - const parentOfHostNative = nativeParentNode(renderer, hostNative); - nativeInsertBefore( - renderer, parentOfHostNative!, commentNode, nativeNextSibling(renderer, hostNative), - false); - } - - hostView[hostTNode.index] = lContainer = - createLContainer(slotValue, hostView, commentNode, hostTNode); - - addToViewTree(hostView, lContainer); - } - - return new R3ViewContainerRef(lContainer, hostTNode, hostView); -} - - /** Returns a ChangeDetectorRef (a.k.a. a ViewRef) */ export function injectChangeDetectorRef(isPipe = false): ViewEngine_ChangeDetectorRef { return createViewRef(getCurrentTNode()!, getLView(), isPipe); diff --git a/packages/core/test/bundling/forms/bundle.golden_symbols.json b/packages/core/test/bundling/forms/bundle.golden_symbols.json index f9138b4ed2..6325a87e2c 100644 --- a/packages/core/test/bundling/forms/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms/bundle.golden_symbols.json @@ -470,6 +470,9 @@ { "name": "R3TemplateRef" }, + { + "name": "R3ViewContainerRef" + }, { "name": "RADIO_VALUE_ACCESSOR" }, @@ -626,6 +629,9 @@ { "name": "ViewEngineTemplateRef" }, + { + "name": "VE_ViewContainerRef" + }, { "name": "Validators" }, diff --git a/packages/core/test/bundling/router/bundle.golden_symbols.json b/packages/core/test/bundling/router/bundle.golden_symbols.json index 6ca5181716..c00bdbf7b8 100644 --- a/packages/core/test/bundling/router/bundle.golden_symbols.json +++ b/packages/core/test/bundling/router/bundle.golden_symbols.json @@ -575,6 +575,9 @@ { "name": "R3TemplateRef" }, + { + "name": "R3ViewContainerRef" + }, { "name": "ROUTER_CONFIGURATION" }, @@ -845,6 +848,9 @@ { "name": "ViewEngineTemplateRef" }, + { + "name": "VE_ViewContainerRef" + }, { "name": "Version" }, diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 5546c4e8dd..ada284be31 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -89,6 +89,9 @@ { "name": "R3TemplateRef" }, + { + "name": "R3ViewContainerRef" + }, { "name": "RecordViewTuple" }, @@ -140,6 +143,9 @@ { "name": "ViewEngineTemplateRef" }, + { + "name": "VE_ViewContainerRef" + }, { "name": "ViewContainerRef" }, diff --git a/packages/core/test/render3/perf/ng_template/index.ts b/packages/core/test/render3/perf/ng_template/index.ts index 4cd53bcd99..5e7b929683 100644 --- a/packages/core/test/render3/perf/ng_template/index.ts +++ b/packages/core/test/render3/perf/ng_template/index.ts @@ -6,17 +6,18 @@ * found in the LICENSE file at https://angular.io/license */ import {injectTemplateRef} from '@angular/core/src/linker/template_ref'; +import {injectViewContainerRef} from '@angular/core/src/linker/view_container_ref'; 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'; import {TNodeType} from '../../../../src/render3/interfaces/node'; import {LViewFlags, TViewType} from '../../../../src/render3/interfaces/view'; -import {injectViewContainerRef} from '../../../../src/render3/view_engine_compatibility'; import {createBenchmark} from '../micro_bench'; import {createAndRenderLView} from '../setup'; + class TemplateRefToken { /** * @internal @@ -32,7 +33,7 @@ class ViewContainerRefToken { * @nocollapse */ static __NG_ELEMENT_ID__(): ViewContainerRef { - return injectViewContainerRef(ViewContainerRef); + return injectViewContainerRef(); } } diff --git a/packages/core/test/render3/render_util.ts b/packages/core/test/render3/render_util.ts index bf25b9d015..95970699bf 100644 --- a/packages/core/test/render3/render_util.ts +++ b/packages/core/test/render3/render_util.ts @@ -454,7 +454,7 @@ export const text: RText = null as any as Text; export function enableIvyInjectableFactories() { (ElementRef as any)[NG_ELEMENT_ID] = () => R3_ELEMENT_REF_FACTORY(); (TemplateRef as any)[NG_ELEMENT_ID] = () => R3_TEMPLATE_REF_FACTORY(); - (ViewContainerRef as any)[NG_ELEMENT_ID] = () => R3_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef); + (ViewContainerRef as any)[NG_ELEMENT_ID] = () => R3_VIEW_CONTAINER_REF_FACTORY(); (ChangeDetectorRef as any)[NG_ELEMENT_ID] = () => R3_CHANGE_DETECTOR_REF_FACTORY(); (Renderer2 as any)[NG_ELEMENT_ID] = () => R3_RENDERER2_FACTORY(); }