angular/packages/compiler/src/assertions.ts
JoostK 7862f5657e refactor(compiler): remove unused assertion function (#44411)
This code is no longer used now that ViewEngine has been removed.

PR Close #44411
2022-01-04 15:54:09 -08:00

30 lines
1,017 B
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
*/
const UNUSABLE_INTERPOLATION_REGEXPS = [
/^\s*$/, // empty
/[<>]/, // html tag
/^[{}]$/, // i18n expansion
/&(#|[a-z])/i, // character reference,
/^\/\//, // comment
];
export function assertInterpolationSymbols(identifier: string, value: any): void {
if (value != null && !(Array.isArray(value) && value.length == 2)) {
throw new Error(`Expected '${identifier}' to be an array, [start, end].`);
} else if (value != null) {
const start = value[0] as string;
const end = value[1] as string;
// Check for unusable interpolation symbols
UNUSABLE_INTERPOLATION_REGEXPS.forEach(regexp => {
if (regexp.test(start) || regexp.test(end)) {
throw new Error(`['${start}', '${end}'] contains unusable interpolation symbol.`);
}
});
}
}