sequence expression instead of identity function

pull/5419/head
Tan Li Hau 5 years ago
parent 0e5ca3013b
commit 193718f8ad

@ -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
]
});
}
}
}

@ -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)}
Loading…
Cancel
Save