-
-
Notifications
You must be signed in to change notification settings - Fork 726
Open
Open
Copy link
Labels
A-minifierArea - MinifierArea - Minifier
Description
The current implementation of foo unnecessarily reassigns the input parameter to a new variable (node = inputNode) solely to change its type. This can be simplified by using the parameter directly and removing the redundant variable declaration.
Current Code
// input
export function foo(inputNode) {
// re-assign to change type
let node = inputNode;
do {
node = node.parent
} while (node !== null)
return node
}Proposed Optimization
The reassignment is unnecessary. We can rewrite the function using the parameter node directly and simplify the loop syntax:
// expected output
export function foo(node) {
do
node = node.parent
while (node !== null)
return node
}This allows users to change the type of node without encountering the cost of declaring an additional variable.
Metadata
Metadata
Assignees
Labels
A-minifierArea - MinifierArea - Minifier