diff --git a/src/compile/nodes/shared/Expression.ts b/src/compile/nodes/shared/Expression.ts index dbe5f9bd7f..2e11e8dd18 100644 --- a/src/compile/nodes/shared/Expression.ts +++ b/src/compile/nodes/shared/Expression.ts @@ -2,7 +2,7 @@ import Component from '../../Component'; import { walk } from 'estree-walker'; import isReference from 'is-reference'; import flattenReference from '../../../utils/flattenReference'; -import { createScopes, Scope } from '../../../utils/annotateWithScopes'; +import { createScopes, Scope, extractNames } from '../../../utils/annotateWithScopes'; import { Node } from '../../../interfaces'; import globalWhitelist from '../../../utils/globalWhitelist'; import deindent from '../../../utils/deindent'; @@ -247,9 +247,15 @@ export default class Expression { if (function_expression) { if (node.type === 'AssignmentExpression') { - // TODO handle destructuring assignments - const { name } = getObject(node.left); - pending_assignments.add(name); + const names = node.left.type === 'MemberExpression' + ? [getObject(node.left).name] + : extractNames(node.left); + + names.forEach(name => { + if (!scope.declarations.has(name)) { + pending_assignments.add(name); + } + }); } } else { if (node.type === 'AssignmentExpression') { diff --git a/test/runtime/samples/instrumentation-script-destructuring/main.html b/test/runtime/samples/instrumentation-script-destructuring/main.html index 6da761a96a..9c96ffe621 100644 --- a/test/runtime/samples/instrumentation-script-destructuring/main.html +++ b/test/runtime/samples/instrumentation-script-destructuring/main.html @@ -1,5 +1,5 @@ + + + + +

x: {x}

\ No newline at end of file