Skip to content

Commit

Permalink
chore: avoid creating unnecessary thunks (#9841)
Browse files Browse the repository at this point in the history
Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
Rich-Harris and Rich-Harris authored Dec 7, 2023
1 parent 8dfb289 commit 26c6d6f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-seahorses-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: avoid creating thunk for call expressions when appropriate
11 changes: 10 additions & 1 deletion packages/svelte/src/compiler/utils/builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,18 @@ export function template(elements, expressions) {

/**
* @param {import('estree').Expression | import('estree').BlockStatement} expression
* @returns {import('estree').ArrowFunctionExpression}
* @returns {import('estree').Expression}
*/
export function thunk(expression) {
if (
expression.type === 'CallExpression' &&
expression.callee.type !== 'Super' &&
expression.callee.type !== 'MemberExpression' &&
expression.arguments.length === 0
) {
return expression.callee;
}

return arrow([], expression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export default function Main($$anchor, $$props) {
var custom_element_1 = $.sibling($.sibling(svg_1));

/* Update */
$.attr_effect(div, "foobar", () => y());
$.attr_effect(svg_1, "viewBox", () => y());
$.set_custom_element_data_effect(custom_element_1, "fooBar", () => y());
$.attr_effect(div, "foobar", y);
$.attr_effect(svg_1, "viewBox", y);
$.set_custom_element_data_effect(custom_element_1, "fooBar", y);

var node_foobar;
var svg_viewBox;
Expand All @@ -45,4 +45,4 @@ export default function Main($$anchor, $$props) {

$.close_frag($$anchor, fragment);
$.pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Svelte_element($$anchor, $$props) {
var fragment = $.comment($$anchor);
var node = $.child_frag(fragment);

$.element(node, () => tag());
$.element(node, tag);
$.close_frag($$anchor, fragment);
$.pop();
}

1 comment on commit 26c6d6f

@vercel
Copy link

@vercel vercel bot commented on 26c6d6f Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview-svelte.vercel.app
svelte-5-preview-git-main-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-octane.vercel.app

Please sign in to comment.