Skip to content

Commit

Permalink
Return early to make the if statement easier to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
JB committed Nov 19, 2021
1 parent 6580261 commit 5bc70f7
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,20 @@ function walk(
node.params.forEach((p) =>
(eswalk as any)(p.type === 'AssignmentPattern' ? p.left : p, {
enter(child: Node, parent: Node) {
if (child.type !== 'Identifier') return
// do not record as scope variable if is a destructuring keyword
if (isStaticPropertyKey(child, parent)) return
// do not record if this is a default value
// assignment of a destructuring variable
if (
child.type === 'Identifier' &&
// do not record as scope variable if is a destructuring key
!isStaticPropertyKey(child, parent) &&
// do not record if this is a default value
// assignment of a destructuring variable
(
!parent ||
(
!(parent.type === 'AssignmentPattern' && parent.right === child) &&
!(parent.type === 'TemplateLiteral' && parent.expressions.includes(child))
)
)
(parent?.type === 'AssignmentPattern' &&
parent?.right === child) ||
(parent?.type === 'TemplateLiteral' &&
parent?.expressions.includes(child))
) {
setScope(node, child.name)
return
}
setScope(node, child.name)
}
})
)
Expand All @@ -352,8 +350,7 @@ function walk(
node.id.elements.forEach((element) => {
setScope(parentFunction, (element as Identifier).name)
})
}
else {
} else {
setScope(parentFunction, (node.id as Identifier).name)
}
}
Expand Down

0 comments on commit 5bc70f7

Please sign in to comment.