Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9fe7062

Browse filesBrowse files
committed
refactor(core): consolidate element end instruction logic
There was some identical logic between the `elementEnd` and `elementContainerEnd` instructions. These changes consolidate it.
1 parent 6d196d8 commit 9fe7062
Copy full SHA for 9fe7062

File tree

3 files changed

+49
-60
lines changed
Filter options

3 files changed

+49
-60
lines changed

‎packages/core/src/render3/instructions/element.ts

Copy file name to clipboardExpand all lines: packages/core/src/render3/instructions/element.ts
+20-28Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import {
2424
setSegmentHead,
2525
} from '../../hydration/utils';
2626
import {isDetachedByI18n} from '../../i18n/utils';
27-
import {assertDefined} from '../../util/assert';
28-
import {assertHasParent} from '../assert';
2927
import {clearElementContents, createElementNode} from '../dom_node_manipulation';
3028
import {hasClassInput, hasStyleInput, TNode, TNodeType} from '../interfaces/node';
3129
import {RElement} from '../interfaces/renderer_dom';
@@ -35,19 +33,15 @@ import {assertTNodeType} from '../node_assert';
3533
import {
3634
decreaseElementDepthCount,
3735
enterSkipHydrationBlock,
38-
getCurrentTNode,
3936
getLView,
4037
getNamespace,
4138
getTView,
42-
isCurrentTNodeParent,
4339
isInSkipHydrationBlock,
4440
isSkipHydrationRootTNode,
4541
lastNodeWasCreated,
4642
leaveSkipHydrationBlock,
47-
setCurrentTNode,
48-
setCurrentTNodeAsNotParent,
4943
} from '../state';
50-
import {elementEndFirstCreatePass, elementLikeStartShared} from '../view/elements';
44+
import {elementLikeEndShared, elementLikeStartShared} from '../view/elements';
5145

