Skip to content

fix: properly set location data in OUTDENT nodes#2

Merged
alangpierce merged 1 commit into
decaffeinate-fork-1.10.0from
backport-fix-outdent-location-data
Aug 6, 2016
Merged

fix: properly set location data in OUTDENT nodes#2
alangpierce merged 1 commit into
decaffeinate-fork-1.10.0from
backport-fix-outdent-location-data

Conversation

@alangpierce

Copy link
Copy Markdown
Member

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

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
@alangpierce
alangpierce merged commit 55ee19b into decaffeinate-fork-1.10.0 Aug 6, 2016
@alangpierce
alangpierce deleted the backport-fix-outdent-location-data branch August 6, 2016 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant