Skip to content

Commit 16ec011

Browse files
committed
colocate some code
1 parent 5daef9b commit 16ec011

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/** @import { Expression } from 'estree' */
22
/** @import { AST, SvelteNode } from '#compiler' */
33
/** @import { ComponentContext } from '../../types' */
4+
import { escape_html } from '../../../../../../escaping.js';
45
import { is_event_attribute } from '../../../../../utils/ast.js';
56
import * as b from '../../../../../utils/builders.js';
67
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';
89

910
/**
1011
* Processes an array of template nodes, joining sibling text/expression nodes
@@ -161,3 +162,27 @@ function is_static_element(node) {
161162

162163
return true;
163164
}
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+
}

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,6 @@ import { regex_is_valid_identifier } from '../../../../patterns.js';
99
import { create_derived } from '../../utils.js';
1010
import is_reference from 'is-reference';
1111
import { locator } from '../../../../../state.js';
12-
import { escape_html } from '../../../../../../escaping.js';
13-
14-
/**
15-
* @param {Expression} node
16-
* @param {boolean} [is_attr]
17-
* @returns {Expression}
18-
*/
19-
export function escape_inline_expression(node, is_attr) {
20-
if (node.type === 'Literal') {
21-
if (typeof node.value === 'string') {
22-
return b.literal(escape_html(node.value, is_attr));
23-
}
24-
25-
return node;
26-
}
27-
28-
if (node.type === 'TemplateLiteral') {
29-
return b.template(
30-
node.quasis.map((q) => b.quasi(escape_html(q.value.cooked, is_attr))),
31-
node.expressions.map((expression) => escape_inline_expression(expression, is_attr))
32-
);
33-
}
34-
35-
return b.call('$.escape', node, is_attr && b.true);
36-
}
3712

3813
/**
3914
* @param {Array<AST.Text | AST.ExpressionTag>} values

0 commit comments

Comments
 (0)