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

feat: support logical and member expression #111

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

lihbr
Copy link
Member

@lihbr lihbr commented Apr 10, 2024

πŸ”— Linked issue

N/A

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds support for logical and member expression, allowing for that kind of code modification with builder.raw() (which would have thrown a MagicastError before)

+ import { foo, bar } as config from "./config.json";

  export const a = {
+   bar: config.foo || config.bar
  }

I'm by far not an AST expert so I'm not sure if my changes cover it all. Also I'm not sure if this kind of node support is welcome/within the scope of Magicast, so let me know if not, no big deal ☺️

On another note, I feel like there's a pattern here, maybe we want to support other node types like conditional expressions (foo ? bar : baz) with some kind of generic proxy instead for "readonly" kind of node. Feel free to nudge me towards the direction that fits better the project!

Thanks!

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

codecov bot commented Apr 10, 2024

Codecov Report

Attention: Patch coverage is 93.10345% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 93.53%. Comparing base (46f6cee) to head (79dfb20).

Files Patch % Lines
src/proxy/logical-expression.ts 89.47% 2 Missing ⚠️
src/proxy/member-expression.ts 89.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
- Coverage   93.54%   93.53%   -0.02%     
==========================================
  Files          25       27       +2     
  Lines        1797     1855      +58     
  Branches      335      341       +6     
==========================================
+ Hits         1681     1735      +54     
- Misses        115      119       +4     
  Partials        1        1              

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@antfu antfu merged commit c76c5ac into main Apr 12, 2024
1 of 3 checks passed
@lihbr lihbr deleted the feat/support-logical-and-member-expression branch April 12, 2024 08:28
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.

2 participants