From 96499c898f9fd2a3317d2cc7a35ff174c3efceac Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Mon, 18 Nov 2019 11:23:47 +0100 Subject: [PATCH] refactor(ivy): separate first creation pass in the text instruction (#33894) PR Close #33894 --- .../core/src/render3/instructions/text.ts | 23 ++++++++++++------- .../hello_world/bundle.golden_symbols.json | 3 --- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/core/src/render3/instructions/text.ts b/packages/core/src/render3/instructions/text.ts index b223b7ae1f..7f97e05c16 100644 --- a/packages/core/src/render3/instructions/text.ts +++ b/packages/core/src/render3/instructions/text.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ import {assertDataInRange, assertEqual} from '../../util/assert'; -import {TNodeType} from '../interfaces/node'; +import {TElementNode, TNodeType} from '../interfaces/node'; import {HEADER_OFFSET, RENDERER, TVIEW, T_HOST} from '../interfaces/view'; import {appendChild, createTextNode} from '../node_manipulation'; -import {getBindingIndex, getLView, setIsNotParent} from '../state'; +import {getBindingIndex, getLView, setPreviousOrParentTNode} from '../state'; import {getOrCreateTNode} from './shared'; @@ -25,14 +25,21 @@ import {getOrCreateTNode} from './shared'; */ export function ɵɵtext(index: number, value: string = ''): void { const lView = getLView(); + const tView = lView[TVIEW]; + const adjustedIndex = index + HEADER_OFFSET; + ngDevMode && assertEqual( - getBindingIndex(), lView[TVIEW].bindingStartIndex, + getBindingIndex(), tView.bindingStartIndex, 'text nodes should be created before any bindings'); - ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET); - const textNative = lView[index + HEADER_OFFSET] = createTextNode(value, lView[RENDERER]); - const tNode = getOrCreateTNode(lView[TVIEW], lView[T_HOST], index, TNodeType.Element, null, null); + ngDevMode && assertDataInRange(lView, adjustedIndex); + + const tNode = tView.firstCreatePass ? + getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.Element, null, null) : + tView.data[adjustedIndex] as TElementNode; + + const textNative = lView[adjustedIndex] = createTextNode(value, lView[RENDERER]); + appendChild(textNative, tNode, lView); // Text nodes are self closing. - setIsNotParent(); - appendChild(textNative, tNode, lView); + setPreviousOrParentTNode(tNode, false); } 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 c25378dfcf..c950037e12 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -464,9 +464,6 @@ { "name": "setInjectImplementation" }, - { - "name": "setIsNotParent" - }, { "name": "setPreviousOrParentTNode" },