Misko Hevery 70f1e2e04a refactor(core): Create TNodeType.Text to display full template in TView debug (#39233)
When looking at `TView` debug template only Element nodes were displayed
as `TNode.Element` was used for both `RElement` and `RText`.
Additionally no text was stored in `TNode.value`. The result was that
the whole template could not be reconstructed. This refactoring creates
`TNodeType.Text` and store the text value in `TNode.value`.

The refactoring also changes `TNodeType` into flag-like structure make
it more efficient to check many different types at once.

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

34 lines
1.2 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 {assertDefined, throwError} from '../util/assert';
import {TNode, TNodeType, toTNodeTypeAsString} from './interfaces/node';
export function assertTNodeType(
tNode: TNode|null, expectedTypes: TNodeType, message?: string): void {
assertDefined(tNode, 'should be called with a TNode');
if ((tNode.type & expectedTypes) === 0) {
throwError(
message ||
`Expected [${toTNodeTypeAsString(expectedTypes)}] but got ${
toTNodeTypeAsString(tNode.type)}.`);
}
}
export function assertPureTNodeType(type: TNodeType) {
if (!(type === TNodeType.Element || //
type === TNodeType.Text || //
type === TNodeType.Container || //
type === TNodeType.ElementContainer || //
type === TNodeType.Icu || //
type === TNodeType.Projection || //
type === TNodeType.Placeholder)) {
throwError(`Expected TNodeType to have only a single type selected, but got ${
toTNodeTypeAsString(type)}.`);
}
}