Migrate main/ to ESM internally

Bug: 1006759
Change-Id: I44435dcd09afe2c3cbac7bbda46df415b77c12d9
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1994969
Commit-Queue: Tim van der Lippe <[email protected]>
Reviewed-by: Paul Lewis <[email protected]>
diff --git a/front_end/main/ExecutionContextSelector.js b/front_end/main/ExecutionContextSelector.js
index d731619..521aebd 100644
--- a/front_end/main/ExecutionContextSelector.js
+++ b/front_end/main/ExecutionContextSelector.js
@@ -1,11 +1,12 @@
 // Copyright 2014 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+
 /**
  * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>}
  * @unrestricted
  */
-export default class ExecutionContextSelector {
+export class ExecutionContextSelector {
   /**
    * @param {!SDK.TargetManager} targetManager
    * @param {!UI.Context} context
@@ -36,7 +37,7 @@
     setImmediate(deferred.bind(this));
 
     /**
-     * @this {Main.ExecutionContextSelector}
+     * @this {ExecutionContextSelector}
      */
     function deferred() {
       // We always want the second context for the service worker targets.
@@ -219,14 +220,3 @@
     this._ignoreContextChanged = false;
   }
 }
-
-/* Legacy exported object */
-self.Main = self.Main || {};
-
-/* Legacy exported object */
-Main = Main || {};
-
-/**
- * @constructor
- */
-Main.ExecutionContextSelector = ExecutionContextSelector;
diff --git a/front_end/main/MainImpl.js b/front_end/main/MainImpl.js
index 296fb60..3862661 100644
--- a/front_end/main/MainImpl.js
+++ b/front_end/main/MainImpl.js
@@ -28,6 +28,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import {ExecutionContextSelector} from './ExecutionContextSelector.js';
+
 /**
  * @unrestricted
  */
@@ -220,7 +222,7 @@
     Persistence.persistence = new Persistence.Persistence(Workspace.workspace, Bindings.breakpointManager);
     Persistence.networkPersistenceManager = new Persistence.NetworkPersistenceManager(Workspace.workspace);
 
-    new Main.ExecutionContextSelector(SDK.targetManager, UI.context);
+    new ExecutionContextSelector(SDK.targetManager, UI.context);
     Bindings.blackboxManager = new Bindings.BlackboxManager(Bindings.debuggerWorkspaceBinding);
 
     new PauseListener();
@@ -727,40 +729,3 @@
 }
 
 new MainImpl();
-
-/* Legacy exported object */
-self.Main = self.Main || {};
-
-/* Legacy exported object */
-Main = Main || {};
-
-/**
- * @constructor
- */
-Main.Main = MainImpl;
-
-/**
- * @constructor
- */
-Main.Main.ZoomActionDelegate = ZoomActionDelegate;
-
-/**
- * @constructor
- */
-Main.Main.SearchActionDelegate = SearchActionDelegate;
-
-/**
- * @constructor
- */
-Main.Main.MainMenuItem = MainMenuItem;
-
-/**
- * @constructor
- */
-Main.Main.PauseListener = PauseListener;
-
-/**
- * @constructor
- */
-Main.ReloadActionDelegate = ReloadActionDelegate;
-Main.sendOverProtocol = sendOverProtocol;
diff --git a/front_end/main/SimpleApp.js b/front_end/main/SimpleApp.js
index 5c93fd9..de848ee 100644
--- a/front_end/main/SimpleApp.js
+++ b/front_end/main/SimpleApp.js
@@ -1,6 +1,7 @@
 // Copyright 2014 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+
 /**
  * @implements {Common.App}
  * @unrestricted
@@ -28,22 +29,6 @@
    * @return {!Common.App}
    */
   createApp() {
-    return new Main.SimpleApp();
+    return new SimpleApp();
   }
 }
-
-/* Legacy exported object */
-self.Main = self.Main || {};
-
-/* Legacy exported object */
-Main = Main || {};
-
-/**
- * @constructor
- */
-Main.SimpleApp = SimpleApp;
-
-/**
- * @constructor
- */
-Main.SimpleAppProvider = SimpleAppProvider;
diff --git a/front_end/main/main-legacy.js b/front_end/main/main-legacy.js
new file mode 100644
index 0000000..cb07a09
--- /dev/null
+++ b/front_end/main/main-legacy.js
@@ -0,0 +1,54 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import * as MainModule from './main.js';
+
+self.Main = self.Main || {};
+Main = Main || {};
+
+/**
+ * @constructor
+ */
+Main.ExecutionContextSelector = MainModule.ExecutionContextSelector.ExecutionContextSelector;
+
+/**
+ * @constructor
+ */
+Main.Main = MainModule.MainImpl.MainImpl;
+
+/**
+ * @constructor
+ */
+Main.Main.ZoomActionDelegate = MainModule.MainImpl.ZoomActionDelegate;
+
+/**
+ * @constructor
+ */
+Main.Main.SearchActionDelegate = MainModule.MainImpl.SearchActionDelegate;
+
+/**
+ * @constructor
+ */
+Main.Main.MainMenuItem = MainModule.MainImpl.MainMenuItem;
+
+/**
+ * @constructor
+ */
+Main.Main.PauseListener = MainModule.MainImpl.PauseListener;
+
+/**
+ * @constructor
+ */
+Main.ReloadActionDelegate = MainModule.MainImpl.ReloadActionDelegate;
+Main.sendOverProtocol = MainModule.MainImpl.sendOverProtocol;
+
+/**
+ * @constructor
+ */
+Main.SimpleApp = MainModule.SimpleApp.SimpleApp;
+
+/**
+ * @constructor
+ */
+Main.SimpleAppProvider = MainModule.SimpleApp.SimpleAppProvider;
diff --git a/front_end/main/main.js b/front_end/main/main.js
index 6693d31..2daa91b 100644
--- a/front_end/main/main.js
+++ b/front_end/main/main.js
@@ -2,16 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-import './SimpleApp.js';
-import './ExecutionContextSelector.js';
-import './MainImpl.js';
-
 import * as ExecutionContextSelector from './ExecutionContextSelector.js';
-import * as Main from './MainImpl.js';
+import * as MainImpl from './MainImpl.js';
 import * as SimpleApp from './SimpleApp.js';
 
 export {
   ExecutionContextSelector,
-  Main,
+  MainImpl,
   SimpleApp,
 };
diff --git a/front_end/main/module.json b/front_end/main/module.json
index 77fad77..9f527a6 100644
--- a/front_end/main/module.json
+++ b/front_end/main/module.json
@@ -390,6 +390,7 @@
     "scripts": [],
     "modules": [
         "main.js",
+        "main-legacy.js",
         "SimpleApp.js",
         "ExecutionContextSelector.js",
         "MainImpl.js"