diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index 26e7eae042..0d9acf4c1a 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -26,7 +26,7 @@ import {SanitizerFn} from './interfaces/sanitization'; import {StylingContext} from './interfaces/styling'; import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, TView, T_HOST} from './interfaces/view'; import {appendChild, createTextNode, nativeRemoveNode} from './node_manipulation'; -import {getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from './state'; +import {getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from './state'; import {NO_CHANGE} from './tokens'; import {renderStringify} from './util/misc_utils'; import {getNativeByIndex, getNativeByTNode, getTNode, isLContainer} from './util/view_utils'; @@ -701,7 +701,7 @@ function readCreateOpCodes( previousTNode = currentTNode; currentTNode = createDynamicNodeAtIndex(textNodeIndex, TNodeType.Element, textRNode, null); visitedNodes.push(textNodeIndex); - setIsParent(false); + setIsNotParent(); } else if (typeof opCode == 'number') { switch (opCode & I18nMutateOpCode.MASK_OPCODE) { case I18nMutateOpCode.AppendChild: @@ -726,17 +726,13 @@ function readCreateOpCodes( previousTNode = currentTNode; currentTNode = getTNode(nodeIndex, viewData); if (currentTNode) { - setPreviousOrParentTNode(currentTNode); - if (currentTNode.type === TNodeType.Element) { - setIsParent(true); - } + setPreviousOrParentTNode(currentTNode, currentTNode.type === TNodeType.Element); } break; case I18nMutateOpCode.ElementEnd: const elementIndex = opCode >>> I18nMutateOpCode.SHIFT_REF; previousTNode = currentTNode = getTNode(elementIndex, viewData); - setPreviousOrParentTNode(currentTNode); - setIsParent(false); + setPreviousOrParentTNode(currentTNode, false); break; case I18nMutateOpCode.Attr: const elementNodeIndex = opCode >>> I18nMutateOpCode.SHIFT_REF; @@ -764,7 +760,7 @@ function readCreateOpCodes( attachPatchData(commentRNode, viewData); (currentTNode as TIcuContainerNode).activeCaseIndex = null; // We will add the case nodes later, during the update phase - setIsParent(false); + setIsNotParent(); break; case ELEMENT_MARKER: const tagNameValue = createOpCodes[++i] as string; @@ -785,7 +781,7 @@ function readCreateOpCodes( } } - setIsParent(false); + setIsNotParent(); return visitedNodes; } diff --git a/packages/core/src/render3/instructions/container.ts b/packages/core/src/render3/instructions/container.ts index f5909b2947..5dda4b18ee 100644 --- a/packages/core/src/render3/instructions/container.ts +++ b/packages/core/src/render3/instructions/container.ts @@ -15,7 +15,7 @@ import {LocalRefExtractor, TAttributes, TContainerNode, TNode, TNodeType} from ' import {BINDING_INDEX, HEADER_OFFSET, LView, QUERIES, RENDERER, TVIEW} from '../interfaces/view'; import {assertNodeType} from '../node_assert'; import {appendChild, removeView} from '../node_manipulation'; -import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from '../state'; +import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state'; import {getNativeByTNode, loadInternal} from '../util/view_utils'; import {addToViewTree, createDirectivesAndLocals, createLContainer, createNodeAtIndex, createTView} from './shared'; @@ -37,7 +37,7 @@ export function ɵɵcontainer(index: number): void { tNode.tViews = []; } addTContainerToQueries(lView, tNode); - setIsParent(false); + setIsNotParent(); } /** @@ -77,7 +77,7 @@ export function ɵɵtemplate( addTContainerToQueries(lView, tContainerNode); attachPatchData(getNativeByTNode(tContainerNode, lView), lView); registerPostOrderHooks(tView, tContainerNode); - setIsParent(false); + setIsNotParent(); } /** @@ -91,10 +91,8 @@ export function ɵɵcontainerRefreshStart(index: number): void { const lView = getLView(); const tView = lView[TVIEW]; let previousOrParentTNode = loadInternal(tView.data, index) as TNode; - setPreviousOrParentTNode(previousOrParentTNode); - ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.Container); - setIsParent(true); + setPreviousOrParentTNode(previousOrParentTNode, true); lView[index + HEADER_OFFSET][ACTIVE_INDEX] = 0; @@ -113,12 +111,12 @@ export function ɵɵcontainerRefreshStart(index: number): void { export function ɵɵcontainerRefreshEnd(): void { let previousOrParentTNode = getPreviousOrParentTNode(); if (getIsParent()) { - setIsParent(false); + setIsNotParent(); } else { ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.View); ngDevMode && assertHasParent(previousOrParentTNode); previousOrParentTNode = previousOrParentTNode.parent !; - setPreviousOrParentTNode(previousOrParentTNode); + setPreviousOrParentTNode(previousOrParentTNode, false); } ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.Container); diff --git a/packages/core/src/render3/instructions/element.ts b/packages/core/src/render3/instructions/element.ts index ab7a79a4fe..ed404dbbf9 100644 --- a/packages/core/src/render3/instructions/element.ts +++ b/packages/core/src/render3/instructions/element.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ import {validateAgainstEventAttributes} from '../../sanitization/sanitization'; -import {assertDataInRange, assertEqual} from '../../util/assert'; +import {assertDataInRange, assertDefined, assertEqual} from '../../util/assert'; import {assertHasParent} from '../assert'; import {attachPatchData} from '../context_discovery'; import {registerPostOrderHooks} from '../hooks'; @@ -18,7 +18,7 @@ import {BINDING_INDEX, QUERIES, RENDERER, TVIEW} from '../interfaces/view'; import {assertNodeType} from '../node_assert'; import {appendChild} from '../node_manipulation'; import {applyOnCreateInstructions} from '../node_util'; -import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsParent, setPreviousOrParentTNode} from '../state'; +import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state'; import {getInitialClassNameValue, getInitialStyleStringValue, initializeStaticContext, patchContextWithStaticAttrs, renderInitialClasses, renderInitialStyles} from '../styling/class_and_style_bindings'; import {getStylingContextFromLView, hasClassInput, hasStyleInput} from '../styling/util'; import {registerInitialStylingIntoContext} from '../styling_next/instructions'; @@ -139,12 +139,13 @@ export function ɵɵelementStart( */ export function ɵɵelementEnd(): void { let previousOrParentTNode = getPreviousOrParentTNode(); + ngDevMode && assertDefined(previousOrParentTNode, 'No parent node to close.'); if (getIsParent()) { - setIsParent(false); + setIsNotParent(); } else { ngDevMode && assertHasParent(getPreviousOrParentTNode()); previousOrParentTNode = previousOrParentTNode.parent !; - setPreviousOrParentTNode(previousOrParentTNode); + setPreviousOrParentTNode(previousOrParentTNode, false); } // this is required for all host-level styling-related instructions to run diff --git a/packages/core/src/render3/instructions/element_container.ts b/packages/core/src/render3/instructions/element_container.ts index 4ad34536f2..58db303b72 100644 --- a/packages/core/src/render3/instructions/element_container.ts +++ b/packages/core/src/render3/instructions/element_container.ts @@ -14,7 +14,8 @@ import {BINDING_INDEX, QUERIES, RENDERER, TVIEW} from '../interfaces/view'; import {assertNodeType} from '../node_assert'; import {appendChild} from '../node_manipulation'; import {applyOnCreateInstructions} from '../node_util'; -import {getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from '../state'; +import {getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state'; + import {createDirectivesAndLocals, createNodeAtIndex, executeContentQueries, setNodeStylingTemplate} from './shared'; /** @@ -77,11 +78,11 @@ export function ɵɵelementContainerEnd(): void { const lView = getLView(); const tView = lView[TVIEW]; if (getIsParent()) { - setIsParent(false); + setIsNotParent(); } else { ngDevMode && assertHasParent(previousOrParentTNode); previousOrParentTNode = previousOrParentTNode.parent !; - setPreviousOrParentTNode(previousOrParentTNode); + setPreviousOrParentTNode(previousOrParentTNode, false); } ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.ElementContainer); diff --git a/packages/core/src/render3/instructions/embedded_view.ts b/packages/core/src/render3/instructions/embedded_view.ts index e2e5ea31f8..e805c59143 100644 --- a/packages/core/src/render3/instructions/embedded_view.ts +++ b/packages/core/src/render3/instructions/embedded_view.ts @@ -40,7 +40,7 @@ export function ɵɵembeddedViewStart( let viewToRender = scanForView(lContainer, lContainer[ACTIVE_INDEX] !, viewBlockId); if (viewToRender) { - setIsParent(true); + setIsParent(); enterView(viewToRender, viewToRender[TVIEW].node); } else { // When we create a new LView, we always reset the state of the instructions. @@ -141,6 +141,5 @@ export function ɵɵembeddedViewEnd(): void { const lContainer = lView[PARENT] as LContainer; ngDevMode && assertLContainerOrUndefined(lContainer); leaveView(lContainer[PARENT] !); - setPreviousOrParentTNode(viewHost !); - setIsParent(false); + setPreviousOrParentTNode(viewHost !, false); } diff --git a/packages/core/src/render3/instructions/projection.ts b/packages/core/src/render3/instructions/projection.ts index 301b43bc48..e36df3b93e 100644 --- a/packages/core/src/render3/instructions/projection.ts +++ b/packages/core/src/render3/instructions/projection.ts @@ -10,7 +10,7 @@ import {CssSelectorList} from '../interfaces/projection'; import {T_HOST} from '../interfaces/view'; import {appendProjectedNodes} from '../node_manipulation'; import {matchingProjectionSelectorIndex} from '../node_selector_matcher'; -import {getLView, setIsParent} from '../state'; +import {getLView, setIsNotParent} from '../state'; import {findComponentView} from '../util/view_traversal_utils'; import {createNodeAtIndex} from './shared'; @@ -88,7 +88,7 @@ export function ɵɵprojection( if (tProjectionNode.projection === null) tProjectionNode.projection = selectorIndex; // `` has no content - setIsParent(false); + setIsNotParent(); // re-distribution of projectable nodes is stored on a component's view level appendProjectedNodes(lView, tProjectionNode, selectorIndex, findComponentView(lView)); diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index c2667855cf..85c8eb853e 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -287,8 +287,7 @@ export function createNodeAtIndex( } } - setPreviousOrParentTNode(tNode); - setIsParent(true); + setPreviousOrParentTNode(tNode, true); return tNode as TElementNode & TViewNode & TContainerNode & TElementContainerNode & TProjectionNode & TIcuContainerNode; } @@ -351,8 +350,7 @@ export function createEmbeddedViewAndNode( injectorIndex: number): LView { const _isParent = getIsParent(); const _previousOrParentTNode = getPreviousOrParentTNode(); - setIsParent(true); - setPreviousOrParentTNode(null !); + setPreviousOrParentTNode(null !, true); const lView = createLView(declarationView, tView, context, LViewFlags.CheckAlways, null, null); lView[DECLARATION_VIEW] = declarationView; @@ -366,8 +364,7 @@ export function createEmbeddedViewAndNode( tView.node !.injectorIndex = injectorIndex; } - setIsParent(_isParent); - setPreviousOrParentTNode(_previousOrParentTNode); + setPreviousOrParentTNode(_previousOrParentTNode, _isParent); return lView; } @@ -390,8 +387,7 @@ export function renderEmbeddedTemplate(viewToRender: LView, tView: TView, con tickRootContext(getRootContext(viewToRender)); } else { try { - setIsParent(true); - setPreviousOrParentTNode(null !); + setPreviousOrParentTNode(null !, true); oldView = enterView(viewToRender, viewToRender[T_HOST]); resetPreOrderHookFlags(viewToRender); @@ -406,8 +402,7 @@ export function renderEmbeddedTemplate(viewToRender: LView, tView: TView, con refreshDescendantViews(viewToRender); } finally { leaveView(oldView !); - setIsParent(_isParent); - setPreviousOrParentTNode(_previousOrParentTNode); + setPreviousOrParentTNode(_previousOrParentTNode, _isParent); } } } @@ -1254,7 +1249,7 @@ function addComponentLogic( lView, createLView( lView, tView, null, def.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways, lView[previousOrParentTNode.index], previousOrParentTNode as TElementNode, - rendererFactory, lView[RENDERER_FACTORY].createRenderer(native as RElement, def))); + rendererFactory, rendererFactory.createRenderer(native as RElement, def))); componentView[T_HOST] = previousOrParentTNode as TElementNode; @@ -1695,17 +1690,14 @@ export function storeBindingMetadata(lView: LView, prefix = '', suffix = ''): st export const CLEAN_PROMISE = _CLEAN_PROMISE; -export function initializeTNodeInputs(tNode: TNode | null): PropertyAliases|null { +export function initializeTNodeInputs(tNode: TNode): PropertyAliases|null { // If tNode.inputs is undefined, a listener has created outputs, but inputs haven't // yet been checked. - if (tNode) { - if (tNode.inputs === undefined) { - // mark inputs as checked - tNode.inputs = generatePropertyAliases(tNode, BindingDirection.Input); - } - return tNode.inputs; + if (tNode.inputs === undefined) { + // mark inputs as checked + tNode.inputs = generatePropertyAliases(tNode, BindingDirection.Input); } - return null; + return tNode.inputs; } diff --git a/packages/core/src/render3/instructions/text.ts b/packages/core/src/render3/instructions/text.ts index 13bff5d10d..df0a539473 100644 --- a/packages/core/src/render3/instructions/text.ts +++ b/packages/core/src/render3/instructions/text.ts @@ -10,7 +10,7 @@ import {TNodeType} from '../interfaces/node'; import {RText, isProceduralRenderer} from '../interfaces/renderer'; import {BINDING_INDEX, HEADER_OFFSET, RENDERER, TVIEW} from '../interfaces/view'; import {appendChild, createTextNode} from '../node_manipulation'; -import {getLView, setIsParent} from '../state'; +import {getLView, setIsNotParent} from '../state'; import {NO_CHANGE} from '../tokens'; import {renderStringify} from '../util/misc_utils'; import {getNativeByIndex} from '../util/view_utils'; @@ -34,7 +34,7 @@ export function ɵɵtext(index: number, value?: any): void { const tNode = createNodeAtIndex(index, TNodeType.Element, textNative, null, null); // Text nodes are self closing. - setIsParent(false); + setIsNotParent(); appendChild(textNative, tNode, lView); } diff --git a/packages/core/src/render3/state.ts b/packages/core/src/render3/state.ts index 6d409d0b83..582d77e7bc 100644 --- a/packages/core/src/render3/state.ts +++ b/packages/core/src/render3/state.ts @@ -303,8 +303,9 @@ export function getPreviousOrParentTNode(): TNode { return previousOrParentTNode; } -export function setPreviousOrParentTNode(tNode: TNode) { +export function setPreviousOrParentTNode(tNode: TNode, _isParent: boolean) { previousOrParentTNode = tNode; + isParent = _isParent; } export function setTNodeAndViewData(tNode: TNode, view: LView) { @@ -325,8 +326,11 @@ export function getIsParent(): boolean { return isParent; } -export function setIsParent(value: boolean): void { - isParent = value; +export function setIsNotParent(): void { + isParent = false; +} +export function setIsParent(): void { + isParent = true; } diff --git a/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json b/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json index a9e77d9110..4a213bed80 100644 --- a/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json +++ b/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json @@ -693,7 +693,7 @@ "name": "setInputsFromAttrs" }, { - "name": "setIsParent" + "name": "setIsNotParent" }, { "name": "setNodeStylingTemplate" diff --git a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json index 7e4eba0c56..53c7d21ec3 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -468,7 +468,7 @@ "name": "setInjectImplementation" }, { - "name": "setIsParent" + "name": "setIsNotParent" }, { "name": "setPreviousOrParentTNode" diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 8b49e0c126..d5aaa32bce 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -1386,7 +1386,7 @@ "name": "setInputsFromAttrs" }, { - "name": "setIsParent" + "name": "setIsNotParent" }, { "name": "setNodeStylingTemplate"