From 14e739379b0503327aa5574cdb6e978a011a8935 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Jun 2019 13:51:14 -0400 Subject: [PATCH] handle member expressions in destructuring assignments - fixes #3092 --- src/compiler/compile/utils/scope.ts | 5 ++++ .../destructuring-assignment-array/_config.js | 23 +++++++++++++++++++ .../main.svelte | 18 +++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 test/runtime/samples/destructuring-assignment-array/_config.js create mode 100644 test/runtime/samples/destructuring-assignment-array/main.svelte diff --git a/src/compiler/compile/utils/scope.ts b/src/compiler/compile/utils/scope.ts index 6bf3f9eaf4..75e44f0adf 100644 --- a/src/compiler/compile/utils/scope.ts +++ b/src/compiler/compile/utils/scope.ts @@ -2,6 +2,7 @@ import { walk } from 'estree-walker'; import is_reference from 'is-reference'; import { Node } from '../../interfaces'; import { Node as ESTreeNode } from 'estree'; +import get_object from './get_object'; export function create_scopes(expression: Node) { const map = new WeakMap(); @@ -114,6 +115,10 @@ const extractors = { nodes.push(param); }, + MemberExpression(nodes: Node[], param: Node) { + nodes.push(get_object(param)); + }, + ObjectPattern(nodes: Node[], param: Node) { param.properties.forEach((prop: Node) => { if (prop.type === 'RestElement') { diff --git a/test/runtime/samples/destructuring-assignment-array/_config.js b/test/runtime/samples/destructuring-assignment-array/_config.js new file mode 100644 index 0000000000..ede4552803 --- /dev/null +++ b/test/runtime/samples/destructuring-assignment-array/_config.js @@ -0,0 +1,23 @@ +export default { + html: ` + + `, + + async test({ assert, component, target }) { + await component.swap(0, 1); + + assert.htmlEqual(target.innerHTML, ` + + `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/destructuring-assignment-array/main.svelte b/test/runtime/samples/destructuring-assignment-array/main.svelte new file mode 100644 index 0000000000..aebbfe204c --- /dev/null +++ b/test/runtime/samples/destructuring-assignment-array/main.svelte @@ -0,0 +1,18 @@ + + + \ No newline at end of file