Skip to content

Commit

Permalink
refactor: replace var with const / let (electron#14866)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored and MarshallOfSound committed Sep 28, 2018
1 parent b42493e commit c61db52
Show file tree
Hide file tree
Showing 26 changed files with 195 additions and 201 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extends": "standard",
"env": {
"browser": true
},
"rules": {
"no-var": "error"
}
}
4 changes: 2 additions & 2 deletions lib/browser/api/auto-updater/squirrel-update-win.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ exports.processStart = function () {
// Download the releases specified by the URL and write new results to stdout.
exports.checkForUpdate = function (updateURL, callback) {
return spawnUpdate(['--checkForUpdate', updateURL], false, function (error, stdout) {
var json, ref, ref1, update
let ref, ref1, update
if (error != null) {
return callback(error)
}
try {
// Last line of output is the JSON details about the releases
json = stdout.trim().split('\n').pop()
const json = stdout.trim().split('\n').pop()
update = (ref = JSON.parse(json)) != null ? (ref1 = ref.releasesToApply) != null ? typeof ref1.pop === 'function' ? ref1.pop() : void 0 : void 0 : void 0
} catch (jsonError) {
// Disabled for backwards compatibility:
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/api/navigation-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ipcMain.on('ELECTRON_SYNC_NAVIGATION_CONTROLLER', function (event, method, ...ar
// 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.
var NavigationController = (function () {
const NavigationController = (function () {
function NavigationController (webContents) {
this.webContents = webContents
this.clearHistory()
Expand Down Expand Up @@ -141,7 +141,7 @@ var NavigationController = (function () {
}

NavigationController.prototype.goToOffset = function (offset) {
var pendingIndex
let pendingIndex
if (!this.canGoToOffset(offset)) {
return
}
Expand Down
15 changes: 7 additions & 8 deletions lib/browser/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const util = require('util')
const Module = require('module')
const v8 = require('v8')

// We modified the original process.argv to let node.js load the atom.js,
// We modified the original process.argv to let node.js load the init.js,
// we need to restore it here.
process.argv.splice(1, 1)

Expand All @@ -17,18 +17,18 @@ require('../common/reset-search-paths')
// Import common settings.
require('@electron/internal/common/init')

var globalPaths = Module.globalPaths
const globalPaths = Module.globalPaths

// Expose public APIs.
globalPaths.push(path.join(__dirname, 'api', 'exports'))

if (process.platform === 'win32') {
// Redirect node's console to use our own implementations, since node can not
// handle console output when running as GUI program.
var consoleLog = function (...args) {
const consoleLog = function (...args) {
return process.log(util.format(...args) + '\n')
}
var streamWrite = function (chunk, encoding, callback) {
const streamWrite = function (chunk, encoding, callback) {
if (Buffer.isBuffer(chunk)) {
chunk = chunk.toString(encoding)
}
Expand All @@ -45,15 +45,14 @@ if (process.platform === 'win32') {
// Don't quit on fatal error.
process.on('uncaughtException', function (error) {
// Do nothing if the user has a custom uncaught exception handler.
var dialog, message, ref, stack
if (process.listeners('uncaughtException').length > 1) {
return
}

// Show error in GUI.
dialog = require('electron').dialog
stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
message = 'Uncaught Exception:\n' + stack
const dialog = require('electron').dialog
const stack = error.stack ? error.stack : `${error.name}: ${error.message}`
const message = 'Uncaught Exception:\n' + stack
dialog.showErrorBox('A JavaScript error occurred in the main process', message)
})

Expand Down
1 change: 0 additions & 1 deletion lib/common/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function wrap (func, wrapper) {
process.nextTick = wrapWithActivateUvLoop(process.nextTick)

global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate)

global.clearImmediate = timers.clearImmediate

if (process.type === 'browser') {
Expand Down
2 changes: 1 addition & 1 deletion lib/renderer/extensions/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const getStorageManager = (storageType, extensionId) => {

let items = {}
keys.forEach(function (key) {
var value = storage[key]
let value = storage[key]
if (value == null) value = defaults[key]
items[key] = value
})
Expand Down
4 changes: 2 additions & 2 deletions lib/renderer/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ require('../common/reset-search-paths')
// Import common settings.
require('@electron/internal/common/init')

var globalPaths = Module.globalPaths
const globalPaths = Module.globalPaths

// Expose public APIs.
globalPaths.push(path.join(__dirname, 'api', 'exports'))

// The global variable will be used by ipc for event dispatching
var v8Util = process.atomBinding('v8_util')
const v8Util = process.atomBinding('v8_util')

v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter())

Expand Down
8 changes: 4 additions & 4 deletions script/lib/tls/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var fs = require('fs')
var https = require('https')
var path = require('path')
const fs = require('fs')
const https = require('https')
const path = require('path')

var server = https.createServer({
const server = https.createServer({
key: fs.readFileSync(path.resolve(__dirname, 'tls.key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, 'tls.cert.pem'))
}, (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion script/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const utils = require('./lib/utils')

const electronPath = utils.getAbsoluteElectronExec()

var child = cp.spawn(electronPath, process.argv.slice(2), { stdio: 'inherit' })
const child = cp.spawn(electronPath, process.argv.slice(2), { stdio: 'inherit' })
child.on('close', (code) => process.exit(code))

const handleTerminationSignal = (signal) =>
Expand Down
12 changes: 6 additions & 6 deletions spec/api-browser-window-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ describe('BrowserWindow module', () => {
it('sets the content size', () => {
const size = [400, 400]
w.setContentSize(size[0], size[1])
var after = w.getContentSize()
const after = w.getContentSize()
assert.strictEqual(after[0], size[0])
assert.strictEqual(after[1], size[1])
})
Expand Down Expand Up @@ -3132,7 +3132,7 @@ describe('BrowserWindow module', () => {
}
})

var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
BrowserWindow.removeDevToolsExtension('foo')
BrowserWindow.addDevToolsExtension(extensionPath)

Expand All @@ -3148,9 +3148,9 @@ describe('BrowserWindow module', () => {
})

it('serializes the registered extensions on quit', () => {
var extensionName = 'foo'
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)
var serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions')
const extensionName = 'foo'
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)
const serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions')

BrowserWindow.addDevToolsExtension(extensionPath)
app.emit('will-quit')
Expand All @@ -3166,7 +3166,7 @@ describe('BrowserWindow module', () => {
BrowserWindow.removeExtension('foo')
assert.strictEqual(BrowserWindow.getExtensions().hasOwnProperty('foo'), false)

var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
BrowserWindow.addExtension(extensionPath)
assert.strictEqual(BrowserWindow.getExtensions().hasOwnProperty('foo'), true)

Expand Down
2 changes: 1 addition & 1 deletion spec/api-protocol-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ describe('protocol module', () => {
})

it('does not crash when handler is called twice', (done) => {
var doubleHandler = (request, callback) => {
const doubleHandler = (request, callback) => {
try {
callback(text)
callback()
Expand Down
8 changes: 4 additions & 4 deletions spec/api-web-frame-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ chai.use(dirtyChai)
/* eslint-disable standard/no-callback-literal */

describe('webFrame module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
const fixtures = path.resolve(__dirname, 'fixtures')
let w = null

afterEach(function () {
return closeWindow(w).then(function () { w = null })
})

describe('webFrame.registerURLSchemeAsPrivileged', function () {
it('supports fetch api by default', function (done) {
var url = 'file://' + fixtures + '/assets/logo.png'
const url = 'file://' + fixtures + '/assets/logo.png'
window.fetch(url).then(function (response) {
assert(response.ok)
done()
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('webFrame module', function () {
</html>`, done)
})

var runNumber = 1
let runNumber = 1
function allowsCORSRequests (expected, content, done) {
const standardScheme = remote.getGlobal('standardScheme') + runNumber
const corsScheme = 'cors' + runNumber
Expand Down
Loading

0 comments on commit c61db52

Please sign in to comment.