[js_ast] Don't rewrite compound assignments

Bug: 37337
Change-Id: Ibda0d9233d480cc64732e9e17182b55cde77baf2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107181
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
Stephen Adams 2019-06-24 19:35:07 +00:00 committed by commit-bot@chromium.org
parent bc8b6fb94d
commit c7524cc296
2 changed files with 23 additions and 1 deletions

View file

@ -763,7 +763,10 @@ class Printer implements NodeVisitor {
// Output 'a += 1' as '++a' and 'a -= 1' as '--a'.
_outputIncDec(op, assignment.leftHandSide);
return;
} else if (leftHandSide is VariableUse && rightHandSide is Binary) {
}
if (!assignment.isCompound &&
leftHandSide is VariableUse &&
rightHandSide is Binary) {
Node rLeft = undefer(rightHandSide.left);
Node rRight = undefer(rightHandSide.right);
String op = rightHandSide.op;

View file

@ -29,6 +29,25 @@ main() {
test(map, '# = # - 1', [deferred, variableUseAlias], '--variable');
test(map, '# = # + 2', [variableUse, variableUseAlias], 'variable += 2');
test(map, '# = # + 2', [deferred, variableUseAlias], 'variable += 2');
test(map, '# = # * 2', [variableUse, variableUseAlias], 'variable *= 2');
test(map, '# = # * 2', [deferred, variableUseAlias], 'variable *= 2');
test(map, '# += # + 1', [variableUse, variableUseAlias],
'variable += variable + 1');
test(map, '# += # + 1', [deferred, variableUseAlias],
'variable += variable + 1');
test(map, '# += # - 1', [variableUse, variableUseAlias],
'variable += variable - 1');
test(map, '# += # - 1', [deferred, variableUseAlias],
'variable += variable - 1');
test(map, '# += # + 2', [variableUse, variableUseAlias],
'variable += variable + 2');
test(map, '# += # + 2', [deferred, variableUseAlias],
'variable += variable + 2');
test(map, '# += # * 2', [variableUse, variableUseAlias],
'variable += variable * 2');
test(map, '# += # * 2', [deferred, variableUseAlias],
'variable += variable * 2');
}
void test(Map<Expression, DeferredExpression> map, String template,