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

Selector Property > .key can't match key in const {a = 1} = b; #14799

Closed
fisker opened this issue Jul 14, 2021 · 5 comments · Fixed by #15072
Closed

Selector Property > .key can't match key in const {a = 1} = b; #14799

fisker opened this issue Jul 14, 2021 · 5 comments · Fixed by #15072
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:yes
Projects

Comments

@fisker
Copy link
Contributor

fisker commented Jul 14, 2021

Tell us about your environment

  • ESLint Version: v7.30.0
  • Node Version: v16.4.2
  • npm Version: v7.9.0
  • Operating System: win32 10.0.19043

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

The default parser.

The issue template doesn't fit, so I removed these sections.

I was making an eslint plugin, for this code

const {a = 1} = b;

I should be able to use Property > .key to select the key, but ESLint won't match.

I think this happens because we use the same reference for key and value.left, so they both have the AssignmentPattern as parent. For this reason, I don't think this is an issue by espree or acorn.

This happens to assignment too.

({a = 1} = b);
@fisker fisker added bug ESLint is working incorrectly repro:needed labels Jul 14, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Jul 14, 2021
@fisker fisker changed the title Selector can't much destructuring key, when property is shorthand with default value. Selector Property > .key can't match key in const {a = 1} = b; Jul 14, 2021
@nzakas
Copy link
Member

nzakas commented Jul 14, 2021

I think this happens because we use the same reference for key and value.left, so they both have the AssignmentPattern as parent.

Where are you seeing this?

And can you provide a minimal repro case so we can see the behavior?

Note the query engine is esquery, so it could be an issue there.

@nzakas nzakas moved this from Needs Triage to Triaging in Triage Jul 14, 2021
@mdjermanovic
Copy link
Member

mdjermanovic commented Jul 14, 2021

I think this happens because we use the same reference for key and value.left, so they both have the AssignmentPattern as parent. For this reason, I don't think this is an issue by espree or acorn.

This is a bug in Acorn 7 / Espree 7, nodes in a tree shouldn't have multiple parents. The bug is fixed in Acorn 8 / Espree 8 (relevant test is here).

Once we switch to Espree 8.0.0, we could add a test with Property > .key selector to confirm that it works well in ESLint.

@nzakas
Copy link
Member

nzakas commented Jul 15, 2021

Once we switch to Espree 8.0.0, we could add a test with Property > .key selector to confirm that it works well in ESLint.

Can you try by using Espree 8 locally and let us know the result?

@fisker
Copy link
Contributor Author

fisker commented Jul 15, 2021

This is a bug in Acorn 7 / Espree 7, nodes in a tree shouldn't have multiple parents. The bug is fixed in Acorn 8 / Espree 8 (relevant test is here).

Thank you, I didn't know that.

Can you try by using Espree 8 locally and let us know the result?

Confirmed, updating to Espree 8 fixes this.


Question: ETA for switch to Espree 8.0.0? Do we need workaround in ESLint before that?

@nzakas
Copy link
Member

nzakas commented Jul 16, 2021

@fisker thanks for the followup. The Espree upgrade will happen with the ESLint v8.0.0 release, which we hope we will have a preview release of in a couple weeks.

We can’t upgrade Espree in ESLint v7.x line due to breaking changes.

@nzakas nzakas moved this from Triaging to Blocked in Triage Jul 16, 2021
Triage automation moved this from Blocked to Complete Sep 16, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Mar 16, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:yes
Projects
Triage
Complete
Development

Successfully merging a pull request may close this issue.

3 participants