|
1 | 1 | /** @import { Expression } from 'estree' */
|
2 | 2 | /** @import { AST, SvelteNode } from '#compiler' */
|
3 | 3 | /** @import { ComponentContext } from '../../types' */
|
| 4 | +import { escape_html } from '../../../../../../escaping.js'; |
4 | 5 | import { is_event_attribute } from '../../../../../utils/ast.js';
|
5 | 6 | import * as b from '../../../../../utils/builders.js';
|
6 | 7 | import { is_inlinable_attribute } from '../../../../utils.js';
|
7 |
| -import { build_template_chunk, build_update, escape_inline_expression } from './utils.js'; |
| 8 | +import { build_template_chunk, build_update } from './utils.js'; |
8 | 9 |
|
9 | 10 | /**
|
10 | 11 | * Processes an array of template nodes, joining sibling text/expression nodes
|
@@ -161,3 +162,27 @@ function is_static_element(node) {
|
161 | 162 |
|
162 | 163 | return true;
|
163 | 164 | }
|
| 165 | + |
| 166 | +/** |
| 167 | + * @param {Expression} node |
| 168 | + * @param {boolean} [is_attr] |
| 169 | + * @returns {Expression} |
| 170 | + */ |
| 171 | +function escape_inline_expression(node, is_attr) { |
| 172 | + if (node.type === 'Literal') { |
| 173 | + if (typeof node.value === 'string') { |
| 174 | + return b.literal(escape_html(node.value, is_attr)); |
| 175 | + } |
| 176 | + |
| 177 | + return node; |
| 178 | + } |
| 179 | + |
| 180 | + if (node.type === 'TemplateLiteral') { |
| 181 | + return b.template( |
| 182 | + node.quasis.map((q) => b.quasi(escape_html(q.value.cooked, is_attr))), |
| 183 | + node.expressions.map((expression) => escape_inline_expression(expression, is_attr)) |
| 184 | + ); |
| 185 | + } |
| 186 | + |
| 187 | + return b.call('$.escape', node, is_attr && b.true); |
| 188 | +} |
0 commit comments