Skip to content

Commit

Permalink
Chore: Improve readability of Program position fix part (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored May 3, 2021
1 parent 94508b7 commit 6ffd604
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,27 @@ export default () => Parser => {
* whitespace or leading comments). Acorn also counts trailing whitespace
* as part of the program whereas Esprima only counts up to the last token.
*/
if (program.range) {
program.range[0] = program.body.length ? program.body[0].range[0] : program.range[0];
program.range[1] = extra.lastToken ? extra.lastToken.range[1] : program.range[1];
if (program.body.length) {
const [firstNode] = program.body;

if (program.range) {
program.range[0] = firstNode.range[0];
}
if (program.loc) {
program.loc.start = firstNode.loc.start;
}
program.start = firstNode.start;
}
if (program.loc) {
program.loc.start = program.body.length ? program.body[0].loc.start : program.loc.start;
program.loc.end = extra.lastToken ? extra.lastToken.loc.end : program.loc.end;
if (extra.lastToken) {
if (program.range) {
program.range[1] = extra.lastToken.range[1];
}
if (program.loc) {
program.loc.end = extra.lastToken.loc.end;
}
program.end = extra.lastToken.end;
}

program.start = program.body.length ? program.body[0].start : program.start;
program.end = extra.lastToken ? extra.lastToken.end : program.end;

/*
* https://github.com/eslint/espree/issues/349
Expand Down

0 comments on commit 6ffd604

Please sign in to comment.