2017-12-01 14:23:03 -08:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 12:08:49 -07:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-12-01 14:23:03 -08: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-10-12 21:38:06 -07:00
|
|
|
import {assertDefined, throwError} from '../util/assert';
|
|
|
|
|
import {TNode, TNodeType, toTNodeTypeAsString} from './interfaces/node';
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2020-10-12 21:38:06 -07:00
|
|
|
export function assertTNodeType(
|
|
|
|
|
tNode: TNode|null, expectedTypes: TNodeType, message?: string): void {
|
2018-09-05 16:15:37 -07:00
|
|
|
assertDefined(tNode, 'should be called with a TNode');
|
2020-10-12 21:38:06 -07:00
|
|
|
if ((tNode.type & expectedTypes) === 0) {
|
|
|
|
|
throwError(
|
|
|
|
|
message ||
|
|
|
|
|
`Expected [${toTNodeTypeAsString(expectedTypes)}] but got ${
|
|
|
|
|
toTNodeTypeAsString(tNode.type)}.`);
|
|
|
|
|
}
|
2017-12-18 15:14:09 +01:00
|
|
|
}
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2020-10-12 21:38:06 -07:00
|
|
|
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)}.`);
|
|
|
|
|
}
|
|
|
|
|
}
|