Skip to content

Commit 5db84d7

Browse files
mheveryalxhub
authored andcommitted
refactor(core): Remove TViewNode as it is no longer used. (angular#38707)
Previous commit change the logic to not rely on the `TViewNode` this change removes it entirely. PR Close angular#38707
1 parent eb32b6b commit 5db84d7

File tree

23 files changed

+77
-227
lines changed

23 files changed

+77
-227
lines changed

goldens/size-tracking/integration-payloads.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"master": {
44
"uncompressed": {
55
"runtime-es2015": 1485,
6-
"main-es2015": 141711,
6+
"main-es2015": 140709,
77
"polyfills-es2015": 36571
88
}
99
}
@@ -12,7 +12,7 @@
1212
"master": {
1313
"uncompressed": {
1414
"runtime-es2015": 1485,
15-
"main-es2015": 17362,
15+
"main-es2015": 16650,
1616
"polyfills-es2015": 36657
1717
}
1818
}
@@ -30,7 +30,7 @@
3030
"master": {
3131
"uncompressed": {
3232
"runtime-es2015": 1485,
33-
"main-es2015": 136168,
33+
"main-es2015": 134891,
3434
"polyfills-es2015": 37248
3535
}
3636
}

packages/core/src/render3/component_ref.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,9 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
218218
leaveView();
219219
}
220220

221-
const componentRef = new ComponentRef(
221+
return new ComponentRef(
222222
this.componentType, component,
223223
createElementRef(viewEngine_ElementRef, tElementNode, rootLView), rootLView, tElementNode);
224-
return componentRef;
225224
}
226225
}
227226

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {executeCheckHooks, executeInitAndCheckHooks, incrementInitPhaseFlags} fr
2626
import {CONTAINER_HEADER_OFFSET, HAS_TRANSPLANTED_VIEWS, LContainer, MOVED_VIEWS} from '../interfaces/container';
2727
import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefListOrFactory, PipeDefListOrFactory, RenderFlags, ViewQueriesFunction} from '../interfaces/definition';
2828
import {INJECTOR_BLOOM_PARENT_SIZE, NodeInjectorFactory} from '../interfaces/injector';
29-
import {AttributeMarker, InitialInputData, InitialInputs, LocalRefExtractor, PropertyAliases, PropertyAliasValue, TAttributes, TConstantsOrFactory, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TIcuContainerNode, TNode, TNodeFlags, TNodeProviderIndexes, TNodeType, TProjectionNode, TViewNode} from '../interfaces/node';
29+
import {AttributeMarker, InitialInputData, InitialInputs, LocalRefExtractor, PropertyAliases, PropertyAliasValue, TAttributes, TConstantsOrFactory, TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TIcuContainerNode, TNode, TNodeFlags, TNodeProviderIndexes, TNodeType, TProjectionNode} from '../interfaces/node';
3030
import {isProceduralRenderer, RComment, RElement, Renderer3, RendererFactory3, RNode, RText} from '../interfaces/renderer';
3131
import {SanitizerFn} from '../interfaces/sanitization';
3232
import {isComponentDef, isComponentHost, isContentQueryHost, isLContainer, isRootView} from '../interfaces/type_checks';
@@ -233,8 +233,8 @@ export function getOrCreateTNode(
233233
const tNode = tView.data[adjustedIndex] as TNode ||
234234
createTNodeAtIndex(tView, adjustedIndex, type, name, attrs);
235235
setPreviousOrParentTNode(tNode, true);
236-
return tNode as TElementNode & TViewNode & TContainerNode & TElementContainerNode &
237-
TProjectionNode & TIcuContainerNode;
236+
return tNode as TElementNode & TContainerNode & TElementContainerNode & TProjectionNode &
237+
TIcuContainerNode;
238238
}
239239

