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

change: remove aggregated node types as it may enduce conflicts #5

Merged
merged 2 commits into from
Jun 15, 2024

Conversation

maastrich
Copy link
Collaborator

what does it do ?

  • remove AggregatedType
  • remove hanlders for AggregatedType

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 type Property but it will be Identifier, KeyValueProperty, ...

A second reason is that aggregated types swc.ImportSpecifier and swc.ExportSpecifier could lead to conflict with swc.NamedImportSpecifier and swc.NamedExportSpecifier whose type property is set to ImportSpecifier and ExportSpecifier respectively.

@maastrich maastrich mentioned this pull request Jun 12, 2024
Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.36%. Comparing base (8f967ab) to head (9fde055).

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.
📢 Have feedback on the report? Share it here.

export type AnyNode =
| swc.ArrayExpression
Copy link
Collaborator Author

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

@maastrich maastrich requested a review from morganney June 13, 2024 13:01
@morganney
Copy link
Owner

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 type. Are you saying this is not the case/possible, or that there is little value in supporting that?

@maastrich
Copy link
Collaborator Author

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 type. Are you saying this is not the case/possible, or that there is little value in supporting that?

could be posssible but it should be defined with a way to avoid conflict
it would require to ignore acorn and define a custom ast visitor function 👀

@maastrich
Copy link
Collaborator Author

maastrich commented Jun 14, 2024

@morganney what I was thinking is

  1. handle "classic" node types as is, the BaseVisitor being meant to walk the AST without actions (it cannot handle AggregatedNodes)
  2. handle "classic" AND "aggregated" nodes with the SimpleVisitor object, where any node aggregated within swc.Property would trigger a call for the AggregatedProperty walker
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 AggregatedNodes and ClassicNodes never conflict 🤔

}
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
Copy link
Collaborator Author

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 ?

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.

Thanks @maastrich this is a reasonable next step.

@morganney morganney merged commit 14d7b82 into morganney:main Jun 15, 2024
1 of 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