fix: properly set location data in OUTDENT nodes#2
Merged
alangpierce merged 1 commit intoAug 6, 2016
Merged
Conversation
Backport of jashkenas#4291 . In f609036, a line was changed from `if length > 0 then (length - 1) else 0` to `Math.max 0, length - 1`. However, in some cases, the `length` variable can be `undefined`. The previous code would correctly compute `lastCharacter` as 0, but the new code would compute it as `NaN`. This would cause trouble later on: the end location would just be the end of the current chunk, which would be incorrect. Here's a specific case where the parser was behaving incorrectly: ``` a { b: -> return c d, if e f } g ``` The OUTDENT tokens after the `f` had an undefined length, so the `NaN` made it so the end location was at the end of the file. That meant that various nodes in the AST, like the `return` node, would incorrectly have an end location at the end of the file. To fix, I just reverted the change to that particular line. Also add a test that tokens have locations that are in order
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of jashkenas#4291 .
In f609036, a line was changed from
if length > 0 then (length - 1) else 0toMath.max 0, length - 1. However,in some cases, the
lengthvariable can beundefined. The previous code wouldcorrectly compute
lastCharacteras 0, but the new code would compute it asNaN. This would cause trouble later on: the end location would just be the endof the current chunk, which would be incorrect.
Here's a specific case where the parser was behaving incorrectly:
The OUTDENT tokens after the
fhad an undefined length, so theNaNmade itso the end location was at the end of the file. That meant that various nodes in
the AST, like the
returnnode, would incorrectly have an end location at theend of the file.
To fix, I just reverted the change to that particular line.
Also add a test that tokens have locations that are in order