From 3bfa0e5cd6219ce6408a7bfa6689b3afa1945388 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 3f4460cde4..2166ca4c9c 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 f1c57ed094..28b3c938f9 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 0000000000..3aaa59b747 --- /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 0000000000..7602cde023 --- /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 0000000000..fe91deca17 --- /dev/null +++ b/test/runtime/samples/deconflict-contextual-bind/main.svelte @@ -0,0 +1,8 @@ + + +{#each values as value} + +{/each}