mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
BREAKING CHANGE: The public API for `DebugNode` was accidentally too broad. This change removes 1. Public constructor. Since `DebugNode` is a way for Angular to communicate information on to the developer there is no reason why the developer should ever need to Instantiate the `DebugNode` 2. We are also removing `removeChild`, `addChild`, `insertBefore`, and `insertChildAfter`. All of these methods are used by Angular to constructor the correct `DebugNode` tree. There is no reason why the developer should ever be constructing a `DebugNode` tree And these methods should have never been made public. 3. All properties have been change to `readonly` since `DebugNode` is used by Angular to communicate to developer and there is no reason why these APIs should be writable. While technically breaking change we don’t expect anyone to be effected by this change. PR Close #27223
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
/**
|
|
* @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
|
|
*/
|
|
|
|
import {getComponentDef, getNgModuleDef} from './definition';
|
|
|
|
// The functions in this file verify that the assumptions we are making
|
|
// about state in an instruction are correct before implementing any logic.
|
|
// They are meant only to be called in dev mode as sanity checks.
|
|
|
|
export function assertNumber(actual: any, msg: string) {
|
|
if (typeof actual != 'number') {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertEqual<T>(actual: T, expected: T, msg: string) {
|
|
if (actual != expected) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertNotEqual<T>(actual: T, expected: T, msg: string) {
|
|
if (actual == expected) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertSame<T>(actual: T, expected: T, msg: string) {
|
|
if (actual !== expected) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertLessThan<T>(actual: T, expected: T, msg: string) {
|
|
if (actual >= expected) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertGreaterThan<T>(actual: T, expected: T, msg: string) {
|
|
if (actual <= expected) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertNotDefined<T>(actual: T, msg: string) {
|
|
if (actual != null) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertDefined<T>(actual: T, msg: string) {
|
|
if (actual == null) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertComponentType(
|
|
actual: any,
|
|
msg: string =
|
|
'Type passed in is not ComponentType, it does not have \'ngComponentDef\' property.') {
|
|
if (!getComponentDef(actual)) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
export function assertNgModuleType(
|
|
actual: any,
|
|
msg: string =
|
|
'Type passed in is not NgModuleType, it does not have \'ngModuleDef\' property.') {
|
|
if (!getNgModuleDef(actual)) {
|
|
throwError(msg);
|
|
}
|
|
}
|
|
|
|
function throwError(msg: string): never {
|
|
// tslint:disable-next-line
|
|
debugger; // Left intentionally for better debugger experience.
|
|
throw new Error(`ASSERTION ERROR: ${msg}`);
|
|
}
|
|
|
|
export function assertDomNode(node: any) {
|
|
assertEqual(node instanceof Node, true, 'The provided value must be an instance of a DOM Node');
|
|
}
|