From ab8908a4afb0655913a244b915f7316852d16fdc Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Thu, 14 Jan 2016 14:11:50 -0800 Subject: [PATCH] Use `const` --- atom/common/lib/init.js | 15 +++++---------- atom/common/lib/reset-search-paths.js | 7 ++----- atom/renderer/api/lib/desktop-capturer.js | 13 ++++++------- atom/renderer/api/lib/exports/electron.js | 4 +--- atom/renderer/api/lib/ipc-renderer.js | 13 +++++-------- atom/renderer/lib/chrome-api.js | 7 ++----- atom/renderer/lib/inspector.js | 19 ++++++++----------- 7 files changed, 29 insertions(+), 49 deletions(-) diff --git a/atom/common/lib/init.js b/atom/common/lib/init.js index 2165603e87e6..76fe1b45820a 100644 --- a/atom/common/lib/init.js +++ b/atom/common/lib/init.js @@ -1,12 +1,7 @@ -var Module, fs, path, timers, wrapWithActivateUvLoop; - -fs = require('fs'); - -path = require('path'); - -timers = require('timers'); - -Module = require('module'); +const fs = require('fs'); +const path = require('path'); +const timers = require('timers'); +const Module = require('module'); process.atomBinding = function(name) { var e, error; @@ -32,7 +27,7 @@ if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) { // which would delay the callbacks for arbitrary long time. So we should // initiatively activate the uv loop once setImmediate and process.nextTick is // called. -wrapWithActivateUvLoop = function(func) { +var wrapWithActivateUvLoop = function(func) { return function() { process.activateUvLoop(); return func.apply(this, arguments); diff --git a/atom/common/lib/reset-search-paths.js b/atom/common/lib/reset-search-paths.js index a996cd4ceca8..abf671196735 100644 --- a/atom/common/lib/reset-search-paths.js +++ b/atom/common/lib/reset-search-paths.js @@ -1,8 +1,5 @@ -var Module, path; - -path = require('path'); - -Module = require('module'); +const path = require('path'); +const Module = require('module'); // Clear Node's global search paths. Module.globalPaths.length = 0; diff --git a/atom/renderer/api/lib/desktop-capturer.js b/atom/renderer/api/lib/desktop-capturer.js index 5b44bdf5f23e..f9b7ca393d86 100644 --- a/atom/renderer/api/lib/desktop-capturer.js +++ b/atom/renderer/api/lib/desktop-capturer.js @@ -1,16 +1,15 @@ -var getNextId, ipcRenderer, isValid, nativeImage, nextId, ref, - indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; +const ipcRenderer = require('electron').ipcRenderer; +const nativeImage = require('electron').ref.nativeImage; -ref = require('electron'), ipcRenderer = ref.ipcRenderer, nativeImage = ref.nativeImage; +var nextId = 0; +var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; -nextId = 0; - -getNextId = function() { +var getNextId = function() { return ++nextId; }; // |options.type| can not be empty and has to include 'window' or 'screen'. -isValid = function(options) { +var isValid = function(options) { return ((options != null ? options.types : void 0) != null) && Array.isArray(options.types); }; diff --git a/atom/renderer/api/lib/exports/electron.js b/atom/renderer/api/lib/exports/electron.js index e3fe7b335317..3f0d3254cb8b 100644 --- a/atom/renderer/api/lib/exports/electron.js +++ b/atom/renderer/api/lib/exports/electron.js @@ -1,6 +1,4 @@ -var common; - -common = require('../../../../common/api/lib/exports/electron'); +const common = require('../../../../common/api/lib/exports/electron'); // Import common modules. common.defineProperties(exports); diff --git a/atom/renderer/api/lib/ipc-renderer.js b/atom/renderer/api/lib/ipc-renderer.js index cd6b37c3db45..5b3c0a4eb788 100644 --- a/atom/renderer/api/lib/ipc-renderer.js +++ b/atom/renderer/api/lib/ipc-renderer.js @@ -1,14 +1,11 @@ -var EventEmitter, binding, ipcRenderer, v8Util, - slice = [].slice; +const EventEmitter = require('events').EventEmitter; +const binding = process.atomBinding('ipc'); +const v8Util = process.atomBinding('v8_util'); -EventEmitter = require('events').EventEmitter; - -binding = process.atomBinding('ipc'); - -v8Util = process.atomBinding('v8_util'); +var slice = [].slice; // Created by init.coffee. -ipcRenderer = v8Util.getHiddenValue(global, 'ipc'); +const ipcRenderer = v8Util.getHiddenValue(global, 'ipc'); ipcRenderer.send = function() { var args; diff --git a/atom/renderer/lib/chrome-api.js b/atom/renderer/lib/chrome-api.js index 535f7f2103b5..7ff7d2e87b99 100644 --- a/atom/renderer/lib/chrome-api.js +++ b/atom/renderer/lib/chrome-api.js @@ -1,8 +1,5 @@ -var chrome, url; - -url = require('url'); - -chrome = window.chrome = window.chrome || {}; +const url = require('url'); +const chrome = window.chrome = window.chrome || {}; chrome.extension = { getURL: function(path) { diff --git a/atom/renderer/lib/inspector.js b/atom/renderer/lib/inspector.js index b37e1d3de905..9ef6440720ff 100644 --- a/atom/renderer/lib/inspector.js +++ b/atom/renderer/lib/inspector.js @@ -1,5 +1,3 @@ -var convertToMenuTemplate, createFileSelectorElement, createMenu, pathToHtml5FileObject, showFileChooserDialog; - window.onload = function() { // Use menu API to show context menu. InspectorFrontendHost.showContextMenuAtPoint = createMenu; @@ -8,7 +6,7 @@ window.onload = function() { return WebInspector.createFileSelectorElement = createFileSelectorElement; }; -convertToMenuTemplate = function(items) { +var convertToMenuTemplate = function(items) { var fn, i, item, len, template; template = []; fn = function(item) { @@ -45,11 +43,10 @@ convertToMenuTemplate = function(items) { return template; }; -createMenu = function(x, y, items, document) { - var Menu, menu, remote; - remote = require('electron').remote; - Menu = remote.Menu; - menu = Menu.buildFromTemplate(convertToMenuTemplate(items)); +var createMenu = function(x, y, items, document) { + const remote = require('electron').remote; + const Menu = remote.Menu; + const menu = Menu.buildFromTemplate(convertToMenuTemplate(items)); // The menu is expected to show asynchronously. return setTimeout(function() { @@ -57,7 +54,7 @@ createMenu = function(x, y, items, document) { }); }; -showFileChooserDialog = function(callback) { +var showFileChooserDialog = function(callback) { var dialog, files, remote; remote = require('electron').remote; dialog = remote.dialog; @@ -67,7 +64,7 @@ showFileChooserDialog = function(callback) { } }; -pathToHtml5FileObject = function(path) { +var pathToHtml5FileObject = function(path) { var blob, fs; fs = require('fs'); blob = new Blob([fs.readFileSync(path)]); @@ -75,7 +72,7 @@ pathToHtml5FileObject = function(path) { return blob; }; -createFileSelectorElement = function(callback) { +var createFileSelectorElement = function(callback) { var fileSelectorElement; fileSelectorElement = document.createElement('span'); fileSelectorElement.style.display = 'none';