Skip to content

Commit

Permalink
[fix] handle arrow function on slot inside svelte:fragment (#7667)
Browse files Browse the repository at this point in the history
Fixes #7485
  • Loading branch information
magentaqin committed Jul 28, 2022
1 parent 9ad416b commit 5dd703f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/shared/Expression.ts
Expand Up @@ -323,7 +323,7 @@ export default class Expression {

const func_expression = func_declaration[0];

if (node.type === 'InlineComponent') {
if (node.type === 'InlineComponent' || node.type === 'SlotTemplate') {
// <Comp let:data />
this.replace(func_expression);
} else {
Expand Down
@@ -0,0 +1,8 @@
<script>
export let log;
export let b;
function innerCall(a) {
log(`a: ${a}, b: ${b}`);
}
</script>
<slot name="inner_slot" {innerCall} />
@@ -0,0 +1,12 @@
<script>
import Inner from './Inner.svelte'
export let log;
export let a;
export let b;
</script>

<Inner {log} {b}>
<svelte:fragment let:innerCall slot="inner_slot">
<slot outerCall={() => innerCall(a)} />
</svelte:fragment>
</Inner>
27 changes: 27 additions & 0 deletions test/runtime/samples/component-slot-let-inline-function/_config.js
@@ -0,0 +1,27 @@
let logs;
function log(value) {
logs.push(value);
}

export default {
html: '<button>click me</button>',
props: {
a: 'a',
b: 'b',
log
},
before_test() {
logs = [];
},
async test({ assert, component, target, window }) {
const button = target.querySelector('button');
await button.dispatchEvent(new window.MouseEvent('click'));

assert.deepEqual(logs, ['a: a, b: b']);

component.a = '1';
component.b = '2';
await button.dispatchEvent(new window.MouseEvent('click'));
assert.deepEqual(logs, ['a: a, b: b', 'a: 1, b: 2']);
}
};
@@ -0,0 +1,12 @@
<script>
import Outer from "./Outer.svelte";
export let log = [];
export let a;
export let b;
</script>

<Outer let:outerCall {log} {a} {b}>
<button on:click={outerCall}>
click me
</button>
</Outer>

0 comments on commit 5dd703f

Please sign in to comment.