Skip to content

Commit

Permalink
Convert var's to let's
Browse files Browse the repository at this point in the history
This patch:
- converts all var's to let's throughout the codebase
- enforces the let's over var's via the eslint rule
  • Loading branch information
aslushnikov committed Jun 22, 2017
1 parent 78e8799 commit 819fa35
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 345 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
"arrow-parens": [2, "as-needed"],

// anti-patterns
"no-var": 2,
"no-with": 2,
"no-multi-str": 2,
"no-caller": 2,
Expand Down Expand Up @@ -99,13 +100,11 @@ module.exports = {
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"linebreak-style": [ 2, "unix" ],
"indent": [2, 2, { "SwitchCase": 1, "CallExpression": {"arguments": 2}, "MemberExpression": 2 }],

/**
* Disabled, aspirational rules
*/

"indent": [2, 2, { "SwitchCase": 1, "CallExpression": {"arguments": 2}, "MemberExpression": 2 }],

// brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions
"brace-style": [0, "allman", { "allowSingleLine": true }],

Expand Down
10 changes: 5 additions & 5 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

var Downloader = require('./utils/ChromiumDownloader');
var revision = require('./package').puppeteer.chromium_revision;
var ProgressBar = require('progress');
let Downloader = require('./utils/ChromiumDownloader');
let revision = require('./package').puppeteer.chromium_revision;
let ProgressBar = require('progress');

// Do nothing if the revision is already downloaded.
if (Downloader.revisionInfo(Downloader.currentPlatform(), revision))
Expand All @@ -27,7 +27,7 @@ Downloader.downloadRevision(Downloader.currentPlatform(), revision, onProgress)
console.error('Download failed: ' + error.message);
});

