Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lodash sortBy use #13021

Merged
merged 6 commits into from Mar 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/babel-core/src/transformation/block-hoist-plugin.js
@@ -1,7 +1,5 @@
// @flow

import sortBy from "lodash/sortBy";

import loadConfig, { type Plugin } from "../config";

let LOADED_PLUGIN: Plugin | void;
Expand All @@ -22,6 +20,14 @@ export default function loadBlockHoistPlugin(): Plugin {

return LOADED_PLUGIN;
}
function priority(bodyNode) {
let priority = bodyNode?._blockHoist;
if (priority == null) priority = 1;
if (priority === true) priority = 2;

// Higher priorities should move toward the top.
return -1 * priority;
}

const blockHoistPlugin = {
/**
Expand Down Expand Up @@ -51,14 +57,8 @@ const blockHoistPlugin = {
}
if (!hasChange) return;

node.body = sortBy(node.body, function (bodyNode) {
let priority = bodyNode?._blockHoist;
if (priority == null) priority = 1;
if (priority === true) priority = 2;

// Higher priorities should move toward the top.
return -1 * priority;
});
// Sort in ascending order
node.body.sort((a, b) => priority(a) - priority(b));
},
},
},
Expand Down