2017-12-01 14:23:03 -08:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. 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
|
|
|
|
*/
|
|
|
|
|
2018-05-09 16:49:39 -07:00
|
|
|
import {assertDefined, assertEqual} from './assert';
|
2018-05-17 12:54:57 -07:00
|
|
|
import {LNode, TNodeType} from './interfaces/node';
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-05-17 12:54:57 -07:00
|
|
|
export function assertNodeType(node: LNode, type: TNodeType) {
|
2018-05-09 16:49:39 -07:00
|
|
|
assertDefined(node, 'should be called with a node');
|
2018-05-17 12:54:57 -07:00
|
|
|
assertEqual(node.tNode.type, type, `should be a ${typeName(type)}`);
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
2018-05-17 12:54:57 -07:00
|
|
|
export function assertNodeOfPossibleTypes(node: LNode, ...types: TNodeType[]) {
|
2018-05-09 16:49:39 -07:00
|
|
|
assertDefined(node, 'should be called with a node');
|
2018-05-17 12:54:57 -07:00
|
|
|
const found = types.some(type => node.tNode.type === type);
|
2018-02-12 22:46:15 -08:00
|
|
|
assertEqual(found, true, `Should be one of ${types.map(typeName).join(', ')}`);
|
2017-12-18 15:14:09 +01:00
|
|
|
}
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-05-17 12:54:57 -07:00
|
|
|
function typeName(type: TNodeType): string {
|
|
|
|
if (type == TNodeType.Projection) return 'Projection';
|
|
|
|
if (type == TNodeType.Container) return 'Container';
|
|
|
|
if (type == TNodeType.View) return 'View';
|
|
|
|
if (type == TNodeType.Element) return 'Element';
|
2018-02-12 22:46:15 -08:00
|
|
|
return '<unknown>';
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|