var progressBar = null;
let progressBar = null;
function onProgress(bytesTotal, delta) {
if (!progressBar) {
progressBar = new ProgressBar(`Downloading Chromium - ${toMegabytes(bytesTotal)} [:bar] :percent :etas `, {
Expand All @@ -41,7 +41,7 @@ function onProgress(bytesTotal, delta) {
}

function toMegabytes(bytes) {
var mb = bytes / 1024 / 1024;
let mb = bytes / 1024 / 1024;
return (Math.round(mb * 10) / 10) + ' Mb';
}

42 changes: 21 additions & 21 deletions lib/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
* limitations under the License.
*/

var http = require('http');
var path = require('path');
var removeRecursive = require('rimraf').sync;
var Page = require('./Page');
var childProcess = require('child_process');
var Downloader = require('../utils/ChromiumDownloader');
var Connection = require('./Connection');
let http = require('http');
let path = require('path');
let removeRecursive = require('rimraf').sync;
let Page = require('./Page');
let childProcess = require('child_process');
let Downloader = require('../utils/ChromiumDownloader');
let Connection = require('./Connection');

var CHROME_PROFILE_PATH = path.resolve(__dirname, '..', '.dev_profile');
var browserId = 0;
let CHROME_PROFILE_PATH = path.resolve(__dirname, '..', '.dev_profile');
let browserId = 0;

var DEFAULT_ARGS = [
let DEFAULT_ARGS = [
'--disable-background-timer-throttling',
'--no-first-run',
];
Expand Down Expand Up @@ -54,8 +54,8 @@ class Browser {
if (typeof options.executablePath === 'string') {
this._chromeExecutable = options.executablePath;
} else {
var chromiumRevision = require('../package.json').puppeteer.chromium_revision;
var revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), chromiumRevision);
let chromiumRevision = require('../package.json').puppeteer.chromium_revision;
let revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), chromiumRevision);
console.assert(revisionInfo, 'Chromium revision is not downloaded. Run npm install');
this._chromeExecutable = revisionInfo.executablePath;
}
Expand All @@ -72,8 +72,8 @@ class Browser {
await this._ensureChromeIsRunning();
if (!this._chromeProcess || this._terminated)
throw new Error('ERROR: this chrome instance is not alive any more!');
var client = await Connection.create(this._remoteDebuggingPort);
var page = await Page.create(client);
let client = await Connection.create(this._remoteDebuggingPort);
let page = await Page.create(client);
return page;
}

Expand All @@ -91,15 +91,15 @@ class Browser {
*/
async version() {
await this._ensureChromeIsRunning();
var version = await Connection.version(this._remoteDebuggingPort);
let version = await Connection.version(this._remoteDebuggingPort);
return version.Browser;
}

async _ensureChromeIsRunning() {
if (this._chromeProcess)
return;
this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {});
var stderr = '';
let stderr = '';
this._chromeProcess.stderr.on('data', data => stderr += data.toString('utf8'));
// Cleanup as processes exit.
process.on('exit', () => this._chromeProcess.kill());
Expand All @@ -123,20 +123,20 @@ class Browser {
module.exports = Browser;

function waitForChromeResponsive(remoteDebuggingPort, shouldWaitCallback) {
var fulfill;
var promise = new Promise(x => fulfill = x);
var options = {
let fulfill;
let promise = new Promise(x => fulfill = x);
let options = {
method: 'GET',
host: 'localhost',
port: remoteDebuggingPort,
path: '/json/list'
};
var probeTimeout = 100;
let probeTimeout = 100;
sendRequest();
return promise;

function sendRequest() {
var req = http.request(options, res => {
let req = http.request(options, res => {
fulfill();
});
req.on('error', e => {
Expand Down
26 changes: 13 additions & 13 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

var EventEmitter = require('events');
var WebSocket = require('ws');
var http = require('http');
let EventEmitter = require('events');
let WebSocket = require('ws');
let http = require('http');
const COMMAND_TIMEOUT = 10000;

class Connection extends EventEmitter {
Expand Down Expand Up @@ -44,8 +44,8 @@ class Connection extends EventEmitter {
* @return {!Promise<?Object>}
*/
send(method, params = {}) {
var id = ++this._lastId;
var message = JSON.stringify({id, method, params});
let id = ++this._lastId;
let message = JSON.stringify({id, method, params});
this._ws.send(message);
return new Promise((resolve, reject) => {
this._callbacks.set(id, {resolve, reject, method});
Expand All @@ -56,9 +56,9 @@ class Connection extends EventEmitter {
* @param {string} message
*/
_onMessage(message) {
var object = JSON.parse(message);
let object = JSON.parse(message);
if (object.id && this._callbacks.has(object.id)) {
var callback = this._callbacks.get(object.id);
let callback = this._callbacks.get(object.id);
this._callbacks.delete(object.id);
if (object.error)
callback.reject(new Error(`Protocol error (${callback.method}): ${object.error.message}`));
Expand Down Expand Up @@ -87,11 +87,11 @@ class Connection extends EventEmitter {
* @return {!Promise<!Connection>}
*/
static async create(port) {
var newTab = await runJsonCommand(port, 'new');
var url = newTab.webSocketDebuggerUrl;
let newTab = await runJsonCommand(port, 'new');
let url = newTab.webSocketDebuggerUrl;

return new Promise((resolve, reject) => {
var ws = new WebSocket(url, { perMessageDeflate: false });
let ws = new WebSocket(url, { perMessageDeflate: false });
ws.on('open', () => resolve(new Connection(port, newTab.id, ws)));
ws.on('error', reject);
});
Expand All @@ -112,17 +112,17 @@ class Connection extends EventEmitter {
* @return {!Promise<!Object>}
*/
function runJsonCommand(port, command) {
var request = http.get({
let request = http.get({
hostname: 'localhost',
port: port,
path: '/json/' + command
}, onResponse);
request.setTimeout(COMMAND_TIMEOUT, onTimeout);
var resolve, reject;
let resolve, reject;
return new Promise((res, rej) => { resolve = res; reject = rej; });

function onResponse(response) {
var data = '';
let data = '';
response.on('data', chunk => data += chunk);
response.on('end', () => {
if (response.statusCode !== 200) {
Expand Down
22 changes: 11 additions & 11 deletions lib/FrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

var EventEmitter = require('events');
let EventEmitter = require('events');

class FrameManager extends EventEmitter {
/**
* @param {!Connection} client
* @return {!FrameManager}
*/
static async create(client) {
var mainFramePayload = await client.send('Page.getResourceTree');
let mainFramePayload = await client.send('Page.getResourceTree');
return new FrameManager(client, mainFramePayload.frameTree);
}

Expand Down Expand Up @@ -70,8 +70,8 @@ class FrameManager extends EventEmitter {
this._navigateFrame(this._mainFrame, frameId, null);
return;
}
var parentFrame = this._frames.get(parentFrameId);
var frame = new Frame(parentFrame, frameId, null);
let parentFrame = this._frames.get(parentFrameId);
let frame = new Frame(parentFrame, frameId, null);
this._frames.set(frame._id, frame);
this.emit(FrameManager.Events.FrameAttached, frame);
}
Expand All @@ -80,7 +80,7 @@ class FrameManager extends EventEmitter {
* @param {!Object} framePayload
*/
_frameNavigated(framePayload) {
var frame = this._frames.get(framePayload.id);
let frame = this._frames.get(framePayload.id);
if (!frame) {
// Simulate missed "frameAttached" for a main frame navigation to the new backend process.
console.assert(!framePayload.parentId, 'Main frame shouldn\'t have parent frame id.');
Expand All @@ -93,7 +93,7 @@ class FrameManager extends EventEmitter {
* @param {string} frameId
*/
_frameDetached(frameId) {
var frame = this._frames.get(frameId);
let frame = this._frames.get(frameId);
if (frame)
this._removeFramesRecursively(frame);
}
Expand All @@ -105,7 +105,7 @@ class FrameManager extends EventEmitter {
*/
_navigateFrame(frame, newFrameId, newFramePayload) {
// Detach all child frames first.
for (var child of frame.childFrames())
for (let child of frame.childFrames())
this._removeFramesRecursively(child);
this._frames.delete(frame._id, frame);
frame._id = newFrameId;
Expand All @@ -120,11 +120,11 @@ class FrameManager extends EventEmitter {
* @return {!Frame}
*/
_addFramesRecursively(parentFrame, frameTreePayload) {
var framePayload = frameTreePayload.frame;
var frame = new Frame(parentFrame, framePayload.id, framePayload);
let framePayload = frameTreePayload.frame;
let frame = new Frame(parentFrame, framePayload.id, framePayload);
this._frames.set(frame._id, frame);

for (var i = 0; frameTreePayload.childFrames && i < frameTreePayload.childFrames.length; ++i)
for (let i = 0; frameTreePayload.childFrames && i < frameTreePayload.childFrames.length; ++i)
this._addFramesRecursively(frame, frameTreePayload.childFrames[i]);
return frame;
}
Expand All @@ -133,7 +133,7 @@ class FrameManager extends EventEmitter {
* @param {!Frame} frame
*/
_removeFramesRecursively(frame) {
for (var child of frame.childFrames())
for (let child of frame.childFrames())
this._removeFramesRecursively(child);
frame._detach();
this._frames.delete(frame._id);
Expand Down
2 changes: 1 addition & 1 deletion lib/Navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Navigator {
this._minimumTimer = setTimeout(this._completeNavigation.bind(this, false), this._minTime);
let onload = new Promise(fulfill => this._client.once('Page.loadEventFired', fulfill));
let networkIdle = new Promise(fulfill => this._navigationLoadCallback = fulfill);
var interstitialPromise = new Promise(fulfill => this._client.once('Security.certificateError', fulfill)).then(() => false);
let interstitialPromise = new Promise(fulfill => this._client.once('Security.certificateError', fulfill)).then(() => false);

this._inflightRequests = 0;
// Await for the command to throw exception in case of illegal arguments.
Expand Down
Loading

0 comments on commit 819fa35

Please sign in to comment.