Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggest] improve compatibility with more estree parsers? #58

Closed
3cp opened this issue May 16, 2020 · 8 comments
Closed

[suggest] improve compatibility with more estree parsers? #58

3cp opened this issue May 16, 2020 · 8 comments
Labels

Comments

@3cp
Copy link

3cp commented May 16, 2020

I am trying to use eslint-scope with meriyah which uses different data structure for ranges.

It doesn't have .range: [start, end], but has direct .start and .end.

eslint-scope/lib/scope.js

Lines 711 to 718 in dbddf14

const bodyStart = this.block.body.range[0];
// It's invalid resolution in the following case:
return !(
variable.scope === this &&
ref.identifier.range[0] < bodyStart && // the reference is in the parameter part.
variable.defs.every(d => d.name.range[0] >= bodyStart) // the variable is in the body.
);

If I update the above code from .range[0] to .start, everything works fine with meriyah.

Do you consider to improve compatibility with other estree parsers? To check both .range[0] and .start? Thanks!

FYI, estree spec seems didn't define the shape of ranges, it only defined position. https://github.com/estree/estree/blob/14df8a024956ea289bd55b9c2226a1d5b8a473ee/es5.md#node-objects

@aladdin-add
Copy link
Member

I'm not sure we can go that way, as .start/.end is non-standard and non-recommended.

Related issue(s): RFC25, eslint/eslint#12096, eslint/eslint#12955

@3cp
Copy link
Author

3cp commented May 16, 2020

Oh, thx! I did not know it got that much complications.

@3cp 3cp closed this as completed May 16, 2020
@3cp
Copy link
Author

3cp commented May 16, 2020

I noticed it is acknowledged that both .range and .start .end are non-standard. Same as what I read from estree spec. eslint/eslint#8956

@3cp
Copy link
Author

3cp commented May 18, 2020

I think there is an opportunity to improve.

It's not about .range[0] or .start. I felt this check is doable even without any ranges information, because we knew where the node was (in params or body).

The reason of using ranges to check, is that the reference and definition objects didn't retain that information (in params or body). I am not sure how to retain that information in nested function scopes.

I could not get my head around the code base to come up a solution. But I think it's possible to totally remove the usage of .range[0].

@3cp 3cp reopened this May 18, 2020
@bradzacher
Copy link

If you're looking for a completely estree-compliant version, isn't that what escope is?

@3cp
Copy link
Author

3cp commented May 18, 2020

I came here to find an up-to-date version of escope 😄

@nzakas
Copy link
Member

nzakas commented May 19, 2020

As mentioned previously, the start and stop properties are not part of ESTree. They only appear in Espree because we are built on Acorn, which adds these nonstandard properties. Removing them incurs a performance penalty so we leave them in place. However, we don’t rely on those properties being present and always use range internally.

Because we don’t want to encourage relying on nonstandard properties, we won’t be updating this package to use start and end.

Thanks!

@nzakas nzakas closed this as completed May 19, 2020
@3cp
Copy link
Author

3cp commented May 19, 2020

But I think it's possible to totally remove the usage of .range[0].

@nzakas you probably missed my comment on reopening of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants