mirror of https://github.com/sveltejs/svelte
parent
6ac7038e47
commit
08faaeb601
@ -1,6 +1,28 @@
|
|||||||
import { Node, Identifier } from 'estree';
|
import {
|
||||||
|
Node,
|
||||||
|
Identifier,
|
||||||
|
ArrayExpression,
|
||||||
|
ObjectExpression,
|
||||||
|
ThisExpression,
|
||||||
|
ObjectPattern,
|
||||||
|
ArrayPattern,
|
||||||
|
Literal,
|
||||||
|
} from "estree";
|
||||||
|
|
||||||
export default function get_object(node: Node): Identifier {
|
type ObjectType =
|
||||||
while (node.type === 'MemberExpression') node = node.object;
|
| Identifier
|
||||||
return node as Identifier;
|
| ThisExpression
|
||||||
|
| ArrayExpression
|
||||||
|
| ObjectExpression
|
||||||
|
| ArrayPattern
|
||||||
|
| ObjectPattern
|
||||||
|
| Literal;
|
||||||
|
|
||||||
|
export default function get_object(node: Node): ObjectType {
|
||||||
|
while (true) {
|
||||||
|
if (node.type === "MemberExpression") node = node.object;
|
||||||
|
else if (node.type === "CallExpression") node = node.callee;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
return node as ObjectType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<input>
|
||||||
|
`,
|
||||||
|
|
||||||
|
ssrHtml: `
|
||||||
|
<input value="50">
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const input = target.querySelector('input');
|
||||||
|
assert.equal(input.value, '50');
|
||||||
|
|
||||||
|
component.map.get(component.id).x = 30;
|
||||||
|
component.map = component.map;
|
||||||
|
assert.equal(input.value, '30');
|
||||||
|
|
||||||
|
input.value = '42';
|
||||||
|
await input.dispatchEvent(new window.Event('input'));
|
||||||
|
|
||||||
|
assert.equal(input.value, '42');
|
||||||
|
assert.equal(component.map.get(component.id).x, '42')
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export let id = 1;
|
||||||
|
export let map = new Map();
|
||||||
|
map.set(id, { x: 50, y: 50 });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input bind:value={map.get(id).x} />
|
||||||
Loading…
Reference in new issue