-
-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Labels
✨ FeatureNew refactoring or featureNew refactoring or feature👋 Good first issueGood for newcomersGood for newcomers
Description
Is this request related to a problem? Please describe.
When implementing #1175 we noticed a refactoring we did manually that we wish would have been automated.
Describe the solution you'd like
We want to convert:
function createVisitor(onMatch) {
return {
VariableDeclaration: onMatch
}
}
into:
function createVisitor(onMatch) {
return {
VariableDeclaration(path) {
return onMatch(path)
}
}
}
Of course, this is not always possible. It should only be possible if the value is a Function—which may be tricky to determine, depending if we can resolve its type.
Note that it may be challenging to determine exactly the parameters of the ObjectProperty—depends also if we can resolve the type. However, this should always be valid JS:
function createVisitor(onMatch) {
return {
VariableDeclaration(...params) {
return onMatch(...params)
}
}
}
TS may not be happy in some cases (e.g. onMatch
only expects 1 argument but params
has 2, which works at runtime but makes the compiler complain), but it's a valid refactoring. Hence, it's acceptable.
Metadata
Metadata
Assignees
Labels
✨ FeatureNew refactoring or featureNew refactoring or feature👋 Good first issueGood for newcomersGood for newcomers