From 3996d015dbed7a224996b9947cd79ca856c6b07b Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Sun, 29 Sep 2019 17:06:30 +0200 Subject: [PATCH] Fix #3634: Add left hand side of compound assignment as dependency Compound assignments ('x += y', 'x *= y', etc) should have the left-hand side of the assignment as a dependency. --- src/compiler/compile/Component.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index fa8665ffde50..54d86689fd3f 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -46,6 +46,9 @@ childKeys.EachBlock = childKeys.IfBlock = ['children', 'else']; childKeys.Attribute = ['value']; childKeys.ExportNamedDeclaration = ['declaration', 'specifiers']; +// There is no datatype that describes only the compound operators so we create this list here +const compoundAssignmentOperators = ["+=" , "-=" ,"*=", "/=" ,"%=" ,"**=", "<<=" ,">>=", ">>>=", "|=" ,"^=" ,"&="]; + function remove_node( code: MagicString, start: number, @@ -1265,10 +1268,18 @@ export default class Component { } if (node.type === 'AssignmentExpression') { - extract_identifiers(get_object(node.left)).forEach(node => { + const left = get_object(node.left); + + extract_identifiers(left).forEach(node => { assignee_nodes.add(node); assignees.add(node.name); }); + + + + if (compoundAssignmentOperators.findIndex(op => op === node.operator) !== -1) { + dependencies.add(left.name); + } } else if (node.type === 'UpdateExpression') { const identifier = get_object(node.argument); assignees.add(identifier.name);