Content-Length: 663255 | pFad | http://github.com/angular/angular/commit/967115fb384e5b3e2564af91da57cc1c6c95f73f

8A refactor(core): consolidate element end instruction logic · angular/angular@967115f · GitHub
Skip to content

Commit 967115f

Browse 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 806fcfd commit 967115f

File tree

3 files changed

+51
-52
lines changed

3 files changed

+51
-52
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '../../hydration/utils';
2626
import {isDetachedByI18n} from '../../i18n/utils';
2727
import {assertDefined, assertEqual} from '../../util/assert';
28-
import {assertHasParent} from '../assert';
2928
import {clearElementContents, createElementNode} from '../dom_node_manipulation';
3029
import {hasClassInput, hasStyleInput, TNode, TNodeType} from '../interfaces/node';
3130
import {RElement} from '../interfaces/renderer_dom';
@@ -41,19 +40,15 @@ import {
4140
getLView,
4241
getNamespace,
4342
getTView,
44-
isCurrentTNodeParent,
4543
isInSkipHydrationBlock,
4644
isSkipHydrationRootTNode,
4745
lastNodeWasCreated,
4846
leaveSkipHydrationBlock,
49-
setCurrentTNode,
50-
setCurrentTNodeAsNotParent,
5147
} from '../state';
52-
import {elementEndFirstCreatePass} from '../view/elements';
5348

5449
import {validateElementIsKnown} from './element_validation';
5550
import {setDirectiveInputsWhichShadowsStyling} from './property';
56-
import {elementLikeStartShared} from './shared';
51+
import {elementLikeEndShared, elementLikeStartShared} from './shared';
5752

