Skip to content

Conversation

Pixel998
Copy link
Contributor

@Pixel998 Pixel998 commented Sep 15, 2025

Prerequisites checklist

Program's range currently works as follows:

  1. If there are no tokens, i.e., the source code is only whitespace and/or comments, then the Program's range is the whole source code.
  2. If there's at least one token, then the Program's range starts from the first token's start and ends at the last token's end. Whitespace and comments before the first token and after the last token are not included in the Program's range.

What is the purpose of this pull request?

This PR updates Program’s range and loc so that they always cover the entire source text, regardless of tokens.

  • Program range start is 0.
  • Program range end is length of the source text.

loc follows the same pattern. i.e.:

  • loc.start is always { line: 1, column: 0 }
  • loc.end.line is the number of lines in the source text.
  • loc.end.column is the number of characters in last line of source text.

What changes did you make? (Give an overview)

  • Removed the code that adjusted the Program’s range and loc to mimic Esprima’s behavior.
  • Updated the tests to reflect that Program.range and Program.loc now always span the entire source text.

Related Issues

Fix #648

Is there anything you'd like reviewers to focus on?

@fasttime
Copy link
Member

Is this ready to review?

@Pixel998
Copy link
Contributor Author

@fasttime Yes

@fasttime fasttime moved this from Needs Triage to Triaging in Triage Sep 17, 2025
@fasttime fasttime moved this from Triaging to Implementing in Triage Sep 17, 2025
@fasttime fasttime moved this from Implementing to Blocked in Triage Sep 17, 2025
@fasttime
Copy link
Member

I tested this with ESLint and didn't see any incorrect behavior. A few unit tests were failing or no longer consistent (e.g., "should retrieve comments after a Program node"), but that's expected given the changes. The core logic and rule implementations appeared to be still working without additional modifications.

Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Waiting for a second review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Blocked
Development

Successfully merging this pull request may close these issues.

Change Request: Program range cover whole program
2 participants