Skip to content

Commit

Permalink
optimize: remove 14.14 version check as fs.rmSync is a new method
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 1, 2024
1 parent 4b36240 commit 6305792
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,8 @@ function pluginPolyfillsOldNode({ template, types: t }) {
{
name: "fs.rmSync",
necessary({ node, parent }) {
return (
t.isCallExpression(parent, { callee: node }) &&
parent.arguments.length > 1
);
// To avoid infinite replacement loops
return !t.isLogicalExpression(parent, { operator: "||", left: node });
},
supported({ parent: { arguments: args } }) {
return (
Expand All @@ -517,9 +515,7 @@ function pluginPolyfillsOldNode({ template, types: t }) {
// fs.rmSync has been introduced in Node.js 14.14
// https://nodejs.org/api/fs.html#fsrmsyncpath-options
replacement: template`
((v,w)=>(v=v.split("."),w=w.split("."),+v[0]>+w[0]||v[0]==w[0]&&+v[1]>=+w[1]))(process.versions.node, "14.14")
? fs.rmSync
: function d(/* path */ p) {
fs.rmSync || function d(/* path */ p) {
if (fs.existsSync(p)) {
fs.readdirSync(p).forEach(function (f) {
const /* currentPath */ c = p + "/" + f;
Expand Down

0 comments on commit 6305792

Please sign in to comment.