Skip to content

Conversation

@alangpierce
Copy link
Member

Fixes decaffeinate/decaffeinate#710

The lexer generates fake tokens for interpolated heregexes, and the ending
tokens were being placed where the start (inclusive) and end (inclusive) index
were one past the end of the heregex. This meant that in a case like
[a ///#{b}///], the end tokens of the heregex and also the implicit function
call end were all being placed at the ], so the AST location data would say
that the function call ends at the end of the ]. This caused decaffeinate to
insert the close-paren after the ], which is wrong.

To fix, I can just subtract 1 from the position of those ending heregex tokens
so that their end lines up with the end of the heregex itself. This is similar
to previous fixes that changed OUTDENT and CALL_END tokens so that the end
of the token lines up with the end of the AST node.

Fixes decaffeinate/decaffeinate#710

The lexer generates fake tokens for interpolated heregexes, and the ending
tokens were being placed where the start (inclusive) and end (inclusive) index
were one past the end of the heregex. This meant that in a case like
`[a ///#{b}///]`, the end tokens of the heregex and also the implicit function
call end were all being placed at the `]`, so the AST location data would say
that the function call ends at the end of the `]`. This caused decaffeinate to
insert the close-paren after the `]`, which is wrong.

To fix, I can just subtract 1 from the position of those ending heregex tokens
so that their end lines up with the end of the heregex itself. This is similar
to previous fixes that changed `OUTDENT` and `CALL_END` tokens so that the end
of the token lines up with the end of the AST node.
Copy link

@eventualbuddha eventualbuddha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good. Should we submit upstream?

@alangpierce
Copy link
Member Author

Yep, I can take care of that.

@alangpierce alangpierce merged commit 8562b60 into decaffeinate:decaffeinate-fork-1.10.0 Jan 3, 2017
alangpierce added a commit to alangpierce/coffeescript that referenced this pull request Feb 17, 2017
This is an upstream port of decaffeinate#17

The lexer generates fake tokens for interpolated heregexes, and the ending
tokens were being placed where the start (inclusive) and end (inclusive) index
were one past the end of the heregex. This meant that in a case like
`[a ///#{b}///]`, the end tokens of the heregex and also the implicit function
call end were all being placed at the `]`, so the AST location data would say
that the function call ends at the end of the `]`.

To fix, I can just subtract 1 from the position of those ending heregex tokens
so that their end lines up with the end of the heregex itself. This is similar
to previous fixes that changed `OUTDENT` and `CALL_END` tokens so that the end
of the token lines up with the end of the AST node.
EsrefDurna pushed a commit to EsrefDurna/coffeescript that referenced this pull request Nov 12, 2025
This is an upstream port of decaffeinate#17

The lexer generates fake tokens for interpolated heregexes, and the ending
tokens were being placed where the start (inclusive) and end (inclusive) index
were one past the end of the heregex. This meant that in a case like
`[a ///#{b}///]`, the end tokens of the heregex and also the implicit function
call end were all being placed at the `]`, so the AST location data would say
that the function call ends at the end of the `]`.

To fix, I can just subtract 1 from the position of those ending heregex tokens
so that their end lines up with the end of the heregex itself. This is similar
to previous fixes that changed `OUTDENT` and `CALL_END` tokens so that the end
of the token lines up with the end of the AST node.
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.

2 participants