From 564787d1dd0e1ebd5b6f939af9d4f61793d7677d Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Wed, 31 Aug 2022 15:15:19 +0100
Subject: [PATCH] FIX: Transpile start-discourse.js to fix iOS12 support
 (#18149)

33a2624f09 introduced a JS safe-navigation operator in `discourse-boot.js`. This needs to be transpiled to maintain iOS 12 support.
---
 .../javascripts/discourse/ember-cli-build.js     |  5 -----
 app/assets/javascripts/discourse/lib/scripts.js  | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js
index 3913c2de123..e8784e95516 100644
--- a/app/assets/javascripts/discourse/ember-cli-build.js
+++ b/app/assets/javascripts/discourse/ember-cli-build.js
@@ -179,11 +179,6 @@ module.exports = function (defaults) {
       })
     ),
     applyTerser(prettyTextEngine(app)),
-    concat("public/assets/scripts", {
-      outputFile: `assets/start-discourse.js`,
-      headerFiles: [`start-app.js`],
-      inputFiles: [`discourse-boot.js`],
-    }),
     generateScriptsTree(app),
     applyTerser(discoursePluginsTree),
   ]);
diff --git a/app/assets/javascripts/discourse/lib/scripts.js b/app/assets/javascripts/discourse/lib/scripts.js
index 3c4572b113c..ac73f27f4ae 100644
--- a/app/assets/javascripts/discourse/lib/scripts.js
+++ b/app/assets/javascripts/discourse/lib/scripts.js
@@ -35,5 +35,21 @@ module.exports = function scriptsTree(app) {
     trees.push(transpiledWithDecodedSourcemap);
   }
 
+  // start-discourse.js is a combination of start-app and discourse-boot
+  let startDiscourseTree = funnel(`public/assets/scripts`, {
+    files: ["start-app.js", "discourse-boot.js"],
+    destDir: "scripts",
+  });
+  startDiscourseTree = babelAddon.transpileTree(
+    startDiscourseTree,
+    babelConfig
+  );
+  startDiscourseTree = concat(startDiscourseTree, {
+    outputFile: `assets/start-discourse.js`,
+    headerFiles: [`scripts/start-app.js`],
+    inputFiles: [`scripts/discourse-boot.js`],
+  });
+  trees.push(startDiscourseTree);
+
   return mergeTrees(trees);
 };