diff --git a/packages/core/src/debug/debug_node.ts b/packages/core/src/debug/debug_node.ts index e79f3c1e7c..479d6ed4c9 100644 --- a/packages/core/src/debug/debug_node.ts +++ b/packages/core/src/debug/debug_node.ts @@ -10,17 +10,14 @@ import {Injector} from '../di'; import {getViewComponent} from '../render3/global_utils_api'; import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE} from '../render3/interfaces/container'; import {TElementNode, TNode, TNodeFlags, TNodeType} from '../render3/interfaces/node'; -import {StylingMapArray, TStylingContext} from '../render3/interfaces/styling'; import {isComponentHost, isLContainer} from '../render3/interfaces/type_checks'; -import {LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view'; -import {NodeStylingDebug} from '../render3/styling/styling_debug'; +import {DECLARATION_COMPONENT_VIEW, LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view'; import {getComponent, getContext, getInjectionTokens, getInjector, getListeners, getLocalRefs, isBrowserEvents, loadLContext} from '../render3/util/discovery_utils'; import {INTERPOLATION_DELIMITER, renderStringify} from '../render3/util/misc_utils'; -import {isStylingContext, stylingMapToStringMap} from '../render3/util/styling_utils'; -import {findComponentView} from '../render3/util/view_traversal_utils'; import {getComponentLViewByIndex, getNativeByTNodeOrNull} from '../render3/util/view_utils'; import {assertDomNode} from '../util/assert'; import {DebugContext} from '../view/index'; + import {createProxy} from './proxy'; @@ -533,7 +530,7 @@ function _queryNodeChildrenR3( } else if (tNode.type === TNodeType.Projection) { // Case 3: the TNode is a projection insertion point (i.e. a ). // The nodes projected at this location all need to be processed. - const componentView = findComponentView(lView !); + const componentView = lView ![DECLARATION_COMPONENT_VIEW]; const componentHost = componentView[T_HOST] as TElementNode; const head: TNode|null = (componentHost.projection as(TNode | null)[])[tNode.projection as number]; diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 5c2b8d6e59..c565dd11e5 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -21,14 +21,13 @@ import {DirectiveDef, FactoryFn} from './interfaces/definition'; import {NO_PARENT_INJECTOR, NodeInjectorFactory, PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFlags, TNODE, isFactory} from './interfaces/injector'; import {AttributeMarker, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeProviderIndexes, TNodeType} from './interfaces/node'; import {isComponentDef, isComponentHost} from './interfaces/type_checks'; -import {DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view'; +import {DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; import {enterDI, leaveDI} from './state'; import {isNameOnlyAttributeMarker} from './util/attrs_utils'; import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './util/injector_utils'; import {stringifyForError} from './util/misc_utils'; import {getInitialStylingValue} from './util/styling_utils'; -import {findComponentView} from './util/view_traversal_utils'; @@ -358,7 +357,7 @@ export function getOrCreateInjectable( let injectorIndex = getInjectorIndex(tNode, lView); let parentLocation: RelativeInjectorLocation = NO_PARENT_INJECTOR; let hostTElementNode: TNode|null = - flags & InjectFlags.Host ? findComponentView(lView)[T_HOST] : null; + flags & InjectFlags.Host ? lView[DECLARATION_COMPONENT_VIEW][T_HOST] : null; // If we should skip this injector, or if there is no injector on this node, start by // searching diff --git a/packages/core/src/render3/instructions/projection.ts b/packages/core/src/render3/instructions/projection.ts index 291ca01ce1..730a071a8e 100644 --- a/packages/core/src/render3/instructions/projection.ts +++ b/packages/core/src/render3/instructions/projection.ts @@ -8,12 +8,10 @@ import {newArray} from '../../util/array_utils'; import {TAttributes, TElementNode, TNode, TNodeType} from '../interfaces/node'; import {ProjectionSlots} from '../interfaces/projection'; -import {TVIEW, T_HOST} from '../interfaces/view'; +import {DECLARATION_COMPONENT_VIEW, TVIEW, T_HOST} from '../interfaces/view'; import {applyProjection} from '../node_manipulation'; import {getProjectAsAttrValue, isNodeMatchingSelectorList, isSelectorInSelectorList} from '../node_selector_matcher'; import {getLView, setIsNotParent} from '../state'; -import {findComponentView} from '../util/view_traversal_utils'; - import {getOrCreateTNode} from './shared'; @@ -75,7 +73,7 @@ export function matchingProjectionSlotIndex(tNode: TNode, projectionSlots: Proje * @codeGenApi */ export function ɵɵprojectionDef(projectionSlots?: ProjectionSlots): void { - const componentNode = findComponentView(getLView())[T_HOST] as TElementNode; + const componentNode = getLView()[DECLARATION_COMPONENT_VIEW][T_HOST] as TElementNode; if (!componentNode.projection) { // If no explicit projection slots are defined, fall back to a single diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 58c1e03ec6..4c38f96096 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -173,9 +173,11 @@ export function createLView( lView[SANITIZER] = sanitizer || parentLView && parentLView[SANITIZER] || null !; lView[INJECTOR as any] = injector || parentLView && parentLView[INJECTOR] || null; lView[T_HOST] = tHostNode; - lView[DECLARATION_COMPONENT_VIEW] = tView.type == TViewType.Embedded ? - (parentLView === null ? null : parentLView ![DECLARATION_COMPONENT_VIEW]) : - lView; + ngDevMode && assertEqual( + tView.type == TViewType.Embedded ? parentLView !== null : true, true, + 'Embedded views must have parentLView'); + lView[DECLARATION_COMPONENT_VIEW] = + tView.type == TViewType.Embedded ? parentLView ![DECLARATION_COMPONENT_VIEW] : lView; ngDevMode && attachLViewDebug(lView); return lView; } diff --git a/packages/core/src/render3/interfaces/view.ts b/packages/core/src/render3/interfaces/view.ts index 1c040242ee..4a138f3a35 100644 --- a/packages/core/src/render3/interfaces/view.ts +++ b/packages/core/src/render3/interfaces/view.ts @@ -265,7 +265,7 @@ export interface LView extends Array { * - `LView[DECLARATION_LCONTAINER]` similar problem for queries * - `LContainer[MOVED_VIEWS]` similar problem for queries */ - [DECLARATION_COMPONENT_VIEW]: LView|null; + [DECLARATION_COMPONENT_VIEW]: LView; /** * A declaration point of embedded views (ones instantiated based on the content of a diff --git a/packages/core/src/render3/node_manipulation.ts b/packages/core/src/render3/node_manipulation.ts index c987928317..22f76a7abd 100644 --- a/packages/core/src/render3/node_manipulation.ts +++ b/packages/core/src/render3/node_manipulation.ts @@ -20,7 +20,7 @@ import {ProceduralRenderer3, RElement, RNode, RText, Renderer3, isProceduralRend import {isLContainer, isLView, isRootView} from './interfaces/type_checks'; import {CHILD_HEAD, CLEANUP, DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, FLAGS, HOST, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, T_HOST, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert'; -import {findComponentView, getLViewParent} from './util/view_traversal_utils'; +import {getLViewParent} from './util/view_traversal_utils'; import {getNativeByTNode, unwrapRNode} from './util/view_utils'; const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5; @@ -261,7 +261,7 @@ function trackMovedView(declarationContainer: LContainer, lView: LView) { const movedViews = declarationContainer[MOVED_VIEWS]; const insertedLContainer = lView[PARENT] as LContainer; ngDevMode && assertLContainer(insertedLContainer); - const insertedComponentLView = insertedLContainer[PARENT] ![DECLARATION_COMPONENT_VIEW] !; + const insertedComponentLView = insertedLContainer[PARENT] ![DECLARATION_COMPONENT_VIEW]; ngDevMode && assertDefined(insertedComponentLView, 'Missing insertedComponentLView'); const insertedComponentIsOnPush = (insertedComponentLView[FLAGS] & LViewFlags.CheckAlways) !== LViewFlags.CheckAlways; @@ -695,7 +695,7 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null { return getNativeByTNode(tNode, lView); } } else { - const componentView = findComponentView(lView); + const componentView = lView[DECLARATION_COMPONENT_VIEW]; const componentHost = componentView[T_HOST] as TElementNode; const parentView = getLViewParent(componentView); const firstProjectedTNode: TNode|null = @@ -846,7 +846,7 @@ export function applyProjection(lView: LView, tProjectionNode: TProjectionNode) function applyProjectionRecursive( renderer: Renderer3, action: WalkTNodeTreeAction, lView: LView, tProjectionNode: TProjectionNode, renderParent: RElement | null, beforeNode: RNode | null) { - const componentLView = findComponentView(lView); + const componentLView = lView[DECLARATION_COMPONENT_VIEW]; const componentNode = componentLView[T_HOST] as TElementNode; ngDevMode && assertEqual(typeof tProjectionNode.projection, 'number', 'expecting projection index'); diff --git a/packages/core/src/render3/util/view_traversal_utils.ts b/packages/core/src/render3/util/view_traversal_utils.ts index 18493189d1..0be540c9f9 100644 --- a/packages/core/src/render3/util/view_traversal_utils.ts +++ b/packages/core/src/render3/util/view_traversal_utils.ts @@ -8,14 +8,11 @@ import {assertDefined} from '../../util/assert'; import {assertLView} from '../assert'; -import {TNodeType} from '../interfaces/node'; import {isLContainer, isLView} from '../interfaces/type_checks'; -import {CONTEXT, DECLARATION_VIEW, FLAGS, LView, LViewFlags, PARENT, RootContext, T_HOST} from '../interfaces/view'; - +import {CONTEXT, FLAGS, LView, LViewFlags, PARENT, RootContext} from '../interfaces/view'; import {readPatchedLView} from './view_utils'; - /** * Gets the parent LView of the passed LView, if the PARENT is an LContainer, will get the parent of * that LContainer, which is an LView @@ -43,29 +40,6 @@ export function getRootView(componentOrLView: LView | {}): LView { return lView; } -/** - * Given an `LView`, find the closest declaration view which is not an embedded view. - * - * This method searches for the `LView` associated with the component which declared the `LView`. - * - * This function may return itself if the `LView` passed in is not an embedded `LView`. Otherwise - * it walks the declaration parents until it finds a component view (non-embedded-view.) - * - * @param lView LView for which we want a host element node - * @returns The host node - */ -export function findComponentView(lView: LView): LView { - let rootTNode = lView[T_HOST]; - let declaredView: LView|null; - while (rootTNode !== null && rootTNode.type === TNodeType.View && - (declaredView = lView[DECLARATION_VIEW]) !== null) { - lView = declaredView; - rootTNode = lView[T_HOST]; - } - ngDevMode && assertLView(lView); - return lView; -} - /** * Returns the `RootContext` instance that is associated with * the application where the target is situated. It does this by walking the parent views until it diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index d83d32b65d..d3ad41abdb 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -25,13 +25,12 @@ import {ActiveIndexFlag, CONTAINER_HEADER_OFFSET, LContainer, VIEW_REFS} from '. import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer'; import {isComponentHost, isLContainer, isLView, isRootView} from './interfaces/type_checks'; -import {DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; +import {DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation'; import {getParentInjectorTNode} from './node_util'; import {getLView, getPreviousOrParentTNode} from './state'; import {getParentInjectorView, hasParentInjector} from './util/injector_utils'; -import {findComponentView} from './util/view_traversal_utils'; import {getComponentLViewByIndex, getNativeByTNode, setLContainerActiveIndex, unwrapRNode, viewAttachedToContainer} from './util/view_utils'; import {ViewRef} from './view_ref'; @@ -389,7 +388,7 @@ function createViewRef(tNode: TNode, lView: LView, isPipe: boolean): ViewEngine_ tNode.type === TNodeType.ElementContainer) { // The LView represents the location where the injection is requested from. // We need to locate the containing LView (in case where the `lView` is an embedded view) - const hostComponentView = findComponentView(lView); // look up + const hostComponentView = lView[DECLARATION_COMPONENT_VIEW]; // look up return new ViewRef(hostComponentView, lView); } return null !; diff --git a/packages/core/src/render3/view_ref.ts b/packages/core/src/render3/view_ref.ts index 0a3b5e82e0..091d3c9204 100644 --- a/packages/core/src/render3/view_ref.ts +++ b/packages/core/src/render3/view_ref.ts @@ -15,10 +15,10 @@ import {checkNoChangesInRootView, checkNoChangesInternal, detectChangesInRootVie import {CONTAINER_HEADER_OFFSET} from './interfaces/container'; import {TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {isLContainer} from './interfaces/type_checks'; -import {CONTEXT, FLAGS, HOST, LView, LViewFlags, TVIEW, T_HOST} from './interfaces/view'; +import {CONTEXT, DECLARATION_COMPONENT_VIEW, FLAGS, HOST, LView, LViewFlags, TVIEW, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; import {destroyLView, renderDetachView} from './node_manipulation'; -import {findComponentView, getLViewParent} from './util/view_traversal_utils'; +import {getLViewParent} from './util/view_traversal_utils'; import {unwrapRNode} from './util/view_utils'; @@ -331,7 +331,7 @@ function collectNativeNodes( if (tNodeType === TNodeType.ElementContainer || tNodeType === TNodeType.IcuContainer) { collectNativeNodes(lView, tNode.child, result); } else if (tNodeType === TNodeType.Projection) { - const componentView = findComponentView(lView); + const componentView = lView[DECLARATION_COMPONENT_VIEW]; const componentHost = componentView[T_HOST] as TElementNode; const parentView = getLViewParent(componentView); let firstProjectedNode: TNode|null = diff --git a/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json b/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json index f2190522b2..a1d6182a2e 100644 --- a/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json +++ b/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json @@ -272,9 +272,6 @@ { "name": "findAttrIndexInNode" }, - { - "name": "findComponentView" - }, { "name": "findDirectiveMatches" }, diff --git a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json index 4364d40a7b..c25378dfcf 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -227,9 +227,6 @@ { "name": "extractPipeDef" }, - { - "name": "findComponentView" - }, { "name": "generateExpandoInstructionBlock" }, diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index b6d69ec252..23fec5b572 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -575,9 +575,6 @@ { "name": "findAttrIndexInNode" }, - { - "name": "findComponentView" - }, { "name": "findDirectiveMatches" }, diff --git a/packages/core/test/render3/di_spec.ts b/packages/core/test/render3/di_spec.ts index e6ac07d32e..894feb8eb9 100644 --- a/packages/core/test/render3/di_spec.ts +++ b/packages/core/test/render3/di_spec.ts @@ -223,7 +223,7 @@ describe('di', () => { describe('getOrCreateNodeInjector', () => { it('should handle initial undefined state', () => { const contentView = createLView( - null, createTView(TViewType.Embedded, -1, null, 1, 0, null, null, null, null, null), {}, + null, createTView(TViewType.Component, -1, null, 1, 0, null, null, null, null, null), {}, LViewFlags.CheckAlways, null, null, {} as any, {} as any); enterView(contentView, null); try {