Skip to content

Commit

Permalink
sequence expression instead of identity function
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Sep 19, 2020
1 parent 4688a84 commit 7c9b31b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/compiler/compile/render_ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
]
});
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions test/runtime/samples/store-auto-resubscribe-immediate/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
</script>

{JSON.stringify($value)}

0 comments on commit 7c9b31b

Please sign in to comment.