From 0f4cf99bcdbcb8a60f24520cec1640b04d9217d0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Mar 2019 15:30:24 -0400 Subject: [PATCH] allow reactive declarations to only depend on $$props - fixes #2264 --- src/compile/render-dom/index.ts | 8 +++++-- .../samples/props-reactive/Nested.svelte | 9 ++++++++ .../runtime/samples/props-reactive/_config.js | 22 +++++++++++++++++++ .../samples/props-reactive/main.svelte | 10 +++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/props-reactive/Nested.svelte create mode 100644 test/runtime/samples/props-reactive/_config.js create mode 100644 test/runtime/samples/props-reactive/main.svelte diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 5b37ac031c..40c98987b0 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -346,6 +346,7 @@ export default function dom( const reactive_declarations = component.reactive_declarations.map(d => { const condition = Array.from(d.dependencies) .filter(n => { + if (n === '$$props') return false; const variable = component.var_lookup.get(n); return variable && variable.writable; }) @@ -358,8 +359,11 @@ export default function dom( [✂${d.node.body.start}-${d.node.end}✂] }`; - return deindent` - if (${condition}) ${snippet}` + return condition + ? deindent` + if (${condition}) ${snippet}` + : deindent` + ${snippet}` }); const injected = Array.from(component.injected_reactive_declaration_vars).filter(name => { diff --git a/test/runtime/samples/props-reactive/Nested.svelte b/test/runtime/samples/props-reactive/Nested.svelte new file mode 100644 index 0000000000..094aa8f36a --- /dev/null +++ b/test/runtime/samples/props-reactive/Nested.svelte @@ -0,0 +1,9 @@ + + +

{props.qux}

\ No newline at end of file diff --git a/test/runtime/samples/props-reactive/_config.js b/test/runtime/samples/props-reactive/_config.js new file mode 100644 index 0000000000..49e18546c7 --- /dev/null +++ b/test/runtime/samples/props-reactive/_config.js @@ -0,0 +1,22 @@ +export default { + show: 1, + + props: { + a: 1, + b: 2, + c: 3, + d: 4 + }, + + html: ` +

4

+ `, + + test({ assert, component, target }) { + component.d = 5; + + assert.htmlEqual(target.innerHTML, ` +

5

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/props-reactive/main.svelte b/test/runtime/samples/props-reactive/main.svelte new file mode 100644 index 0000000000..615df8d294 --- /dev/null +++ b/test/runtime/samples/props-reactive/main.svelte @@ -0,0 +1,10 @@ + + + \ No newline at end of file