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 === 'ArrowFunctionExpression' ||
node.type === 'FunctionExpression' ||
node.type === 'UnaryExpression' ||
node.type === 'BinaryExpression' ||
(node.type === 'Identifier' && node.name === 'undefined')
) {
return false;

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

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

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

Loading…
Cancel
Save