Files
angular/packages/core/src/render3/node_assert.ts
T
Paul Gschwendtner 2d0ff0a5d3 ci: add lint error for files with missing trailing new-line (#42478)
For quite a while it is an unspoken convention to add a trailing
new-line files within the Angular repository. This was never enforced
automatically, but has been frequently raised in pull requests through
manual review. This commit sets up a lint rule so that this is
"officially" enforced and doesn't require manual review.

PR Close #42478
2021-06-04 13:31:03 -07:00

35 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)}.`);
}
}