From 4fb0d7abfc0fd12c45621fe5774d400a053d7ba9 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 23 Feb 2020 17:50:57 -0500 Subject: [PATCH] deconflict `value` parameter in contextual bindings (#4452) --- CHANGELOG.md | 1 + .../render_dom/wrappers/InlineComponent/index.ts | 13 ++++++------- .../deconflict-contextual-bind/Widget.svelte | 3 +++ .../samples/deconflict-contextual-bind/_config.js | 3 +++ .../samples/deconflict-contextual-bind/main.svelte | 8 ++++++++ 5 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 test/runtime/samples/deconflict-contextual-bind/Widget.svelte create mode 100644 test/runtime/samples/deconflict-contextual-bind/_config.js create mode 100644 test/runtime/samples/deconflict-contextual-bind/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4460cde48e..2166ca4c9c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index f1c57ed09415..28b3c938f9d3 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -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 = []; @@ -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])}; } `; diff --git a/test/runtime/samples/deconflict-contextual-bind/Widget.svelte b/test/runtime/samples/deconflict-contextual-bind/Widget.svelte new file mode 100644 index 000000000000..3aaa59b74757 --- /dev/null +++ b/test/runtime/samples/deconflict-contextual-bind/Widget.svelte @@ -0,0 +1,3 @@ + diff --git a/test/runtime/samples/deconflict-contextual-bind/_config.js b/test/runtime/samples/deconflict-contextual-bind/_config.js new file mode 100644 index 000000000000..7602cde02323 --- /dev/null +++ b/test/runtime/samples/deconflict-contextual-bind/_config.js @@ -0,0 +1,3 @@ +export default { + preserveIdentifiers: true +}; diff --git a/test/runtime/samples/deconflict-contextual-bind/main.svelte b/test/runtime/samples/deconflict-contextual-bind/main.svelte new file mode 100644 index 000000000000..fe91deca17f1 --- /dev/null +++ b/test/runtime/samples/deconflict-contextual-bind/main.svelte @@ -0,0 +1,8 @@ + + +{#each values as value} + +{/each}