Skip to content

Commit

Permalink
Fix: operator-assignment crash on adjacent division assignment (#12844)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Feb 1, 2020
1 parent 9f39ef0 commit dadc892
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/operator-assignment.js
Expand Up @@ -219,7 +219,7 @@ module.exports = {

if (
operatorToken.range[1] === firstRightToken.range[0] &&
!astUtils.canTokensBeAdjacent(newOperator, firstRightToken)
!astUtils.canTokensBeAdjacent({ type: "Punctuator", value: newOperator }, firstRightToken)
) {
rightTextPrefix = " "; // foo+=+bar -> foo= foo+ +bar
}
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/operator-assignment.js
Expand Up @@ -358,6 +358,11 @@ ruleTester.run("operator-assignment", rule, {
output: "foo= foo+-bar", // tokens can be adjacent
options: ["never"],
errors: UNEXPECTED_OPERATOR_ASSIGNMENT
}, {
code: "foo/=bar",
output: "foo= foo/bar", // tokens can be adjacent
options: ["never"],
errors: UNEXPECTED_OPERATOR_ASSIGNMENT
}, {
code: "foo+=+bar",
output: "foo= foo+ +bar", // tokens cannot be adjacent, insert a space between
Expand Down

0 comments on commit dadc892

Please sign in to comment.