Skip to content

feat!: Program range span entire source text#677

Merged
mdjermanovic merged 3 commits intoeslint:mainfrom
Pixel998:Program-range-cover-whole-program
Nov 6, 2025
Merged

feat!: Program range span entire source text#677
mdjermanovic merged 3 commits intoeslint:mainfrom
Pixel998:Program-range-cover-whole-program

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.

fasttime
fasttime previously approved these changes Sep 17, 2025
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.

@mdjermanovic
Copy link
Member

There's a merge conflict now.

Pixel998 added a commit to Pixel998/eslint that referenced this pull request Sep 26, 2025
Copy link
Member

@mdjermanovic mdjermanovic 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!

@mdjermanovic mdjermanovic marked this pull request as ready for review November 6, 2025 18:11
@mdjermanovic mdjermanovic merged commit 68bbb74 into eslint:main Nov 6, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Blocked to Complete in Triage Nov 6, 2025
@github-actions github-actions bot mentioned this pull request Nov 6, 2025
mdjermanovic pushed a commit to eslint/eslint that referenced this pull request Nov 10, 2025
* chore: align tests with `Program` range change

* update espree

* update test

* use the branch of eslint/js#677 to test changes

* correct index calc in `utils.getFirstIndex/getLastIndex`

* avoid using search() in getFirstIndex() and getLastIndex()

* update migration guide

* update espree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Change Request: Program range cover whole program

3 participants