Skip to content

Commit 51ac6b8

Browse files
committed
dedupe
1 parent 6e20219 commit 51ac6b8

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,35 @@ const global_visitors = {
403403
}
404404

405405
return next();
406+
},
407+
CallExpression(node, context) {
408+
const rune = get_rune(node, context.state.scope);
409+
410+
if (rune === '$host') {
411+
return b.id('undefined');
412+
}
413+
414+
if (rune === '$effect.active') {
415+
return b.literal(false);
416+
}
417+
418+
if (rune === '$state.snapshot') {
419+
return /** @type {import('estree').Expression} */ (context.visit(node.arguments[0]));
420+
}
421+
422+
if (rune === '$state.is') {
423+
return b.call(
424+
'Object.is',
425+
/** @type {import('estree').Expression} */ (context.visit(node.arguments[0])),
426+
/** @type {import('estree').Expression} */ (context.visit(node.arguments[1]))
427+
);
428+
}
429+
430+
if (rune === '$inspect' || rune === '$inspect().with') {
431+
return transform_inspect_rune(node, context);
432+
}
433+
434+
context.next();
406435
}
407436
};
408437

@@ -625,35 +654,6 @@ const javascript_visitors_runes = {
625654
}
626655
context.next();
627656
},
628-
CallExpression(node, context) {
629-
const rune = get_rune(node, context.state.scope);
630-
631-
if (rune === '$host') {
632-
return b.id('undefined');
633-
}
634-
635-
if (rune === '$effect.active') {
636-
return b.literal(false);
637-
}
638-
639-
if (rune === '$state.snapshot') {
640-
return /** @type {import('estree').Expression} */ (context.visit(node.arguments[0]));
641-
}
642-
643-
if (rune === '$state.is') {
644-
return b.call(
645-
'Object.is',
646-
/** @type {import('estree').Expression} */ (context.visit(node.arguments[0])),
647-
/** @type {import('estree').Expression} */ (context.visit(node.arguments[1]))
648-
);
649-
}
650-
651-
if (rune === '$inspect' || rune === '$inspect().with') {
652-
return transform_inspect_rune(node, context);
653-
}
654-
655-
context.next();
656-
},
657657
MemberExpression(node, context) {
658658
if (node.object.type === 'ThisExpression' && node.property.type === 'PrivateIdentifier') {
659659
const field = context.state.private_derived.get(node.property.name);
@@ -1548,6 +1548,7 @@ const template_visitors = {
15481548
spreads.push(/** @type {import('estree').Expression} */ (context.visit(attribute)));
15491549
} else if (attribute.type === 'Attribute') {
15501550
const value = serialize_attribute_value(attribute.value, context, false, true);
1551+
15511552
if (attribute.name === 'name') {
15521553
expression = b.member(b.member_id('$$props.$$slots'), value, true, true);
15531554
} else if (attribute.name !== 'slot') {
@@ -1585,9 +1586,7 @@ const template_visitors = {
15851586
context.state.template.push(
15861587
b.stmt(b.call('$.head', b.id('$$payload'), b.arrow([b.id('$$payload')], block)))
15871588
);
1588-
},
1589-
// @ts-ignore: need to extract this out somehow
1590-
CallExpression: javascript_visitors_runes.CallExpression
1589+
}
15911590
};
15921591

15931592
/**
@@ -1614,8 +1613,8 @@ function serialize_element_attributes(node, context) {
16141613

16151614
let has_spread = false;
16161615
// Use the index to keep the attributes order which is important for spreading
1617-
let class_attribute_idx = -1;
1618-
let style_attribute_idx = -1;
1616+
let class_index = -1;
1617+
let style_index = -1;
16191618
let events_to_capture = new Set();
16201619

16211620
for (const attribute of node.attributes) {
@@ -1649,9 +1648,9 @@ function serialize_element_attributes(node, context) {
16491648
}
16501649
} else {
16511650
if (attribute.name === 'class') {
1652-
class_attribute_idx = attributes.length;
1651+
class_index = attributes.length;
16531652
} else if (attribute.name === 'style') {
1654-
style_attribute_idx = attributes.length;
1653+
style_index = attributes.length;
16551654
}
16561655
attributes.push(attribute);
16571656
}
@@ -1761,21 +1760,21 @@ function serialize_element_attributes(node, context) {
17611760
if (class_directives.length > 0 && !has_spread) {
17621761
const class_attribute = serialize_class_directives(
17631762
class_directives,
1764-
/** @type {import('#compiler').Attribute | null} */ (attributes[class_attribute_idx] ?? null)
1763+
/** @type {import('#compiler').Attribute | null} */ (attributes[class_index] ?? null)
17651764
);
1766-
if (class_attribute_idx === -1) {
1765+
if (class_index === -1) {
17671766
attributes.push(class_attribute);
17681767
}
17691768
}
17701769

17711770
if (style_directives.length > 0 && !has_spread) {
17721771
serialize_style_directives(
17731772
style_directives,
1774-
/** @type {import('#compiler').Attribute | null} */ (attributes[style_attribute_idx] ?? null),
1773+
/** @type {import('#compiler').Attribute | null} */ (attributes[style_index] ?? null),
17751774
context
17761775
);
1777-
if (style_attribute_idx > -1) {
1778-
attributes.splice(style_attribute_idx, 1);
1776+
if (style_index > -1) {
1777+
attributes.splice(style_index, 1);
17791778
}
17801779
}
17811780

0 commit comments

Comments
 (0)