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: visitor overlapping types #8

Merged
merged 4 commits into from
Jun 19, 2024

Conversation

maastrich
Copy link
Collaborator

PR Description

This PR includes the following changes:

  • In src/baseVisitor.ts:

    • Updated the BaseVisitor class to use unknown as the type parameter for RecursiveVisitors.
    • Modified the Identifier method to accept both swc.Identifier and swc.BindingIdentifier types.
    • Updated the TemplateLiteral method to handle both swc.TemplateLiteral and swc.TsTemplateLiteralType types.
  • In test/baseVisitors.test.ts:

    • Added a new test case for TemplateLiteral type with a template string containing a variable.

@@ -348,9 +348,8 @@ export class BaseVisitor<T> implements Required<RecursiveVisitors<T>> {
cb(n.body, st)
}
}
Identifier(n: swc.Identifier, st: T, cb: Callback<T>) {
Identifier<S>(n: swc.Identifier | swc.BindingIdentifier, st: S, cb: Callback<S>) {
if ('typeAnnotation' in n && n.typeAnnotation) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks to the union, typescript can discriminate the node to BindingIdentifier if typeAnnotation is within the node

Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.27%. Comparing base (91b1947) to head (3fd78da).

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #8      +/-   ##
==========================================
+ Coverage   97.25%   97.27%   +0.01%     
==========================================
  Files           2        2              
  Lines        1057     1064       +7     
  Branches       78       80       +2     
==========================================
+ Hits         1028     1035       +7     
  Misses         24       24              
  Partials        5        5              

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

@morganney
Copy link
Owner

@maastrich I’ve invited you to be a collaborator which means you should be able to push branches to the repository without requiring forks. Did you want to accept the invite?

@maastrich
Copy link
Collaborator Author

sure, will do from now on, may be for the next PR (if needed)
thanks for your trust 🙏

@morganney
Copy link
Owner

Can you bump the version in package.json to 1.0.0-rc.1 and the npm install so I can release?

for (const quasis of n.quasis) {
cb(quasis, st)
}

for (const expressions of n.expressions) {
cb(expressions, st)
if ('expressions' in n) {
Copy link
Owner

Choose a reason for hiding this comment

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

Was in necessary for the type narrowing or would if (n.expressions) work too? If so I think I prefer the latter syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in is necessary in this case

@maastrich
Copy link
Collaborator Author

@morganney done

Copy link
Owner

@morganney morganney left a comment

Choose a reason for hiding this comment

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

Thank you sir 👍

@morganney morganney merged commit 604e300 into morganney:main Jun 19, 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.

2 participants