2016-06-23 16:47:54 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 16:47:54 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2016-06-23 16:47:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-03-29 18:04:16 +00:00
|
|
|
const UNUSABLE_INTERPOLATION_REGEXPS = [
|
2024-05-15 14:26:56 +00:00
|
|
|
/@/, // control flow reserved symbol
|
2016-06-21 23:55:17 +00:00
|
|
|
/^\s*$/, // empty
|
|
|
|
|
/[<>]/, // html tag
|
|
|
|
|
/^[{}]$/, // i18n expansion
|
2016-06-24 21:31:35 +00:00
|
|
|
/&(#|[a-z])/i, // character reference,
|
|
|
|
|
/^\/\//, // comment
|
2016-06-20 16:52:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function assertInterpolationSymbols(identifier: string, value: any): void {
|
2017-03-02 17:37:01 +00:00
|
|
|
if (value != null && !(Array.isArray(value) && value.length == 2)) {
|
2016-06-23 00:25:42 +00:00
|
|
|
throw new Error(`Expected '${identifier}' to be an array, [start, end].`);
|
2017-08-16 16:00:03 +00:00
|
|
|
} else if (value != null) {
|
2016-06-20 16:52:41 +00:00
|
|
|
const start = value[0] as string;
|
|
|
|
|
const end = value[1] as string;
|
2019-03-29 18:04:16 +00:00
|
|
|
// Check for unusable interpolation symbols
|
|
|
|
|
UNUSABLE_INTERPOLATION_REGEXPS.forEach((regexp) => {
|
2016-06-20 16:52:41 +00:00
|
|
|
if (regexp.test(start) || regexp.test(end)) {
|
2016-06-23 00:25:42 +00:00
|
|
|
throw new Error(`['${start}', '${end}'] contains unusable interpolation symbol.`);
|
2016-06-20 16:52:41 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|