Merge pull request #16703 from Snuffleupagus/babel-corejs
[api-minor] Let Babel handle the necessary `core-js` polyfills automatically
This commit is contained in:
		
						commit
						e81c084a92
					
				
							
								
								
									
										10
									
								
								gulpfile.mjs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								gulpfile.mjs
									
									
									
									
									
								
							@ -211,6 +211,14 @@ function createWebpackConfig(
 | 
			
		||||
  }
 | 
			
		||||
  const babelExcludeRegExp = new RegExp(`(${babelExcludes.join("|")})`);
 | 
			
		||||
 | 
			
		||||
  const babelPresets = skipBabel
 | 
			
		||||
    ? undefined
 | 
			
		||||
    : [
 | 
			
		||||
        [
 | 
			
		||||
          "@babel/preset-env",
 | 
			
		||||
          { corejs: "3.31.1", shippedProposals: true, useBuiltIns: "usage" },
 | 
			
		||||
        ],
 | 
			
		||||
      ];
 | 
			
		||||
  const babelPlugins = ["@babel/plugin-transform-modules-commonjs"];
 | 
			
		||||
 | 
			
		||||
  const plugins = [];
 | 
			
		||||
@ -289,7 +297,7 @@ function createWebpackConfig(
 | 
			
		||||
          loader: "babel-loader",
 | 
			
		||||
          exclude: babelExcludeRegExp,
 | 
			
		||||
          options: {
 | 
			
		||||
            presets: skipBabel ? undefined : ["@babel/preset-env"],
 | 
			
		||||
            presets: babelPresets,
 | 
			
		||||
            plugins: babelPlugins,
 | 
			
		||||
            targets: BABEL_TARGETS,
 | 
			
		||||
          },
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ import {
 | 
			
		||||
  getVerbosityLevel,
 | 
			
		||||
  info,
 | 
			
		||||
  InvalidPDFException,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  MissingPDFException,
 | 
			
		||||
  PasswordException,
 | 
			
		||||
  PromiseCapability,
 | 
			
		||||
@ -39,7 +40,6 @@ import { LocalPdfManager, NetworkPdfManager } from "./pdf_manager.js";
 | 
			
		||||
import { AnnotationFactory } from "./annotation.js";
 | 
			
		||||
import { clearGlobalCaches } from "./cleanup_helper.js";
 | 
			
		||||
import { incrementalUpdate } from "./writer.js";
 | 
			
		||||
import { isNodeJS } from "../shared/is_node.js";
 | 
			
		||||
import { MessageHandler } from "../shared/message_handler.js";
 | 
			
		||||
import { PDFWorkerStream } from "./worker_stream.js";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,7 @@ import {
 | 
			
		||||
  info,
 | 
			
		||||
  InvalidPDFException,
 | 
			
		||||
  isArrayBuffer,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  MAX_IMAGE_SIZE_TO_CACHE,
 | 
			
		||||
  MissingPDFException,
 | 
			
		||||
  PasswordException,
 | 
			
		||||
@ -59,7 +60,6 @@ import {
 | 
			
		||||
import { FontFaceObject, FontLoader } from "./font_loader.js";
 | 
			
		||||
import { CanvasGraphics } from "./canvas.js";
 | 
			
		||||
import { GlobalWorkerOptions } from "./worker_options.js";
 | 
			
		||||
import { isNodeJS } from "../shared/is_node.js";
 | 
			
		||||
import { MessageHandler } from "../shared/message_handler.js";
 | 
			
		||||
import { Metadata } from "./metadata.js";
 | 
			
		||||
import { OptionalContentConfig } from "./optional_content_config.js";
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ import {
 | 
			
		||||
  IDENTITY_MATRIX,
 | 
			
		||||
  ImageKind,
 | 
			
		||||
  info,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  OPS,
 | 
			
		||||
  shadow,
 | 
			
		||||
  TextRenderingMode,
 | 
			
		||||
@ -37,7 +38,6 @@ import {
 | 
			
		||||
  TilingPattern,
 | 
			
		||||
} from "./pattern_helper.js";
 | 
			
		||||
import { convertBlackAndWhiteToRGBA } from "../shared/image_utils.js";
 | 
			
		||||
import { isNodeJS } from "../shared/is_node.js";
 | 
			
		||||
 | 
			
		||||
// <canvas> contexts store most of the state we need natively.
 | 
			
		||||
// However, PDF needs a bit more state, which we store here.
 | 
			
		||||
 | 
			
		||||
@ -17,12 +17,12 @@ import {
 | 
			
		||||
  assert,
 | 
			
		||||
  bytesToString,
 | 
			
		||||
  FeatureTest,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  shadow,
 | 
			
		||||
  string32,
 | 
			
		||||
  unreachable,
 | 
			
		||||
  warn,
 | 
			
		||||
} from "../shared/util.js";
 | 
			
		||||
import { isNodeJS } from "../shared/is_node.js";
 | 
			
		||||
 | 
			
		||||
class FontLoader {
 | 
			
		||||
  #systemFonts = new Set();
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,7 @@ import {
 | 
			
		||||
  BaseFilterFactory,
 | 
			
		||||
  BaseStandardFontDataFactory,
 | 
			
		||||
} from "./base_factory.js";
 | 
			
		||||
import { isNodeJS } from "../shared/util.js";
 | 
			
		||||
 | 
			
		||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
 | 
			
		||||
  throw new Error(
 | 
			
		||||
@ -27,6 +28,26 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) {
 | 
			
		||||
  (function checkDOMMatrix() {
 | 
			
		||||
    if (globalThis.DOMMatrix || !isNodeJS) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
 | 
			
		||||
  })();
 | 
			
		||||
 | 
			
		||||
  (function checkPath2D() {
 | 
			
		||||
    if (globalThis.Path2D || !isNodeJS) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    const { CanvasRenderingContext2D } = __non_webpack_require__("canvas");
 | 
			
		||||
    const { polyfillPath2D } = __non_webpack_require__("path2d-polyfill");
 | 
			
		||||
 | 
			
		||||
    globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
 | 
			
		||||
    polyfillPath2D(globalThis);
 | 
			
		||||
  })();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const fetchData = function (url) {
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    const fs = __non_webpack_require__("fs");
 | 
			
		||||
 | 
			
		||||
@ -19,12 +19,12 @@ import {
 | 
			
		||||
  FONT_IDENTITY_MATRIX,
 | 
			
		||||
  IDENTITY_MATRIX,
 | 
			
		||||
  ImageKind,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  OPS,
 | 
			
		||||
  TextRenderingMode,
 | 
			
		||||
  Util,
 | 
			
		||||
  warn,
 | 
			
		||||
} from "../shared/util.js";
 | 
			
		||||
import { isNodeJS } from "../shared/is_node.js";
 | 
			
		||||
 | 
			
		||||
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
 | 
			
		||||
  throw new Error(
 | 
			
		||||
 | 
			
		||||
@ -1,45 +0,0 @@
 | 
			
		||||
/* Copyright 2017 Mozilla Foundation
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
/* globals __non_webpack_require__ */
 | 
			
		||||
 | 
			
		||||
import { isNodeJS } from "./is_node.js";
 | 
			
		||||
 | 
			
		||||
// Support: Node.js
 | 
			
		||||
(function checkDOMMatrix() {
 | 
			
		||||
  if (globalThis.DOMMatrix || !isNodeJS) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
 | 
			
		||||
})();
 | 
			
		||||
 | 
			
		||||
// Support: Node.js
 | 
			
		||||
(function checkPath2D() {
 | 
			
		||||
  if (globalThis.Path2D || !isNodeJS) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  const { CanvasRenderingContext2D } = __non_webpack_require__("canvas");
 | 
			
		||||
  const { polyfillPath2D } = __non_webpack_require__("path2d-polyfill");
 | 
			
		||||
 | 
			
		||||
  globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
 | 
			
		||||
  polyfillPath2D(globalThis);
 | 
			
		||||
})();
 | 
			
		||||
 | 
			
		||||
// Support: Chrome<98
 | 
			
		||||
(function checkStructuredClone() {
 | 
			
		||||
  if (globalThis.structuredClone) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  require("core-js/web/structured-clone.js");
 | 
			
		||||
})();
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
/* Copyright 2018 Mozilla Foundation
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
/* globals process */
 | 
			
		||||
 | 
			
		||||
// NW.js / Electron is a browser context, but copies some Node.js objects; see
 | 
			
		||||
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
 | 
			
		||||
// https://www.electronjs.org/docs/api/process#processversionselectron-readonly
 | 
			
		||||
// https://www.electronjs.org/docs/api/process#processtype-readonly
 | 
			
		||||
const isNodeJS =
 | 
			
		||||
  (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
 | 
			
		||||
  typeof process === "object" &&
 | 
			
		||||
  process + "" === "[object process]" &&
 | 
			
		||||
  !process.versions.nw &&
 | 
			
		||||
  !(process.versions.electron && process.type && process.type !== "browser");
 | 
			
		||||
 | 
			
		||||
export { isNodeJS };
 | 
			
		||||
@ -12,16 +12,18 @@
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
/* globals process */
 | 
			
		||||
 | 
			
		||||
// Skip compatibility checks for modern builds and if we already ran the module.
 | 
			
		||||
if (
 | 
			
		||||
  typeof PDFJSDev !== "undefined" &&
 | 
			
		||||
  !PDFJSDev.test("SKIP_BABEL") &&
 | 
			
		||||
  !globalThis._pdfjsCompatibilityChecked
 | 
			
		||||
) {
 | 
			
		||||
  globalThis._pdfjsCompatibilityChecked = true;
 | 
			
		||||
  require("./compatibility.js");
 | 
			
		||||
}
 | 
			
		||||
// NW.js / Electron is a browser context, but copies some Node.js objects; see
 | 
			
		||||
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
 | 
			
		||||
// https://www.electronjs.org/docs/api/process#processversionselectron-readonly
 | 
			
		||||
// https://www.electronjs.org/docs/api/process#processtype-readonly
 | 
			
		||||
const isNodeJS =
 | 
			
		||||
  (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
 | 
			
		||||
  typeof process === "object" &&
 | 
			
		||||
  process + "" === "[object process]" &&
 | 
			
		||||
  !process.versions.nw &&
 | 
			
		||||
  !(process.versions.electron && process.type && process.type !== "browser");
 | 
			
		||||
 | 
			
		||||
const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
 | 
			
		||||
const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
 | 
			
		||||
@ -1066,6 +1068,7 @@ export {
 | 
			
		||||
  InvalidPDFException,
 | 
			
		||||
  isArrayBuffer,
 | 
			
		||||
  isArrayEqual,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  LINE_DESCENT_FACTOR,
 | 
			
		||||
  LINE_FACTOR,
 | 
			
		||||
  MAX_IMAGE_SIZE_TO_CACHE,
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ import {
 | 
			
		||||
  AnnotationType,
 | 
			
		||||
  ImageKind,
 | 
			
		||||
  InvalidPDFException,
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  MissingPDFException,
 | 
			
		||||
  objectSize,
 | 
			
		||||
  OPS,
 | 
			
		||||
@ -53,7 +54,6 @@ import {
 | 
			
		||||
import { AutoPrintRegExp } from "../../web/ui_utils.js";
 | 
			
		||||
import { GlobalImageCache } from "../../src/core/image_utils.js";
 | 
			
		||||
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { Metadata } from "../../src/display/metadata.js";
 | 
			
		||||
 | 
			
		||||
describe("api", function () {
 | 
			
		||||
 | 
			
		||||
@ -13,8 +13,11 @@
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { setVerbosityLevel, VerbosityLevel } from "../../src/shared/util.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import {
 | 
			
		||||
  isNodeJS,
 | 
			
		||||
  setVerbosityLevel,
 | 
			
		||||
  VerbosityLevel,
 | 
			
		||||
} from "../../src/shared/util.js";
 | 
			
		||||
 | 
			
		||||
// Sets longer timeout, similar to `jasmine-boot.js`.
 | 
			
		||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@
 | 
			
		||||
 | 
			
		||||
import { buildGetDocumentParams } from "./test_utils.js";
 | 
			
		||||
import { getDocument } from "../../src/display/api.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import { SVGGraphics } from "../../src/display/svg.js";
 | 
			
		||||
 | 
			
		||||
const XLINK_NS = "http://www.w3.org/1999/xlink";
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { bytesToString, isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import {
 | 
			
		||||
  DOMCanvasFactory,
 | 
			
		||||
  DOMSVGFactory,
 | 
			
		||||
@ -21,8 +22,6 @@ import {
 | 
			
		||||
  isValidFetchUrl,
 | 
			
		||||
  PDFDateString,
 | 
			
		||||
} from "../../src/display/display_utils.js";
 | 
			
		||||
import { bytesToString } from "../../src/shared/util.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
 | 
			
		||||
describe("display_utils", function () {
 | 
			
		||||
  describe("DOMCanvasFactory", function () {
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,7 @@ import {
 | 
			
		||||
  waitOnEventOrTimeout,
 | 
			
		||||
  WaitOnType,
 | 
			
		||||
} from "../../web/event_utils.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
 | 
			
		||||
describe("event_utils", function () {
 | 
			
		||||
  describe("EventBus", function () {
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
import { GlobalWorkerOptions } from "pdfjs/display/worker_options.js";
 | 
			
		||||
import { isNodeJS } from "pdfjs/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import { TestReporter } from "./testreporter.js";
 | 
			
		||||
 | 
			
		||||
async function initializePDFJS(callback) {
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,7 @@
 | 
			
		||||
 */
 | 
			
		||||
/* globals __non_webpack_require__ */
 | 
			
		||||
 | 
			
		||||
import { AbortException } from "../../src/shared/util.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { AbortException, isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import { PDFNodeStream } from "../../src/display/node_stream.js";
 | 
			
		||||
 | 
			
		||||
// Ensure that these tests only run in Node.js environments.
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ import { FindState, PDFFindController } from "../../web/pdf_find_controller.js";
 | 
			
		||||
import { buildGetDocumentParams } from "./test_utils.js";
 | 
			
		||||
import { EventBus } from "../../web/event_utils.js";
 | 
			
		||||
import { getDocument } from "../../src/display/api.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import { SimpleLinkService } from "../../web/pdf_link_service.js";
 | 
			
		||||
 | 
			
		||||
const tracemonkeyFileName = "tracemonkey.pdf";
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,7 @@
 | 
			
		||||
 | 
			
		||||
import { NullStream, StringStream } from "../../src/core/stream.js";
 | 
			
		||||
import { Page, PDFDocument } from "../../src/core/document.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import { Ref } from "../../src/core/primitives.js";
 | 
			
		||||
 | 
			
		||||
const TEST_PDFS_PATH = isNodeJS ? "./test/pdfs/" : "../pdfs/";
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,7 @@ import {
 | 
			
		||||
} from "../../src/display/text_layer.js";
 | 
			
		||||
import { buildGetDocumentParams } from "./test_utils.js";
 | 
			
		||||
import { getDocument } from "../../src/display/api.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
 | 
			
		||||
describe("textLayer", function () {
 | 
			
		||||
  it("creates textLayer from ReadableStream", async function () {
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { isNodeJS } from "../../src/shared/is_node.js";
 | 
			
		||||
import { isNodeJS } from "../../src/shared/util.js";
 | 
			
		||||
import { XFAFactory } from "../../src/core/xfa/factory.js";
 | 
			
		||||
 | 
			
		||||
describe("XFAFactory", function () {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user