chore: skip generating $.proxy() calls for more expressions (#9979)

* chore: skip emitting $.proxy() calls for more expressions

* Update pretty-ties-help.md

---------

Co-authored-by: Dominic Gannaway <trueadm@users.noreply.github.com>
pull/10054/head
Jeremy Deutsch 12 months ago committed by GitHub
parent 60575ad494
commit 346041f454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: skip generating $.proxy() calls for unary and binary expressions

@ -525,6 +525,8 @@ export function should_proxy_or_freeze(node) {
node.type === 'Literal' || node.type === 'Literal' ||
node.type === 'ArrowFunctionExpression' || node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionExpression' || node.type === 'FunctionExpression' ||
node.type === 'UnaryExpression' ||
node.type === 'BinaryExpression' ||
(node.type === 'Identifier' && node.name === 'undefined') (node.type === 'Identifier' && node.name === 'undefined')
) { ) {
return false; return false;

@ -9,16 +9,18 @@ export default function Function_prop_no_getter($$anchor, $$props) {
let count = $.source(0); let count = $.source(0);
function onmouseup() { function onmouseup() {
$.set(count, $.proxy($.get(count) + 2)); $.set(count, $.get(count) + 2);
} }
const plusOne = (num) => num + 1;
/* Init */ /* Init */
var fragment = $.comment($$anchor); var fragment = $.comment($$anchor);
var node = $.child_frag(fragment); var node = $.child_frag(fragment);
Button(node, { Button(node, {
onmousedown: () => $.set(count, $.proxy($.get(count) + 1)), onmousedown: () => $.set(count, $.get(count) + 1),
onmouseup, onmouseup,
onmouseenter: () => $.set(count, $.proxy(plusOne($.get(count)))),
children: ($$anchor, $$slotProps) => { children: ($$anchor, $$slotProps) => {
/* Init */ /* Init */
var node_1 = $.space($$anchor); var node_1 = $.space($$anchor);

@ -11,6 +11,7 @@ export default function Function_prop_no_getter($$payload, $$props) {
count += 2; count += 2;
} }
const plusOne = (num) => num + 1;
const anchor = $.create_anchor($$payload); const anchor = $.create_anchor($$payload);
$$payload.out += `${anchor}`; $$payload.out += `${anchor}`;
@ -18,6 +19,7 @@ export default function Function_prop_no_getter($$payload, $$props) {
Button($$payload, { Button($$payload, {
onmousedown: () => count += 1, onmousedown: () => count += 1,
onmouseup, onmouseup,
onmouseenter: () => count = plusOne(count),
children: ($$payload, $$slotProps) => { children: ($$payload, $$slotProps) => {
$$payload.out += `clicks: ${$.escape(count)}`; $$payload.out += `clicks: ${$.escape(count)}`;
} }

@ -4,8 +4,10 @@
function onmouseup() { function onmouseup() {
count += 2; count += 2;
} }
const plusOne = (num) => num + 1;
</script> </script>
<Button onmousedown={() => count += 1} {onmouseup}> <Button onmousedown={() => count += 1} {onmouseup} onmouseenter={() => count = plusOne(count)}>
clicks: {count} clicks: {count}
</Button> </Button>

Loading…
Cancel
Save