Update to Babel 8

This commit is contained in:
Nicolò Ribaudo 2026-06-19 13:13:37 +02:00
parent 25eae30e4e
commit b9609d0365
No known key found for this signature in database
GPG Key ID: AAFDA9101C58F338
5 changed files with 2361 additions and 846 deletions

View File

@ -319,6 +319,16 @@ function babelPluginStripSrcPath() {
}; };
} }
function babelPluginAddHeaderComment(babel, { header }) {
return {
visitor: {
Program(path) {
path.addComment("leading", header);
},
},
};
}
function preprocessPDFJSCode(ctx, content) { function preprocessPDFJSCode(ctx, content) {
return transformSync(content, { return transformSync(content, {
configFile: false, configFile: false,
@ -327,6 +337,7 @@ function preprocessPDFJSCode(ctx, content) {
} }
export { export {
babelPluginAddHeaderComment,
babelPluginPDFJSPreprocessor, babelPluginPDFJSPreprocessor,
babelPluginStripSrcPath, babelPluginStripSrcPath,
preprocessPDFJSCode, preprocessPDFJSCode,

View File

@ -13,7 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
import * as babel from "@babel/core";
import { import {
babelPluginAddHeaderComment,
babelPluginPDFJSPreprocessor, babelPluginPDFJSPreprocessor,
babelPluginStripSrcPath, babelPluginStripSrcPath,
preprocessPDFJSCode, preprocessPDFJSCode,
@ -24,7 +26,6 @@ import {
} from "./external/ccov/coverage_format.mjs"; } from "./external/ccov/coverage_format.mjs";
import { exec, execSync, spawn, spawnSync } from "child_process"; import { exec, execSync, spawn, spawnSync } from "child_process";
import autoprefixer from "autoprefixer"; import autoprefixer from "autoprefixer";
import babel from "@babel/core";
import { buildPrefsSchema } from "./external/chromium/prefs.mjs"; import { buildPrefsSchema } from "./external/chromium/prefs.mjs";
import crypto from "crypto"; import crypto from "crypto";
import { finished } from "stream/promises"; import { finished } from "stream/promises";
@ -104,11 +105,11 @@ const AUTOPREFIXER_CONFIG = {
// Default Babel targets used for generic, components, minified-pre // Default Babel targets used for generic, components, minified-pre
const BABEL_TARGETS = ENV_TARGETS.join(", "); const BABEL_TARGETS = ENV_TARGETS.join(", ");
const BABEL_PRESET_ENV_OPTS = Object.freeze({ const BABEL_COREJS_OPTS = Object.freeze({
corejs: "3.49.0", method: "usage-global",
version: "3.49.0",
exclude: ["web.structured-clone"], exclude: ["web.structured-clone"],
shippedProposals: true, shippedProposals: true,
useBuiltIns: "usage",
}); });
const DEFINES = Object.freeze({ const DEFINES = Object.freeze({
@ -325,9 +326,7 @@ function createWebpackConfig(
/node_modules[\\/]core-js/, /node_modules[\\/]core-js/,
]; ];
const babelPresets = skipBabel const babelPresets = skipBabel ? undefined : ["@babel/preset-env"];
? undefined
: [["@babel/preset-env", BABEL_PRESET_ENV_OPTS]];
const babelPlugins = [ const babelPlugins = [
[ [
babelPluginPDFJSPreprocessor, babelPluginPDFJSPreprocessor,
@ -337,6 +336,9 @@ function createWebpackConfig(
}, },
], ],
]; ];
if (!skipBabel) {
babelPlugins.push(["babel-plugin-polyfill-corejs3", BABEL_COREJS_OPTS]);
}
if (bundleDefines.COVERAGE) { if (bundleDefines.COVERAGE) {
babelPlugins.push("babel-plugin-istanbul"); babelPlugins.push("babel-plugin-istanbul");
} }
@ -1683,9 +1685,9 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
const licenseHeader = fs const licenseHeader = fs
.readFileSync("./src/license_header.js") .readFileSync("./src/license_header.js")
.toString() .toString()
.split("\n") .trim()
.slice(1, -2) .replace(/^\/\*/, "")
.map(line => line.replace(/^\s*\*\s?/, "")); .replace(/\*\/$/, "");
const ctx = { const ctx = {
rootPath: __dirname, rootPath: __dirname,
@ -1725,6 +1727,9 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
[babelPluginPDFJSPreprocessor, ctx], [babelPluginPDFJSPreprocessor, ctx],
[babelPluginStripSrcPath], [babelPluginStripSrcPath],
]; ];
if (!skipBabel) {
plugins.push(["babel-plugin-polyfill-corejs3", BABEL_COREJS_OPTS]);
}
if (enableCoverage) { if (enableCoverage) {
plugins.push([ plugins.push([
"babel-plugin-istanbul", "babel-plugin-istanbul",
@ -1734,28 +1739,16 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
}, },
]); ]);
} }
plugins.push([ plugins.push([babelPluginAddHeaderComment, { header: licenseHeader }]);
"add-header-comment",
{
header: licenseHeader,
},
]);
const result = babel.transform(file.contents.toString(), { const result = babel.transformSync(file.contents.toString(), {
...(enableCoverage && { ...(enableCoverage && {
filename: file.path, filename: file.path,
babelrc: false, babelrc: false,
configFile: false, configFile: false,
}), }),
sourceType: "module", sourceType: "module",
presets: skipBabel presets: skipBabel ? undefined : ["@babel/preset-env"],
? undefined
: [
[
"@babel/preset-env",
{ ...BABEL_PRESET_ENV_OPTS, loose: false, modules: false },
],
],
plugins, plugins,
targets: BABEL_TARGETS, targets: BABEL_TARGETS,
sourceMaps: enableSourceMaps, sourceMaps: enableSourceMaps,

3143
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@
"name": "pdf.js", "name": "pdf.js",
"type": "module", "type": "module",
"devDependencies": { "devDependencies": {
"@babel/core": "^7.29.7", "@babel/core": "^8.0.1",
"@babel/preset-env": "^7.29.7", "@babel/preset-env": "^8.0.2",
"@babel/runtime": "^7.29.7", "@babel/runtime": "^8.0.0",
"@eslint/json": "^2.0.0", "@eslint/json": "^2.0.0",
"@fluent/bundle": "^0.19.1", "@fluent/bundle": "^0.19.1",
"@fluent/dom": "^0.10.2", "@fluent/dom": "^0.10.2",
@ -14,8 +14,8 @@
"@types/node": "^26.0.0", "@types/node": "^26.0.0",
"autoprefixer": "^10.5.1", "autoprefixer": "^10.5.1",
"babel-loader": "^10.1.1", "babel-loader": "^10.1.1",
"babel-plugin-add-header-comment": "^1.0.3",
"babel-plugin-istanbul": "^8.0.2", "babel-plugin-istanbul": "^8.0.2",
"babel-plugin-polyfill-corejs3": "^1.0.0",
"cached-iterable": "^0.3.0", "cached-iterable": "^0.3.0",
"caniuse-lite": "^1.0.30001799", "caniuse-lite": "^1.0.30001799",
"core-js": "^3.49.0", "core-js": "^3.49.0",

View File

@ -16,7 +16,7 @@
// PLEASE NOTE: This code is intended for development purposes only and // PLEASE NOTE: This code is intended for development purposes only and
// should NOT be used in production environments. // should NOT be used in production environments.
import babel from "@babel/core"; import * as babel from "@babel/core";
import fs from "fs"; import fs from "fs";
import fsPromises from "fs/promises"; import fsPromises from "fs/promises";
import http from "http"; import http from "http";