2019-04-01 15:36:43 -07:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 12:08:49 -07:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-04-01 15:36:43 -07:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2020-08-04 12:42:12 -07:00
|
|
|
import {assertEqual, assertIndexInRange} from '../../util/assert';
|
2019-11-18 11:23:47 +01:00
|
|
|
import {TElementNode, TNodeType} from '../interfaces/node';
|
2020-01-30 14:57:44 -08:00
|
|
|
import {HEADER_OFFSET, RENDERER, T_HOST} from '../interfaces/view';
|
2019-04-01 15:36:43 -07:00
|
|
|
import {appendChild, createTextNode} from '../node_manipulation';
|
2020-01-30 14:57:44 -08:00
|
|
|
import {getBindingIndex, getLView, getTView, setPreviousOrParentTNode} from '../state';
|
2020-08-04 12:42:12 -07:00
|
|
|
|
2019-08-27 16:44:11 +02:00
|
|
|
import {getOrCreateTNode} from './shared';
|
2019-05-31 14:41:07 -07:00
|
|
|
|
|
|
|
|
2019-04-01 15:36:43 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create static text node
|
|
|
|
*
|
|
|
|
* @param index Index of the node in the data array
|
2019-08-27 15:16:50 +02:00
|
|
|
* @param value Static string value to write.
|
2019-04-04 11:41:52 -07:00
|
|
|
*
|
2019-04-10 13:45:26 -07:00
|
|
|
* @codeGenApi
|
2019-04-01 15:36:43 -07:00
|
|
|
*/
|
2019-08-27 15:16:50 +02:00
|
|
|
export function ɵɵtext(index: number, value: string = ''): void {
|
2019-04-01 15:36:43 -07:00
|
|
|
const lView = getLView();
|
2020-01-30 14:57:44 -08:00
|
|
|
const tView = getTView();
|
2019-11-18 11:23:47 +01:00
|
|
|
const adjustedIndex = index + HEADER_OFFSET;
|
|
|
|
|
2020-04-13 16:40:21 -07:00
|
|
|
ngDevMode &&
|
|
|
|
assertEqual(
|
|
|
|
getBindingIndex(), tView.bindingStartIndex,
|
|
|
|
'text nodes should be created before any bindings');
|
2020-08-04 12:42:12 -07:00
|
|
|
ngDevMode && assertIndexInRange(lView, adjustedIndex);
|
2019-04-01 15:36:43 -07:00
|
|
|
|
2019-11-18 11:23:47 +01:00
|
|
|
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]);
|
2020-01-30 14:57:44 -08:00
|
|
|
appendChild(tView, lView, textNative, tNode);
|
2019-11-18 11:23:47 +01:00
|
|
|
|
|
|
|
// Text nodes are self closing.
|
|
|
|
setPreviousOrParentTNode(tNode, false);
|
2019-04-01 15:36:43 -07:00
|
|
|
}
|