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

fix(jest-globals): set array accessor type for parser compatibility #586

Merged
merged 5 commits into from
Jul 28, 2024

Conversation

puglyfe
Copy link
Contributor

@puglyfe puglyfe commented Jul 12, 2024

Fixes #585

Given an expression statement like someSpy.calls.argsFor(0)[1], different parsers assign different type values to the argsFor arg node.

babel and flow parse it as type: "Literal", where as babylon, ts and tsx parse it as type: "NumericLiteral". When parsed as NumericLiteral, it results in invalid syntax when used as an array accessor.

This change updates the transform to explicitly set it as type: "Literal" regardless of the parser used. I also updated the test for this scenario to use multiple parsers. It's maybe a pattern that would be useful elsewhere, but I'll leave that as a separate effort 😅

I also added support for argsFor args that are type: "Identifier" (e.g. argsFor(someVariable)).

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.64%. Comparing base (a94e2b5) to head (87677dc).
Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #586      +/-   ##
==========================================
+ Coverage   92.38%   92.64%   +0.25%     
==========================================
  Files          26       27       +1     
  Lines        1944     2012      +68     
  Branches      405      417      +12     
==========================================
+ Hits         1796     1864      +68     
  Misses        102      102              
  Partials       46       46              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@skovhus
Copy link
Owner

skovhus commented Jul 28, 2024

Thanks!

@skovhus skovhus merged commit a418ab5 into skovhus:main Jul 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jasmine-globals: argsFor gets incorrectly transformed with certain parsers
2 participants