Skip to content

Commit 83a1334

Browse files
karaIgorMinar
authored andcommitted
refactor(ivy): migrate previousOrParentNode to use TNodes (angular#25829)
PR Close angular#25829
1 parent 2a21ca0 commit 83a1334

File tree

10 files changed

+193
-170
lines changed

10 files changed

+193
-170
lines changed

packages/core/src/render3/component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function renderComponent<T>(
111111
componentDef.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways);
112112
rootView[INJECTOR] = opts.injector || null;
113113

114-
const oldView = enterView(rootView, null !);
114+
const oldView = enterView(rootView, null);
115115
let elementNode: LElementNode;
116116
let component: T;
117117
try {
@@ -121,7 +121,7 @@ export function renderComponent<T>(
121121
elementNode = hostElement(componentTag, hostNode, componentDef, sanitizer);
122122

123123
// Create directive instance with factory() and store at index 0 in directives array
124-
component = baseDirectiveCreate(0, componentDef.factory() as T, componentDef);
124+
component = baseDirectiveCreate(0, componentDef.factory() as T, componentDef, elementNode);
125125
if (componentDef.hostBindings) {
126126
queueHostBindingForCheck(0, componentDef.hostVars);
127127
}

packages/core/src/render3/component_ref.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
126126
rootView[INJECTOR] = ngModule && ngModule.injector || null;
127127

128128
// rootView is the parent when bootstrapping
129-
const oldView = enterView(rootView, null !);
129+
const oldView = enterView(rootView, null);
130130

131131
let component: T;
132132
let elementNode: LElementNode;
@@ -137,7 +137,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
137137
elementNode = hostElement(componentTag, hostNode, this.componentDef);
138138

139139
// Create directive instance with factory() and store at index 0 in directives array
140-
component = baseDirectiveCreate(0, this.componentDef.factory(), this.componentDef);
140+
component =
141+
baseDirectiveCreate(0, this.componentDef.factory(), this.componentDef, elementNode);
141142
if (this.componentDef.hostBindings) {
142143
queueHostBindingForCheck(0, this.componentDef.hostVars);
143144
}

packages/core/src/render3/di.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {Type} from '../type';
2424

2525
import {assertDefined, assertGreaterThan, assertLessThan} from './assert';
2626
import {ComponentFactoryResolver} from './component_ref';
27-
import {addToViewTree, assertPreviousIsParent, createEmbeddedViewNode, createLContainer, createLNodeObject, createTNode, getPreviousOrParentNode, getRenderer, isComponent, renderEmbeddedTemplate, resolveDirective} from './instructions';
27+
import {addToViewTree, assertPreviousIsParent, createEmbeddedViewNode, createLContainer, createLNodeObject, createTNode, getPreviousOrParentNode, getPreviousOrParentTNode, getRenderer, isComponent, renderEmbeddedTemplate, resolveDirective} from './instructions';
2828
import {VIEWS} from './interfaces/container';
2929
import {DirectiveDefInternal, RenderFlags} from './interfaces/definition';
3030
import {LInjector} from './interfaces/injector';
@@ -273,10 +273,9 @@ export function injectRenderer2(): Renderer2 {
273273
* @experimental
274274
*/
275275
export function injectAttribute(attrNameToInject: string): string|undefined {
276-
const lNode = getPreviousOrParentNode();
276+
const tNode = getPreviousOrParentTNode();
277277
ngDevMode && assertNodeOfPossibleTypes(
278-
lNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
279-
const tNode = lNode.tNode;
278+
tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
280279
ngDevMode && assertDefined(tNode, 'expecting tNode');
281280
const attrs = tNode.attrs;
282281
if (attrs) {
@@ -573,8 +572,9 @@ export const QUERY_READ_ELEMENT_REF =
573572

574573
export const QUERY_READ_FROM_NODE =
575574
(new ReadFromInjectorFn<any>((injector: LInjector, node: LNode, directiveIdx: number) => {
576-
ngDevMode && assertNodeOfPossibleTypes(
577-
node, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
575+
ngDevMode &&
576+
assertNodeOfPossibleTypes(
577+
node.tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
578578
if (directiveIdx > -1) {
579579
return node.view[DIRECTIVES] ![directiveIdx];
580580
}
@@ -605,17 +605,17 @@ class ElementRef implements viewEngine_ElementRef {
605605
export function getOrCreateContainerRef(di: LInjector): viewEngine_ViewContainerRef {
606606
if (!di.viewContainerRef) {
607607
const vcRefHost = di.node;
608+
const hostTNode = vcRefHost.tNode as TElementNode | TContainerNode;
608609

609610
ngDevMode && assertNodeOfPossibleTypes(
610-
vcRefHost, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
611+
hostTNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
611612
const hostParent = getParentLNode(vcRefHost) !;
612613
const lContainer = createLContainer(hostParent, vcRefHost.view, true);
613614
const comment = vcRefHost.view[RENDERER].createComment(ngDevMode ? 'container' : '');
614-
const lContainerNode: LContainerNode =
615-
createLNodeObject(TNodeType.Container, vcRefHost.view, hostParent, comment, lContainer);
615+
const lContainerNode: LContainerNode = createLNodeObject(
616+
TNodeType.Container, vcRefHost.view, vcRefHost.nodeInjector, comment, lContainer);
616617
appendChild(hostParent, comment, vcRefHost.view);
617618

618-
const hostTNode = vcRefHost.tNode as TElementNode | TContainerNode;
619619
if (!hostTNode.dynamicContainerNode) {
620620
hostTNode.dynamicContainerNode =
621621
createTNode(TNodeType.Container, -1, null, null, hostTNode, null);
@@ -785,9 +785,9 @@ class ViewContainerRef implements viewEngine_ViewContainerRef {
785785
*/
786786
export function getOrCreateTemplateRef<T>(di: LInjector): viewEngine_TemplateRef<T> {
787787
if (!di.templateRef) {
788-
ngDevMode && assertNodeType(di.node, TNodeType.Container);
789788
const hostNode = di.node as LContainerNode;
790789
const hostTNode = hostNode.tNode;
790+
ngDevMode && assertNodeType(hostTNode, TNodeType.Container);
791791
ngDevMode && assertDefined(hostTNode.tViews, 'TView must be allocated');
792792
di.templateRef = new TemplateRef<any>(
793793
hostNode.view, getOrCreateElementRef(di), hostTNode.tViews as TView, getRenderer(),
@@ -845,4 +845,4 @@ class TemplateRef<T> implements viewEngine_TemplateRef<T> {
845845
*/
846846
export function templateRefExtractor(lNode: LNodeWithLocalRefs) {
847847
return getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(lNode));
848-
}
848+
}

0 commit comments

Comments
 (0)