Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON imports instead of PDFJSDev.json #19068

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default [
__non_webpack_import__: "readonly",
},

ecmaVersion: 2022,
ecmaVersion: 2025,
sourceType: "module",
},

Expand Down
15 changes: 0 additions & 15 deletions external/builder/babel-plugin-pdfjs-preprocessor.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { types as t, transformSync } from "@babel/core";
import fs from "fs";
import { join as joinPaths } from "path";
import vm from "vm";

const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
const ROOT_PREFIX = "$ROOT/";

function isPDFJSPreprocessor(obj) {
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
Expand Down Expand Up @@ -40,18 +37,6 @@ function handlePreprocessorAction(ctx, actionName, args, path) {
return result;
}
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");
} catch (e) {
Expand Down
3 changes: 0 additions & 3 deletions external/builder/fixtures_babel/evals-expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ var g = {
},
j: 2
};
var h = {
test: "test"
};
var i = '0';
var j = {
i: 1
Expand Down
1 change: 0 additions & 1 deletion external/builder/fixtures_babel/evals.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var d = PDFJSDev.test('FALSE');
var e = PDFJSDev.eval('TRUE');
var f = PDFJSDev.eval('TEXT');
var g = PDFJSDev.eval('OBJ');
var h = PDFJSDev.json('$ROOT/external/builder/fixtures_babel/evals.json');
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved
var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0';
var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
var k = !PDFJSDev.test('TRUE');
Expand Down
1 change: 0 additions & 1 deletion external/builder/fixtures_babel/evals.json

This file was deleted.

1 change: 1 addition & 0 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ function createWebpackConfig(
module: {
rules: [
{
test: /\.[mc]?js$/,
loader: "babel-loader",
exclude: babelExcludeRegExp,
options: {
Expand Down
10 changes: 5 additions & 5 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { BasePreferences } from "./preferences.js";
import { GenericL10n } from "./genericl10n.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")) {
throw new Error(
'Module "pdfjs-web/chromecom" shall not be used outside CHROME build.'
Expand Down Expand Up @@ -194,11 +197,8 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {

// Use Chrome's definition of UI language instead of PDF.js's #lang=...,
// because the shown string should match the UI at chrome://extensions.
// These strings are from chrome/app/resources/generated_resources_*.xtb.
const i18nFileAccessLabel = PDFJSDev.json(
"$ROOT/web/chrome-i18n-allow-access-to-file-urls.json"
)[chrome.i18n.getUILanguage?.()];

const i18nFileAccessLabel =
i18nFileAccessLabels[chrome.i18n.getUILanguage?.()];
if (i18nFileAccessLabel) {
document.getElementById("chrome-file-access-label").textContent =
i18nFileAccessLabel;
Expand Down