-
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
change: remove aggregated node types as it may enduce conflicts #5
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5 +/- ##
==========================================
+ Coverage 51.69% 53.36% +1.66%
==========================================
Files 2 2
Lines 677 624 -53
Branches 12 12
==========================================
- Hits 350 333 -17
+ Misses 327 291 -36 ☔ View full report in Codecov by Sentry. |
export type AnyNode = | ||
| swc.ArrayExpression |
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.
note that all removed types form AnyNode
is provided by on of the AggregatedNode
and will not be lost
Hi @maastrich I will try to get to this later tonight, work has been keeping me busy. Overall the idea with the AggregateType was that you could attach a handler for one of them, and then filter the logic based on the node's actual |
could be posssible but it should be defined with a way to avoid conflict |
@morganney what I was thinking is
simple(ast, {
ArrayExpression(node, st) {
console.log("only trigger for 'swc.ArrayExpression' node")
},
AggregatedPattern(node, st) {
console.log("triggers for 'swc.ArrayPattern | swc.BindingIdentifier | swc.RestElement | swc.ObjectPattern | swc.AssignmentPattern | swc.Expression' nodes")
}
}) This way, we can ensure that the named of |
} | ||
export type SimpleVisitors<State> = { | ||
[type in AnyNode['type']]?: (node: Extract<AnyNode, { type: type }>, state: State) => void | ||
} & { | ||
[type in keyof AggregateType]?: (node: AggregateType[type], state: State) => void | ||
[type in keyof AggregatedNode as `Aggregated${type}`]?: never //(node: AggregatedNode[type], state: State) => void |
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.
should stay never until it is handled ?
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 @maastrich this is a reasonable next step.
what does it do ?
why is it useful ?
AggregatedType led to think that we can listen on nodes like
Property
while it is not the case, no node will have a typeProperty
but it will beIdentifier
,KeyValueProperty
, ...A second reason is that aggregated types
swc.ImportSpecifier
andswc.ExportSpecifier
could lead to conflict withswc.NamedImportSpecifier
andswc.NamedExportSpecifier
whose type property is set toImportSpecifier
andExportSpecifier
respectively.