preserve arrow function event handlers

pull/3533/head
Richard Harris 5 years ago
parent 063e9292b8
commit 6ea7d77f68

@ -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

@ -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);

@ -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) {

@ -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) {

@ -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 };
}

@ -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 };
}

Loading…
Cancel
Save