From db4cefbac3e51f4300053cd293bba76ff20ab494 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Tue, 29 Sep 2020 15:45:05 +0200
Subject: [PATCH] Add basic support for the optional chaining operator `?.`

For now we need to use a Babel-plugin, since part of our build system doesn't support this fully (e.g. Babel-loader, Webpack 4.x, and SystemJS).

While the `?.` operator will thus always be transpiled by Babel, even in modern builds, simply supporting it for development purposes seems like a step in the right direction.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
---
 gulpfile.js  | 6 ++++++
 package.json | 1 +
 web/app.js   | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gulpfile.js b/gulpfile.js
index 431675136..e197e7155 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -224,6 +224,12 @@ function createWebpackConfig(defines, output) {
                   loose: true,
                 },
               ],
+              [
+                "@babel/plugin-proposal-optional-chaining",
+                {
+                  loose: true,
+                },
+              ],
               "@babel/plugin-transform-modules-commonjs",
               [
                 "@babel/plugin-transform-runtime",
diff --git a/package.json b/package.json
index 8f8d56235..54ab7c993 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
   "devDependencies": {
     "@babel/core": "^7.11.6",
     "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
+    "@babel/plugin-proposal-optional-chaining": "^7.11.0",
     "@babel/plugin-transform-modules-commonjs": "^7.10.4",
     "@babel/plugin-transform-runtime": "^7.11.5",
     "@babel/preset-env": "^7.11.5",
diff --git a/web/app.js b/web/app.js
index fa9070834..252fdbc07 100644
--- a/web/app.js
+++ b/web/app.js
@@ -846,7 +846,7 @@ const PDFViewerApplication = {
           return undefined; // Ignore errors for previously opened PDF files.
         }
 
-        const message = exception && exception.message;
+        const message = exception?.message;
         let loadingErrorMessage;
         if (exception instanceof InvalidPDFException) {
           // change error message also for other builds