refactor(core): renamed `previousOrParent` to `currentTNode` (#38707)

The previous name of `previousOrParent` was confusing. Changed the
terminology to `currentTNode`.

PR Close #38707
This commit is contained in:
Misko Hevery 2020-09-14 13:43:44 -07:00 committed by Alex Rickabaugh
parent 7bd18fca19
commit 5448e84cf0
26 changed files with 194 additions and 201 deletions

View File

@ -6,15 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import { assertDefined, assertEqual, assertNumber, throwError } from '../util/assert';
import { getComponentDef, getNgModuleDef } from './definition';
import { LContainer } from './interfaces/container';
import { DirectiveDef } from './interfaces/definition';
import { PARENT_INJECTOR } from './interfaces/injector';
import { TNode } from './interfaces/node';
import { isLContainer, isLView } from './interfaces/type_checks';
import { HEADER_OFFSET, LView, TVIEW, TView } from './interfaces/view';
import {assertDefined, assertEqual, assertNumber, throwError} from '../util/assert';
import {getComponentDef, getNgModuleDef} from './definition';
import {LContainer} from './interfaces/container';
import {DirectiveDef} from './interfaces/definition';
import {PARENT_INJECTOR} from './interfaces/injector';
import {TNode} from './interfaces/node';
import {isLContainer, isLView} from './interfaces/type_checks';
import {HEADER_OFFSET, LView, TVIEW, TView} from './interfaces/view';
// [Assert functions do not constraint type when they are guarded by a truthy
@ -49,13 +48,13 @@ export function assertNgModuleType(
}
}
export function assertPreviousIsParent(isParent: boolean) {
assertEqual(isParent, true, 'previousOrParentTNode should be a parent');
export function assertCurrentTNodeIsParent(isParent: boolean) {
assertEqual(isParent, true, 'currentTNode should be a parent');
}
export function assertHasParent(tNode: TNode|null) {
assertDefined(tNode, 'previousOrParentTNode should exist!');
assertDefined(tNode!.parent, 'previousOrParentTNode should have a parent');
assertDefined(tNode, 'currentTNode should exist!');
assertDefined(tNode!.parent, 'currentTNode should have a parent');
}
export function assertDataNext(lView: LView, index: number, arr?: any[]) {

View File

@ -11,7 +11,7 @@
import {Type} from '../core';
import {Injector} from '../di/injector';
import {Sanitizer} from '../sanitization/sanitizer';
import {assertIndexInRange} from '../util/assert';
import {assertDefined, assertIndexInRange} from '../util/assert';
import {assertComponentType} from './assert';
import {getComponentDef} from './definition';
@ -24,7 +24,7 @@ import {PlayerHandler} from './interfaces/player';
import {domRendererFactory3, RElement, Renderer3, RendererFactory3} from './interfaces/renderer';
import {CONTEXT, HEADER_OFFSET, LView, LViewFlags, RootContext, RootContextFlags, TVIEW, TViewType} from './interfaces/view';
import {writeDirectClass, writeDirectStyle} from './node_manipulation';
import {enterView, getPreviousOrParentTNode, leaveView, setSelectedIndex} from './state';
import {enterView, getCurrentTNode, leaveView, setSelectedIndex} from './state';
import {computeStaticStyling} from './styling/static_styling';
import {setUpAttributes} from './util/attrs_utils';
import {publishDefaultGlobalUtils} from './util/global_utils';
@ -229,7 +229,8 @@ export function createRootComponent<T>(
componentDef.contentQueries(RenderFlags.Create, component, rootLView.length - 1);
}
const rootTNode = getPreviousOrParentTNode()!;
const rootTNode = getCurrentTNode()!;
ngDevMode && assertDefined(rootTNode, 'tNode should have been already created');
if (tView.firstCreatePass &&
(componentDef.hostBindings !== null || componentDef.hostAttrs !== null)) {
const elementIndex = rootTNode.index - HEADER_OFFSET;

View File

@ -19,7 +19,7 @@ import {NodeInjectorFactory} from './interfaces/injector';
import {TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNodeProviderIndexes} from './interfaces/node';
import {isComponentDef} from './interfaces/type_checks';
import {DestroyHookData, LView, TData, TVIEW, TView} from './interfaces/view';
import {getLView, getPreviousOrParentTNode, getTView} from './state';
import {getCurrentTNode, getLView, getTView} from './state';
@ -76,7 +76,7 @@ function resolveProvider(
let token: any = isTypeProvider(provider) ? provider : resolveForwardRef(provider.provide);
let providerFactory: () => any = providerToFactory(provider);
const tNode = getPreviousOrParentTNode()!;
const tNode = getCurrentTNode()!;
const beginIndex = tNode.providerIndexes & TNodeProviderIndexes.ProvidersStartIndexMask;
const endIndex = tNode.directiveStart;
const cptViewProvidersCount =

View File

@ -18,9 +18,10 @@ import {SanitizerFn} from '../interfaces/sanitization';
import {isLContainer} from '../interfaces/type_checks';
import {HEADER_OFFSET, LView, RENDERER, T_HOST, TView} from '../interfaces/view';
import {appendChild, applyProjection, createTextNode, nativeRemoveNode} from '../node_manipulation';
import {getBindingIndex, getLView, getPreviousOrParentTNode, getTView, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {getBindingIndex, getCurrentTNode, getLView, getTView, setCurrentTNode, setCurrentTNodeAsNotParent} from '../state';
import {renderStringify} from '../util/misc_utils';
import {getNativeByIndex, getNativeByTNode, getTNode, load} from '../util/view_utils';
import {getLocaleId} from './i18n_locale_id';
@ -90,7 +91,7 @@ export function applyCreateOpCodes(
currentTNode =
createDynamicNodeAtIndex(tView, lView, textNodeIndex, TNodeType.Element, textRNode, null);
visitedNodes.push(textNodeIndex);
setIsNotParent();
setCurrentTNodeAsNotParent();
} else if (typeof opCode == 'number') {
switch (opCode & I18nMutateOpCode.MASK_INSTRUCTION) {
case I18nMutateOpCode.AppendChild:
@ -120,13 +121,13 @@ export function applyCreateOpCodes(
previousTNode = currentTNode;
currentTNode = getTNode(tView, nodeIndex);
if (currentTNode) {
setPreviousOrParentTNode(currentTNode, isParent);
setCurrentTNode(currentTNode, isParent);
}
break;
case I18nMutateOpCode.ElementEnd:
const elementIndex = opCode >>> I18nMutateOpCode.SHIFT_REF;
previousTNode = currentTNode = getTNode(tView, elementIndex);
setPreviousOrParentTNode(currentTNode, false);
setCurrentTNode(currentTNode, false);
break;
case I18nMutateOpCode.Attr:
const elementNodeIndex = opCode >>> I18nMutateOpCode.SHIFT_REF;
@ -157,7 +158,7 @@ export function applyCreateOpCodes(
visitedNodes.push(commentNodeIndex);
attachPatchData(commentRNode, lView);
// We will add the case nodes later, during the update phase
setIsNotParent();
setCurrentTNodeAsNotParent();
break;
case ELEMENT_MARKER:
const tagNameValue = createOpCodes[++i] as string;
@ -179,7 +180,7 @@ export function applyCreateOpCodes(
}
}
setIsNotParent();
setCurrentTNodeAsNotParent();
return visitedNodes;
}
@ -411,7 +412,7 @@ export function i18nEndFirstPass(tView: TView, lView: LView) {
ngDevMode && assertDefined(tI18n, `You should call i18nStart before i18nEnd`);
// Find the last node that was added before `i18nEnd`
const lastCreatedNode = getPreviousOrParentTNode();
const lastCreatedNode = getCurrentTNode();
// Read the instructions to insert/move/remove DOM elements
const visitedNodes = applyCreateOpCodes(tView, rootIndex, tI18n.create, lView);
@ -465,7 +466,7 @@ function removeNode(tView: TView, lView: LView, index: number, markAsDetached: b
function createDynamicNodeAtIndex(
tView: TView, lView: LView, index: number, type: TNodeType, native: RElement|RText|null,
name: string|null): TElementNode|TIcuContainerNode {
const previousOrParentTNode = getPreviousOrParentTNode();
const currentTNode = getCurrentTNode();
ngDevMode && assertIndexInRange(lView, index + HEADER_OFFSET);
lView[index + HEADER_OFFSET] = native;
// FIXME(misko): Why does this create A TNode??? I would not expect this to be here.
@ -473,8 +474,8 @@ function createDynamicNodeAtIndex(
// We are creating a dynamic node, the previous tNode might not be pointing at this node.
// We will link ourselves into the tree later with `appendI18nNode`.
if (previousOrParentTNode && previousOrParentTNode.next === tNode) {
previousOrParentTNode.next = null;
if (currentTNode && currentTNode.next === tNode) {
currentTNode.next = null;
}
return tNode;

View File

@ -100,7 +100,7 @@ export function i18nMutateOpCodesToString(
return `(lView[${ref}] as Element).setAttribute("${parser.consumeString()}", "${
parser.consumeString()}")`;
case I18nMutateOpCode.ElementEnd:
return `setPreviousOrParentTNode(tView.data[${ref}] as TNode)`;
return `setCurrentTNode(tView.data[${ref}] as TNode)`;
case I18nMutateOpCode.RemoveNestedIcu:
return `removeNestedICU(${ref})`;
}

View File

@ -20,7 +20,7 @@ import {TNodeType} from '../interfaces/node';
import {RComment, RElement} from '../interfaces/renderer';
import {SanitizerFn} from '../interfaces/sanitization';
import {HEADER_OFFSET, LView, T_HOST, TView} from '../interfaces/view';
import {getIsParent, getPreviousOrParentTNode} from '../state';
import {getCurrentTNode, isCurrentTNodeParent} from '../state';
import {attachDebugGetter} from '../util/debug_utils';
import {getNativeByIndex, getTNode} from '../util/view_utils';
@ -70,9 +70,8 @@ export function i18nStartFirstPass(
lView: LView, tView: TView, index: number, message: string, subTemplateIndex?: number) {
const startIndex = tView.blueprint.length - HEADER_OFFSET;
i18nVarsCount = 0;
const previousOrParentTNode = getPreviousOrParentTNode()!;
const parentTNode =
getIsParent() ? previousOrParentTNode : previousOrParentTNode && previousOrParentTNode.parent;
const currentTNode = getCurrentTNode()!;
const parentTNode = isCurrentTNodeParent() ? currentTNode : currentTNode && currentTNode.parent;
let parentIndex =
parentTNode && parentTNode !== lView[T_HOST] ? parentTNode.index - HEADER_OFFSET : index;
let parentIndexPointer = 0;
@ -86,11 +85,11 @@ export function i18nStartFirstPass(
// keep track whether an element was a parent node or not, so that the logic that consumes
// the generated `I18nMutateOpCode`s can leverage this information to properly set TNode state
// (whether it's a parent or sibling).
if (index > 0 && previousOrParentTNode !== parentTNode) {
let previousTNodeIndex = previousOrParentTNode.index - HEADER_OFFSET;
if (index > 0 && currentTNode !== parentTNode) {
let previousTNodeIndex = currentTNode.index - HEADER_OFFSET;
// If current TNode is a sibling node, encode it using a negative index. This information is
// required when the `Select` action is processed (see the `readCreateOpCodes` function).
if (!getIsParent()) {
if (!isCurrentTNodeParent()) {
previousTNodeIndex = ~previousTNodeIndex;
}
// Create an OpCode to select the previous TNode
@ -212,7 +211,7 @@ export function i18nStartFirstPass(
*/
export function i18nAttributesFirstPass(
lView: LView, tView: TView, index: number, values: string[]) {
const previousElement = getPreviousOrParentTNode()!;
const previousElement = getCurrentTNode()!;
const previousElementIndex = previousElement.index - HEADER_OFFSET;
const updateOpCodes: I18nUpdateOpCodes = [];
if (ngDevMode) {

View File

@ -10,7 +10,7 @@ import {assertInjectImplementationNot, ɵɵinject} from '../../di/injector_compa
import {Type} from '../../interface/type';
import {getOrCreateInjectable, injectAttributeImpl} from '../di';
import {TDirectiveHostNode} from '../interfaces/node';
import {getLView, getPreviousOrParentTNode} from '../state';
import {getCurrentTNode, getLView} from '../state';
/**
* Returns the value associated to the given token from the injectors.
@ -48,7 +48,7 @@ export function ɵɵdirectiveInject<T>(
ngDevMode && assertInjectImplementationNot(ɵɵdirectiveInject);
return ɵɵinject(token, flags);
}
const tNode = getPreviousOrParentTNode();
const tNode = getCurrentTNode();
return getOrCreateInjectable<T>(
tNode as TDirectiveHostNode, lView, resolveForwardRef(token), flags);
}
@ -59,7 +59,7 @@ export function ɵɵdirectiveInject<T>(
* @codeGenApi
*/
export function ɵɵinjectAttribute(attrNameToInject: string): string|null {
return injectAttributeImpl(getPreviousOrParentTNode()!, attrNameToInject);
return injectAttributeImpl(getCurrentTNode()!, attrNameToInject);
}
/**

View File

@ -16,7 +16,7 @@ import {isContentQueryHost, isDirectiveHost} from '../interfaces/type_checks';
import {HEADER_OFFSET, LView, RENDERER, T_HOST, TVIEW, TView} from '../interfaces/view';
import {assertNodeType} from '../node_assert';
import {appendChild, writeDirectClass, writeDirectStyle} from '../node_manipulation';
import {decreaseElementDepthCount, getBindingIndex, getElementDepthCount, getIsParent, getLView, getNamespace, getPreviousOrParentTNode, getTView, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {decreaseElementDepthCount, getBindingIndex, getCurrentTNode, getElementDepthCount, getLView, getNamespace, getTView, increaseElementDepthCount, isCurrentTNodeParent, setCurrentTNode, setCurrentTNodeAsNotParent} from '../state';
import {computeStaticStyling} from '../styling/static_styling';
import {setUpAttributes} from '../util/attrs_utils';
import {getConstant} from '../util/view_utils';
@ -87,7 +87,7 @@ export function ɵɵelementStart(
const tNode = tView.firstCreatePass ?
elementStartFirstCreatePass(index, tView, lView, native, name, attrsIndex, localRefsIndex) :
tView.data[adjustedIndex] as TElementNode;
setPreviousOrParentTNode(tNode, true);
setCurrentTNode(tNode, true);
const mergedAttrs = tNode.mergedAttrs;
if (mergedAttrs !== null) {
@ -128,17 +128,17 @@ export function ɵɵelementStart(
* @codeGenApi
*/
export function ɵɵelementEnd(): void {
let previousOrParentTNode = getPreviousOrParentTNode()!;
ngDevMode && assertDefined(previousOrParentTNode, 'No parent node to close.');
if (getIsParent()) {
setIsNotParent();
let currentTNode = getCurrentTNode()!;
ngDevMode && assertDefined(currentTNode, 'No parent node to close.');
if (isCurrentTNodeParent()) {
setCurrentTNodeAsNotParent();
} else {
ngDevMode && assertHasParent(getPreviousOrParentTNode());
previousOrParentTNode = previousOrParentTNode.parent!;
setPreviousOrParentTNode(previousOrParentTNode, false);
ngDevMode && assertHasParent(getCurrentTNode());
currentTNode = currentTNode.parent!;
setCurrentTNode(currentTNode, false);
}
const tNode = previousOrParentTNode;
const tNode = currentTNode;
ngDevMode && assertNodeType(tNode, TNodeType.Element);
@ -146,9 +146,9 @@ export function ɵɵelementEnd(): void {
const tView = getTView();
if (tView.firstCreatePass) {
registerPostOrderHooks(tView, previousOrParentTNode);
if (isContentQueryHost(previousOrParentTNode)) {
tView.queries!.elementEnd(previousOrParentTNode);
registerPostOrderHooks(tView, currentTNode);
if (isContentQueryHost(currentTNode)) {
tView.queries!.elementEnd(currentTNode);
}
}

View File

@ -14,7 +14,7 @@ import {isContentQueryHost, isDirectiveHost} from '../interfaces/type_checks';
import {HEADER_OFFSET, LView, RENDERER, T_HOST, TView} from '../interfaces/view';
import {assertNodeType} from '../node_assert';
import {appendChild} from '../node_manipulation';
import {getBindingIndex, getIsParent, getLView, getPreviousOrParentTNode, getTView, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {getBindingIndex, getCurrentTNode, getLView, getTView, isCurrentTNodeParent, setCurrentTNode, setCurrentTNodeAsNotParent} from '../state';
import {computeStaticStyling} from '../styling/static_styling';
import {getConstant} from '../util/view_utils';
@ -74,7 +74,7 @@ export function ɵɵelementContainerStart(
const tNode = tView.firstCreatePass ?
elementContainerStartFirstCreatePass(index, tView, lView, attrsIndex, localRefsIndex) :
tView.data[adjustedIndex] as TElementContainerNode;
setPreviousOrParentTNode(tNode, true);
setCurrentTNode(tNode, true);
ngDevMode && ngDevMode.rendererCreateComment++;
const native = lView[adjustedIndex] =
@ -98,22 +98,22 @@ export function ɵɵelementContainerStart(
* @codeGenApi
*/
export function ɵɵelementContainerEnd(): void {
let previousOrParentTNode = getPreviousOrParentTNode()!;
let currentTNode = getCurrentTNode()!;
const tView = getTView();
if (getIsParent()) {
setIsNotParent();
if (isCurrentTNodeParent()) {
setCurrentTNodeAsNotParent();
} else {
ngDevMode && assertHasParent(previousOrParentTNode);
previousOrParentTNode = previousOrParentTNode.parent!;
setPreviousOrParentTNode(previousOrParentTNode, false);
ngDevMode && assertHasParent(currentTNode);
currentTNode = currentTNode.parent!;
setCurrentTNode(currentTNode, false);
}
ngDevMode && assertNodeType(previousOrParentTNode, TNodeType.ElementContainer);
ngDevMode && assertNodeType(currentTNode, TNodeType.ElementContainer);
if (tView.firstCreatePass) {
registerPostOrderHooks(tView, previousOrParentTNode);
if (isContentQueryHost(previousOrParentTNode)) {
tView.queries!.elementEnd(previousOrParentTNode);
registerPostOrderHooks(tView, currentTNode);
if (isContentQueryHost(currentTNode)) {
tView.queries!.elementEnd(currentTNode);
}
}
}

View File

@ -15,7 +15,7 @@ import {GlobalTargetResolver, isProceduralRenderer, RElement, Renderer3} from '.
import {isDirectiveHost} from '../interfaces/type_checks';
import {CLEANUP, FLAGS, LView, LViewFlags, RENDERER, TView} from '../interfaces/view';
import {assertNodeOfPossibleTypes} from '../node_assert';
import {getCurrentDirectiveDef, getLView, getPreviousOrParentTNode, getTView} from '../state';
import {getCurrentDirectiveDef, getCurrentTNode, getLView, getTView} from '../state';
import {getComponentLViewByIndex, getNativeByTNode, unwrapRNode} from '../util/view_utils';
import {getLCleanup, handleError, loadComponentRenderer, markViewDirty} from './shared';
@ -41,7 +41,7 @@ export function ɵɵlistener(
eventTargetResolver?: GlobalTargetResolver): typeof ɵɵlistener {
const lView = getLView();
const tView = getTView();
const tNode = getPreviousOrParentTNode()!;
const tNode = getCurrentTNode()!;
listenerInternal(
tView, lView, lView[RENDERER], tNode, eventName, listenerFn, useCapture, eventTargetResolver);
return ɵɵlistener;
@ -71,7 +71,7 @@ export function ɵɵlistener(
export function ɵɵsyntheticHostListener(
eventName: string, listenerFn: (e?: any) => any, useCapture = false,
eventTargetResolver?: GlobalTargetResolver): typeof ɵɵsyntheticHostListener {
const tNode = getPreviousOrParentTNode()!;
const tNode = getCurrentTNode()!;
const lView = getLView();
const tView = getTView();
const currentDef = getCurrentDirectiveDef(tView.data);

View File

@ -11,7 +11,7 @@ import {ProjectionSlots} from '../interfaces/projection';
import {DECLARATION_COMPONENT_VIEW, T_HOST} from '../interfaces/view';
import {applyProjection} from '../node_manipulation';
import {getProjectAsAttrValue, isNodeMatchingSelectorList, isSelectorInSelectorList} from '../node_selector_matcher';
import {getLView, getTView, setIsNotParent} from '../state';
import {getLView, getTView, setCurrentTNodeAsNotParent} from '../state';
import {getOrCreateTNode} from './shared';
@ -131,7 +131,7 @@ export function ɵɵprojection(
if (tProjectionNode.projection === null) tProjectionNode.projection = selectorIndex;
// `<ng-content>` has no content
setIsNotParent();
setCurrentTNodeAsNotParent();
// We might need to delay the projection of nodes if they are in the middle of an i18n block
if (!delayProjection) {

View File

@ -33,7 +33,7 @@ import {isComponentDef, isComponentHost, isContentQueryHost, isLContainer, isRoo
import {CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, FLAGS, HEADER_OFFSET, HOST, InitPhaseState, INJECTOR, LView, LViewFlags, NEXT, PARENT, RENDERER, RENDERER_FACTORY, RootContext, RootContextFlags, SANITIZER, T_HOST, TData, TRANSPLANTED_VIEWS_TO_REFRESH, TVIEW, TView, TViewType} from '../interfaces/view';
import {assertNodeNotOfTypes, assertNodeOfPossibleTypes} from '../node_assert';
import {isInlineTemplate, isNodeMatchingSelectorList} from '../node_selector_matcher';
import {enterView, getBindingsEnabled, getCheckNoChangesMode, getCurrentDirectiveIndex, getIsParent, getPreviousOrParentTNode, getSelectedIndex, leaveView, setBindingIndex, setBindingRootForHostBindings, setCheckNoChangesMode, setCurrentDirectiveIndex, setCurrentQueryIndex, setPreviousOrParentTNode, setSelectedIndex} from '../state';
import {enterView, getBindingsEnabled, getCheckNoChangesMode, getCurrentDirectiveIndex, getCurrentTNode, getSelectedIndex, isCurrentTNodeParent, leaveView, setBindingIndex, setBindingRootForHostBindings, setCheckNoChangesMode, setCurrentDirectiveIndex, setCurrentQueryIndex, setCurrentTNode, setSelectedIndex} from '../state';
import {NO_CHANGE} from '../tokens';
import {isAnimationProp, mergeHostAttrs} from '../util/attrs_utils';
import {INTERPOLATION_DELIMITER, renderStringify, stringifyForError} from '../util/misc_utils';
@ -232,7 +232,7 @@ export function getOrCreateTNode(
const adjustedIndex = index + HEADER_OFFSET;
const tNode = tView.data[adjustedIndex] as TNode ||
createTNodeAtIndex(tView, adjustedIndex, type, name, attrs);
setPreviousOrParentTNode(tNode, true);
setCurrentTNode(tNode, true);
return tNode as TElementNode & TContainerNode & TElementContainerNode & TProjectionNode &
TIcuContainerNode;
}
@ -240,10 +240,9 @@ export function getOrCreateTNode(
function createTNodeAtIndex(
tView: TView, adjustedIndex: number, type: TNodeType, name: string|null,
attrs: TAttributes|null) {
const previousOrParentTNode = getPreviousOrParentTNode();
const isParent = getIsParent();
const parent =
isParent ? previousOrParentTNode : previousOrParentTNode && previousOrParentTNode.parent;
const currentTNode = getCurrentTNode();
const isParent = isCurrentTNodeParent();
const parent = isParent ? currentTNode : currentTNode && currentTNode.parent;
// Parents cannot cross component boundaries because components will be used in multiple places.
const tNode = tView.data[adjustedIndex] =
createTNode(tView, parent as TElementNode | TContainerNode, type, adjustedIndex, name, attrs);
@ -253,12 +252,12 @@ function createTNodeAtIndex(
if (tView.firstChild === null) {
tView.firstChild = tNode;
}
if (previousOrParentTNode) {
if (isParent && previousOrParentTNode.child == null && tNode.parent !== null) {
if (currentTNode !== null) {
if (isParent && currentTNode.child == null && tNode.parent !== null) {
// We are in the same view, which means we are adding content node to the parent view.
previousOrParentTNode.child = tNode;
currentTNode.child = tNode;
} else if (!isParent) {
previousOrParentTNode.next = tNode;
currentTNode.next = tNode;
}
}
return tNode;
@ -1125,7 +1124,7 @@ function logUnknownPropertyError(propName: string, tNode: TNode): void {
* Instantiate a root component.
*/
export function instantiateRootComponent<T>(tView: TView, lView: LView, def: ComponentDef<T>): T {
const rootTNode = getPreviousOrParentTNode()!;
const rootTNode = getCurrentTNode()!;
if (tView.firstCreatePass) {
if (def.providersResolver) def.providersResolver(def);
generateExpandoInstructionBlock(tView, rootTNode, 1);

View File

@ -13,7 +13,7 @@ import {LocalRefExtractor, TAttributes, TContainerNode, TNodeType} from '../inte
import {isDirectiveHost} from '../interfaces/type_checks';
import {HEADER_OFFSET, LView, RENDERER, TView, TViewType} from '../interfaces/view';
import {appendChild} from '../node_manipulation';
import {getLView, getTView, setPreviousOrParentTNode} from '../state';
import {getLView, getTView, setCurrentTNode} from '../state';
import {getConstant} from '../util/view_utils';
import {addToViewTree, createDirectivesInstances, createLContainer, createTView, getOrCreateTNode, resolveDirectives, saveResolvedLocalsInData} from './shared';
@ -77,7 +77,7 @@ export function ɵɵtemplate(
templateFirstCreatePass(
index, tView, lView, templateFn, decls, vars, tagName, attrsIndex, localRefsIndex) :
tView.data[adjustedIndex] as TContainerNode;
setPreviousOrParentTNode(tNode, false);
setCurrentTNode(tNode, false);
const comment = lView[RENDERER].createComment(ngDevMode ? 'container' : '');
appendChild(tView, lView, comment, tNode);

View File

@ -9,7 +9,7 @@ import {assertEqual, assertIndexInRange} from '../../util/assert';
import {TElementNode, TNodeType} from '../interfaces/node';
import {HEADER_OFFSET, RENDERER, T_HOST} from '../interfaces/view';
import {appendChild, createTextNode} from '../node_manipulation';
import {getBindingIndex, getLView, getTView, setPreviousOrParentTNode} from '../state';
import {getBindingIndex, getLView, getTView, setCurrentTNode} from '../state';
import {getOrCreateTNode} from './shared';
@ -42,5 +42,5 @@ export function ɵɵtext(index: number, value: string = ''): void {
appendChild(tView, lView, textNative, tNode);
// Text nodes are self closing.
setPreviousOrParentTNode(tNode, false);
setCurrentTNode(tNode, false);
}

View File

@ -28,7 +28,7 @@ import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, u
import {LQueries, LQuery, TQueries, TQuery, TQueryMetadata, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
import {DECLARATION_LCONTAINER, LView, PARENT, QUERIES, TVIEW, TView} from './interfaces/view';
import {assertNodeOfPossibleTypes} from './node_assert';
import {getCurrentQueryIndex, getLView, getPreviousOrParentTNode, getTView, setCurrentQueryIndex} from './state';
import {getCurrentQueryIndex, getCurrentTNode, getLView, getTView, setCurrentQueryIndex} from './state';
import {isCreationMode} from './util/view_utils';
import {createContainerRef, createElementRef, createTemplateRef} from './view_engine_compatibility';
@ -504,8 +504,7 @@ export function ɵɵcontentQuery<T>(
directiveIndex: number, predicate: Type<any>|InjectionToken<unknown>|string[], descend: boolean,
read?: any): void {
contentQueryInternal(
getTView(), getLView(), predicate, descend, read, false, getPreviousOrParentTNode()!,
directiveIndex);
getTView(), getLView(), predicate, descend, read, false, getCurrentTNode()!, directiveIndex);
}
/**
@ -524,8 +523,7 @@ export function ɵɵstaticContentQuery<T>(
directiveIndex: number, predicate: Type<any>|InjectionToken<unknown>|string[], descend: boolean,
read?: any): void {
contentQueryInternal(
getTView(), getLView(), predicate, descend, read, true, getPreviousOrParentTNode()!,
directiveIndex);
getTView(), getLView(), predicate, descend, read, true, getCurrentTNode()!, directiveIndex);
}
function contentQueryInternal<T>(

View File

@ -54,12 +54,12 @@ interface LFrame {
*
* This is used in conjunction with `isParent`.
*/
previousOrParentTNode: TNode|null;
currentTNode: TNode|null;
/**
* If `isParent` is:
* - `true`: then `previousOrParentTNode` points to a parent node.
* - `false`: then `previousOrParentTNode` points to previous node (sibling).
* - `true`: then `currentTNode` points to a parent node.
* - `false`: then `currentTNode` points to previous node (sibling).
*/
isParent: boolean;
@ -262,24 +262,24 @@ export function ɵɵrestoreView(viewToRestore: OpaqueViewState) {
instructionState.lFrame.contextLView = viewToRestore as any as LView;
}
export function getPreviousOrParentTNode(): TNode|null {
return instructionState.lFrame.previousOrParentTNode;
export function getCurrentTNode(): TNode|null {
return instructionState.lFrame.currentTNode;
}
export function setPreviousOrParentTNode(tNode: TNode, isParent: boolean) {
export function setCurrentTNode(tNode: TNode, isParent: boolean) {
ngDevMode && assertTNodeForTView(tNode, instructionState.lFrame.tView);
instructionState.lFrame.previousOrParentTNode = tNode;
instructionState.lFrame.currentTNode = tNode;
instructionState.lFrame.isParent = isParent;
}
export function getIsParent(): boolean {
export function isCurrentTNodeParent(): boolean {
return instructionState.lFrame.isParent;
}
export function setIsNotParent(): void {
export function setCurrentTNodeAsNotParent(): void {
instructionState.lFrame.isParent = false;
}
export function setIsParent(): void {
export function setCurrentTNodeAsParent(): void {
instructionState.lFrame.isParent = true;
}
@ -389,7 +389,7 @@ export function enterDI(newView: LView, tNode: TNode) {
ngDevMode && assertLViewOrUndefined(newView);
const newLFrame = allocLFrame();
instructionState.lFrame = newLFrame;
newLFrame.previousOrParentTNode = tNode!;
newLFrame.currentTNode = tNode!;
newLFrame.lView = newView;
}
@ -421,7 +421,7 @@ export function enterView(newView: LView): void {
const tView = newView[TVIEW];
instructionState.lFrame = newLFrame;
ngDevMode && tView.firstChild && assertTNodeForTView(tView.firstChild, tView);
newLFrame.previousOrParentTNode = tView.firstChild!;
newLFrame.currentTNode = tView.firstChild!;
newLFrame.lView = newView;
newLFrame.tView = tView;
newLFrame.contextLView = newView!;
@ -440,20 +440,20 @@ function allocLFrame() {
function createLFrame(parent: LFrame|null): LFrame {
const lFrame: LFrame = {
previousOrParentTNode: null, //
isParent: true, //
lView: null!, //
tView: null!, //
selectedIndex: 0, //
contextLView: null!, //
elementDepthCount: 0, //
currentNamespace: null, //
currentDirectiveIndex: -1, //
bindingRootIndex: -1, //
bindingIndex: -1, //
currentQueryIndex: 0, //
parent: parent!, //
child: null, //
currentTNode: null, //
isParent: true, //
lView: null!, //
tView: null!, //
selectedIndex: 0, //
contextLView: null!, //
elementDepthCount: 0, //
currentNamespace: null, //
currentDirectiveIndex: -1, //
bindingRootIndex: -1, //
bindingIndex: -1, //
currentQueryIndex: 0, //
parent: parent!, //
child: null, //
};
parent !== null && (parent.child = lFrame); // link the new LFrame for reuse.
return lFrame;
@ -462,7 +462,7 @@ function createLFrame(parent: LFrame|null): LFrame {
/**
* A lightweight version of leave which is used with DI.
*
* This function only resets `previousOrParentTNode` and `LView` as those are the only properties
* This function only resets `currentTNode` and `LView` as those are the only properties
* used with DI (`enterDI()`).
*
* NOTE: This function is reexported as `leaveDI`. However `leaveDI` has return type of `void` where
@ -471,7 +471,7 @@ function createLFrame(parent: LFrame|null): LFrame {
function leaveViewLight(): LFrame {
const oldLFrame = instructionState.lFrame;
instructionState.lFrame = oldLFrame.parent;
oldLFrame.previousOrParentTNode = null!;
oldLFrame.currentTNode = null!;
oldLFrame.lView = null!;
return oldLFrame;
}

View File

@ -6,33 +6,33 @@
* found in the LICENSE file at https://angular.io/license
*/
import { ChangeDetectorRef as ViewEngine_ChangeDetectorRef } from '../change_detection/change_detector_ref';
import { Injector } from '../di/injector';
import { ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef } from '../linker/component_factory';
import { ElementRef as ViewEngine_ElementRef } from '../linker/element_ref';
import { NgModuleRef as viewEngine_NgModuleRef } from '../linker/ng_module_factory';
import { TemplateRef as ViewEngine_TemplateRef } from '../linker/template_ref';
import { ViewContainerRef as ViewEngine_ViewContainerRef } from '../linker/view_container_ref';
import { EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_ViewRef } from '../linker/view_ref';
import { Renderer2 } from '../render/api';
import { addToArray, removeFromArray } from '../util/array_utils';
import { assertDefined, assertEqual, assertGreaterThan, assertLessThan } from '../util/assert';
import { assertLContainer, assertNodeInjector } from './assert';
import { getParentInjectorLocation, NodeInjector } from './di';
import { addToViewTree, createLContainer, createLView, renderView } from './instructions/shared';
import { CONTAINER_HEADER_OFFSET, LContainer, NATIVE, VIEW_REFS } from './interfaces/container';
import { TNODE } from './interfaces/injector';
import { TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeType } from './interfaces/node';
import { isProceduralRenderer, RComment, RElement } from './interfaces/renderer';
import { isComponentHost, isLContainer, isLView, isRootView } from './interfaces/type_checks';
import { DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, LView, LViewFlags, PARENT, QUERIES, RENDERER, TVIEW, TView, T_HOST } from './interfaces/view';
import { assertNodeOfPossibleTypes } from './node_assert';
import { addViewToContainer, appendChild, destroyLView, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode } from './node_manipulation';
import { getLView, getPreviousOrParentTNode } from './state';
import { getParentInjectorIndex, getParentInjectorView, hasParentInjector } from './util/injector_utils';
import { getComponentLViewByIndex, getNativeByTNode, unwrapRNode, viewAttachedToContainer } from './util/view_utils';
import { ViewRef } from './view_ref';
import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref';
import {Injector} from '../di/injector';
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref';
import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref';
import {ViewContainerRef as ViewEngine_ViewContainerRef} from '../linker/view_container_ref';
import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_ViewRef} from '../linker/view_ref';
import {Renderer2} from '../render/api';
import {addToArray, removeFromArray} from '../util/array_utils';
import {assertDefined, assertEqual, assertGreaterThan, assertLessThan} from '../util/assert';
import {assertLContainer, assertNodeInjector} from './assert';
import {getParentInjectorLocation, NodeInjector} from './di';
import {addToViewTree, createLContainer, createLView, renderView} from './instructions/shared';
import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE, VIEW_REFS} from './interfaces/container';
import {TNODE} from './interfaces/injector';
import {TContainerNode, TDirectiveHostNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node';
import {isProceduralRenderer, RComment, RElement} from './interfaces/renderer';
import {isComponentHost, isLContainer, isLView, isRootView} from './interfaces/type_checks';
import {DECLARATION_COMPONENT_VIEW, DECLARATION_LCONTAINER, LView, LViewFlags, PARENT, QUERIES, RENDERER, T_HOST, TVIEW, TView} from './interfaces/view';
import {assertNodeOfPossibleTypes} from './node_assert';
import {addViewToContainer, appendChild, destroyLView, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode} from './node_manipulation';
import {getCurrentTNode, getLView} from './state';
import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from './util/injector_utils';
import {getComponentLViewByIndex, getNativeByTNode, unwrapRNode, viewAttachedToContainer} from './util/view_utils';
import {ViewRef} from './view_ref';
@ -43,7 +43,7 @@ import { ViewRef } from './view_ref';
*/
export function injectElementRef(ElementRefToken: typeof ViewEngine_ElementRef):
ViewEngine_ElementRef {
return createElementRef(ElementRefToken, getPreviousOrParentTNode()!, getLView());
return createElementRef(ElementRefToken, getCurrentTNode()!, getLView());
}
let R3ElementRef: {new (native: RElement|RComment): ViewEngine_ElementRef};
@ -78,8 +78,7 @@ let R3TemplateRef: {
export function injectTemplateRef<T>(
TemplateRefToken: typeof ViewEngine_TemplateRef,
ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_TemplateRef<T>|null {
return createTemplateRef<T>(
TemplateRefToken, ElementRefToken, getPreviousOrParentTNode()!, getLView());
return createTemplateRef<T>(TemplateRefToken, ElementRefToken, getCurrentTNode()!, getLView());
}
/**
@ -149,8 +148,7 @@ let R3ViewContainerRef: {
export function injectViewContainerRef(
ViewContainerRefToken: typeof ViewEngine_ViewContainerRef,
ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_ViewContainerRef {
const previousTNode =
getPreviousOrParentTNode() as TElementNode | TElementContainerNode | TContainerNode;
const previousTNode = getCurrentTNode() as TElementNode | TElementContainerNode | TContainerNode;
return createContainerRef(ViewContainerRefToken, ElementRefToken, previousTNode, getLView());
}
@ -407,7 +405,7 @@ export function createContainerRef(
/** Returns a ChangeDetectorRef (a.k.a. a ViewRef) */
export function injectChangeDetectorRef(isPipe = false): ViewEngine_ChangeDetectorRef {
return createViewRef(getPreviousOrParentTNode()!, getLView(), isPipe);
return createViewRef(getCurrentTNode()!, getLView(), isPipe);
}
/**
@ -453,7 +451,7 @@ export function injectRenderer2(): Renderer2 {
// We need the Renderer to be based on the component that it's being injected into, however since
// DI happens before we've entered its view, `getLView` will return the parent view instead.
const lView = getLView();
const tNode = getPreviousOrParentTNode()!;
const tNode = getCurrentTNode()!;
const nodeAtIndex = getComponentLViewByIndex(tNode.index, lView);
return getOrCreateRenderer2(isLView(nodeAtIndex) ? nodeAtIndex : lView);
}

View File

@ -687,7 +687,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
'(lView[0] as Element).appendChild(lView[2])',
'lView[4] = document.createTextNode("World")',
'(lView[2] as Element).appendChild(lView[4])',
'setPreviousOrParentTNode(tView.data[2] as TNode)',
'setCurrentTNode(tView.data[2] as TNode)',
'lView[5] = document.createTextNode("!")',
'(lView[0] as Element).appendChild(lView[5])',
]);

View File

@ -171,10 +171,10 @@
"name": "getConstant"
},
{
"name": "getFirstLContainer"
"name": "getCurrentTNode"
},
{
"name": "getIsParent"
"name": "getFirstLContainer"
},
{
"name": "getLView"
@ -200,9 +200,6 @@
{
"name": "getOrCreateTNode"
},
{
"name": "getPreviousOrParentTNode"
},
{
"name": "getSimpleChangesStore"
},
@ -245,6 +242,9 @@
{
"name": "isCssClassMatching"
},
{
"name": "isCurrentTNodeParent"
},
{
"name": "isInlineTemplate"
},
@ -323,6 +323,9 @@
{
"name": "setCurrentQueryIndex"
},
{
"name": "setCurrentTNode"
},
{
"name": "setDirectiveInputsWhichShadowsStyling"
},
@ -335,9 +338,6 @@
{
"name": "setInputsFromAttrs"
},
{
"name": "setPreviousOrParentTNode"
},
{
"name": "setSelectedIndex"
},

View File

@ -965,6 +965,9 @@
{
"name": "getConstant"
},
{
"name": "getCurrentTNode"
},
{
"name": "getDOM"
},
@ -986,9 +989,6 @@
{
"name": "getInjectorIndex"
},
{
"name": "getIsParent"
},
{
"name": "getLCleanup"
},
@ -1052,9 +1052,6 @@
{
"name": "getPreviousIndex"
},
{
"name": "getPreviousOrParentTNode"
},
{
"name": "getPromiseCtor"
},
@ -1172,6 +1169,9 @@
{
"name": "isCssClassMatching"
},
{
"name": "isCurrentTNodeParent"
},
{
"name": "isDirectiveHost"
},
@ -1499,6 +1499,9 @@
{
"name": "setCurrentQueryIndex"
},
{
"name": "setCurrentTNode"
},
{
"name": "setDirectiveInputsWhichShadowsStyling"
},
@ -1517,9 +1520,6 @@
{
"name": "setLocaleId"
},
{
"name": "setPreviousOrParentTNode"
},
{
"name": "setSelectedIndex"
},

View File

@ -119,6 +119,9 @@
{
"name": "getComponentLViewByIndex"
},
{
"name": "getCurrentTNode"
},
{
"name": "getFirstLContainer"
},
@ -134,9 +137,6 @@
{
"name": "getOrCreateTNode"
},
{
"name": "getPreviousOrParentTNode"
},
{
"name": "getSimpleChangesStore"
},
@ -206,15 +206,15 @@
{
"name": "setCurrentQueryIndex"
},
{
"name": "setCurrentTNode"
},
{
"name": "setIncludeViewProviders"
},
{
"name": "setInjectImplementation"
},
{
"name": "setPreviousOrParentTNode"
},
{
"name": "setSelectedIndex"
},

View File

@ -1280,6 +1280,9 @@
{
"name": "getCurrentQueryIndex"
},
{
"name": "getCurrentTNode"
},
{
"name": "getDOM"
},
@ -1310,9 +1313,6 @@
{
"name": "getInjectorIndex"
},
{
"name": "getIsParent"
},
{
"name": "getLCleanup"
},
@ -1388,9 +1388,6 @@
{
"name": "getPreviousIndex"
},
{
"name": "getPreviousOrParentTNode"
},
{
"name": "getPromiseCtor"
},
@ -1508,6 +1505,9 @@
{
"name": "isCssClassMatching"
},
{
"name": "isCurrentTNodeParent"
},
{
"name": "isDirectiveHost"
},
@ -1832,6 +1832,9 @@
{
"name": "setCurrentQueryIndex"
},
{
"name": "setCurrentTNode"
},
{
"name": "setDirectiveInputsWhichShadowsStyling"
},
@ -1850,9 +1853,6 @@
{
"name": "setLocaleId"
},
{
"name": "setPreviousOrParentTNode"
},
{
"name": "setRouterState"
},

View File

@ -344,6 +344,9 @@
{
"name": "getConstant"
},
{
"name": "getCurrentTNode"
},
{
"name": "getDebugContext"
},
@ -353,9 +356,6 @@
{
"name": "getInjectorIndex"
},
{
"name": "getIsParent"
},
{
"name": "getLCleanup"
},
@ -410,9 +410,6 @@
{
"name": "getPreviousIndex"
},
{
"name": "getPreviousOrParentTNode"
},
{
"name": "getSelectedIndex"
},
@ -482,6 +479,9 @@
{
"name": "isCssClassMatching"
},
{
"name": "isCurrentTNodeParent"
},
{
"name": "isDirectiveHost"
},
@ -650,6 +650,9 @@
{
"name": "setCurrentQueryIndex"
},
{
"name": "setCurrentTNode"
},
{
"name": "setDirectiveInputsWhichShadowsStyling"
},
@ -665,9 +668,6 @@
{
"name": "setInputsFromAttrs"
},
{
"name": "setPreviousOrParentTNode"
},
{
"name": "setSelectedIndex"
},

View File

@ -128,7 +128,7 @@ describe('i18n debug', () => {
it('should print ElementEnd', () => {
expect(i18nMutateOpCodesToString([
1 << I18nMutateOpCode.SHIFT_REF | I18nMutateOpCode.ElementEnd,
])).toEqual(['setPreviousOrParentTNode(tView.data[1] as TNode)']);
])).toEqual(['setCurrentTNode(tView.data[1] as TNode)']);
});
it('should print RemoveNestedIcu', () => {

View File

@ -112,13 +112,13 @@ describe('Runtime i18n', () => {
'(lView[1] as Element).appendChild(lView[2])',
'lView[5] = document.createTextNode("world")',
'(lView[2] as Element).appendChild(lView[5])',
'setPreviousOrParentTNode(tView.data[2] as TNode)',
'setCurrentTNode(tView.data[2] as TNode)',
'lView[6] = document.createTextNode(" and ")',
'(lView[1] as Element).appendChild(lView[6])',
'(lView[1] as Element).appendChild(lView[3])',
'lView[7] = document.createTextNode("universe")',
'(lView[3] as Element).appendChild(lView[7])',
'setPreviousOrParentTNode(tView.data[3] as TNode)',
'setCurrentTNode(tView.data[3] as TNode)',
'lView[8] = document.createTextNode("!")',
'(lView[1] as Element).appendChild(lView[8])',
]),
@ -221,8 +221,7 @@ describe('Runtime i18n', () => {
'(lView[1] as Element).appendChild(lView[3])',
'(lView[1] as Element).appendChild(lView[16381])',
'lView[4] = document.createTextNode("after")',
'(lView[1] as Element).appendChild(lView[4])',
'setPreviousOrParentTNode(tView.data[1] as TNode)'
'(lView[1] as Element).appendChild(lView[4])', 'setCurrentTNode(tView.data[1] as TNode)'
]),
update: [],
icus: null
@ -242,8 +241,7 @@ describe('Runtime i18n', () => {
create: debugMatch([
'(lView[0] as Element).appendChild(lView[1])',
'lView[2] = document.createTextNode("middle")',
'(lView[1] as Element).appendChild(lView[2])',
'setPreviousOrParentTNode(tView.data[1] as TNode)'
'(lView[1] as Element).appendChild(lView[2])', 'setCurrentTNode(tView.data[1] as TNode)'
]),
update: [],
icus: null

View File

@ -236,7 +236,7 @@ export function resetDOM() {
containerEl.setAttribute('host', '');
document.body.appendChild(containerEl);
hostView = null;
// TODO: assert that the global state is clean (e.g. ngData, previousOrParentNode, etc)
// TODO: assert that the global state is clean (e.g. ngData, currentTNode, etc)
}