Skip to content

Commit 18d71fd

Browse files
authored
chore: reuse expression nodes (#15513)
1 parent dab1a1b commit 18d71fd

File tree

10 files changed

+13
-15
lines changed

10 files changed

+13
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ export function client_component(analysis, options) {
596596
/** @type {ESTree.Property[]} */ (
597597
[
598598
prop_def.attribute ? b.init('attribute', b.literal(prop_def.attribute)) : undefined,
599-
prop_def.reflect ? b.init('reflect', b.literal(true)) : undefined,
599+
prop_def.reflect ? b.init('reflect', b.true) : undefined,
600600
prop_def.type ? b.init('type', b.literal(prop_def.type)) : undefined
601601
].filter(Boolean)
602602
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { parse_directive_name } from './shared/utils.js';
1111
export function AnimateDirective(node, context) {
1212
const expression =
1313
node.expression === null
14-
? b.literal(null)
14+
? b.null
1515
: b.thunk(/** @type {Expression} */ (context.visit(node.expression)));
1616

1717
// in after_update to ensure it always happens after bind:this

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function AwaitBlock(node, context) {
6060
expression,
6161
node.pending
6262
? b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.pending)))
63-
: b.literal(null),
63+
: b.null,
6464
then_block,
6565
catch_block
6666
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function BinaryExpression(node, context) {
1616
'$.strict_equals',
1717
/** @type {Expression} */ (context.visit(node.left)),
1818
/** @type {Expression} */ (context.visit(node.right)),
19-
operator === '!==' && b.literal(false)
19+
operator === '!==' && b.false
2020
);
2121
}
2222

@@ -25,7 +25,7 @@ export function BinaryExpression(node, context) {
2525
'$.equals',
2626
/** @type {Expression} */ (context.visit(node.left)),
2727
/** @type {Expression} */ (context.visit(node.right)),
28-
operator === '!=' && b.literal(false)
28+
operator === '!=' && b.false
2929
);
3030
}
3131
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export function IfBlock(node, context) {
4040
b.if(
4141
/** @type {Expression} */ (context.visit(node.test)),
4242
b.stmt(b.call(b.id('$$render'), b.id(consequent_id))),
43-
alternate_id
44-
? b.stmt(b.call(b.id('$$render'), b.id(alternate_id), b.literal(false)))
45-
: undefined
43+
alternate_id ? b.stmt(b.call(b.id('$$render'), b.id(alternate_id), b.false)) : undefined
4644
)
4745
])
4846
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
689689
'=',
690690
b.member(node_id, 'value'),
691691
b.conditional(
692-
b.binary('==', b.literal(null), b.assignment('=', b.member(node_id, '__value'), value)),
692+
b.binary('==', b.null, b.assignment('=', b.member(node_id, '__value'), value)),
693693
b.literal(''), // render null/undefined values as empty string to support placeholder options
694694
value
695695
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function SlotElement(node, context) {
5959

6060
const fallback =
6161
node.fragment.nodes.length === 0
62-
? b.literal(null)
62+
? b.null
6363
: b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.fragment)));
6464

6565
const slot = b.call(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function build_set_attributes(
9595
const call = b.call(
9696
'$.set_attributes',
9797
element_id,
98-
is_dynamic ? attributes_id : b.literal(null),
98+
is_dynamic ? attributes_id : b.null,
9999
b.object(values),
100100
element.metadata.scoped &&
101101
context.state.analysis.css.hash !== '' &&
@@ -120,7 +120,7 @@ export function build_set_attributes(
120120
*/
121121
export function build_attribute_value(value, context, memoize = (value) => value) {
122122
if (value === true) {
123-
return { value: b.literal(true), has_state: false };
123+
return { value: b.true, has_state: false };
124124
}
125125

126126
if (!Array.isArray(value) || value.length === 1) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function SlotElement(node, context) {
3838

3939
const fallback =
4040
node.fragment.nodes.length === 0
41-
? b.literal(null)
41+
? b.null
4242
: b.thunk(/** @type {BlockStatement} */ (context.visit(node.fragment)));
4343

4444
const slot = b.call(

packages/svelte/src/compiler/utils/builders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ export function do_while(test, body) {
485485

486486
const true_instance = literal(true);
487487
const false_instance = literal(false);
488-
const null_instane = literal(null);
488+
const null_instance = literal(null);
489489

490490
/** @type {ESTree.DebuggerStatement} */
491491
const debugger_builder = {
@@ -647,7 +647,7 @@ export {
647647
return_builder as return,
648648
if_builder as if,
649649
this_instance as this,
650-
null_instane as null,
650+
null_instance as null,
651651
debugger_builder as debugger
652652
};
653653

0 commit comments

Comments
 (0)