From bb6a1b6c679ff9ad09795496b9a37b85b591ba2d Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 8 Aug 2020 14:01:23 +0800 Subject: [PATCH] fix #5427 - do not declare variable for member assignment in reactive declaration --- src/compiler/compile/render_ssr/index.ts | 6 ++++-- .../samples/reactive-value-assign-property/_config.js | 5 +++++ .../samples/reactive-value-assign-property/main.svelte | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/reactive-value-assign-property/_config.js create mode 100644 test/runtime/samples/reactive-value-assign-property/main.svelte diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index c87fe3bdd92b..ff6db2b13a01 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -99,8 +99,10 @@ export default function ssr( ? b` ${injected.map(name => b`let ${name};`)} ${statement}` - : b` - let ${left} = ${right}`; + : left.type === "Identifier" + ? b` + let ${left} = ${right}` + : b`${left} = ${right}`; } } else { // TODO do not add label if it's not referenced statement = b`$: { ${statement} }`; diff --git a/test/runtime/samples/reactive-value-assign-property/_config.js b/test/runtime/samples/reactive-value-assign-property/_config.js new file mode 100644 index 000000000000..7b6c1d296559 --- /dev/null +++ b/test/runtime/samples/reactive-value-assign-property/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +

Hello world!

+ `, +}; diff --git a/test/runtime/samples/reactive-value-assign-property/main.svelte b/test/runtime/samples/reactive-value-assign-property/main.svelte new file mode 100644 index 000000000000..58e0fdb03c39 --- /dev/null +++ b/test/runtime/samples/reactive-value-assign-property/main.svelte @@ -0,0 +1,6 @@ + + +

Hello {user.name}!

\ No newline at end of file