Skip to content

Commit f752b1e

Browse files
authored
chore: simplify SSR (#11977)
* chore: simplify SSR escaping * treat solo expressions the same as sequence expressions * reduce some indirection * more * tidy * tidy * remove unused types * more * this doesnt do anything * more * Anchor is unused * simplify * simplify * move special case handling * more * simplify * simplify * simplify * more * unnecessary * simplify * remove unused arg * more * more * unnecessary * more * more * dedupe
1 parent 2be6d43 commit f752b1e

File tree

6 files changed

+309
-549
lines changed

6 files changed

+309
-549
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ import { function_visitor, serialize_hoistable_params } from '../utils.js';
33

44
/** @type {import('../types.js').ComponentVisitors} */
55
export const javascript_visitors = {
6-
Program(node, { visit }) {
7-
return /** @type {import('estree').Program} */ ({
8-
...node,
9-
body: node.body.map((node) => /** @type {import('estree').Node} */ (visit(node)))
10-
});
11-
},
12-
BlockStatement(node, { visit }) {
13-
return /** @type {import('estree').BlockStatement} */ ({
14-
...node,
15-
body: node.body.map((node) => /** @type {import('estree').Node} */ (visit(node)))
16-
});
17-
},
186
FunctionExpression: function_visitor,
197
ArrowFunctionExpression: function_visitor,
208
FunctionDeclaration(node, context) {

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,37 +1435,29 @@ function get_node_id(expression, state, name) {
14351435
}
14361436

14371437
/**
1438-
* @param {true | Array<import('#compiler').Text | import('#compiler').ExpressionTag>} attribute_value
1438+
* @param {true | Array<import('#compiler').Text | import('#compiler').ExpressionTag>} value
14391439
* @param {import('../types').ComponentContext} context
1440-
* @returns {[boolean, import('estree').Expression]}
1440+
* @returns {[contains_call_expression: boolean, import('estree').Expression]}
14411441
*/
1442-
function serialize_attribute_value(attribute_value, context) {
1443-
let contains_call_expression = false;
1444-
1445-
if (attribute_value === true) {
1446-
return [contains_call_expression, b.literal(true)];
1442+
function serialize_attribute_value(value, context) {
1443+
if (value === true) {
1444+
return [false, b.literal(true)];
14471445
}
14481446

1449-
if (attribute_value.length === 0) {
1450-
return [contains_call_expression, b.literal('')]; // is this even possible?
1451-
}
1447+
if (value.length === 1) {
1448+
const chunk = value[0];
14521449

1453-
if (attribute_value.length === 1) {
1454-
const value = attribute_value[0];
1455-
if (value.type === 'Text') {
1456-
return [contains_call_expression, b.literal(value.data)];
1457-
} else {
1458-
if (value.type === 'ExpressionTag') {
1459-
contains_call_expression = value.metadata.contains_call_expression;
1460-
}
1461-
return [
1462-
contains_call_expression,
1463-
/** @type {import('estree').Expression} */ (context.visit(value.expression))
1464-
];
1450+
if (chunk.type === 'Text') {
1451+
return [false, b.literal(chunk.data)];
14651452
}
1453+
1454+
return [
1455+
chunk.metadata.contains_call_expression,
1456+
/** @type {import('estree').Expression} */ (context.visit(chunk.expression))
1457+
];
14661458
}
14671459

1468-
return serialize_template_literal(attribute_value, context.visit, context.state);
1460+
return serialize_template_literal(value, context.visit, context.state);
14691461
}
14701462

14711463
/**

0 commit comments

Comments
 (0)