Update babel to v8.0.0-rc.1 (#18822)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: fisker Cheung <lionkay@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-02-01 08:57:18 +08:00
1 parent cc38e7430d
commit 88ee8a5b3e
21 files changed
+301 -177

No files matched your search

@@ -0,0 +1,24 @@
import url from "node:url";
import esbuild from "esbuild";
import {
PRODUCTION_MINIMAL_NODE_JS_VERSION,
PROJECT_ROOT,
} from "./utilities/index.js";
const file = url.fileURLToPath(
new URL("../vendors/babel-code-frame-for-test.js", import.meta.url),
);
async function buildBabelCodeFrameForTest() {
await esbuild.build({
entryPoints: ["@babel/code-frame"],
bundle: true,
target: [`node${PRODUCTION_MINIMAL_NODE_JS_VERSION}`],
format: "esm",
outfile: file,
mainFields: ["browser"],
absWorkingDir: PROJECT_ROOT,
});
}
export { buildBabelCodeFrameForTest };
+5 -1
View File
@@ -4,7 +4,10 @@ import browserslistToEsbuild from "browserslist-to-esbuild";
import esbuild from "esbuild";
import createEsmUtils from "esm-utils";
import projectPackageJson from "../../../package.json" with { type: "json" };
import { PRODUCTION_MINIMAL_NODE_JS_VERSION } from "../../utilities/index.js";
import {
PRODUCTION_MINIMAL_NODE_JS_VERSION,
PROJECT_ROOT,
} from "../../utilities/index.js";
import esbuildPluginAddDefaultExport from "../esbuild-plugins/add-default-export.js";
import esbuildPluginEvaluate from "../esbuild-plugins/evaluate.js";
import esbuildPluginPrimitiveDefine from "../esbuild-plugins/primitive-define.js";
@@ -223,6 +226,7 @@ function getEsbuildOptions({ packageConfig, file, cliOptions, buildOptions }) {
"class-private-method": true,
},
packages: "bundle",
absWorkingDir: PROJECT_ROOT,
};
if (buildOptions.platform === "universal") {
+10 -39
View File
@@ -75,6 +75,16 @@ const mainModule = {
find: "export default lib;",
replacement: "export default { parse };",
},
{
module: require.resolve("@babel/code-frame"),
process(text) {
text = text.replace(
"from 'node:util'",
`from ${JSON.stringify(path.join(dirname, "../shims/node-util.js"))}`,
);
return text;
},
},
],
addDefaultExport: true,
reuseDocModule: true,
@@ -85,45 +95,6 @@ const mainModule = {
input: "src/standalone.js",
umdVariableName: "prettier",
replaceModule: [
{
module: require.resolve("@babel/code-frame"),
process(text) {
text = text.replaceAll(
/(?<=\n)let tokenize;\n\{\n.*?\n\}(?=\n)/gs,
"",
);
text = text.replaceAll(
/(?<=\n)function highlight\(text\) \{\n.*?\n\}(?=\n)/gs,
"function highlight(text) {return text}",
);
text = text.replaceAll(
/(?<=\n)function getDefs\(enabled\) \{\n.*?\n\}(?=\n)/gs,
outdent`
function getDefs() {
return new Proxy({}, {get: () => (text) => text})
}
`,
);
text = text.replaceAll(
"const defsOn = buildDefs(picocolors.createColors(true));",
"",
);
text = text.replaceAll(
"const defsOff = buildDefs(picocolors.createColors(false));",
"",
);
text = text.replaceAll(
"const shouldHighlight = opts.forceColor || isColorSupported() && opts.highlightCode;",
"const shouldHighlight = false;",
);
return text;
},
},
// Smaller size
{
module: getPackageFile("picocolors/picocolors.browser.js"),
+4
View File
@@ -0,0 +1,4 @@
import * as util from "node:util";
export const styleText =
util.styleText ?? ((format, text /* , options*/) => text);
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env node
import spawn from "nano-spawn";
async function getChangedFiles() {
const { stdout } = await spawn("git", ["diff", "--name-only"]);
return stdout.split("\n");
}
async function ensureNoFilesChanged() {
const changedFiles = await getChangedFiles();
if (changedFiles.length === 0) {
console.log("✅ No files changed.");
return;
}
console.log(
`❌ ${changedFiles.length} file${changedFiles.length === 1 ? "" : "s"} changed:`,
);
console.log(changedFiles.map((file) => ` - ${file}`).join("\n"));
console.log();
try {
await spawn("git", ["diff", "--exit-code"], { stdio: "inherit" });
} catch (error) {
process.exitCode = error.exitCode;
}
}
await ensureNoFilesChanged();
-36
View File
@@ -1,36 +0,0 @@
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import esbuild from "esbuild";
// `@babel/code-frame` and `@babel/highlight` use syntax that is not available in Node.js 14,
// such as `??=`. When bundled into dist/ they are compiled to be compatible with Node.js 14,
// however we also need to load them at runtime from node_modules to run our tests.
// We can use an `--experimental-loader` to compile them on-the-fly with esbuild.
export async function getSource(url, context, defaultGetSource) {
if (context.format === "module") {
if (url.includes("/node_modules/js-tokens/")) {
const text = await readFile(fileURLToPath(url), "utf8");
const commonJsExport = 'export { jsTokens as "module.exports" };';
if (text.includes(commonJsExport)) {
return { source: text.replace(commonJsExport, "") };
}
}
if (
url.includes("/node_modules/@babel/code-frame/") ||
url.includes("/node_modules/@babel/highlight/")
) {
const raw = await readFile(fileURLToPath(url));
try {
const result = await esbuild.transform(raw, { target: "node14" });
return { source: result.code };
} catch (error) {
error.message += ` (in ${url})`;
throw error;
}
}
}
return defaultGetSource(url, context, defaultGetSource);
}
+1 -5
View File
@@ -85,7 +85,7 @@ const jestDependencies = [
"pretty-format",
];
let content = JSON.stringify(
const content = JSON.stringify(
{
...packageJson,
resolutions: {
@@ -99,8 +99,4 @@ let content = JSON.stringify(
2,
);
if (process.platform === "win32") {
content = content.replace("$PWD/", new URL("../", import.meta.url).href);
}
fs.writeFileSync(packageJsonFile, content);