Misko Hevery 54303688fa refactor(core): Consistent use of HEADER_OFFSET (in ɵɵ* instructions only) (#39233)
IMPORTANT: `HEADER_OFFSET` should only be refereed to the in the `ɵɵ*` instructions to translate
instruction index into `LView` index. All other indexes should be in the `LView` index space and
there should be no need to refer to `HEADER_OFFSET` anywhere else.

PR Close #39233
2020-10-21 18:33:00 -07:00

47 lines
1.5 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
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, setCurrentTNode} from '../state';
import {getOrCreateTNode} from './shared';
/**
* Create static text node
*
* @param index Index of the node in the data array
* @param value Static string value to write.
*
* @codeGenApi
*/
export function ɵɵtext(index: number, value: string = ''): void {
const lView = getLView();
const tView = getTView();
const adjustedIndex = index + HEADER_OFFSET;
ngDevMode &&
assertEqual(
getBindingIndex(), tView.bindingStartIndex,
'text nodes should be created before any bindings');
ngDevMode && assertIndexInRange(lView, adjustedIndex);
const tNode = tView.firstCreatePass ?
getOrCreateTNode(tView, adjustedIndex, TNodeType.Text, value, null) :
tView.data[adjustedIndex] as TElementNode;
const textNative = lView[adjustedIndex] = createTextNode(lView[RENDERER], value);
appendChild(tView, lView, textNative, tNode);
// Text nodes are self closing.
setCurrentTNode(tNode, false);
}