-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
@@ -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) { |
There was a problem hiding this comment.
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
@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? |
sure, will do from now on, may be for the next PR (if needed) |
Can you bump the version in package.json to 1.0.0-rc.1 and the |
for (const quasis of n.quasis) { | ||
cb(quasis, st) | ||
} | ||
|
||
for (const expressions of n.expressions) { | ||
cb(expressions, st) | ||
if ('expressions' in n) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@morganney done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you sir 👍
PR Description
This PR includes the following changes:
In
src/baseVisitor.ts
:BaseVisitor
class to useunknown
as the type parameter forRecursiveVisitors
.Identifier
method to accept bothswc.Identifier
andswc.BindingIdentifier
types.TemplateLiteral
method to handle bothswc.TemplateLiteral
andswc.TsTemplateLiteralType
types.In
test/baseVisitors.test.ts
:TemplateLiteral
type with a template string containing a variable.