Skip to content

Commit

Permalink
deconflict value parameter in contextual bindings (sveltejs#4452)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry authored and jesseskinner committed Feb 27, 2020
1 parent d531657 commit 4fb0d7a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Deconflict `value` parameter name used in contextual bindings ([#4445](https://github.com/sveltejs/svelte/issues/4445))
* Fix dev mode validation of `{#each}` blocks using strings ([#4450](https://github.com/sveltejs/svelte/issues/4450))

## 3.19.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ export default class InlineComponentWrapper extends Wrapper {
contextual_dependencies.push(object.name, property.name);
}

const value = block.get_unique_name('value');
const params: any[] = [value];
const params = [x`#value`];
if (contextual_dependencies.length > 0) {
const args = [];

Expand All @@ -349,23 +348,23 @@ export default class InlineComponentWrapper extends Wrapper {


block.chunks.init.push(b`
function ${id}(${value}) {
${callee}.call(null, ${value}, ${args});
function ${id}(#value) {
${callee}.call(null, #value, ${args});
}
`);

block.maintain_context = true; // TODO put this somewhere more logical
} else {
block.chunks.init.push(b`
function ${id}(${value}) {
${callee}.call(null, ${value});
function ${id}(#value) {
${callee}.call(null, #value);
}
`);
}

const body = b`
function ${id}(${params}) {
${lhs} = ${value};
${lhs} = #value;
${renderer.invalidate(dependencies[0])};
}
`;
Expand Down
3 changes: 3 additions & 0 deletions test/runtime/samples/deconflict-contextual-bind/Widget.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
export let prop;
</script>
3 changes: 3 additions & 0 deletions test/runtime/samples/deconflict-contextual-bind/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
preserveIdentifiers: true
};
8 changes: 8 additions & 0 deletions test/runtime/samples/deconflict-contextual-bind/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import Widget from './Widget.svelte';
const values = ['foo', 'bar'];
</script>

{#each values as value}
<Widget bind:value/>
{/each}

0 comments on commit 4fb0d7a

Please sign in to comment.