240240
function createTNodeAtIndex(
@@ -244,12 +244,7 @@ function createTNodeAtIndex(
244244
const isParent = getIsParent();
245245
const parent =
246246
isParent ? previousOrParentTNode : previousOrParentTNode && previousOrParentTNode.parent;
247-
// Parents cannot cross component boundaries because components will be used in multiple places,
248-
// so it's only set if the view is the same.
249-
// FIXME(misko): This check for `TNodeType.View` should not be needed. But removing it breaks DI,
250-
// so more investigation is needed.
251-
const parentInSameView = parent !== null && parent.type !== TNodeType.View;
252-
const tParentNode = parentInSameView ? parent as TElementNode | TContainerNode : null;
247+
// Parents cannot cross component boundaries because components will be used in multiple places.
253248
const tNode = tView.data[adjustedIndex] =
254249
createTNode(tView, parent as TElementNode | TContainerNode, type, adjustedIndex, name, attrs);
255250
// Assign a pointer to the first child node of a given view. The first node is not always the one
@@ -259,8 +254,7 @@ function createTNodeAtIndex(
259254
tView.firstChild = tNode;
260255
}
261256
if (previousOrParentTNode) {
262-
if (isParent && previousOrParentTNode.child == null &&
263-
(tNode.parent !== null || previousOrParentTNode.type === TNodeType.View)) {
257+
if (isParent && previousOrParentTNode.child == null && tNode.parent !== null) {
264258
// We are in the same view, which means we are adding content node to the parent view.
265259
previousOrParentTNode.child = tNode;
266260
} else if (!isParent) {
@@ -806,6 +800,24 @@ export function storeCleanupWithContext(
806800
* @param tViews Any TViews attached to this node
807801
* @returns the TNode object
808802
*/
803+
export function createTNode(
804+
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType.Container,
805+
adjustedIndex: number, tagName: string|null, attrs: TAttributes|null): TContainerNode;
806+
export function createTNode(
807+
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType.Element,
808+
adjustedIndex: number, tagName: string|null, attrs: TAttributes|null): TElementNode;
809+
export function createTNode(
810+
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType.ElementContainer,
811+
adjustedIndex: number, tagName: string|null, attrs: TAttributes|null): TElementContainerNode;
812+
export function createTNode(
813+
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType.IcuContainer,
814+
adjustedIndex: number, tagName: string|null, attrs: TAttributes|null): TIcuContainerNode;
815+
export function createTNode(
816+
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType.Projection,
817+
adjustedIndex: number, tagName: string|null, attrs: TAttributes|null): TProjectionNode;
818+
export function createTNode(
819+
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType, adjustedIndex: number,
820+
tagName: string|null, attrs: TAttributes|null): TNode;
809821
export function createTNode(
810822
tView: TView, tParent: TElementNode|TContainerNode|null, type: TNodeType, adjustedIndex: number,
811823
tagName: string|null, attrs: TAttributes|null): TNode {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {assertFirstCreatePass} from '../assert';
99
import {attachPatchData} from '../context_discovery';
1010
import {registerPostOrderHooks} from '../hooks';
1111
import {ComponentTemplate} from '../interfaces/definition';
12-
import {LocalRefExtractor, TAttributes, TContainerNode, TNodeType, TViewNode} from '../interfaces/node';
12+
import {LocalRefExtractor, TAttributes, TContainerNode, TNodeType} from '../interfaces/node';
1313
import {isDirectiveHost} from '../interfaces/type_checks';
14-
import {HEADER_OFFSET, LView, RENDERER, T_HOST, TView, TViewType} from '../interfaces/view';
14+
import {HEADER_OFFSET, LView, RENDERER, TView, TViewType} from '../interfaces/view';
1515
import {appendChild} from '../node_manipulation';
1616
import {getLView, getTView, setPreviousOrParentTNode} from '../state';
1717
import {getConstant} from '../util/view_utils';
18+
import {addToViewTree, createDirectivesInstances, createLContainer, createTView, getOrCreateTNode, resolveDirectives, saveResolvedLocalsInData} from './shared';
1819

19-
import {addToViewTree, createDirectivesInstances, createLContainer, createTNode, createTView, getOrCreateTNode, resolveDirectives, saveResolvedLocalsInData} from './shared';
2020

2121

2222
function templateFirstCreatePass(

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,18 @@ export const enum TNodeType {
2424
* The TNode contains information about an `<ng-content>` projection
2525
*/
2626
Projection = 1,
27-
/**
28-
* The TNode contains information about an {@link LView}
29-
*/
30-
View = 2,
3127
/**
3228
* The TNode contains information about a DOM element aka {@link RNode}.
3329
*/
34-
Element = 3,
30+
Element = 2,
3531
/**
3632
* The TNode contains information about an `<ng-container>` element {@link RNode}.
3733
*/
38-
ElementContainer = 4,
34+
ElementContainer = 3,
3935
/**
4036
* The TNode contains information about an ICU comment used in `i18n`.
4137
*/
42-
IcuContainer = 5,
38+
IcuContainer = 4,
4339
}
4440

4541
/**
@@ -49,10 +45,9 @@ export const enum TNodeType {
4945
export const TNodeTypeAsString = [
5046
'Container', // 0
5147
'Projection', // 1
52-
'View', // 2
53-
'Element', // 3
54-
'ElementContainer', // 4
55-
'IcuContainer' // 5
48+
'Element', // 2
49+
'ElementContainer', // 3
50+
'IcuContainer' // 4
5651
] as const;
5752

5853

@@ -726,16 +721,6 @@ export interface TIcuContainerNode extends TNode {
726721
projection: null;
727722
}
728723

729-
/** Static data for a view */
730-
export interface TViewNode extends TNode {
731-
/** If -1, it's a dynamically created view. Otherwise, it is the view block ID. */
732-
index: number;
733-
child: TElementNode|TTextNode|TElementContainerNode|TContainerNode|TProjectionNode|null;
734-
parent: TContainerNode|null;
735-
tViews: null;
736-
projection: null;
737-
}
738-
739724
/** Static data for an LProjectionNode */
740725
export interface TProjectionNode extends TNode {
741726
/** Index in the data[] array */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {Sanitizer} from '../../sanitization/sanitizer';
1515
import {LContainer} from './container';
1616
import {ComponentDef, ComponentTemplate, DirectiveDef, DirectiveDefList, HostBindingsFunction, PipeDef, PipeDefList, ViewQueriesFunction} from './definition';
1717
import {I18nUpdateOpCodes, TI18n} from './i18n';
18-
import {TConstants, TElementNode, TNode, TNodeTypeAsString, TViewNode} from './node';
18+
import {TConstants, TNode, TNodeTypeAsString} from './node';
1919
import {PlayerHandler} from './player';
2020
import {LQueries, TQueries} from './query';
2121
import {RComment, RElement, Renderer3, RendererFactory3} from './renderer';

packages/core/src/render3/node_assert.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {assertDefined, assertEqual} from '../util/assert';
1010

11-
import {TContainerNode, TElementContainerNode, TElementNode, TIcuContainerNode, TNode, TNodeType, TProjectionNode} from './interfaces/node';
11+
import {TContainerNode, TElementContainerNode, TElementNode, TIcuContainerNode, TNode, TNodeType, TNodeTypeAsString, TProjectionNode} from './interfaces/node';
1212

1313
export function assertNodeType(
1414
tNode: TNode, type: TNodeType.Container): asserts tNode is TContainerNode;
@@ -20,7 +20,6 @@ export function assertNodeType(
2020
tNode: TNode, type: TNodeType.IcuContainer): asserts tNode is TIcuContainerNode;
2121
export function assertNodeType(
2222
tNode: TNode, type: TNodeType.Projection): asserts tNode is TProjectionNode;
23-
export function assertNodeType(tNode: TNode, type: TNodeType.View): asserts tNode is TContainerNode;
2423
export function assertNodeType(tNode: TNode, type: TNodeType): asserts tNode is TNode {
2524
assertDefined(tNode, 'should be called with a TNode');
2625
assertEqual(tNode.type, type, `should be a ${typeName(type)}`);
@@ -46,11 +45,5 @@ export function assertNodeNotOfTypes(tNode: TNode, types: TNodeType[], message?:
4645
}
4746

4847
function typeName(type: TNodeType): string {
49-
if (type == TNodeType.Projection) return 'Projection';
50-
if (type == TNodeType.Container) return 'Container';
51-
if (type == TNodeType.IcuContainer) return 'IcuContainer';
52-
if (type == TNodeType.View) return 'View';
53-
if (type == TNodeType.Element) return 'Element';
54-
if (type == TNodeType.ElementContainer) return 'ElementContainer';
55-
return '<unknown>';
48+
return TNodeTypeAsString[type] || '<unknown>';
5649
}

packages/core/src/render3/node_manipulation.ts

Lines changed: 17 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,24 @@
99
import {ViewEncapsulation} from '../metadata/view';
1010
import {Renderer2} from '../render/api';
1111
import {addToArray, removeFromArray} from '../util/array_utils';
12-
import {assertDefined, assertDomNode, assertEqual, assertSame, assertString} from '../util/assert';
12+
import {assertDefined, assertDomNode, assertEqual, assertString} from '../util/assert';
1313

1414
import {assertLContainer, assertLView, assertTNodeForLView} from './assert';
1515
import {attachPatchData} from './context_discovery';
1616
import {CONTAINER_HEADER_OFFSET, HAS_TRANSPLANTED_VIEWS, LContainer, MOVED_VIEWS, NATIVE, unusedValueExportToPlacateAjd as unused1} from './interfaces/container';
1717
import {ComponentDef} from './interfaces/definition';
1818
import {NodeInjectorFactory} from './interfaces/injector';
19-
import {TElementNode, TNode, TNodeFlags, TNodeType, TProjectionNode, TViewNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node';
19+
import {TElementNode, TNode, TNodeFlags, TNodeType, TProjectionNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node';
2020
import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection';
2121
import {isProceduralRenderer, ProceduralRenderer3, RElement, Renderer3, RNode, RText, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer';
2222
import {isLContainer, isLView} from './interfaces/type_checks';
2323
import {CHILD_HEAD, CLEANUP, DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, DestroyHookData, FLAGS, HookData, HookFn, HOST, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, T_HOST, TVIEW, TView, TViewType, unusedValueExportToPlacateAjd as unused5} from './interfaces/view';
2424
import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert';
2525
import {getLViewParent} from './util/view_traversal_utils';
26-
import {getNativeByTNode, getNonViewFirstChild, unwrapRNode, updateTransplantedViewCount} from './util/view_utils';
26+
import {getNativeByTNode, unwrapRNode, updateTransplantedViewCount} from './util/view_utils';
2727

2828
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5;
2929

30-
export function getLContainer(tNode: TViewNode, embeddedView: LView): LContainer|null {
31-
ngDevMode && assertLView(embeddedView);
32-
const container = embeddedView[PARENT] as LContainer;
33-
if (tNode.index === -1) {
34-
// This is a dynamically created view inside a dynamic container.
35-
// The parent isn't an LContainer if the embedded view hasn't been attached yet.
36-
return isLContainer(container) ? container : null;
37-
} else {
38-
ngDevMode && assertLContainer(container);
39-
// This is a inline view node (e.g. embeddedViewStart)
40-
return container;
41-
}
42-
}
43-
44-
45-
/**
46-
* Retrieves render parent for a given view.
47-
* Might be null if a view is not yet attached to any container.
48-
*/
49-
export function getContainerRenderParent(tViewNode: TViewNode, view: LView): RElement|null {
50-
const container = getLContainer(tViewNode, view);
51-
return container ? nativeParentNode(view[RENDERER], container[NATIVE]) : null;
52-
}
53-
5430
const enum WalkTNodeTreeAction {
5531
/** node create in the native environment. Run on initial creation. */
5632
Create = 0,
@@ -211,11 +187,15 @@ export function destroyViewTree(rootView: LView): void {
211187
// Only clean up view when moving to the side or up, as destroy hooks
212188
// should be called in order from the bottom up.
213189
while (lViewOrLContainer && !lViewOrLContainer![NEXT] && lViewOrLContainer !== rootView) {
214-
isLView(lViewOrLContainer) && cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer);
215-
lViewOrLContainer = getParentState(lViewOrLContainer, rootView);
190+
if (isLView(lViewOrLContainer)) {
191+
cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer);
192+
}
193+
lViewOrLContainer = lViewOrLContainer[PARENT];
216194
}
217195
if (lViewOrLContainer === null) lViewOrLContainer = rootView;
218-
isLView(lViewOrLContainer) && cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer);
196+
if (isLView(lViewOrLContainer)) {
197+
cleanUpView(lViewOrLContainer[TVIEW], lViewOrLContainer);
198+
}
219199
next = lViewOrLContainer && lViewOrLContainer![NEXT];
220200
}
221201
lViewOrLContainer = next;
@@ -381,32 +361,6 @@ export function destroyLView(tView: TView, lView: LView) {
381361
}
382362
}
383363

384-
/**
385-
* Determines which LViewOrLContainer to jump to when traversing back up the
386-
* tree in destroyViewTree.
387-
*
388-
* Normally, the view's parent LView should be checked, but in the case of
389-
* embedded views, the container (which is the view node's parent, but not the
390-
* LView's parent) needs to be checked for a possible next property.
391-
*
392-
* @param lViewOrLContainer The LViewOrLContainer for which we need a parent state
393-
* @param rootView The rootView, so we don't propagate too far up the view tree
394-
* @returns The correct parent LViewOrLContainer
395-
*/
396-
export function getParentState(lViewOrLContainer: LView|LContainer, rootView: LView): LView|
397-
LContainer|null {
398-
let tNode;
399-
if (isLView(lViewOrLContainer) && (tNode = lViewOrLContainer[T_HOST]) &&
400-
tNode.type === TNodeType.View) {
401-
// if it's an embedded view, the state needs to go up to the container, in case the
402-
// container has a next
403-
return getLContainer(tNode as TViewNode, lViewOrLContainer);
404-
} else {
405-
// otherwise, use parent view for containers or component views
406-
return lViewOrLContainer[PARENT] === rootView ? null : lViewOrLContainer[PARENT];
407-
}
408-
}
409-
410364
/**
411365
* Calls onDestroys hooks for all directives and pipes in a given view and then removes all
412366
* listeners. Listeners are removed as the last step so events delivered in the onDestroys hooks
@@ -531,30 +485,18 @@ function getRenderParent(tView: TView, tNode: TNode, currentView: LView): REleme
531485
// can't be used as a render parent.
532486
let parentTNode = tNode.parent;
533487
while (parentTNode != null &&
534-
(parentTNode.type === TNodeType.ElementContainer || parentTNode.type === TNodeType.View ||
488+
(parentTNode.type === TNodeType.ElementContainer ||
535489
parentTNode.type === TNodeType.IcuContainer)) {
536490
tNode = parentTNode;
537491
parentTNode = tNode.parent;
538492
}
539493

540494
// If the parent tNode is null, then we are inserting across views: either into an embedded view
541495
// or a component view.
542-
if (parentTNode == null) {
543-
const hostTNode = currentView[T_HOST]!;
544-
if (hostTNode && hostTNode.type === TNodeType.View) {
545-
// We are inserting a root element of an embedded view We might delay insertion of children
546-
// for a given view if it is disconnected. This might happen for 2 main reasons:
547-
// - view is not inserted into any container(view was created but not inserted yet)
548-
// - view is inserted into a container but the container itself is not inserted into the DOM
549-
// (container might be part of projection or child of a view that is not inserted yet).
550-
// In other words we can insert children of a given view if this view was inserted into a
551-
// container and the container itself has its render parent determined.
552-
return getContainerRenderParent(hostTNode as TViewNode, currentView);
553-
} else {
554-
// We are inserting a root element of the component view into the component host element and
555-
// it should always be eager.
556-
return currentView[HOST];
557-
}
496+
if (parentTNode === null) {
497+
// We are inserting a root element of the component view into the component host element and
498+
// it should always be eager.
499+
return currentView[HOST];
558500
} else {
559501
const isIcuCase = tNode && tNode.type === TNodeType.IcuContainer;
560502
// If the parent of this node is an ICU container, then it is represented by comment node and we
@@ -650,13 +592,7 @@ export function nativeNextSibling(renderer: Renderer3, node: RNode): RNode|null
650592
* @param lView
651593
*/
652594
function getNativeAnchorNode(parentTNode: TNode, lView: LView): RNode|null {
653-
if (parentTNode.type === TNodeType.View) {
654-
const lContainer = getLContainer(parentTNode as TViewNode, lView);
655-
if (lContainer === null) return null;
656-
const index = lContainer.indexOf(lView, CONTAINER_HEADER_OFFSET) - CONTAINER_HEADER_OFFSET;
657-
return getBeforeNodeForView(index, lContainer);
658-
} else if (
659-
parentTNode.type === TNodeType.ElementContainer ||
595+
if (parentTNode.type === TNodeType.ElementContainer ||
660596
parentTNode.type === TNodeType.IcuContainer) {
661597
return getNativeByTNode(parentTNode, lView);
662598
}
@@ -743,7 +679,7 @@ export function getBeforeNodeForView(viewIndexInContainer: number, lContainer: L
743679
const nextViewIndex = CONTAINER_HEADER_OFFSET + viewIndexInContainer + 1;
744680
if (nextViewIndex < lContainer.length) {
745681
const lView = lContainer[nextViewIndex] as LView;
746-
const firstTNodeOfView = getNonViewFirstChild(lView[TVIEW]);
682+
const firstTNodeOfView = lView[TVIEW].firstChild;
747683
if (firstTNodeOfView !== null) {
748684
return getFirstNativeNode(lView, firstTNodeOfView);
749685
}

0 commit comments

Comments
 (0)