From f295c51cc5fb5a7f61750578a72141422dc36b49 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 19 Feb 2024 11:28:10 +0100 Subject: [PATCH] Use more optional chaining, and other modern JS, in the building code --- external/builder/babel-plugin-pdfjs-preprocessor.mjs | 9 ++------- external/builder/builder.mjs | 2 +- gulpfile.mjs | 7 +++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/external/builder/babel-plugin-pdfjs-preprocessor.mjs b/external/builder/babel-plugin-pdfjs-preprocessor.mjs index 87b024bab..945d22c47 100644 --- a/external/builder/babel-plugin-pdfjs-preprocessor.mjs +++ b/external/builder/babel-plugin-pdfjs-preprocessor.mjs @@ -11,7 +11,7 @@ function isPDFJSPreprocessor(obj) { } function evalWithDefines(code, defines) { - if (!code || !code.trim()) { + if (!code?.trim()) { throw new Error("No JavaScript expression given"); } return vm.runInNewContext(code, defines, { displayErrors: false }); @@ -56,12 +56,7 @@ function handlePreprocessorAction(ctx, actionName, args, path) { throw new Error("Unsupported action"); } catch (e) { throw path.buildCodeFrameError( - "Could not process " + - PDFJS_PREPROCESSOR_NAME + - "." + - actionName + - ": " + - e.message + `Could not process ${PDFJS_PREPROCESSOR_NAME}.${actionName}: ${e.message}` ); } } diff --git a/external/builder/builder.mjs b/external/builder/builder.mjs index 783ef9b30..929a9cf87 100644 --- a/external/builder/builder.mjs +++ b/external/builder/builder.mjs @@ -84,7 +84,7 @@ function preprocess(inFilename, outFilename, defines) { out.push(line); }; function evaluateCondition(code) { - if (!code || !code.trim()) { + if (!code?.trim()) { throw new Error("No JavaScript expression given at " + loc()); } try { diff --git a/gulpfile.mjs b/gulpfile.mjs index f686876db..dc14960dc 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -124,9 +124,8 @@ function transform(charEncoding, transformFunction) { }); } -function safeSpawnSync(command, parameters, options) { +function safeSpawnSync(command, parameters, options = {}) { // Execute all commands in a shell. - options = options || {}; options.shell = true; // `options.shell = true` requires parameters to be quoted. parameters = parameters.map(param => { @@ -410,7 +409,7 @@ function checkChromePreferencesFile(chromePrefsPath, webPrefs) { // Deprecated keys are allowed in the managed preferences file. // The code maintainer is responsible for adding migration logic to // extensions/chromium/options/migration.js and web/chromecom.js . - return !description || !description.startsWith("DEPRECATED."); + return !description?.startsWith("DEPRECATED."); }); let ret = true; @@ -520,7 +519,7 @@ function createSandboxExternal(defines) { function createTemporaryScriptingBundle(defines, extraOptions = undefined) { return createScriptingBundle(defines, { - disableVersionInfo: !!(extraOptions && extraOptions.disableVersionInfo), + disableVersionInfo: !!extraOptions?.disableVersionInfo, disableSourceMaps: true, disableLicenseHeader: true, }).pipe(gulp.dest(TMP_DIR));