Skip to content

Commit

Permalink
Fix sveltejs#3634: Add left hand side of compound assignment as depen…
Browse files Browse the repository at this point in the history
…dency

Compound assignments ('x += y', 'x *= y', etc) should have the
left-hand side of the assignment as a dependency.
  • Loading branch information
blackwolf12333 committed Sep 29, 2019
1 parent 4bacb0c commit 3996d01
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3996d01

Please sign in to comment.