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); args.push(original_params);
} }
// TODO is this still necessary? const body = code.slice(node.body.start, node.body.end).trim();
let body = code.slice(node.body.start, node.body.end).trim();
if (node.body.type !== 'BlockStatement') {
body = `{\n\treturn ${body};\n}`;
}
const fn = deindent` const fn = node.type === 'FunctionExpression'
${node.async && 'async '}function${node.generator && '*'} ${name}(${args.join(', ')}) ${body} ? `${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) { if (dependencies.size === 0 && contextual_dependencies.size === 0) {
// we can hoist this out of the component completely // we can hoist this out of the component completely

@ -53,9 +53,7 @@ function foo(node, callback) {
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let { bar } = $$props; let { bar } = $$props;
function foo_function() { const foo_function = () => handleFoo(bar);
return handleFoo(bar);
}
$$self.$set = $$props => { $$self.$set = $$props => {
if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar);

@ -46,9 +46,7 @@ function create_fragment(ctx) {
}; };
} }
function func() { const func = () => import('./Foo.svelte');
return import('./Foo.svelte');
}
class Component extends SvelteComponent { class Component extends SvelteComponent {
constructor(options) { constructor(options) {

@ -40,9 +40,7 @@ function create_fragment(ctx) {
}; };
} }
function touchstart_handler(e) { const touchstart_handler = (e) => e.preventDefault();
return e.preventDefault();
}
class Component extends SvelteComponent { class Component extends SvelteComponent {
constructor(options) { constructor(options) {

@ -60,9 +60,9 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let x = 0; let x = 0;
function click_handler() { const click_handler = () => {
if (true) $$invalidate('x', x += 1); if (true) $$invalidate('x', x += 1);
} };
return { x, click_handler }; return { x, click_handler };
} }

@ -60,7 +60,7 @@ function create_fragment(ctx) {
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let things = []; let things = [];
function click_handler() { things.push(1); $$invalidate('things', things) } const click_handler = () => { things.push(1); $$invalidate('things', things) };
return { things, click_handler }; return { things, click_handler };
} }

Loading…
Cancel
Save