diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index fddd1972bf..668dcb45f8 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -322,15 +322,11 @@ export default class Expression { args.push(original_params); } - // TODO is this still necessary? - let body = code.slice(node.body.start, node.body.end).trim(); - if (node.body.type !== 'BlockStatement') { - body = `{\n\treturn ${body};\n}`; - } + const body = code.slice(node.body.start, node.body.end).trim(); - const fn = deindent` - ${node.async && 'async '}function${node.generator && '*'} ${name}(${args.join(', ')}) ${body} - `; + const fn = node.type === 'FunctionExpression' + ? `${node.async ? 'async ' : ''}function${node.generator ? '*' : ''} ${name}(${args.join(', ')}) ${body}` + : `const ${name} = ${node.async ? 'async ' : ''}(${args.join(', ')}) => ${body};`; if (dependencies.size === 0 && contextual_dependencies.size === 0) { // we can hoist this out of the component completely diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index ea55f1629b..34d5ca10aa 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -53,9 +53,7 @@ function foo(node, callback) { function instance($$self, $$props, $$invalidate) { let { bar } = $$props; - function foo_function() { - return handleFoo(bar); - } + const foo_function = () => handleFoo(bar); $$self.$set = $$props => { if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index 9a6a67bcd9..8692cd89b2 100644 --- a/test/js/samples/dynamic-import/expected.js +++ b/test/js/samples/dynamic-import/expected.js @@ -46,9 +46,7 @@ function create_fragment(ctx) { }; } -function func() { - return import('./Foo.svelte'); -} +const func = () => import('./Foo.svelte'); class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/event-handler-no-passive/expected.js b/test/js/samples/event-handler-no-passive/expected.js index e8ca72c556..69285a29c6 100644 --- a/test/js/samples/event-handler-no-passive/expected.js +++ b/test/js/samples/event-handler-no-passive/expected.js @@ -40,9 +40,7 @@ function create_fragment(ctx) { }; } -function touchstart_handler(e) { - return e.preventDefault(); -} +const touchstart_handler = (e) => e.preventDefault(); class Component extends SvelteComponent { constructor(options) { diff --git a/test/js/samples/instrumentation-template-if-no-block/expected.js b/test/js/samples/instrumentation-template-if-no-block/expected.js index d24aeabf7f..4591d8c797 100644 --- a/test/js/samples/instrumentation-template-if-no-block/expected.js +++ b/test/js/samples/instrumentation-template-if-no-block/expected.js @@ -60,9 +60,9 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let x = 0; - function click_handler() { + const click_handler = () => { if (true) $$invalidate('x', x += 1); - } + }; return { x, click_handler }; } diff --git a/test/js/samples/instrumentation-template-x-equals-x/expected.js b/test/js/samples/instrumentation-template-x-equals-x/expected.js index c9868ace50..b08130016b 100644 --- a/test/js/samples/instrumentation-template-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-template-x-equals-x/expected.js @@ -60,7 +60,7 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let things = []; - function click_handler() { things.push(1); $$invalidate('things', things) } + const click_handler = () => { things.push(1); $$invalidate('things', things) }; return { things, click_handler }; }