Skip to content

Commit

Permalink
perf: reduce .filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Aug 12, 2023
1 parent 40702d5 commit ed24762
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ c();

inlineTest('split return sequence expression',
`
if(a) return b(), c();
return a(), b(), c()
`,
`
if (a) {
b();
return c();
}
a();
b();
return c();
Expand Down Expand Up @@ -125,11 +132,13 @@ try {

inlineTest('split throw sequence expression',
`
throw a(), b()
if(e !== null) throw a(), e
`,
`
a();
throw b();
if (e !== null) {
a();
throw e;
}
`,
)

Expand Down
12 changes: 6 additions & 6 deletions packages/unminify/src/transformations/function-to-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const transformAST: ASTTransformation = (context) => {

root
.find(j.FunctionDeclaration)
.filter((path) => {
if (j.MethodDefinition.check(path.parent)) return false
if (j.Property.check(path.parent)) return false
if (containsThisExpression(path.node)) return false
return true
})
.forEach((path) => {
if (j.MethodDefinition.check(path.parent.node)) return
if (j.Property.check(path.parent.node)) return
if (j.ExportDeclaration.check(path.parentPath.node)) return
if (j.ExportDefaultDeclaration.check(path.parent.node)) return
if (containsThisExpression(path.node)) return

const { node } = path
const { id } = node
if (!id) return
Expand Down

0 comments on commit ed24762

Please sign in to comment.