* Parse a template and validate all embedded expressions.
(template: string)
| 126 | * Parse a template and validate all embedded expressions. |
| 127 | */ |
| 128 | public parseTemplate(template: string): { parts: TemplatePart[]; errors: ExpressionError[] } { |
| 129 | const parts = parseTemplateParts(template); |
| 130 | const errors: ExpressionError[] = []; |
| 131 | |
| 132 | for (const part of parts) { |
| 133 | if (part.type === 'expression') { |
| 134 | try { |
| 135 | const { invalidNodes } = this.parse(part.value); |
| 136 | if (invalidNodes.length > 0) { |
| 137 | errors.push(new ExpressionError('Invalid expression')); |
| 138 | } |
| 139 | } catch (error) { |
| 140 | errors.push(error as ExpressionError); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return { parts, errors }; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Evaluate a template string containing `{{ expression }}` placeholders. |