8000 Previous or parent t nodes always matches tview 10.1.x by mhevery · Pull Request #39029 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Previous or parent t nodes always matches tview 10.1.x #39029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(core): change getPreviousOrParentTNode to return `TNode|nu…
…ll` (#38707)

This change makes `getPreviousOrParentTNode` return `TNode|null` (rather
than just `TNode`) which is more reflective of the reality. The
`getPreviousOrParentTNode` can be `null` upon entering the `LView`.

PR Close #38707
  • Loading branch information
mhevery committed Sep 28, 2020
commit 0fa208f624adf0f3c3cb7bd5e05ac52645323717
2 changes: 1 addition & 1 deletion packages/core/src/render3/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function createRootComponent<T>(
componentDef.contentQueries(RenderFlags.Create, component, rootLView.length - 1);
}

const rootTNode = getPreviousOrParentTNode();
const rootTNode = getPreviousOrParentTNode()!;
if (tView.firstCreatePass &&
(componentDef.hostBindings !== null || componentDef.hostAttrs !== null)) {
const elementIndex = rootTNode.index - HEADER_OFFSET;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/di_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = getPreviousOrParentTNode()!;
const beginIndex = tNode.providerIndexes & TNodeProviderIndexes.ProvidersStartIndexMask;
const endIndex = tNode.directiveStart;
const cptViewProvidersCount =
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/i18n/i18n_parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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 previousOrParentTNode = getPreviousOrParentTNode()!;
const parentTNode =
getIsParent() ? previousOrParentTNode : previousOrParentTNode && previousOrParentTNode.parent;
let parentIndex =
Expand Down Expand Up @@ -212,7 +212,7 @@ export function i18nStartFirstPass(
*/
export function i18nAttributesFirstPass(
lView: LView, tView: TView, index: number, values: string[]) {
const previousElement = getPreviousOrParentTNode();
const previousElement = getPreviousOrParentTNode()!;
const previousElementIndex = previousElement.index - HEADER_OFFSET;
const updateOpCodes: I18nUpdateOpCodes = [];
if (ngDevMode) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/instructions/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function ɵɵdirectiveInject<T>(
* @codeGenApi
*/
export function ɵɵinjectAttribute(attrNameToInject: string): string|null {
return injectAttributeImpl(getPreviousOrParentTNode(), attrNameToInject);
return injectAttributeImpl(getPreviousOrParentTNode()!, attrNameToInject);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/instructions/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function ɵɵelementStart(
* @codeGenApi
*/
export function ɵɵelementEnd(): void {
let previousOrParentTNode = getPreviousOrParentTNode();
let previousOrParentTNode = getPreviousOrParentTNode()!;
ngDevMode && assertDefined(previousOrParentTNode, 'No parent node to close.');
if (getIsParent()) {
setIsNotParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function ɵɵelementContainerStart(
* @codeGenApi
*/
export function ɵɵelementContainerEnd(): void {
let previousOrParentTNode = getPreviousOrParentTNode();
let previousOrParentTNode = getPreviousOrParentTNode()!;
const tView = getTView();
if (getIsParent()) {
setIsNotParent();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function ɵɵlistener(
eventTargetResolver?: GlobalTargetResolver): typeof ɵɵlistener {
const lView = getLView();
const tView = getTView();
const tNode = getPreviousOrParentTNode();
const tNode = getPreviousOrParentTNode()!;
listenerInternal(
tView, lView, lView[RENDERER], tNode, eventName, listenerFn, useCapture, eventTargetResolver);
return ɵɵlistener;
Expand Down Expand Up @@ -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 = getPreviousOrParentTNode()!;
const lView = getLView();
const tView = getTView();
const currentDef = getCurrentDirectiveDef(tView.data);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/instructions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,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 = getPreviousOrParentTNode()!;
if (tView.firstCreatePass) {
if (def.providersResolver) def.providersResolver(def);
generateExpandoInstructionBlock(tView, rootTNode, 1);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +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(),
getTView(), getLView(), predicate, descend, read, false, getPreviousOrParentTNode()!,
directiveIndex);
}

Expand All @@ -524,7 +524,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(),
getTView(), getLView(), predicate, descend, read, true, getPreviousOrParentTNode()!,
directiveIndex);
}

Expand Down
33 changes: 16 additions & 17 deletions packages/core/src/render3/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ interface LFrame {
*
* This is used in conjunction with `isParent`.
*/
// FIXME(misko): should be `TNode|null` (add comment explaining it.)
previousOrParentTNode: TNode;
previousOrParentTNode: TNode|null;

/**
* If `isParent` is:
Expand Down Expand Up @@ -263,7 +262,7 @@ export function ɵɵrestoreView(viewToRestore: OpaqueViewState) {
instructionState.lFrame.contextLView = viewToRestore as any as LView;
}

export function getPreviousOrParentTNode(): TNode {
export function getPreviousOrParentTNode(): TNode|null {
return instructionState.lFrame.previousOrParentTNode;
}

Expand Down Expand Up @@ -441,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, //
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, //
};
parent !== null && (parent.child = lFrame); // link the new LFrame for reuse.
return lFrame;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/render3/v DE16 iew_engine_compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, getPreviousOrParentTNode()!, getLView());
}

let R3ElementRef: {new (native: RElement|RComment): ViewEngine_ElementRef};
Expand Down Expand Up @@ -79,7 +79,7 @@ export function injectTemplateRef<T>(
TemplateRefToken: typeof ViewEngine_TemplateRef,
ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_TemplateRef<T>|null {
return createTemplateRef<T>(
TemplateRefToken, ElementRefToken, getPreviousOrParentTNode(), getLView());
TemplateRefToken, ElementRefToken, getPreviousOrParentTNode()!, getLView());
}

/**
Expand Down Expand Up @@ -407,7 +407,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(getPreviousOrParentTNode()!, getLView(), isPipe);
}

/**
Expand Down Expand Up @@ -453,7 +453,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 = getPreviousOrParentTNode()!;
const nodeAtIndex = getComponentLViewByIndex(tNode.index, lView);
return getOrCreateRenderer2(isLView(nodeAtIndex) ? nodeAtIndex : lView);
}
0