5246
import {validateElementIsKnown} from './element_validation';
5347
import {setDirectiveInputsWhichShadowsStyling} from './property';
@@ -104,36 +98,34 @@ export function ɵɵelementStart(
10498
* @codeGenApi
10599
*/
106100
export function ɵɵelementEnd(): typeof ɵɵelementEnd {
107-
let currentTNode = getCurrentTNode()!;
108101
const tView = getTView();
109-
ngDevMode && assertDefined(currentTNode, 'No parent node to close.');
110-
if (isCurrentTNodeParent()) {
111-
setCurrentTNodeAsNotParent();
112-
} else {
113-
ngDevMode && assertHasParent(getCurrentTNode());
114-
currentTNode = currentTNode.parent!;
115-
setCurrentTNode(currentTNode, false);
116-
}
117-
118-
const tNode = currentTNode;
119-
ngDevMode && assertTNodeType(tNode, TNodeType.AnyRNode);
102+
const currentTNode = elementLikeEndShared();
103+
ngDevMode && assertTNodeType(currentTNode, TNodeType.AnyRNode);
120104

121-
if (isSkipHydrationRootTNode(tNode)) {
105+
if (isSkipHydrationRootTNode(currentTNode)) {
122106
leaveSkipHydrationBlock();
123107
}
124108

125109
decreaseElementDepthCount();
126110

127-
if (tView.firstCreatePass) {
128-
elementEndFirstCreatePass(tView, tNode);
129-
}
130-
131-
if (tNode.classesWithoutHost != null && hasClassInput(tNode)) {
132-
setDirectiveInputsWhichShadowsStyling(tView, tNode, getLView(), tNode.classesWithoutHost, true);
111+
if (currentTNode.classesWithoutHost != null && hasClassInput(currentTNode)) {
112+
setDirectiveInputsWhichShadowsStyling(
113+
tView,
114+
currentTNode,
115+
getLView(),
116+
currentTNode.classesWithoutHost,
117+
true,
118+
);
133119
}
134120

135-
if (tNode.stylesWithoutHost != null && hasStyleInput(tNode)) {
136-
setDirectiveInputsWhichShadowsStyling(tView, tNode, getLView(), tNode.stylesWithoutHost, false);
121+
if (currentTNode.stylesWithoutHost != null && hasStyleInput(currentTNode)) {
122+
setDirectiveInputsWhichShadowsStyling(
123+
tView,
124+
currentTNode,
125+
getLView(),
126+
currentTNode.stylesWithoutHost,
127+
false,
128+
);
137129
}
138130
return ɵɵelementEnd;
139131
}

‎packages/core/src/render3/instructions/element_container.ts

Copy file name to clipboardExpand all lines: packages/core/src/render3/instructions/element_container.ts
+3-30Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,13 @@ import {
1515
} from '../../hydration/utils';
1616
import {isDetachedByI18n} from '../../i18n/utils';
1717
import {assertNumber} from '../../util/assert';
18-
import {assertHasParent} from '../assert';
1918
import {createCommentNode} from '../dom_node_manipulation';
20-
import {registerPostOrderHooks} from '../hooks';
2119
import {TNode, TNodeType} from '../interfaces/node';
2220
import {RComment} from '../interfaces/renderer_dom';
23-
import {isContentQueryHost} from '../interfaces/type_checks';
2421
import {HYDRATION, LView, RENDERER, TView} from '../interfaces/view';
2522
import {assertTNodeType} from '../node_assert';
26-
import {
27-
getCurrentTNode,
28-
getTView,
29-
isCurrentTNodeParent,
30-
isInSkipHydrationBlock,
31-
lastNodeWasCreated,
32-
setCurrentTNode,
33-
setCurrentTNodeAsNotParent,
34-
} from '../state';
35-
import {elementLikeStartShared} from '../view/elements';
23+
import {isInSkipHydrationBlock, lastNodeWasCreated} from '../state';
24+
import {elementLikeEndShared, elementLikeStartShared} from '../view/elements';
3625

3726
/**
3827
* Creates a logical container for other nodes (<ng-container>) backed by a comment node in the DOM.
@@ -72,24 +61,8 @@ export function ɵɵelementContainerStart(
7261
* @codeGenApi
7362
*/
7463
export function ɵɵelementContainerEnd(): typeof ɵɵelementContainerEnd {
75-
let currentTNode = getCurrentTNode()!;
76-
const tView = getTView();
77-
if (isCurrentTNodeParent()) {
78-
setCurrentTNodeAsNotParent();
79-
} else {
80-
ngDevMode && assertHasParent(currentTNode);
81-
currentTNode = currentTNode.parent!;
82-
setCurrentTNode(currentTNode, false);
83-
}
84-
64+
const currentTNode = elementLikeEndShared();
8565
ngDevMode && assertTNodeType(currentTNode, TNodeType.ElementContainer);
86-
87-
if (tView.firstCreatePass) {
88-
registerPostOrderHooks(tView, currentTNode);
89-
if (isContentQueryHost(currentTNode)) {
90-
tView.queries!.elementEnd(currentTNode);
91-
}
92-
}
9366
return ɵɵelementContainerEnd;
9467
}
9568

‎packages/core/src/render3/view/elements.ts

Copy file name to clipboardExpand all lines: packages/core/src/render3/view/elements.ts
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
import {isDetachedByI18n} from '../../i18n/utils';
10-
import {assertEqual, assertIndexInRange} from '../../util/assert';
11-
import {assertFirstCreatePass} from '../assert';
10+
import {assertDefined, assertEqual, assertIndexInRange} from '../../util/assert';
11+
import {assertFirstCreatePass, assertHasParent} from '../assert';
1212
import {attachPatchData} from '../context_discovery';
1313
import {setupStaticAttributes} from '../dom_node_manipulation';
1414
import {registerPostOrderHooks} from '../hooks';
@@ -32,11 +32,14 @@ import {executeContentQueries} from '../queries/query_execution';
3232
import {
3333
getBindingIndex,
3434
getBindingsEnabled,
35+
getCurrentTNode,
3536
getElementDepthCount,
3637
getLView,
3738
getTView,
3839
increaseElementDepthCount,
40+
isCurrentTNodeParent,
3941
setCurrentTNode,
42+
setCurrentTNodeAsNotParent,
4043
wasLastNodeCreated,
4144
} from '../state';
4245
import {computeStaticStyling} from '../styling/static_styling';
@@ -177,3 +180,24 @@ export function elementEndFirstCreatePass(tView: TView, tNode: TNode) {
177180
tView.queries!.elementEnd(tNode);
178181
}
179182
}
183+
184+
/** Shared code between instructions that indicate the end of an element. */
185+
export function elementLikeEndShared(): TNode {
186+
const tView = getTView();
187+
let currentTNode = getCurrentTNode()!;
188+
ngDevMode && assertDefined(currentTNode, 'No parent node to close.');
189+
190+
if (isCurrentTNodeParent()) {
191+
setCurrentTNodeAsNotParent();
192+
} else {
193+
ngDevMode && assertHasParent(getCurrentTNode());
194+
currentTNode = currentTNode.parent!;
195+
setCurrentTNode(currentTNode, false);
196+
}
197+
198+
if (tView.firstCreatePass) {
199+
elementEndFirstCreatePass(tView, currentTNode);
200+
}
201+
202+
return currentTNode;
203+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.