-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't shrink loop bounds by assuming the body is at the end (#74)
Fixes decaffeinate/decaffeinate#333 Fixes decaffeinate/decaffeinate#502 The code to fix CoffeeScript location data was incorrectly assuming that the last node of a loop is the loop body, but that isn't true in postfix loops, so it was causing the end location to be artificially early. Probably, the ideal behavior (assuming location data actually needs to be fixed here) is to take the max of all nodes, but that didn't seem trivial. Instead, an easy fix is to just do the same thing we do for the `if` case: just use the body to extend the bounds if necessary, but never shrink it. This also seems more robust in general, probably. At the very least, it's really simple and doesn't break any decaffeinate tests.
- Loading branch information
1 parent
2229f42
commit 16b0596
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a for a in b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"type": "Program", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
13 | ||
], | ||
"raw": "a for a in b\n", | ||
"body": { | ||
"type": "Block", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
12 | ||
], | ||
"statements": [ | ||
{ | ||
"type": "ForIn", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
12 | ||
], | ||
"keyAssignee": null, | ||
"valAssignee": { | ||
"type": "Identifier", | ||
"line": 1, | ||
"column": 7, | ||
"range": [ | ||
6, | ||
7 | ||
], | ||
"data": "a", | ||
"raw": "a" | ||
}, | ||
"body": { | ||
"type": "Block", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
1 | ||
], | ||
"statements": [ | ||
{ | ||
"type": "Identifier", | ||
"line": 1, | ||
"column": 1, | ||
"range": [ | ||
0, | ||
1 | ||
], | ||
"data": "a", | ||
"raw": "a" | ||
} | ||
], | ||
"raw": "a", | ||
"inline": false | ||
}, | ||
"target": { | ||
"type": "Identifier", | ||
"line": 1, | ||
"column": 12, | ||
"range": [ | ||
11, | ||
12 | ||
], | ||
"data": "b", | ||
"raw": "b" | ||
}, | ||
"filter": null, | ||
"step": null, | ||
"raw": "a for a in b" | ||
} | ||
], | ||
"raw": "a for a in b" | ||
} | ||
} |