From 3a0fb42737080bfe411d2dcd3adff41cdef7ca60 Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Thu, 14 Jan 2016 13:18:52 -0800 Subject: [PATCH] Use `const` --- atom/browser/api/lib/menu-item.js | 4 +-- atom/browser/api/lib/menu.js | 26 ++++++-------- atom/browser/api/lib/navigation-controller.js | 7 ++-- atom/browser/api/lib/power-monitor.js | 7 ++-- atom/browser/api/lib/protocol.js | 8 ++--- atom/browser/api/lib/screen.js | 7 ++-- atom/browser/api/lib/session.js | 12 +++---- atom/browser/api/lib/tray.js | 10 ++---- atom/browser/api/lib/web-contents.js | 23 +++++++------ atom/browser/lib/chrome-extension.js | 34 +++++++------------ 10 files changed, 55 insertions(+), 83 deletions(-) diff --git a/atom/browser/api/lib/menu-item.js b/atom/browser/api/lib/menu-item.js index b8357dd3491..80fdd46fd89 100644 --- a/atom/browser/api/lib/menu-item.js +++ b/atom/browser/api/lib/menu-item.js @@ -26,8 +26,8 @@ MenuItem = (function() { MenuItem.types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']; function MenuItem(options) { - var Menu, click, ref; - Menu = require('electron').Menu; + var click, ref; + const Menu = require('electron').Menu; click = options.click, this.selector = options.selector, this.type = options.type, this.role = options.role, this.label = options.label, this.sublabel = options.sublabel, this.accelerator = options.accelerator, this.icon = options.icon, this.enabled = options.enabled, this.visible = options.visible, this.checked = options.checked, this.submenu = options.submenu; if ((this.submenu != null) && this.submenu.constructor !== Menu) { this.submenu = Menu.buildFromTemplate(this.submenu); diff --git a/atom/browser/api/lib/menu.js b/atom/browser/api/lib/menu.js index 5af39e18af3..69ad4fec051 100644 --- a/atom/browser/api/lib/menu.js +++ b/atom/browser/api/lib/menu.js @@ -1,19 +1,15 @@ -var BrowserWindow, EventEmitter, Menu, MenuItem, applicationMenu, bindings, generateGroupId, indexOfItemById, indexToInsertByPosition, nextGroupId, ref, v8Util; - -ref = require('electron'), BrowserWindow = ref.BrowserWindow, MenuItem = ref.MenuItem; - -EventEmitter = require('events').EventEmitter; - -v8Util = process.atomBinding('v8_util'); - -bindings = process.atomBinding('menu'); +const BrowserWindow = require('electron').BrowserWindow; +const MenuItem = require('electron').MenuItem; +const EventEmitter = require('events').EventEmitter; +const v8Util = process.atomBinding('v8_util'); +const bindings = process.atomBinding('menu'); // Automatically generated radio menu item's group id. -nextGroupId = 0; +var nextGroupId = 0; // Search between seperators to find a radio menu item and return its group id, // otherwise generate a group id. -generateGroupId = function(items, pos) { +var generateGroupId = function(items, pos) { var i, item, j, k, ref1, ref2, ref3; if (pos > 0) { for (i = j = ref1 = pos - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) { @@ -40,7 +36,7 @@ generateGroupId = function(items, pos) { }; // Returns the index of item according to |id|. -indexOfItemById = function(items, id) { +var indexOfItemById = function(items, id) { var i, item, j, len; for (i = j = 0, len = items.length; j < len; i = ++j) { item = items[i]; @@ -52,7 +48,7 @@ indexOfItemById = function(items, id) { }; // Returns the index of where to insert the item according to |position|. -indexToInsertByPosition = function(items, position) { +var indexToInsertByPosition = function(items, position) { var id, insertIndex, query, ref1; if (!position) { return items.length; @@ -87,7 +83,7 @@ indexToInsertByPosition = function(items, position) { return insertIndex; }; -Menu = bindings.Menu; +const Menu = bindings.Menu; Menu.prototype.__proto__ = EventEmitter.prototype; @@ -265,7 +261,7 @@ Menu.prototype._callMenuWillShow = function() { return results; }; -applicationMenu = null; +var applicationMenu = null; Menu.setApplicationMenu = function(menu) { var j, len, results, w, windows; diff --git a/atom/browser/api/lib/navigation-controller.js b/atom/browser/api/lib/navigation-controller.js index 5478b6dd326..80756eb13e4 100644 --- a/atom/browser/api/lib/navigation-controller.js +++ b/atom/browser/api/lib/navigation-controller.js @@ -1,7 +1,6 @@ -var NavigationController, ipcMain, - slice = [].slice; +const ipcMain = require('electron').ipcMain; -ipcMain = require('electron').ipcMain; +var slice = [].slice; // The history operation in renderer is redirected to browser. ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function() { @@ -21,7 +20,7 @@ ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function() { // control on user land, and only rely on WebContents.loadURL for navigation. // This helps us avoid Chromium's various optimizations so we can ensure renderer // process is restarted everytime. -NavigationController = (function() { +var NavigationController = (function() { function NavigationController(webContents) { this.webContents = webContents; this.clearHistory(); diff --git a/atom/browser/api/lib/power-monitor.js b/atom/browser/api/lib/power-monitor.js index df4b28c6eb6..239eb3b4d47 100644 --- a/atom/browser/api/lib/power-monitor.js +++ b/atom/browser/api/lib/power-monitor.js @@ -1,8 +1,5 @@ -var EventEmitter, powerMonitor; - -EventEmitter = require('events').EventEmitter; - -powerMonitor = process.atomBinding('power_monitor').powerMonitor; +const EventEmitter = require('events').EventEmitter; +const powerMonitor = process.atomBinding('power_monitor').powerMonitor; powerMonitor.__proto__ = EventEmitter.prototype; diff --git a/atom/browser/api/lib/protocol.js b/atom/browser/api/lib/protocol.js index f04eab121f1..41cb48db09b 100644 --- a/atom/browser/api/lib/protocol.js +++ b/atom/browser/api/lib/protocol.js @@ -1,15 +1,13 @@ -var app, logAndThrow, protocol; - -app = require('electron').app; +const app = require('electron').app; if (!app.isReady()) { throw new Error('Can not initialize protocol module before app is ready'); } -protocol = process.atomBinding('protocol').protocol; +const protocol = process.atomBinding('protocol').protocol; // Warn about removed APIs. -logAndThrow = function(callback, message) { +var logAndThrow = function(callback, message) { console.error(message); if (callback) { return callback(new Error(message)); diff --git a/atom/browser/api/lib/screen.js b/atom/browser/api/lib/screen.js index 3dca49e99d9..04965278a3c 100644 --- a/atom/browser/api/lib/screen.js +++ b/atom/browser/api/lib/screen.js @@ -1,8 +1,5 @@ -var EventEmitter, screen; - -EventEmitter = require('events').EventEmitter; - -screen = process.atomBinding('screen').screen; +const EventEmitter = require('events').EventEmitter; +const screen = process.atomBinding('screen').screen; screen.__proto__ = EventEmitter.prototype; diff --git a/atom/browser/api/lib/session.js b/atom/browser/api/lib/session.js index 8ba9e61be45..dc65264349f 100644 --- a/atom/browser/api/lib/session.js +++ b/atom/browser/api/lib/session.js @@ -1,10 +1,6 @@ -var EventEmitter, PERSIST_PERFIX, bindings, wrapSession; - -EventEmitter = require('events').EventEmitter; - -bindings = process.atomBinding('session'); - -PERSIST_PERFIX = 'persist:'; +const EventEmitter = require('events').EventEmitter; +const bindings = process.atomBinding('session'); +const PERSIST_PERFIX = 'persist:'; // Returns the Session from |partition| string. exports.fromPartition = function(partition) { @@ -29,7 +25,7 @@ Object.defineProperty(exports, 'defaultSession', { } }); -wrapSession = function(session) { +var wrapSession = function(session) { // session is an EventEmitter. return session.__proto__ = EventEmitter.prototype; }; diff --git a/atom/browser/api/lib/tray.js b/atom/browser/api/lib/tray.js index a2b732964ea..342683552f6 100644 --- a/atom/browser/api/lib/tray.js +++ b/atom/browser/api/lib/tray.js @@ -1,10 +1,6 @@ -var EventEmitter, Tray, deprecate; - -deprecate = require('electron').deprecate; - -EventEmitter = require('events').EventEmitter; - -Tray = process.atomBinding('tray').Tray; +const deprecate = require('electron').deprecate; +const EventEmitter = require('events').EventEmitter; +const Tray = process.atomBinding('tray').Tray; Tray.prototype.__proto__ = EventEmitter.prototype; diff --git a/atom/browser/api/lib/web-contents.js b/atom/browser/api/lib/web-contents.js index c507daab077..47f5eb4639b 100644 --- a/atom/browser/api/lib/web-contents.js +++ b/atom/browser/api/lib/web-contents.js @@ -1,21 +1,22 @@ 'use strict'; -var EventEmitter, Menu, NavigationController, PDFPageSize, binding, deprecate, getNextId, ipcMain, nextId, ref, session, wrapWebContents, - slice = [].slice; +const EventEmitter = require('events').EventEmitter; +const deprecate = require('electron').deprecate; +const ipcMain = require('electron').ipcMain; +const session = require('electron').session; +const NavigationController = require('electron').NavigationController; +const Menu = require('electron').Menu; -EventEmitter = require('events').EventEmitter; +const binding = process.atomBinding('web_contents'); -ref = require('electron'), deprecate = ref.deprecate, ipcMain = ref.ipcMain, session = ref.session, NavigationController = ref.NavigationController, Menu = ref.Menu; +let slice = [].slice; +let nextId = 0; -binding = process.atomBinding('web_contents'); - -nextId = 0; - -getNextId = function() { +let getNextId = function() { return ++nextId; }; -PDFPageSize = { +let PDFPageSize = { A5: { custom_display_name: "A5", height_microns: 210000, @@ -64,7 +65,7 @@ const webFrameMethods = [ 'setZoomLevelLimits', ]; -wrapWebContents = function(webContents) { +let wrapWebContents = function(webContents) { // webContents is an EventEmitter. var controller, method, name, ref1; webContents.__proto__ = EventEmitter.prototype; diff --git a/atom/browser/lib/chrome-extension.js b/atom/browser/lib/chrome-extension.js index 44e7f947e39..32459c3a20e 100644 --- a/atom/browser/lib/chrome-extension.js +++ b/atom/browser/lib/chrome-extension.js @@ -1,33 +1,28 @@ -var app, electron, extensionInfoMap, fs, getExtensionInfoFromPath, getHostForPath, getPathForHost, hostPathMap, hostPathMapNextKey, loadedExtensions, loadedExtensionsPath, path, url; - -electron = require('electron'); - -fs = require('fs'); - -path = require('path'); - -url = require('url'); +const electron = require('electron'); +const app = electron.app; +const fs = require('fs'); +const path = require('path'); +const url = require('url'); // Mapping between hostname and file path. -hostPathMap = {}; +var hostPathMap = {}; +var hostPathMapNextKey = 0; -hostPathMapNextKey = 0; - -getHostForPath = function(path) { +var getHostForPath = function(path) { var key; key = "extension-" + (++hostPathMapNextKey); hostPathMap[key] = path; return key; }; -getPathForHost = function(host) { +var getPathForHost = function(host) { return hostPathMap[host]; }; // Cache extensionInfo. -extensionInfoMap = {}; +var extensionInfoMap = {}; -getExtensionInfoFromPath = function(srcDirectory) { +var getExtensionInfoFromPath = function(srcDirectory) { var manifest, page; manifest = JSON.parse(fs.readFileSync(path.join(srcDirectory, 'manifest.json'))); if (extensionInfoMap[manifest.name] == null) { @@ -51,11 +46,8 @@ getExtensionInfoFromPath = function(srcDirectory) { }; // The loaded extensions cache and its persistent path. -loadedExtensions = null; -loadedExtensionsPath = null; - -// Persistent loaded extensions. -app = electron.app; +var loadedExtensions = null; +var loadedExtensionsPath = null; app.on('will-quit', function() { var e, error1, error2;