From eff7f504d412f3a2b3cf888f0cdf0265c98c8fac Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 1 Jul 2019 22:41:07 -0400 Subject: [PATCH] correctly transform inline shorthand methods - fixes #2906 --- src/compiler/compile/nodes/shared/Expression.ts | 4 ++++ .../samples/shorthand-method-in-template/Foo.svelte | 5 +++++ .../samples/shorthand-method-in-template/_config.js | 3 +++ .../samples/shorthand-method-in-template/main.svelte | 9 +++++++++ 4 files changed, 21 insertions(+) create mode 100644 test/runtime/samples/shorthand-method-in-template/Foo.svelte create mode 100644 test/runtime/samples/shorthand-method-in-template/_config.js create mode 100644 test/runtime/samples/shorthand-method-in-template/main.svelte diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index e85c1de5e5..b9d54bea04 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -442,6 +442,10 @@ export default class Expression { `); } + if (parent && parent.method) { + code.prependRight(node.start, ': '); + } + function_expression = null; dependencies = null; contextual_dependencies = null; diff --git a/test/runtime/samples/shorthand-method-in-template/Foo.svelte b/test/runtime/samples/shorthand-method-in-template/Foo.svelte new file mode 100644 index 0000000000..bbe542622d --- /dev/null +++ b/test/runtime/samples/shorthand-method-in-template/Foo.svelte @@ -0,0 +1,5 @@ + + +{bar.answer()} \ No newline at end of file diff --git a/test/runtime/samples/shorthand-method-in-template/_config.js b/test/runtime/samples/shorthand-method-in-template/_config.js new file mode 100644 index 0000000000..ddd282644d --- /dev/null +++ b/test/runtime/samples/shorthand-method-in-template/_config.js @@ -0,0 +1,3 @@ +export default { + html: '42' +}; \ No newline at end of file diff --git a/test/runtime/samples/shorthand-method-in-template/main.svelte b/test/runtime/samples/shorthand-method-in-template/main.svelte new file mode 100644 index 0000000000..9ebd11aacb --- /dev/null +++ b/test/runtime/samples/shorthand-method-in-template/main.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file