Use JSON imports instead of PDFJSDev.json
JSON imports are now supported by all tools used in PDF.js' build process. The `chromecom.js` file is bundled by webpack and import attributes are thus removed, so browser compatibility for this new syntax is not relevant.
This commit is contained in:
parent
658a0a16c1
commit
a8592d86a9
@ -77,7 +77,7 @@ export default [
|
|||||||
__non_webpack_import__: "readonly",
|
__non_webpack_import__: "readonly",
|
||||||
},
|
},
|
||||||
|
|
||||||
ecmaVersion: 2022,
|
ecmaVersion: 2025,
|
||||||
sourceType: "module",
|
sourceType: "module",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
import { types as t, transformSync } from "@babel/core";
|
import { types as t, transformSync } from "@babel/core";
|
||||||
import fs from "fs";
|
|
||||||
import { join as joinPaths } from "path";
|
|
||||||
import vm from "vm";
|
import vm from "vm";
|
||||||
|
|
||||||
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
|
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
|
||||||
const ROOT_PREFIX = "$ROOT/";
|
|
||||||
|
|
||||||
function isPDFJSPreprocessor(obj) {
|
function isPDFJSPreprocessor(obj) {
|
||||||
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
|
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
|
||||||
@ -40,18 +37,6 @@ function handlePreprocessorAction(ctx, actionName, args, path) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "json":
|
|
||||||
if (!t.isStringLiteral(arg)) {
|
|
||||||
throw new Error("Path to JSON is not provided");
|
|
||||||
}
|
|
||||||
let jsonPath = arg.value;
|
|
||||||
if (jsonPath.startsWith(ROOT_PREFIX)) {
|
|
||||||
jsonPath = joinPaths(
|
|
||||||
ctx.rootPath,
|
|
||||||
jsonPath.substring(ROOT_PREFIX.length)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return JSON.parse(fs.readFileSync(jsonPath, "utf8"));
|
|
||||||
}
|
}
|
||||||
throw new Error("Unsupported action");
|
throw new Error("Unsupported action");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -10,9 +10,6 @@ var g = {
|
|||||||
},
|
},
|
||||||
j: 2
|
j: 2
|
||||||
};
|
};
|
||||||
var h = {
|
|
||||||
test: "test"
|
|
||||||
};
|
|
||||||
var i = '0';
|
var i = '0';
|
||||||
var j = {
|
var j = {
|
||||||
i: 1
|
i: 1
|
||||||
|
|||||||
1
external/builder/fixtures_babel/evals.js
vendored
1
external/builder/fixtures_babel/evals.js
vendored
@ -5,7 +5,6 @@ var d = PDFJSDev.test('FALSE');
|
|||||||
var e = PDFJSDev.eval('TRUE');
|
var e = PDFJSDev.eval('TRUE');
|
||||||
var f = PDFJSDev.eval('TEXT');
|
var f = PDFJSDev.eval('TEXT');
|
||||||
var g = PDFJSDev.eval('OBJ');
|
var g = PDFJSDev.eval('OBJ');
|
||||||
var h = PDFJSDev.json('$ROOT/external/builder/fixtures_babel/evals.json');
|
|
||||||
var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0';
|
var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0';
|
||||||
var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
|
var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
|
||||||
var k = !PDFJSDev.test('TRUE');
|
var k = !PDFJSDev.test('TRUE');
|
||||||
|
|||||||
1
external/builder/fixtures_babel/evals.json
vendored
1
external/builder/fixtures_babel/evals.json
vendored
@ -1 +0,0 @@
|
|||||||
{ "test": "test" }
|
|
||||||
@ -382,6 +382,7 @@ function createWebpackConfig(
|
|||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
|
test: /\.[mc]?js$/,
|
||||||
loader: "babel-loader",
|
loader: "babel-loader",
|
||||||
exclude: babelExcludeRegExp,
|
exclude: babelExcludeRegExp,
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
@ -20,6 +20,9 @@ import { BasePreferences } from "./preferences.js";
|
|||||||
import { GenericL10n } from "./genericl10n.js";
|
import { GenericL10n } from "./genericl10n.js";
|
||||||
import { GenericScripting } from "./generic_scripting.js";
|
import { GenericScripting } from "./generic_scripting.js";
|
||||||
|
|
||||||
|
// These strings are from chrome/app/resources/generated_resources_*.xtb.
|
||||||
|
import i18nFileAccessLabels from "./chrome-i18n-allow-access-to-file-urls.json" with { type: "json" };
|
||||||
|
|
||||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Module "pdfjs-web/chromecom" shall not be used outside CHROME build.'
|
'Module "pdfjs-web/chromecom" shall not be used outside CHROME build.'
|
||||||
@ -194,11 +197,8 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
|
|||||||
|
|
||||||
// Use Chrome's definition of UI language instead of PDF.js's #lang=...,
|
// Use Chrome's definition of UI language instead of PDF.js's #lang=...,
|
||||||
// because the shown string should match the UI at chrome://extensions.
|
// because the shown string should match the UI at chrome://extensions.
|
||||||
// These strings are from chrome/app/resources/generated_resources_*.xtb.
|
const i18nFileAccessLabel =
|
||||||
const i18nFileAccessLabel = PDFJSDev.json(
|
i18nFileAccessLabels[chrome.i18n.getUILanguage?.()];
|
||||||
"$ROOT/web/chrome-i18n-allow-access-to-file-urls.json"
|
|
||||||
)[chrome.i18n.getUILanguage?.()];
|
|
||||||
|
|
||||||
if (i18nFileAccessLabel) {
|
if (i18nFileAccessLabel) {
|
||||||
document.getElementById("chrome-file-access-label").textContent =
|
document.getElementById("chrome-file-access-label").textContent =
|
||||||
i18nFileAccessLabel;
|
i18nFileAccessLabel;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user