Content-Length: 901296 | pFad | http://github.com/angular/angular/commit/6783fb7eaebf341e2d7fababcf6042cfa7d19dca

AC refactor(core): consolidate element end instruction logic (#61409) · angular/angular@6783fb7 · GitHub
Skip to content

Commit 6783fb7

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(core): consolidate element end instruction logic (#61409)
There was some identical logic between the `elementEnd` and `elementContainerEnd` instructions. These changes consolidate it. PR Close #61409
1 parent 049fe82 commit 6783fb7

File tree

10 files changed

+59
-60
lines changed

10 files changed

+59
-60
lines changed

packages/core/src/render3/component_ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import {executeContentQueries} from './queries/query_execution';
7777
import {enterView, leaveView} from './state';
7878
import {debugStringifyTypeForError, stringifyForError} from './util/stringify_utils';
7979
import {getComponentLViewByIndex, getTNode} from './util/view_utils';
80-
import {elementEndFirstCreatePass, elementLikeStartFirstCreatePass} from './view/elements';
80+
import {elementLikeEndFirstCreatePass, elementLikeStartFirstCreatePass} from './view/elements';
8181
import {ViewRef} from './view_ref';
8282
import {createLView, createTView, getInitialLViewFlagsFromDef} from './view/construction';
8383
import {BINDING, Binding, DirectiveWithBindings} from './dynamic_bindings';
@@ -328,7 +328,7 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
328328
createDirectivesInstances(rootTView, rootLView, hostTNode);
329329
executeContentQueries(rootTView, hostTNode, rootLView);
330330

331-
elementEndFirstCreatePass(rootTView, hostTNode);
331+
elementLikeEndFirstCreatePass(rootTView, hostTNode);
332332

333333
if (projectableNodes !== undefined) {
334334
projectNodes(hostTNode, this.ngContentSelectors, projectableNodes);

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 {elementLikeEndFirstCreatePass, 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+
elementLikeEndFirstCreatePass(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//

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function elementLikeStartFirstCreatePass(
6969
return tNode;
7070
}
7171

72-
export function elementEndFirstCreatePass(tView: TView, tNode: TNode) {
72+
export function elementLikeEndFirstCreatePass(tView: TView, tNode: TNode) {
7373
ngDevMode && assertFirstCreatePass(tView);
7474
registerPostOrderHooks(tView, tNode);
7575
if (isContentQueryHost(tNode)) {

packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
"detectChangesInternal",
274274
"diPublicInInjector",
275275
"documentElement",
276-
"elementEndFirstCreatePass",
276+
"elementLikeEndFirstCreatePass",
277277
"elementLikeStartFirstCreatePass",
278278
"enterDI",
279279
"enterView",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
"detectChangesInViewIfAttached",
276276
"detectChangesInternal",
277277
"diPublicInInjector",
278-
"elementEndFirstCreatePass",
278+
"elementLikeEndFirstCreatePass",
279279
"elementLikeStartFirstCreatePass",
280280
"enterDI",
281281
"enterView",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
"detectChangesInViewIfAttached",
327327
"detectChangesInternal",
328328
"diPublicInInjector",
329-
"elementEndFirstCreatePass",
329+
"elementLikeEndFirstCreatePass",
330330
"elementLikeStartFirstCreatePass",
331331
"enterDI",
332332
"enterView",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
"detectChangesInViewIfAttached",
318318
"detectChangesInternal",
319319
"diPublicInInjector",
320-
"elementEndFirstCreatePass",
320+
"elementLikeEndFirstCreatePass",
321321
"elementLikeStartFirstCreatePass",
322322
"enterDI",
323323
"enterView",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
"detectChangesInViewIfAttached",
385385
"detectChangesInternal",
386386
"diPublicInInjector",
387-
"elementEndFirstCreatePass",
387+
"elementLikeEndFirstCreatePass",
388388
"elementLikeStartFirstCreatePass",
389389
"emptyPathMatch",
390390
"encodeUriQuery",

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/6783fb7eaebf341e2d7fababcf6042cfa7d19dca

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy