Skip to content

Commit 7c64b18

Browse files
mheveryalxhub
authored andcommitted
refactor(ivy): Remove findComponentView since we now store it in LView[DECLARATION_COMPONENT_VIEW] (angular#33810)
PR Close angular#33810
1 parent 8f03489 commit 7c64b18

File tree

13 files changed

+24
-64
lines changed

13 files changed

+24
-64
lines changed

packages/core/src/debug/debug_node.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ import {Injector} from '../di';
1010
import {getViewComponent} from '../render3/global_utils_api';
1111
import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE} from '../render3/interfaces/container';
1212
import {TElementNode, TNode, TNodeFlags, TNodeType} from '../render3/interfaces/node';
13-
import {StylingMapArray, TStylingContext} from '../render3/interfaces/styling';
1413
import {isComponentHost, isLContainer} from '../render3/interfaces/type_checks';
15-
import {LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view';
16-
import {NodeStylingDebug} from '../render3/styling/styling_debug';
14+
import {DECLARATION_COMPONENT_VIEW, LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view';
1715
import {getComponent, getContext, getInjectionTokens, getInjector, getListeners, getLocalRefs, isBrowserEvents, loadLContext} from '../render3/util/discovery_utils';
1816
import {INTERPOLATION_DELIMITER, renderStringify} from '../render3/util/misc_utils';
19-
import {isStylingContext, stylingMapToStringMap} from '../render3/util/styling_utils';
20-
import {findComponentView} from '../render3/util/view_traversal_utils';
2117
import {getComponentLViewByIndex, getNativeByTNodeOrNull} from '../render3/util/view_utils';
2218
import {assertDomNode} from '../util/assert';
2319
import {DebugContext} from '../view/index';
20+
2421
import {createProxy} from './proxy';
2522

2623

@@ -533,7 +530,7 @@ function _queryNodeChildrenR3(
533530
} else if (tNode.type === TNodeType.Projection) {
534531
// Case 3: the TNode is a projection insertion point (i.e. a <ng-content>).
535532
// The nodes projected at this location all need to be processed.
536-
const componentView = findComponentView(lView !);
533+
const componentView = lView ![DECLARATION_COMPONENT_VIEW];
537534
const componentHost = componentView[T_HOST] as TElementNode;
538535
const head: TNode|null =
539536
(componentHost.projection as(TNode | null)[])[tNode.projection as number];

packages/core/src/render3/di.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ import {DirectiveDef, FactoryFn} from './interfaces/definition';
2121
import {NO_PARENT_INJECTOR, NodeInjectorFactory, PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFlags, TNODE, isFactory} from './interfaces/injector';
2222
import {AttributeMarker, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeProviderIndexes, TNodeType} from './interfaces/node';
2323
import {isComponentDef, isComponentHost} from './interfaces/type_checks';
24-
import {DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view';
24+
import {DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view';
2525
import {assertNodeOfPossibleTypes} from './node_assert';
2626
import {enterDI, leaveDI} from './state';
2727
import {isNameOnlyAttributeMarker} from './util/attrs_utils';
2828
import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './util/injector_utils';
2929
import {stringifyForError} from './util/misc_utils';
3030
import {getInitialStylingValue} from './util/styling_utils';
31-
import {findComponentView} from './util/view_traversal_utils';
3231

3332

3433

@@ -358,7 +357,7 @@ export function getOrCreateInjectable<T>(
358357
let injectorIndex = getInjectorIndex(tNode, lView);
359358
let parentLocation: RelativeInjectorLocation = NO_PARENT_INJECTOR;
360359
let hostTElementNode: TNode|null =
361-
flags & InjectFlags.Host ? findComponentView(lView)[T_HOST] : null;
360+
flags & InjectFlags.Host ? lView[DECLARATION_COMPONENT_VIEW][T_HOST] : null;
362361

363362
// If we should skip this injector, or if there is no injector on this node, start by
364363
// searching

packages/core/src/render3/instructions/projection.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
import {newArray} from '../../util/array_utils';
99
import {TAttributes, TElementNode, TNode, TNodeType} from '../interfaces/node';
1010
import {ProjectionSlots} from '../interfaces/projection';
11-
import {TVIEW, T_HOST} from '../interfaces/view';
11+
import {DECLARATION_COMPONENT_VIEW, TVIEW, T_HOST} from '../interfaces/view';
1212
import {applyProjection} from '../node_manipulation';
1313
import {getProjectAsAttrValue, isNodeMatchingSelectorList, isSelectorInSelectorList} from '../node_selector_matcher';
1414
import {getLView, setIsNotParent} from '../state';
15-
import {findComponentView} from '../util/view_traversal_utils';
16-
1715
import {getOrCreateTNode} from './shared';
1816

1917

@@ -75,7 +73,7 @@ export function matchingProjectionSlotIndex(tNode: TNode, projectionSlots: Proje
7573
* @codeGenApi
7674
*/
7775
export function ɵɵprojectionDef(projectionSlots?: ProjectionSlots): void {
78-
const componentNode = findComponentView(getLView())[T_HOST] as TElementNode;
76+
const componentNode = getLView()[DECLARATION_COMPONENT_VIEW][T_HOST] as TElementNode;
7977

8078
if (!componentNode.projection) {
8179
// If no explicit projection slots are defined, fall back to a single

packages/core/src/render3/instructions/shared.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ export function createLView<T>(
173173
lView[SANITIZER] = sanitizer || parentLView && parentLView[SANITIZER] || null !;
174174
lView[INJECTOR as any] = injector || parentLView && parentLView[INJECTOR] || null;
175175
lView[T_HOST] = tHostNode;
176-
lView[DECLARATION_COMPONENT_VIEW] = tView.type == TViewType.Embedded ?
177-
(parentLView === null ? null : parentLView ![DECLARATION_COMPONENT_VIEW]) :
178-
lView;
176+
ngDevMode && assertEqual(
177+
tView.type == TViewType.Embedded ? parentLView !== null : true, true,
178+
'Embedded views must have parentLView');
179+
lView[DECLARATION_COMPONENT_VIEW] =
180+
tView.type == TViewType.Embedded ? parentLView ![DECLARATION_COMPONENT_VIEW] : lView;
179181
ngDevMode && attachLViewDebug(lView);
180182
return lView;
181183
}

packages/core/src/render3/interfaces/view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export interface LView extends Array<any> {
265265
* - `LView[DECLARATION_LCONTAINER]` similar problem for queries
266266
* - `LContainer[MOVED_VIEWS]` similar problem for queries
267267
*/
268-
[DECLARATION_COMPONENT_VIEW]: LView|null;
268+
[DECLARATION_COMPONENT_VIEW]: LView;
269269

270270
/**
271271
* A declaration point of embedded views (ones instantiated based on the content of a

packages/core/src/render3/node_manipulation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {ProceduralRenderer3, RElement, RNode, RText, Renderer3, isProceduralRend
2020
import {isLContainer, isLView, isRootView} from './interfaces/type_checks';
2121
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';
2222
import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert';
23-
import {findComponentView, getLViewParent} from './util/view_traversal_utils';
23+
import {getLViewParent} from './util/view_traversal_utils';
2424
import {getNativeByTNode, unwrapRNode} from './util/view_utils';
2525

2626
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5;
@@ -261,7 +261,7 @@ function trackMovedView(declarationContainer: LContainer, lView: LView) {
261261
const movedViews = declarationContainer[MOVED_VIEWS];
262262
const insertedLContainer = lView[PARENT] as LContainer;
263263
ngDevMode && assertLContainer(insertedLContainer);
264-
const insertedComponentLView = insertedLContainer[PARENT] ![DECLARATION_COMPONENT_VIEW] !;
264+
const insertedComponentLView = insertedLContainer[PARENT] ![DECLARATION_COMPONENT_VIEW];
265265
ngDevMode && assertDefined(insertedComponentLView, 'Missing insertedComponentLView');
266266
const insertedComponentIsOnPush =
267267
(insertedComponentLView[FLAGS] & LViewFlags.CheckAlways) !== LViewFlags.CheckAlways;
@@ -695,7 +695,7 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null {
695695
return getNativeByTNode(tNode, lView);
696696
}
697697
} else {
698-
const componentView = findComponentView(lView);
698+
const componentView = lView[DECLARATION_COMPONENT_VIEW];
699699
const componentHost = componentView[T_HOST] as TElementNode;
700700
const parentView = getLViewParent(componentView);
701701
const firstProjectedTNode: TNode|null =
@@ -846,7 +846,7 @@ export function applyProjection(lView: LView, tProjectionNode: TProjectionNode)
846846
function applyProjectionRecursive(
847847
renderer: Renderer3, action: WalkTNodeTreeAction, lView: LView,
848848
tProjectionNode: TProjectionNode, renderParent: RElement | null, beforeNode: RNode | null) {
849-
const componentLView = findComponentView(lView);
849+
const componentLView = lView[DECLARATION_COMPONENT_VIEW];
850850
const componentNode = componentLView[T_HOST] as TElementNode;
851851
ngDevMode &&
852852
assertEqual(typeof tProjectionNode.projection, 'number', 'expecting projection index');

packages/core/src/render3/util/view_traversal_utils.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88

99
import {assertDefined} from '../../util/assert';
1010
import {assertLView} from '../assert';
11-
import {TNodeType} from '../interfaces/node';
1211
import {isLContainer, isLView} from '../interfaces/type_checks';
13-
import {CONTEXT, DECLARATION_VIEW, FLAGS, LView, LViewFlags, PARENT, RootContext, T_HOST} from '../interfaces/view';
14-
12+
import {CONTEXT, FLAGS, LView, LViewFlags, PARENT, RootContext} from '../interfaces/view';
1513
import {readPatchedLView} from './view_utils';
1614

1715

18-
1916
/**
2017
* Gets the parent LView of the passed LView, if the PARENT is an LContainer, will get the parent of
2118
* that LContainer, which is an LView
@@ -43,29 +40,6 @@ export function getRootView(componentOrLView: LView | {}): LView {
4340
return lView;
4441
}
4542

46-
/**
47-
* Given an `LView`, find the closest declaration view which is not an embedded view.
48-
*
49-
* This method searches for the `LView` associated with the component which declared the `LView`.
50-
*
51-
* This function may return itself if the `LView` passed in is not an embedded `LView`. Otherwise
52-
* it walks the declaration parents until it finds a component view (non-embedded-view.)
53-
*
54-
* @param lView LView for which we want a host element node
55-
* @returns The host node
56-
*/
57-
export function findComponentView(lView: LView): LView {
58-
let rootTNode = lView[T_HOST];
59-
let declaredView: LView|null;
60-
while (rootTNode !== null && rootTNode.type === TNodeType.View &&
61-
(declaredView = lView[DECLARATION_VIEW]) !== null) {
62-
lView = declaredView;
63-
rootTNode = lView[T_HOST];
64-
}
65-
ngDevMode && assertLView(lView);
66-
return lView;
67-
}
68-
6943
/**
7044
* Returns the `RootContext` instance that is associated with
7145
* the application where the target is situated. It does this by walking the parent views until it

packages/core/src/render3/view_engine_compatibility.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ import {ActiveIndexFlag, CONTAINER_HEADER_OFFSET, LContainer, VIEW_REFS} from '.
2525
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node';
2626
import {RComment, RElement, isProceduralRenderer} from './interfaces/renderer';
2727
import {isComponentHost, isLContainer, isLView, isRootView} from './interfaces/type_checks';
28-
import {DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view';
28+
import {DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, LView, LViewFlags, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view';
2929
import {assertNodeOfPossibleTypes} from './node_assert';
3030
import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation';
3131
import {getParentInjectorTNode} from './node_util';
3232
import {getLView, getPreviousOrParentTNode} from './state';
3333
import {getParentInjectorView, hasParentInjector} from './util/injector_utils';
34-
import {findComponentView} from './util/view_traversal_utils';
3534
import {getComponentLViewByIndex, getNativeByTNode, setLContainerActiveIndex, unwrapRNode, viewAttachedToContainer} from './util/view_utils';
3635
import {ViewRef} from './view_ref';
3736

@@ -389,7 +388,7 @@ function createViewRef(tNode: TNode, lView: LView, isPipe: boolean): ViewEngine_
389388
tNode.type === TNodeType.ElementContainer) {
390389
// The LView represents the location where the injection is requested from.
391390
// We need to locate the containing LView (in case where the `lView` is an embedded view)
392-
const hostComponentView = findComponentView(lView); // look up
391+
const hostComponentView = lView[DECLARATION_COMPONENT_VIEW]; // look up
393392
return new ViewRef(hostComponentView, lView);
394393
}
395394
return null !;

packages/core/src/render3/view_ref.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {checkNoChangesInRootView, checkNoChangesInternal, detectChangesInRootVie
1515
import {CONTAINER_HEADER_OFFSET} from './interfaces/container';
1616
import {TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node';
1717
import {isLContainer} from './interfaces/type_checks';
18-
import {CONTEXT, FLAGS, HOST, LView, LViewFlags, TVIEW, T_HOST} from './interfaces/view';
18+
import {CONTEXT, DECLARATION_COMPONENT_VIEW, FLAGS, HOST, LView, LViewFlags, TVIEW, T_HOST} from './interfaces/view';
1919
import {assertNodeOfPossibleTypes} from './node_assert';
2020
import {destroyLView, renderDetachView} from './node_manipulation';
21-
import {findComponentView, getLViewParent} from './util/view_traversal_utils';
21+
import {getLViewParent} from './util/view_traversal_utils';
2222
import {unwrapRNode} from './util/view_utils';
2323

2424

@@ -331,7 +331,7 @@ function collectNativeNodes(
331331
if (tNodeType === TNodeType.ElementContainer || tNodeType === TNodeType.IcuContainer) {
332332
collectNativeNodes(lView, tNode.child, result);
333333
} else if (tNodeType === TNodeType.Projection) {
334-
const componentView = findComponentView(lView);
334+
const componentView = lView[DECLARATION_COMPONENT_VIEW];
335335
const componentHost = componentView[T_HOST] as TElementNode;
336336
const parentView = getLViewParent(componentView);
337337
let firstProjectedNode: TNode|null =

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,6 @@
272272
{
273273
"name": "findAttrIndexInNode"
274274
},
275-
{
276-
"name": "findComponentView"
277-
},
278275
{
279276
"name": "findDirectiveMatches"
280277
},

0 commit comments

Comments
 (0)