Skip to content

Commit

Permalink
[fix] correctly track dependencies of let: bindings (#7448)
Browse files Browse the repository at this point in the history
Fixes #7440
  • Loading branch information
tanhauhau committed Apr 13, 2022
1 parent 39d2dfc commit 4aff59b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Fix `{@const}` tag not working inside Component when there's no `let:` [#7189](https://github.com/sveltejs/svelte/issues/7189)
* Ignore comments in `{#each}` blocks when containing elements with `animate:` ([#3999](https://github.com/sveltejs/svelte/issues/3999))
* Add a third parameter to the returned function of `createEventDispatcher` that allows passing an object of `{ cancelable: true }` to create a cancelable custom event. The returned function when called will also return a boolean depending on whether the event is cancelled ([#7064](https://github.com/sveltejs/svelte/pull/7064))
* Fix value of `let:` bindings not updating in certain cases ([#7440](https://github.com/sveltejs/svelte/issues/7440))

## 3.47.0

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/shared/Expression.ts
Expand Up @@ -90,7 +90,7 @@ export default class Expression {
}

if (template_scope.is_let(name)) {
if (!function_expression) { // TODO should this be `!lazy` ?
if (!lazy) {
contextual_dependencies.add(name);
dependencies.add(name);
}
Expand Down
@@ -0,0 +1 @@
<slot/>
@@ -0,0 +1,5 @@
<script>
export let prop
</script>

<slot value={prop} />
25 changes: 25 additions & 0 deletions test/runtime/samples/component-slot-let-in-slot-2/_config.js
@@ -0,0 +1,25 @@
let logs;
function log(value) {
logs.push(value);
}

export default {
props: {
prop: 'a',
log
},
html: '<button></button>',
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']);

component.prop = 'b';
await button.dispatchEvent(new window.MouseEvent('click'));
assert.deepEqual(logs, ['a', 'b']);
}
};
11 changes: 11 additions & 0 deletions test/runtime/samples/component-slot-let-in-slot-2/main.svelte
@@ -0,0 +1,11 @@
<script>
import Outer from './Outer.svelte'
import Inner from './Inner.svelte'
export let prop
export let log;
</script>

<Outer {prop} let:value>
<Inner><button on:click={() => { log(value); }} /></Inner>
</Outer>

0 comments on commit 4aff59b

Please sign in to comment.