diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index 927d8a5104..3b794ae9b5 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -23,7 +23,7 @@ import {ComponentDef, ComponentType, RenderFlags} from './interfaces/definition' import {TElementNode, TNode, TNodeFlags, TNodeType} from './interfaces/node'; import {PlayerHandler} from './interfaces/player'; import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from './interfaces/renderer'; -import {CONTEXT, FLAGS, HEADER_OFFSET, HOST, HOST_NODE, LView, LViewFlags, RootContext, RootContextFlags, TVIEW} from './interfaces/view'; +import {CONTEXT, FLAGS, HEADER_OFFSET, HOST, LView, LViewFlags, RootContext, RootContextFlags, TVIEW, T_HOST} from './interfaces/view'; import {enterView, getPreviousOrParentTNode, leaveView, resetComponentState, setCurrentDirectiveDef} from './state'; import {defaultScheduler, getRootView, readPatchedLView, renderStringify} from './util'; @@ -122,8 +122,8 @@ export function renderComponent( const renderer = rendererFactory.createRenderer(hostRNode, componentDef); const rootView: LView = createLView( - null, createTView(-1, null, 1, 0, null, null, null), rootContext, rootFlags, rendererFactory, - renderer, undefined, opts.injector || null); + null, createTView(-1, null, 1, 0, null, null, null), rootContext, rootFlags, null, null, + rendererFactory, renderer, undefined, opts.injector || null); const oldView = enterView(rootView, null); let component: T; @@ -163,13 +163,13 @@ export function createRootComponentView( rendererFactory: RendererFactory3, renderer: Renderer3, sanitizer?: Sanitizer | null): LView { resetComponentState(); const tView = rootView[TVIEW]; + const tNode: TElementNode = createNodeAtIndex(0, TNodeType.Element, rNode, null, null); const componentView = createLView( rootView, getOrCreateTView( def.template, def.consts, def.vars, def.directiveDefs, def.pipeDefs, def.viewQuery), - null, def.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways, rendererFactory, renderer, - sanitizer); - const tNode = createNodeAtIndex(0, TNodeType.Element, rNode, null, null); + null, def.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways, rootView[HEADER_OFFSET], tNode, + rendererFactory, renderer, sanitizer); if (tView.firstTemplatePass) { diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, rootView), rootView, def.type); @@ -179,8 +179,6 @@ export function createRootComponentView( } // Store component view at node index, with node as the HOST - componentView[HOST] = rootView[HEADER_OFFSET]; - componentView[HOST_NODE] = tNode as TElementNode; return rootView[HEADER_OFFSET] = componentView; } diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index 354c59f668..78721801a4 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -161,7 +161,7 @@ export class ComponentFactory extends viewEngine_ComponentFactory { // Create the root view. Uses empty TView and ContentTemplate. const rootLView = createLView( - null, createTView(-1, null, 1, 0, null, null, null), rootContext, rootFlags, + null, createTView(-1, null, 1, 0, null, null, null), rootContext, rootFlags, null, null, rendererFactory, renderer, sanitizer, rootViewInjector); // rootView is the parent when bootstrapping diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 11035c4a7d..ca0a8f66c6 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -18,7 +18,7 @@ import {NG_ELEMENT_ID} from './fields'; import {DirectiveDef} from './interfaces/definition'; import {NO_PARENT_INJECTOR, NodeInjectorFactory, PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFlags, TNODE, isFactory} from './interfaces/injector'; import {AttributeMarker, TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeProviderIndexes, TNodeType} from './interfaces/node'; -import {DECLARATION_VIEW, HOST_NODE, INJECTOR, LView, TData, TVIEW, TView} from './interfaces/view'; +import {DECLARATION_VIEW, INJECTOR, LView, TData, TVIEW, TView, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; import {getLView, getPreviousOrParentTNode, setTNodeAndViewData} from './state'; import {findComponentView, getParentInjectorIndex, getParentInjectorView, hasParentInjector, isComponent, isComponentDef, renderStringify} from './util'; @@ -205,11 +205,11 @@ export function getParentInjectorLocation(tNode: TNode, view: LView): RelativeIn // For most cases, the parent injector index can be found on the host node (e.g. for component // or container), so this loop will be skipped, but we must keep the loop here to support // the rarer case of deeply nested tags or inline views. - let hostTNode = view[HOST_NODE]; + let hostTNode = view[T_HOST]; let viewOffset = 1; while (hostTNode && hostTNode.injectorIndex === -1) { view = view[DECLARATION_VIEW] !; - hostTNode = view ? view[HOST_NODE] : null; + hostTNode = view ? view[T_HOST] : null; viewOffset++; } @@ -332,7 +332,7 @@ export function getOrCreateInjectable( let injectorIndex = getInjectorIndex(tNode, lView); let parentLocation: RelativeInjectorLocation = NO_PARENT_INJECTOR; let hostTElementNode: TNode|null = - flags & InjectFlags.Host ? findComponentView(lView)[HOST_NODE] : null; + flags & InjectFlags.Host ? findComponentView(lView)[T_HOST] : null; // If we should skip this injector, or if there is no injector on this node, start by // searching diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index 31d6ff3125..a791d7f4a7 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -19,7 +19,7 @@ import {TElementNode, TIcuContainerNode, TNode, TNodeType} from './interfaces/no import {RComment, RElement} from './interfaces/renderer'; import {SanitizerFn} from './interfaces/sanitization'; import {StylingContext} from './interfaces/styling'; -import {BINDING_INDEX, HEADER_OFFSET, HOST_NODE, LView, RENDERER, TVIEW, TView} from './interfaces/view'; +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 {NO_CHANGE} from './tokens'; @@ -368,9 +368,8 @@ function i18nStartFirstPass( const previousOrParentTNode = getPreviousOrParentTNode(); const parentTNode = getIsParent() ? getPreviousOrParentTNode() : previousOrParentTNode && previousOrParentTNode.parent; - let parentIndex = parentTNode && parentTNode !== viewData[HOST_NODE] ? - parentTNode.index - HEADER_OFFSET : - index; + let parentIndex = + parentTNode && parentTNode !== viewData[T_HOST] ? parentTNode.index - HEADER_OFFSET : index; let parentIndexPointer = 0; parentIndexStack[parentIndexPointer] = parentIndex; const createOpCodes: I18nMutateOpCodes = []; @@ -482,7 +481,7 @@ function appendI18nNode(tNode: TNode, parentTNode: TNode, previousTNode: TNode | tNode.next = null; } - if (parentTNode !== viewData[HOST_NODE]) { + if (parentTNode !== viewData[T_HOST]) { tNode.parent = parentTNode as TElementNode; } @@ -665,7 +664,7 @@ function readCreateOpCodes( if (destinationNodeIndex === index) { // If the destination node is `i18nStart`, we don't have a // top-level node and we should use the host node instead - destinationTNode = viewData[HOST_NODE] !; + destinationTNode = viewData[T_HOST] !; } else { destinationTNode = getTNode(destinationNodeIndex, viewData); } diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index 28935daa5c..b4cfa1e870 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -30,9 +30,9 @@ import {AttributeMarker, InitialInputData, InitialInputs, LocalRefExtractor, Pro import {PlayerFactory} from './interfaces/player'; import {CssSelectorList, NG_PROJECT_AS_ATTR_NAME} from './interfaces/projection'; import {LQueries} from './interfaces/query'; -import {GlobalTargetResolver, ProceduralRenderer3, RComment, RElement, RText, Renderer3, RendererFactory3, isProceduralRenderer} from './interfaces/renderer'; +import {GlobalTargetResolver, ProceduralRenderer3, RComment, RElement, RNode, RText, Renderer3, RendererFactory3, isProceduralRenderer} from './interfaces/renderer'; import {SanitizerFn} from './interfaces/sanitization'; -import {BINDING_INDEX, CLEANUP, CONTAINER_INDEX, CONTEXT, DECLARATION_VIEW, FLAGS, HEADER_OFFSET, HOST, HOST_NODE, INJECTOR, InitPhaseState, LView, LViewFlags, NEXT, OpaqueViewState, PARENT, QUERIES, RENDERER, RENDERER_FACTORY, RootContext, RootContextFlags, SANITIZER, TAIL, TData, TVIEW, TView} from './interfaces/view'; +import {BINDING_INDEX, CLEANUP, CONTAINER_INDEX, CONTEXT, DECLARATION_VIEW, FLAGS, HEADER_OFFSET, HOST, INJECTOR, InitPhaseState, LView, LViewFlags, NEXT, OpaqueViewState, PARENT, QUERIES, RENDERER, RENDERER_FACTORY, RootContext, RootContextFlags, SANITIZER, TAIL, TData, TVIEW, TView, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert'; import {appendChild, appendProjectedNode, createTextNode, getLViewChild, insertView, removeView} from './node_manipulation'; import {isNodeMatchingSelectorList, matchingSelectorIndex} from './node_selector_matcher'; @@ -156,6 +156,7 @@ function refreshChildComponents(components: number[] | null): void { export function createLView( parentLView: LView | null, tView: TView, context: T | null, flags: LViewFlags, + host: RElement | null, tHostNode: TViewNode | TElementNode | null, rendererFactory?: RendererFactory3 | null, renderer?: Renderer3 | null, sanitizer?: Sanitizer | null, injector?: Injector | null): LView { const lView = tView.blueprint.slice() as LView; @@ -168,6 +169,8 @@ export function createLView( ngDevMode && assertDefined(lView[RENDERER], 'Renderer is required'); lView[SANITIZER] = sanitizer || parentLView && parentLView[SANITIZER] || null !; lView[INJECTOR as any] = injector || parentLView && parentLView[INJECTOR] || null; + lView[HOST] = host; + lView[T_HOST] = tHostNode; return lView; } @@ -216,7 +219,7 @@ export function createNodeAtIndex( // Parents cannot cross component boundaries because components will be used in multiple places, // so it's only set if the view is the same. - const parentInSameView = parent && parent !== lView[HOST_NODE]; + const parentInSameView = parent && parent !== lView[T_HOST]; const tParentNode = parentInSameView ? parent as TElementNode | TContainerNode : null; tNode = tView.data[adjustedIndex] = createTNode(tParentNode, type, adjustedIndex, name, attrs); @@ -258,7 +261,7 @@ export function assignTViewNodeToLView( TNodeType.View, index, null, null) as TViewNode; } - return lView[HOST_NODE] = tNode as TViewNode; + return lView[T_HOST] = tNode as TViewNode; } @@ -306,28 +309,28 @@ export function allocExpando(view: LView, numSlotsToAlloc: number) { */ export function renderTemplate( hostNode: RElement, templateFn: ComponentTemplate, consts: number, vars: number, context: T, - providedRendererFactory: RendererFactory3, hostView: LView | null, + providedRendererFactory: RendererFactory3, componentView: LView | null, directives?: DirectiveDefListOrFactory | null, pipes?: PipeDefListOrFactory | null, sanitizer?: Sanitizer | null): LView { - if (hostView == null) { + if (componentView === null) { resetComponentState(); const renderer = providedRendererFactory.createRenderer(null, null); // We need to create a root view so it's possible to look up the host element through its index const hostLView = createLView( null, createTView(-1, null, 1, 0, null, null, null), {}, - LViewFlags.CheckAlways | LViewFlags.IsRoot, providedRendererFactory, renderer); + LViewFlags.CheckAlways | LViewFlags.IsRoot, null, null, providedRendererFactory, renderer); enterView(hostLView, null); // SUSPECT! why do we need to enter the View? const componentTView = getOrCreateTView(templateFn, consts, vars, directives || null, pipes || null, null); - hostView = createLView( - hostLView, componentTView, context, LViewFlags.CheckAlways, providedRendererFactory, - renderer, sanitizer); - hostView[HOST_NODE] = createNodeAtIndex(0, TNodeType.Element, hostNode, null, null); + const hostTNode = createNodeAtIndex(0, TNodeType.Element, hostNode, null, null); + componentView = createLView( + hostLView, componentTView, context, LViewFlags.CheckAlways, hostNode, hostTNode, + providedRendererFactory, renderer, sanitizer); } - renderComponentOrTemplate(hostView, context, templateFn); - return hostView; + renderComponentOrTemplate(componentView, context, templateFn); + return componentView; } /** @@ -343,7 +346,7 @@ export function createEmbeddedViewAndNode( setIsParent(true); setPreviousOrParentTNode(null !); - const lView = createLView(declarationView, tView, context, LViewFlags.CheckAlways); + const lView = createLView(declarationView, tView, context, LViewFlags.CheckAlways, null, null); lView[DECLARATION_VIEW] = declarationView; if (queries) { @@ -382,7 +385,7 @@ export function renderEmbeddedTemplate(viewToRender: LView, tView: TView, con setIsParent(true); setPreviousOrParentTNode(null !); - oldView = enterView(viewToRender, viewToRender[HOST_NODE]); + oldView = enterView(viewToRender, viewToRender[T_HOST]); namespaceHTML(); tView.template !(getRenderFlags(viewToRender), context); // This must be set to false immediately after the first creation run because in an @@ -417,7 +420,7 @@ export function nextContext(level: number = 1): T { function renderComponentOrTemplate( hostView: LView, context: T, templateFn?: ComponentTemplate) { const rendererFactory = hostView[RENDERER_FACTORY]; - const oldView = enterView(hostView, hostView[HOST_NODE]); + const oldView = enterView(hostView, hostView[T_HOST]); const normalExecutionPath = !getCheckNoChangesMode(); const creationModeIsActive = isCreationMode(hostView); try { @@ -1962,13 +1965,13 @@ function addComponentLogic( lView, previousOrParentTNode.index as number, 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))); - componentView[HOST_NODE] = previousOrParentTNode as TElementNode; + componentView[T_HOST] = previousOrParentTNode as TElementNode; // Component view will always be created before any injected LContainers, // so this is a regular element, wrap it with the component view - componentView[HOST] = lView[previousOrParentTNode.index]; lView[previousOrParentTNode.index] = componentView; if (lView[TVIEW].firstTemplatePass) { @@ -2308,7 +2311,7 @@ export function embeddedViewStart(viewBlockId: number, consts: number, vars: num viewToRender = createLView( lView, getOrCreateEmbeddedTView(viewBlockId, consts, vars, containerTNode as TContainerNode), null, - LViewFlags.CheckAlways); + LViewFlags.CheckAlways, null, null); if (lContainer[QUERIES]) { viewToRender[QUERIES] = lContainer[QUERIES] !.createView(); @@ -2360,7 +2363,7 @@ function getOrCreateEmbeddedTView( /** Marks the end of an embedded view. */ export function embeddedViewEnd(): void { const lView = getLView(); - const viewHost = lView[HOST_NODE]; + const viewHost = lView[T_HOST]; if (isCreationMode(lView)) { refreshDescendantViews(lView); // creation mode pass @@ -2452,7 +2455,7 @@ export function viewAttached(view: LView): boolean { * @param rawSelectors A collection of CSS selectors in the raw, un-parsed form */ export function projectionDef(selectors?: CssSelectorList[], textSelectors?: string[]): void { - const componentNode = findComponentView(getLView())[HOST_NODE] as TElementNode; + const componentNode = findComponentView(getLView())[T_HOST] as TElementNode; if (!componentNode.projection) { const noOfNodeBuckets = selectors ? selectors.length + 1 : 1; @@ -2511,7 +2514,7 @@ export function projection(nodeIndex: number, selectorIndex: number = 0, attrs?: // re-distribution of projectable nodes is stored on a component's view level const componentView = findComponentView(lView); - const componentNode = componentView[HOST_NODE] as TElementNode; + const componentNode = componentView[T_HOST] as TElementNode; let nodeToProject = (componentNode.projection as(TNode | null)[])[selectorIndex]; let projectedView = componentView[PARENT] !; let projectionNodeIndex = -1; @@ -2523,7 +2526,7 @@ export function projection(nodeIndex: number, selectorIndex: number = 0, attrs?: if (nodeToProject.type === TNodeType.Projection) { // This node is re-projected, so we must go up the tree to get its projected nodes. const currentComponentView = findComponentView(projectedView); - const currentComponentHost = currentComponentView[HOST_NODE] as TElementNode; + const currentComponentHost = currentComponentView[T_HOST] as TElementNode; const firstProjectedNode = (currentComponentHost.projection as( TNode | null)[])[nodeToProject.projection as number]; @@ -2799,7 +2802,7 @@ export function checkNoChangesInRootView(lView: LView): void { /** Checks the view of the component provided. Does not gate on dirty checks or execute doCheck. */ export function checkView(hostView: LView, component: T) { const hostTView = hostView[TVIEW]; - const oldView = enterView(hostView, hostView[HOST_NODE]); + const oldView = enterView(hostView, hostView[T_HOST]); const templateFn = hostTView.template !; const creationMode = isCreationMode(hostView); diff --git a/packages/core/src/render3/interfaces/view.ts b/packages/core/src/render3/interfaces/view.ts index 20f41e30f4..dff84dfe0d 100644 --- a/packages/core/src/render3/interfaces/view.ts +++ b/packages/core/src/render3/interfaces/view.ts @@ -32,7 +32,7 @@ export const PARENT = 2; export const NEXT = 3; export const QUERIES = 4; export const HOST = 5; -export const HOST_NODE = 6; // Rename to `T_HOST`? +export const T_HOST = 6; export const BINDING_INDEX = 7; export const CLEANUP = 8; export const CONTEXT = 9; @@ -118,7 +118,7 @@ export interface LView extends Array { * * If null, this is the root view of an application (root component is in this view). */ - [HOST_NODE]: TViewNode|TElementNode|null; + [T_HOST]: TViewNode|TElementNode|null; /** * The binding index we should access next. diff --git a/packages/core/src/render3/node_manipulation.ts b/packages/core/src/render3/node_manipulation.ts index 4fb1b6ce05..d0307d63cc 100644 --- a/packages/core/src/render3/node_manipulation.ts +++ b/packages/core/src/render3/node_manipulation.ts @@ -7,6 +7,7 @@ */ import {ViewEncapsulation} from '../metadata/view'; + import {attachPatchData} from './context_discovery'; import {callHooks} from './hooks'; import {LContainer, NATIVE, VIEWS, unusedValueExportToPlacateAjd as unused1} from './interfaces/container'; @@ -14,7 +15,7 @@ import {ComponentDef} from './interfaces/definition'; import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeFlags, TNodeType, TViewNode, unusedValueExportToPlacateAjd as unused2} from './interfaces/node'; import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection'; import {ProceduralRenderer3, RComment, RElement, RNode, RText, Renderer3, isProceduralRenderer, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer'; -import {CLEANUP, CONTAINER_INDEX, FLAGS, HEADER_OFFSET, HOST_NODE, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; +import {CLEANUP, CONTAINER_INDEX, FLAGS, HEADER_OFFSET, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, T_HOST, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; import {assertNodeType} from './node_assert'; import {findComponentView, getNativeByTNode, isComponent, isLContainer, isRootView, readElementValue, renderStringify} from './util'; @@ -107,7 +108,7 @@ function walkTNodeTree( } } else if (tNode.type === TNodeType.Projection) { const componentView = findComponentView(currentView !); - const componentHost = componentView[HOST_NODE] as TElementNode; + const componentHost = componentView[T_HOST] as TElementNode; const head: TNode|null = (componentHost.projection as(TNode | null)[])[tNode.projection as number]; @@ -398,7 +399,7 @@ export function destroyLView(view: LView) { */ export function getParentState(state: LView | LContainer, rootView: LView): LView|LContainer|null { let tNode; - if (state.length >= HEADER_OFFSET && (tNode = (state as LView) ![HOST_NODE]) && + if (state.length >= HEADER_OFFSET && (tNode = (state as LView) ![T_HOST]) && tNode.type === TNodeType.View) { // if it's an embedded view, the state needs to go up to the container, in case the // container has a next @@ -429,7 +430,7 @@ function cleanUpView(viewOrContainer: LView | LContainer): void { executeOnDestroys(view); removeListeners(view); - const hostTNode = view[HOST_NODE]; + const hostTNode = view[T_HOST]; // For component views only, the local renderer is destroyed as clean up time. if (hostTNode && hostTNode.type === TNodeType.Element && isProceduralRenderer(view[RENDERER])) { ngDevMode && ngDevMode.rendererDestroy++; @@ -513,7 +514,7 @@ function getRenderParent(tNode: TNode, currentView: LView): RElement|null { // If the parent is null, then we are inserting across views: either into an embedded view or a // component view. if (parent == null) { - const hostTNode = currentView[HOST_NODE] !; + const hostTNode = currentView[T_HOST] !; if (hostTNode.type === TNodeType.View) { // We are inserting a root element of an embedded view We might delay insertion of children // for a given view if it is disconnected. This might happen for 2 main reasons: @@ -556,7 +557,7 @@ function getRenderParent(tNode: TNode, currentView: LView): RElement|null { * a host element. */ function getHostNative(currentView: LView): RElement|null { - const hostTNode = currentView[HOST_NODE]; + const hostTNode = currentView[T_HOST]; return hostTNode && hostTNode.type === TNodeType.Element ? (getNativeByTNode(hostTNode, currentView[PARENT] !) as RElement) : null; @@ -651,7 +652,7 @@ export function appendChild(childEl: RNode | RNode[], childTNode: TNode, current const renderParent = getRenderParent(childTNode, currentView); if (renderParent != null) { const renderer = currentView[RENDERER]; - const parentTNode: TNode = childTNode.parent || currentView[HOST_NODE] !; + const parentTNode: TNode = childTNode.parent || currentView[T_HOST] !; const anchorNode = getNativeAnchorNode(parentTNode, currentView); if (Array.isArray(childEl)) { for (let nativeNode of childEl) { @@ -680,7 +681,7 @@ function getHighestElementOrICUContainer(tNode: TNode): TNode { export function getBeforeNodeForView(index: number, views: LView[], containerNative: RComment) { if (index + 1 < views.length) { const view = views[index + 1] as LView; - const viewTNode = view[HOST_NODE] as TViewNode; + const viewTNode = view[T_HOST] as TViewNode; return viewTNode.child ? getNativeByTNode(viewTNode.child, view) : containerNative; } else { return containerNative; diff --git a/packages/core/src/render3/state.ts b/packages/core/src/render3/state.ts index 092dbc287c..869ce8a2a1 100644 --- a/packages/core/src/render3/state.ts +++ b/packages/core/src/render3/state.ts @@ -7,11 +7,12 @@ */ import {assertDefined} from '../util/assert'; + import {executeHooks} from './hooks'; import {ComponentDef, DirectiveDef} from './interfaces/definition'; import {TElementNode, TNode, TNodeFlags, TViewNode} from './interfaces/node'; import {LQueries} from './interfaces/query'; -import {BINDING_INDEX, CONTEXT, DECLARATION_VIEW, FLAGS, HOST_NODE, InitPhaseState, LView, LViewFlags, OpaqueViewState, QUERIES, TVIEW} from './interfaces/view'; +import {BINDING_INDEX, CONTEXT, DECLARATION_VIEW, FLAGS, InitPhaseState, LView, LViewFlags, OpaqueViewState, QUERIES, TVIEW, T_HOST} from './interfaces/view'; import {isContentQueryHost} from './util'; @@ -178,7 +179,7 @@ export function getOrCreateCurrentQueries( // If this is the first content query on a node, any existing LQueries needs to be cloned. // In subsequent template passes, the cloning occurs before directive instantiation // in `createDirectivesAndLocals`. - if (previousOrParentTNode && previousOrParentTNode !== lView[HOST_NODE] && + if (previousOrParentTNode && previousOrParentTNode !== lView[T_HOST] && !isContentQueryHost(previousOrParentTNode)) { currentQueries && (currentQueries = lView[QUERIES] = currentQueries.clone()); previousOrParentTNode.flags |= TNodeFlags.hasContentQuery; diff --git a/packages/core/src/render3/util.ts b/packages/core/src/render3/util.ts index a90a6c3001..e07469bf69 100644 --- a/packages/core/src/render3/util.ts +++ b/packages/core/src/render3/util.ts @@ -16,7 +16,8 @@ import {NO_PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFl import {TContainerNode, TElementNode, TNode, TNodeFlags, TNodeType} from './interfaces/node'; import {RComment, RElement, RText} from './interfaces/renderer'; import {StylingContext} from './interfaces/styling'; -import {CONTEXT, DECLARATION_VIEW, FLAGS, HEADER_OFFSET, HOST, HOST_NODE, LView, LViewFlags, PARENT, RootContext, TData, TVIEW, TView} from './interfaces/view'; +import {CONTEXT, DECLARATION_VIEW, FLAGS, HEADER_OFFSET, HOST, LView, LViewFlags, PARENT, RootContext, TData, TVIEW, TView, T_HOST} from './interfaces/view'; + /** @@ -235,12 +236,12 @@ export function getParentInjectorTNode( let viewOffset = getParentInjectorViewOffset(location); // view offset is 1 let parentView = startView; - let parentTNode = startView[HOST_NODE] as TElementNode; + let parentTNode = startView[T_HOST] as TElementNode; // view offset is superior to 1 while (viewOffset > 1) { parentView = parentView[DECLARATION_VIEW] !; - parentTNode = parentView[HOST_NODE] as TElementNode; + parentTNode = parentView[T_HOST] as TElementNode; viewOffset--; } return parentTNode; @@ -270,12 +271,12 @@ export function addAllToArray(items: any[], arr: any[]) { * @returns The host node */ export function findComponentView(lView: LView): LView { - let rootTNode = lView[HOST_NODE]; + let rootTNode = lView[T_HOST]; while (rootTNode && rootTNode.type === TNodeType.View) { ngDevMode && assertDefined(lView[DECLARATION_VIEW], 'lView[DECLARATION_VIEW]'); lView = lView[DECLARATION_VIEW] !; - rootTNode = lView[HOST_NODE]; + rootTNode = lView[T_HOST]; } return lView; diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index c30e2a7bef..f0e6d850dc 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -16,12 +16,13 @@ import {ViewContainerRef as ViewEngine_ViewContainerRef} from '../linker/view_co import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_ViewRef} from '../linker/view_ref'; import {Renderer2} from '../render/api'; import {assertDefined, assertGreaterThan, assertLessThan} from '../util/assert'; + import {NodeInjector, getParentInjectorLocation} from './di'; import {addToViewTree, createEmbeddedViewAndNode, createLContainer, renderEmbeddedTemplate} from './instructions'; import {ACTIVE_INDEX, LContainer, NATIVE, VIEWS} from './interfaces/container'; import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, TViewNode} from './interfaces/node'; import {RComment, RElement, Renderer3, isProceduralRenderer} from './interfaces/renderer'; -import {CONTAINER_INDEX, CONTEXT, HOST_NODE, LView, QUERIES, RENDERER, TView} from './interfaces/view'; +import {CONTAINER_INDEX, CONTEXT, LView, QUERIES, RENDERER, TView, T_HOST} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; import {addRemoveViewFromContainer, appendChild, detachView, getBeforeNodeForView, insertView, nativeInsertBefore, nativeNextSibling, nativeParentNode, removeView} from './node_manipulation'; import {getLView, getPreviousOrParentTNode} from './state'; @@ -29,6 +30,7 @@ import {findComponentView, getComponentViewByIndex, getNativeByTNode, getParentI import {ViewRef} from './view_ref'; + /** * Creates an ElementRef from the most recent node. * @@ -112,7 +114,7 @@ export function createTemplateRef( } renderEmbeddedTemplate(lView, this._tView, context); const viewRef = new ViewRef(lView, context, -1); - viewRef._tViewNode = lView[HOST_NODE] as TViewNode; + viewRef._tViewNode = lView[T_HOST] as TViewNode; return viewRef; } }; diff --git a/packages/core/src/render3/view_ref.ts b/packages/core/src/render3/view_ref.ts index b88ec8cb94..46e7c7a525 100644 --- a/packages/core/src/render3/view_ref.ts +++ b/packages/core/src/render3/view_ref.ts @@ -13,7 +13,7 @@ import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, InternalViewRef as viewEn import {checkNoChanges, checkNoChangesInRootView, checkView, detectChangesInRootView, detectChangesInternal, markViewDirty, storeCleanupFn, viewAttached} from './instructions'; import {TNode, TNodeType, TViewNode} from './interfaces/node'; -import {FLAGS, HOST, HOST_NODE, LView, LViewFlags, PARENT, RENDERER_FACTORY} from './interfaces/view'; +import {FLAGS, HOST, LView, LViewFlags, PARENT, RENDERER_FACTORY, T_HOST} from './interfaces/view'; import {destroyLView} from './node_manipulation'; import {getNativeByTNode} from './util'; @@ -41,7 +41,7 @@ export class ViewRef implements viewEngine_EmbeddedViewRef, viewEngine_Int get rootNodes(): any[] { if (this._lView[HOST] == null) { - const tView = this._lView[HOST_NODE] as TViewNode; + const tView = this._lView[T_HOST] as TViewNode; return collectNativeNodes(this._lView, tView, []); } return []; 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 75d4591dda..c6373060a6 100644 --- a/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json +++ b/packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json @@ -51,7 +51,7 @@ "name": "HOST" }, { - "name": "HOST_NODE" + "name": "T_HOST" }, { "name": "INJECTOR" 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 7c867161ba..5045c31c3a 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -45,7 +45,7 @@ "name": "HOST" }, { - "name": "HOST_NODE" + "name": "T_HOST" }, { "name": "INJECTOR" diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index a7ddca0a12..597509676b 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -81,7 +81,7 @@ "name": "HOST" }, { - "name": "HOST_NODE" + "name": "T_HOST" }, { "name": "INJECTOR" diff --git a/packages/core/test/render3/di_spec.ts b/packages/core/test/render3/di_spec.ts index c6d81ffa32..0499dc8f55 100644 --- a/packages/core/test/render3/di_spec.ts +++ b/packages/core/test/render3/di_spec.ts @@ -2320,8 +2320,8 @@ describe('di', () => { describe('getOrCreateNodeInjector', () => { it('should handle initial undefined state', () => { const contentView = createLView( - null, createTView(-1, null, 1, 0, null, null, null), null, LViewFlags.CheckAlways, - {} as any, {} as any); + null, createTView(-1, null, 1, 0, null, null, null), null, LViewFlags.CheckAlways, null, + null, {} as any, {} as any); const oldView = enterView(contentView, null); try { const parentTNode = createNodeAtIndex(0, TNodeType.Element, null, null, null); diff --git a/packages/core/test/render3/styling/class_and_style_bindings_spec.ts b/packages/core/test/render3/styling/class_and_style_bindings_spec.ts index 690e104c87..29d9a82642 100644 --- a/packages/core/test/render3/styling/class_and_style_bindings_spec.ts +++ b/packages/core/test/render3/styling/class_and_style_bindings_spec.ts @@ -34,8 +34,8 @@ describe('style and class based bindings', () => { const rootContext = createRootContext(requestAnimationFrame.bind(window), playerHandler || null); const lView = createLView( - null, createTView(-1, null, 1, 0, null, null, null), rootContext, LViewFlags.IsRoot, - domRendererFactory3, domRendererFactory3.createRenderer(element, null)); + null, createTView(-1, null, 1, 0, null, null, null), rootContext, LViewFlags.IsRoot, null, + null, domRendererFactory3, domRendererFactory3.createRenderer(element, null)); return lView; }