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

refactor(js_syntax): use dedicated declarations for binding patterns #1800

Merged
merged 5 commits into from
Feb 13, 2024

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Feb 12, 2024

Summary

Fix #1648
Fix #1652.

Previously, Biome returned the parent declaration for any binding patterns.
For instance:

const { a, b = a } = {};
      ^^^^^^^^^^^^
      declaration of both `a` and `b`
export { b }

Because rules such as noInvalidUseBeforeDeclaration and noUnusedVariables rely on the actual declarations, this resulted in wrong false positive or wrong false negative: in the previous example, a is wrongly reported as unused and its use is wrongly reported as a use before declaration.

Now, a and b have distinct and dedicated declarations:

const { a, b = a } = {};
        ^  ^^^^^
        |  declaration of `b`
        declaration of `a`
export { b }

This avoids the two previous issues.

I had to replace JsBindingWithDefault by JsArrayBindingPatternElement in order to get a proper type for the declaration of an array pattern element. This makes also the CST more consistent, because is analog to JsObjectBindingPatternShorthandProperty and JsObjectBindingPatternProperty and it reuses JsInitializerClause.
For consistency, I also replaced JsAssignementWithDefault by JsArrayAssignementPatternElement

Remaining tasks:

  • add changelog entries

Test Plan

  • New tests added.

Copy link

netlify bot commented Feb 12, 2024

Deploy Preview for biomejs canceled.

Name Link
🔨 Latest commit 54d4bb0
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/65cb6751f4a06e00086ffbb3

@github-actions github-actions bot added A-Core Area: core A-Linter Area: linter A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS labels Feb 12, 2024
@Conaclos Conaclos requested review from a team February 12, 2024 21:29
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 49701 49701 0
Passed 48721 48721 0
Failed 980 980 0
Panics 0 0 0
Coverage 98.03% 98.03% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6322 6322 0
Passed 2036 2036 0
Failed 4286 4286 0
Panics 0 0 0
Coverage 32.20% 32.20% 0.00%

ts/babel

Test result main count This PR count Difference
Total 662 662 0
Passed 593 593 0
Failed 69 69 0
Panics 0 0 0
Coverage 89.58% 89.58% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17646 17646 0
Passed 13439 13439 0
Failed 4205 4205 0
Panics 2 2 0
Coverage 76.16% 76.16% 0.00%

Copy link

codspeed-hq bot commented Feb 12, 2024

CodSpeed Performance Report

Merging #1800 will not alter performance

Comparing conaclos/declaration-fixes (54d4bb0) with main (dca6a7a)

Summary

✅ 93 untouched benchmarks

Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Haven’t looked at all the code changes, but appreciate the clear explanation. Sounds like a good solution 👍

@Conaclos Conaclos force-pushed the conaclos/declaration-fixes branch from 8c257d8 to fe914ea Compare February 13, 2024 12:34
@github-actions github-actions bot added A-Website Area: website A-Changelog Area: changelog labels Feb 13, 2024
@Conaclos Conaclos force-pushed the conaclos/declaration-fixes branch from 8e5de09 to 54d4bb0 Compare February 13, 2024 12:57
@github-actions github-actions bot removed the L-CSS Language: CSS label Feb 13, 2024
@Conaclos Conaclos merged commit 5a4e21f into main Feb 13, 2024
23 checks passed
@Conaclos Conaclos deleted the conaclos/declaration-fixes branch February 13, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Core Area: core A-Formatter Area: formatter A-Linter Area: linter A-Parser Area: parser A-Tooling Area: internal tools A-Website Area: website L-JavaScript Language: JavaScript and super languages
Projects
None yet
3 participants