diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 61e1ebc6b1..2bf4eb821a 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -8,6 +8,7 @@ import { walk } from 'estree-walker'; import stringifyProps from '../../utils/stringifyProps'; import addToSet from '../../utils/addToSet'; import getObject from '../../utils/getObject'; +import { extractNames } from '../../utils/annotateWithScopes'; export default function dom( component: Component, @@ -168,12 +169,16 @@ export default function dom( } if (node.type === 'AssignmentExpression') { - const { name } = getObject(node.left); - - if (scope.findOwner(name) === component.instance_scope) { - pending_assignments.add(name); - component.has_reactive_assignments = true; - } + const names = node.left.type === 'MemberExpression' + ? [getObject(node.left).name] + : extractNames(node.left); + + names.forEach(name => { + if (scope.findOwner(name) === component.instance_scope) { + pending_assignments.add(name); + component.has_reactive_assignments = true; + } + }); } if (pending_assignments.size > 0) { diff --git a/test/runtime/samples/instrumentation-script-destructuring/_config.js b/test/runtime/samples/instrumentation-script-destructuring/_config.js new file mode 100644 index 0000000000..a0b2de9e77 --- /dev/null +++ b/test/runtime/samples/instrumentation-script-destructuring/_config.js @@ -0,0 +1,29 @@ +export default { + html: ` + + + +
x: 0
+ `, + + async test({ assert, component, target, window }) { + const buttons = target.querySelectorAll('button'); + const click = new window.MouseEvent('click'); + + await buttons[0].dispatchEvent(click); + assert.htmlEqual(target.innerHTML, ` + + + +x: 1
+ `); + + await buttons[1].dispatchEvent(click); + assert.htmlEqual(target.innerHTML, ` + + + +x: 2
+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/instrumentation-script-destructuring/main.html b/test/runtime/samples/instrumentation-script-destructuring/main.html new file mode 100644 index 0000000000..6da761a96a --- /dev/null +++ b/test/runtime/samples/instrumentation-script-destructuring/main.html @@ -0,0 +1,16 @@ + + + + + +x: {x}
\ No newline at end of file