5853
/**
5954
* Create DOM element. The instruction must later be followed by `elementEnd()` call.
@@ -118,36 +113,37 @@ export function ɵɵelementStart(
118113
* @codeGenApi
119114
*/
120115
export function ɵɵelementEnd(): typeof ɵɵelementEnd {
121-
let currentTNode = getCurrentTNode()!;
122116
const tView = getTView();
123-
ngDevMode && assertDefined(currentTNode, 'No parent node to close.');
124-
if (isCurrentTNodeParent()) {
125-
setCurrentTNodeAsNotParent();
126-
} else {
127-
ngDevMode && assertHasParent(getCurrentTNode());
128-
currentTNode = currentTNode.parent!;
129-
setCurrentTNode(currentTNode, false);
130-
}
117+
const initialTNode = getCurrentTNode()!;
118+
ngDevMode && assertDefined(initialTNode, 'No parent node to close.');
131119

132-
const tNode = currentTNode;
133-
ngDevMode && assertTNodeType(tNode, TNodeType.AnyRNode);
120+
const currentTNode = elementLikeEndShared(tView, initialTNode);
121+
ngDevMode && assertTNodeType(currentTNode, TNodeType.AnyRNode);
134122

135-
if (isSkipHydrationRootTNode(tNode)) {
123+
if (isSkipHydrationRootTNode(currentTNode)) {
136124
leaveSkipHydrationBlock();
137125
}
138126

139127
decreaseElementDepthCount();
140128

141-
if (tView.firstCreatePass) {
142-
elementEndFirstCreatePass(tView, tNode);
143-
}
144-
145-
if (tNode.classesWithoutHost != null && hasClassInput(tNode)) {
146-
setDirectiveInputsWhichShadowsStyling(tView, tNode, getLView(), tNode.classesWithoutHost, true);
129+
if (currentTNode.classesWithoutHost != null && hasClassInput(currentTNode)) {
130+
setDirectiveInputsWhichShadowsStyling(
131+
tView,
132+
currentTNode,
133+
getLView(),
134+
currentTNode.classesWithoutHost,
135+
true,
136+
);
147137
}
148138

149-
if (tNode.stylesWithoutHost != null && hasStyleInput(tNode)) {
150-
setDirectiveInputsWhichShadowsStyling(tView, tNode, getLView(), tNode.stylesWithoutHost, false);
139+
if (currentTNode.stylesWithoutHost != null && hasStyleInput(currentTNode)) {
140+
setDirectiveInputsWhichShadowsStyling(
141+
tView,
142+
currentTNode,
143+
getLView(),
144+
currentTNode.stylesWithoutHost,
145+
false,
146+
);
151147
}
152148
return ɵɵelementEnd;
153149
}

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ import {
1414
setSegmentHead,
1515
} from '../../hydration/utils';
1616
import {isDetachedByI18n} from '../../i18n/utils';
17-
import {assertEqual, assertNumber} from '../../util/assert';
18-
import {assertHasParent} from '../assert';
17+
import {assertDefined, assertEqual, assertNumber} from '../../util/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';
2623
import {
@@ -29,13 +26,10 @@ import {
2926
getCurrentTNode,
3027
getLView,
3128
getTView,
32-
isCurrentTNodeParent,
3329
isInSkipHydrationBlock,
3430
lastNodeWasCreated,
35-
setCurrentTNode,
36-
setCurrentTNodeAsNotParent,
3731
} from '../state';
38-
import {elementLikeStartShared} from './shared';
32+
import {elementLikeEndShared, elementLikeStartShared} from './shared';
3933

4034
/**
4135
* Creates a logical container for other nodes (<ng-container>) backed by a comment node in the DOM.
@@ -87,24 +81,11 @@ export function ɵɵelementContainerStart(
8781
* @codeGenApi
8882
*/
8983
export function ɵɵelementContainerEnd(): typeof ɵɵelementContainerEnd {
90-
let currentTNode = getCurrentTNode()!;
9184
const tView = getTView();
92-
if (isCurrentTNodeParent()) {
93-
setCurrentTNodeAsNotParent();
94-
} else {
95-
ngDevMode && assertHasParent(currentTNode);
96-
currentTNode = currentTNode.parent!;
97-
setCurrentTNode(currentTNode, false);
98-
}
99-
85+
const initialTNode = getCurrentTNode()!;
86+
ngDevMode && assertDefined(initialTNode, 'No parent node to close.');
87+
const currentTNode = elementLikeEndShared(tView, initialTNode);
10088
ngDevMode && assertTNodeType(currentTNode, TNodeType.ElementContainer);
101-
102-
if (tView.firstCreatePass) {
103-
registerPostOrderHooks(tView, currentTNode);
104-
if (isContentQueryHost(currentTNode)) {
105-
tView.queries!.elementEnd(currentTNode);
106-
}
107-
}
10889
return ɵɵelementContainerEnd;
10990
}
11091

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {assertIndexInRange, assertNotSame} from '../../util/assert';
2020
import {escapeCommentText} from '../../util/dom';
2121
import {normalizeDebugBindingName, normalizeDebugBindingValue} from '../../ng_reflect';
2222
import {stringify} from '../../util/stringify';
23-
import {assertFirstCreatePass, assertLView} from '../assert';
23+
import {assertFirstCreatePass, assertHasParent, assertLView} from '../assert';
2424
import {attachPatchData} from '../context_discovery';
2525
import {getNodeInjectable, getOrCreateNodeInjectorForNode} from '../di';
2626
import {throwMultipleComponentError} from '../errors';
@@ -60,12 +60,15 @@ import {profiler} from '../profiler';
6060
import {ProfilerEvent} from '../profiler_types';
6161
import {
6262
getCurrentDirectiveIndex,
63+
getCurrentTNode,
6364
getElementDepthCount,
6465
getSelectedIndex,
6566
increaseElementDepthCount,
67+
isCurrentTNodeParent,
6668
isInCheckNoChangesMode,
6769
setCurrentDirectiveIndex,
6870
setCurrentTNode,
71+
setCurrentTNodeAsNotParent,
6972
setSelectedIndex,
7073
wasLastNodeCreated,
7174
} from '../state';
@@ -79,7 +82,7 @@ import {createComponentLView} from '../view/construction';
7982
import {selectIndexInternal} from './advance';
8083
import {handleUnknownPropertyError, isPropertyValid, matchingSchemas} from './element_validation';
8184
import {writeToDirectiveInput} from './write_to_directive_input';
82-
import {elementLikeStartFirstCreatePass} from '../view/elements';
85+
import {elementEndFirstCreatePass, elementLikeStartFirstCreatePass} from '../view/elements';
8386
import {isDetachedByI18n} from '../../i18n/utils';
8487
import {appendChild} from '../node_manipulation';
8588
import {executeContentQueries} from '../queries/query_execution';
@@ -635,6 +638,25 @@ export function elementLikeStartShared(
635638
return tNode;
636639
}
637640

641+
/** Shared code between instructions that indicate the end of an element. */
642+
export function elementLikeEndShared(tView: TView, tNode: TNode): TNode {
643+
let currentTNode = tNode;
644+
645+
if (isCurrentTNodeParent()) {
646+
setCurrentTNodeAsNotParent();
647+
} else {
648+
ngDevMode && assertHasParent(getCurrentTNode());
649+
currentTNode = currentTNode.parent!;
650+
setCurrentTNode(currentTNode, false);
651+
}
652+
653+
if (tView.firstCreatePass) {
654+
elementEndFirstCreatePass(tView, currentTNode);
655+
}
656+
657+
return currentTNode;
658+
}
659+
638660
//github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com//
639661
//github.com// Bindings & interpolations
640662
//github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com///github.com//

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/angular/angular/commit/967115fb384e5b3e2564af91da57cc1c6c95f73f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy