From 6ff34a5c2a775c6ebb73890cfc6a8a54e1af48f6 Mon Sep 17 00:00:00 2001 From: jens-cappelle Date: Tue, 12 Nov 2019 16:03:30 +0100 Subject: [PATCH] lib: replace var with let/const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/30391 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: Gireesh Punathil Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- lib/events.js | 22 +++++++++++----------- lib/internal/process/task_queues.js | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/events.js b/lib/events.js index f3fa65153ce2be..a5f978d731b5bf 100644 --- a/lib/events.js +++ b/lib/events.js @@ -37,7 +37,7 @@ const { } } = primordials; -var spliceOne; +let spliceOne; const { kEnhanceStackBeforeInspector, @@ -70,7 +70,7 @@ EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are // added to it. This is a useful default which helps finding memory leaks. -var defaultMaxListeners = 10; +let defaultMaxListeners = 10; function checkListener(listener) { if (typeof listener !== 'function') { @@ -127,7 +127,7 @@ EventEmitter.prototype.getMaxListeners = function getMaxListeners() { // Returns the length and line number of the first sequence of `a` that fully // appears in `b` with a length of at least 4. function identicalSequenceRange(a, b) { - for (var i = 0; i < a.length - 3; i++) { + for (let i = 0; i < a.length - 3; i++) { // Find the first entry of b that matches the current entry of a. const pos = b.indexOf(a[i]); if (pos !== -1) { @@ -224,7 +224,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) { } else { const len = handler.length; const listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) + for (let i = 0; i < len; ++i) ReflectApply(listeners[i], this, args); } @@ -232,9 +232,9 @@ EventEmitter.prototype.emit = function emit(type, ...args) { }; function _addListener(target, type, listener, prepend) { - var m; - var events; - var existing; + let m; + let events; + let existing; checkListener(listener); @@ -363,7 +363,7 @@ EventEmitter.prototype.removeListener = } else if (typeof list !== 'function') { let position = -1; - for (var i = list.length - 1; i >= 0; i--) { + for (let i = list.length - 1; i >= 0; i--) { if (list[i] === listener || list[i].listener === listener) { originalListener = list[i].listener; position = i; @@ -432,7 +432,7 @@ EventEmitter.prototype.removeAllListeners = this.removeListener(type, listeners); } else if (listeners !== undefined) { // LIFO order - for (var i = listeners.length - 1; i >= 0; i--) { + for (let i = listeners.length - 1; i >= 0; i--) { this.removeListener(type, listeners[i]); } } @@ -496,14 +496,14 @@ EventEmitter.prototype.eventNames = function eventNames() { function arrayClone(arr, n) { const copy = new Array(n); - for (var i = 0; i < n; ++i) + for (let i = 0; i < n; ++i) copy[i] = arr[i]; return copy; } function unwrapListeners(arr) { const ret = new Array(arr.length); - for (var i = 0; i < ret.length; ++i) { + for (let i = 0; i < ret.length; ++i) { ret[i] = arr[i].listener || arr[i]; } return ret; diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index 8906b4aa1e2426..35578e54bb937c 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -105,7 +105,7 @@ function nextTick(callback) { if (process._exiting) return; - var args; + let args; switch (arguments.length) { case 1: break; case 2: args = [arguments[1]]; break; @@ -113,7 +113,7 @@ function nextTick(callback) { case 4: args = [arguments[1], arguments[2], arguments[3]]; break; default: args = new Array(arguments.length - 1); - for (var i = 1; i < arguments.length; i++) + for (let i = 1; i < arguments.length; i++) args[i - 1] = arguments[i]; }