Skip to content

Commit

Permalink
Wrap Babel 7 helpers in !BABEL_8_BREAKING
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 15, 2024
1 parent dac7164 commit 1a1f06e
Show file tree
Hide file tree
Showing 6 changed files with 807 additions and 782 deletions.
32 changes: 25 additions & 7 deletions packages/babel-helpers/scripts/generate-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ function helper(minVersion: string, source: string): Helper {
})
}
export default {
export { helpers as default };
const helpers: Record<string, Helper> = {
__proto__: null,
`;

let babel7extraOutput = "";

for (const file of (await fs.promises.readdir(HELPERS_FOLDER)).sort()) {
if (IGNORED_FILES.has(file)) continue;
if (file.startsWith(".")) continue; // ignore e.g. vim swap files
Expand All @@ -58,10 +61,7 @@ export default {
}
const { minVersion } = minVersionMatch.groups;

if (IS_BABEL_8() && code.includes("@onlyBabel7")) {
continue;
}

const onlyBabel7 = code.includes("@onlyBabel7");
const mangleFns = code.includes("@mangleFns");
const noMangleFns = [];

Expand Down Expand Up @@ -121,15 +121,33 @@ export default {
})
).code;

output += `\
const helperStr = `\
// size: ${code.length}, gzip size: ${gzipSync(code).length}
${JSON.stringify(helperName)}: helper(
${JSON.stringify(minVersion)},
${JSON.stringify(code)},
),
`;

if (onlyBabel7) {
if (!IS_BABEL_8()) babel7extraOutput += helperStr;
} else {
output += helperStr;
}
}

output += "};";

if (babel7extraOutput) {
output += `
if (!process.env.BABEL_8_BREAKING) {
Object.assign(helpers, {
${babel7extraOutput}
});
}
`;
}

output += "} as Record<string, Helper>;";
return output;
}
260 changes: 133 additions & 127 deletions packages/babel-helpers/src/helpers-generated.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* @minVersion 7.4.4 */
/* @onlyBabel7 */

import classApplyDescriptorDestructureSet from "classApplyDescriptorDestructureSet";
import classPrivateFieldGet2 from "classPrivateFieldGet2";
Expand Down
Loading

0 comments on commit 1a1f06e

Please sign in to comment.