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.
pull/3640/head
Peter Maatman 6 years ago
parent 88f2fcfbb5
commit d57204bc6f

@ -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);

Loading…
Cancel
Save