From 7c9b31be0fd6ee2bfd6073d3c2d6eb66b776ad88 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 19 Sep 2020 10:25:07 +0800 Subject: [PATCH] sequence expression instead of identity function --- src/compiler/compile/render_ssr/index.ts | 11 +++++++++-- .../store-auto-resubscribe-immediate/main.svelte | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index 8ca7663e7091..b395a5973744 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -5,7 +5,7 @@ import { string_literal } from '../utils/stringify'; import Renderer from './Renderer'; import { INode as TemplateNode } from '../nodes/interfaces'; // TODO import Text from '../nodes/Text'; -import { LabeledStatement, Statement, Node } from 'estree'; +import { LabeledStatement, Statement, Node, Expression } from 'estree'; import { walk } from 'estree-walker'; import { extract_names } from 'periscopic'; @@ -99,7 +99,14 @@ export default function ssr( }); if (vars.length) { - this.replace(x`@identity(${node}, ${vars})`); + this.replace({ + type: 'SequenceExpression', + expressions: [ + node, + ...vars, + assignee as Expression + ] + }); } } } diff --git a/test/runtime/samples/store-auto-resubscribe-immediate/main.svelte b/test/runtime/samples/store-auto-resubscribe-immediate/main.svelte index f402662a53e2..10721c4b4957 100644 --- a/test/runtime/samples/store-auto-resubscribe-immediate/main.svelte +++ b/test/runtime/samples/store-auto-resubscribe-immediate/main.svelte @@ -8,16 +8,24 @@ // should resubscribe immediately value = writable({ foo: $value.foo + 2, bar: $value.bar - 2 }); // { foo: 5, bar: 4 } + // should mutate the store value $value.baz = $value.foo + $value.bar; // { foo: 5, bar: 4, baz: 9 } // should resubscribe immediately value = writable({ qux: $value.baz - $value.foo }); // { qux: 4 } - // should update the store immediately - $value = { baz: $value.qux }; // { baz: 4 } + // making sure instrumentation returns the expression value + $value = { + one: writable( + $value = { + two: ({ $value } = { '$value': { fred: $value.qux } }) // { fred: 4 } + }, // { two: { $value: { fred: 4 } } } + ), // { one: { two: { $value: { fred: 4 } } } } + }; - value.update(val => ({ answer: val.baz })); // { answer: 4 } - value = value; // for ssr + const one = $value.one; + + value.update(val => ({ answer: $one.two.$value.fred })); // { answer: 4 } {JSON.stringify($value)} \ No newline at end of file