Skip to content

Commit

Permalink
Use Array.sort in hoist-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
benasher44 committed May 6, 2022
1 parent 8e1e8dd commit a5358a2
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/transformers/hoist-jest.ts
Expand Up @@ -86,22 +86,9 @@ export function factory({ configSet }: TsCompilerInstance) {
if (statements.length <= 1) {
return statements
}

const pivot = statements[0]
const leftPart: _ts.Statement[] = []
const rightPart: _ts.Statement[] = []
for (let i = 1; i < statements.length; i++) {
const currentStatement = statements[i]
if (isJestGlobalImport(currentStatement)) {
leftPart.push(currentStatement)
} else {
isHoistableStatement(currentStatement) && !isHoistableStatement(pivot) && !isJestGlobalImport(pivot)
? leftPart.push(currentStatement)
: rightPart.push(currentStatement)
}
}

return sortStatements(leftPart).concat(pivot, sortStatements(rightPart))
return statements.sort((stmtA, stmtB) =>
isJestGlobalImport(stmtA) || (isHoistableStatement(stmtA) && !isHoistableStatement(stmtB) && !isJestGlobalImport(stmtB)) ? -1 : 1
);
}

const createVisitor = (ctx: _ts.TransformationContext, _: _ts.SourceFile) => {
Expand Down

0 comments on commit a5358a2

Please sign in to comment.