diff --git a/lib/_debugger.js b/lib/_debugger.js index e1f0f812a5d2b5..2bab958418e941 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -26,8 +26,8 @@ exports.start = function(argv, stdin, stdout) { stdin = stdin || process.stdin; stdout = stdout || process.stdout; - var args = ['--debug-brk'].concat(argv), - interface_ = new Interface(stdin, stdout, args); + const args = ['--debug-brk'].concat(argv); + const interface_ = new Interface(stdin, stdout, args); stdin.resume(); @@ -198,8 +198,8 @@ Client.prototype._removeScript = function(desc) { Client.prototype._onResponse = function(res) { - var cb, - index = -1; + var cb; + var index = -1; this._reqCallbacks.some(function(fn, i) { if (fn.request_seq == res.body.request_seq) { @@ -296,11 +296,11 @@ Client.prototype.reqLookup = function(refs, cb) { }; Client.prototype.reqScopes = function(cb) { - var self = this, - req = { - command: 'scopes', - arguments: {} - }; + const self = this; + const req = { + command: 'scopes', + arguments: {} + }; cb = cb || function() {}; this.req(req, function(err, res) { @@ -526,8 +526,8 @@ Client.prototype.mirrorObject = function(handle, depth, cb) { return; } - var mirror, - waiting = 1; + var mirror; + var waiting = 1; if (handle.className == 'Array') { mirror = []; @@ -678,8 +678,8 @@ var helpMessage = 'Commands: ' + commands.map(function(group) { function SourceUnderline(sourceText, position, repl) { if (!sourceText) return ''; - var head = sourceText.slice(0, position), - tail = sourceText.slice(position); + const head = sourceText.slice(0, position); + var tail = sourceText.slice(position); // Colourize char if stdout supports colours if (repl.useColors) { @@ -699,8 +699,8 @@ function SourceInfo(body) { if (body.script) { if (body.script.name) { - var name = body.script.name, - dir = path.resolve() + '/'; + var name = body.script.name; + const dir = path.resolve() + '/'; // Change path to relative, if possible if (name.indexOf(dir) === 0) { @@ -977,8 +977,8 @@ Interface.prototype.controlEval = function(code, context, filename, callback) { Interface.prototype.debugEval = function(code, context, filename, callback) { if (!this.requireConnection()) return; - var self = this, - client = this.client; + const self = this; + const client = this.client; // Repl asked for scope variables if (code === '.scope') { @@ -1012,9 +1012,9 @@ Interface.prototype.debugEval = function(code, context, filename, callback) { // Adds spaces and prefix to number // maxN is a maximum number we should have space for function leftPad(n, prefix, maxN) { - var s = n.toString(), - nchars = Math.max(2, String(maxN).length) + 1, - nspaces = nchars - s.length - 1; + const s = n.toString(); + const nchars = Math.max(2, String(maxN).length) + 1; + const nspaces = nchars - s.length - 1; for (var i = 0; i < nspaces; i++) { prefix += ' '; @@ -1086,10 +1086,10 @@ Interface.prototype.list = function(delta) { delta || (delta = 5); - var self = this, - client = this.client, - from = client.currentSourceLine - delta + 1, - to = client.currentSourceLine + delta + 1; + const self = this; + const client = this.client; + const from = client.currentSourceLine - delta + 1; + const to = client.currentSourceLine + delta + 1; self.pause(); client.reqSource(from, to, function(err, res) { @@ -1104,12 +1104,12 @@ Interface.prototype.list = function(delta) { var lineno = res.fromLine + i + 1; if (lineno < from || lineno > to) continue; - var current = lineno == 1 + client.currentSourceLine, - breakpoint = client.breakpoints.some(function(bp) { - return (bp.scriptReq === client.currentScript || - bp.script === client.currentScript) && - bp.line == lineno; - }); + const current = lineno == 1 + client.currentSourceLine; + const breakpoint = client.breakpoints.some(function(bp) { + return (bp.scriptReq === client.currentScript || + bp.script === client.currentScript) && + bp.line == lineno; + }); if (lineno == 1) { // The first line needs to have the module wrapper filtered out of @@ -1147,8 +1147,8 @@ Interface.prototype.list = function(delta) { Interface.prototype.backtrace = function() { if (!this.requireConnection()) return; - var self = this, - client = this.client; + const self = this; + const client = this.client; self.pause(); client.fullTrace(function(err, bt) { @@ -1161,8 +1161,8 @@ Interface.prototype.backtrace = function() { if (bt.totalFrames == 0) { self.print('(empty stack)'); } else { - var trace = [], - firstFrameNative = bt.frames[0].script.isNative; + const trace = []; + const firstFrameNative = bt.frames[0].script.isNative; for (var i = 0; i < bt.frames.length; i++) { var frame = bt.frames[i]; @@ -1191,9 +1191,9 @@ Interface.prototype.backtrace = function() { Interface.prototype.scripts = function() { if (!this.requireConnection()) return; - var client = this.client, - displayNatives = arguments[0] || false, - scripts = []; + const client = this.client; + const displayNatives = arguments[0] || false; + const scripts = []; this.pause(); for (var id in client.scripts) { @@ -1331,9 +1331,9 @@ Interface.prototype.setBreakpoint = function(script, line, condition, silent) { if (!this.requireConnection()) return; - var self = this, - scriptId, - ambiguous; + const self = this; + var scriptId; + var ambiguous; // setBreakpoint() should insert breakpoint on current line if (script === undefined) { @@ -1437,10 +1437,10 @@ Interface.prototype.setBreakpoint = function(script, line, Interface.prototype.clearBreakpoint = function(script, line) { if (!this.requireConnection()) return; - var ambiguous, - breakpoint, - scriptId, - index; + var ambiguous; + var breakpoint; + var scriptId; + var index; this.client.breakpoints.some(function(bp, i) { if (bp.scriptId === script || @@ -1482,10 +1482,8 @@ Interface.prototype.clearBreakpoint = function(script, line) { return this.error('Breakpoint not found on line ' + line); } - var self = this, - req = { - breakpoint: breakpoint - }; + var self = this; + const req = {breakpoint}; self.pause(); self.client.clearBreakpoint(req, function(err, res) { @@ -1521,8 +1519,8 @@ Interface.prototype.breakpoints = function() { Interface.prototype.pause_ = function() { if (!this.requireConnection()) return; - var self = this, - cmd = 'process._debugPause();'; + const self = this; + const cmd = 'process._debugPause();'; this.pause(); this.client.reqFrameEval(cmd, NO_FRAME, function(err, res) { @@ -1643,11 +1641,11 @@ Interface.prototype.killChild = function() { // Spawns child process (and restores breakpoints) Interface.prototype.trySpawn = function(cb) { - var self = this, - breakpoints = this.breakpoints || [], - port = exports.port, - host = '127.0.0.1', - childArgs = this.args; + const self = this; + const breakpoints = this.breakpoints || []; + var port = exports.port; + var host = '127.0.0.1'; + var childArgs = this.args; this.killChild(); assert(!this.child); @@ -1698,8 +1696,8 @@ Interface.prototype.trySpawn = function(cb) { this.pause(); - var client = self.client = new Client(), - connectionAttempts = 0; + const client = self.client = new Client(); + var connectionAttempts = 0; client.once('ready', function() { self.stdout.write(' ok\n'); diff --git a/lib/_http_server.js b/lib/_http_server.js index 7527bffe7fa07d..2872b6fb3a831f 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -63,7 +63,7 @@ const STATUS_CODES = exports.STATUS_CODES = { 426 : 'Upgrade Required', // RFC 2817 428 : 'Precondition Required', // RFC 6585 429 : 'Too Many Requests', // RFC 6585 - 431 : 'Request Header Fields Too Large',// RFC 6585 + 431 : 'Request Header Fields Too Large', // RFC 6585 451 : 'Unavailable For Legal Reasons', 500 : 'Internal Server Error', 501 : 'Not Implemented', diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js index c6497f959ecd3c..42b7f283bc7d87 100644 --- a/lib/_tls_legacy.js +++ b/lib/_tls_legacy.js @@ -224,9 +224,9 @@ CryptoStream.prototype._write = function write(data, encoding, cb) { CryptoStream.prototype._writePending = function writePending() { - var data = this._pending, - encoding = this._pendingEncoding, - cb = this._pendingCallback; + const data = this._pending; + const encoding = this._pendingEncoding; + const cb = this._pendingCallback; this._pending = null; this._pendingEncoding = ''; @@ -252,9 +252,9 @@ CryptoStream.prototype._read = function read(size) { out = this.pair.ssl.encOut; } - var bytesRead = 0, - start = this._buffer.offset, - last = start; + var bytesRead = 0; + const start = this._buffer.offset; + var last = start; do { assert(last === this._buffer.offset); var read = this._buffer.use(this.pair.ssl, out, size - bytesRead); @@ -604,8 +604,8 @@ function onhandshakedone() { function onclienthello(hello) { - var self = this, - once = false; + const self = this; + var once = false; this._resumingSession = true; function callback(err, session) { diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index d3df48a4c59fc7..dd293121cbc782 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -383,8 +383,8 @@ TLSSocket.prototype._init = function(socket, wrap) { // For clients, we will always have either a given ca list or be using // default one - var requestCert = !!options.requestCert || !options.isServer, - rejectUnauthorized = !!options.rejectUnauthorized; + const requestCert = !!options.requestCert || !options.isServer; + const rejectUnauthorized = !!options.rejectUnauthorized; this._requestCert = requestCert; this._rejectUnauthorized = rejectUnauthorized; @@ -486,8 +486,8 @@ TLSSocket.prototype._init = function(socket, wrap) { }; TLSSocket.prototype.renegotiate = function(options, callback) { - var requestCert = this._requestCert, - rejectUnauthorized = this._rejectUnauthorized; + var requestCert = this._requestCert; + var rejectUnauthorized = this._rejectUnauthorized; if (this.destroyed) return; @@ -981,10 +981,10 @@ exports.connect = function(/* [port, host], options, cb */) { var hostname = options.servername || options.host || (options.socket && options.socket._host) || - 'localhost', - NPN = {}, - ALPN = {}, - context = options.secureContext || tls.createSecureContext(options); + 'localhost'; + const NPN = {}; + const ALPN = {}; + const context = options.secureContext || tls.createSecureContext(options); tls.convertNPNProtocols(options.NPNProtocols, NPN); tls.convertALPNProtocols(options.ALPNProtocols, ALPN); diff --git a/lib/assert.js b/lib/assert.js index 4a1406cfca261f..737b819cb1e774 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -198,8 +198,8 @@ function objEquiv(a, b, strict) { return a === b; if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false; - var aIsArgs = isArguments(a), - bIsArgs = isArguments(b); + const aIsArgs = isArguments(a); + const bIsArgs = isArguments(b); if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) return false; if (aIsArgs) { @@ -207,9 +207,9 @@ function objEquiv(a, b, strict) { b = pSlice.call(b); return _deepEqual(a, b, strict); } - var ka = Object.keys(a), - kb = Object.keys(b), - key, i; + const ka = Object.keys(a); + const kb = Object.keys(b); + var key, i; // having the same number of owned properties (keys incorporates // hasOwnProperty) if (ka.length !== kb.length) diff --git a/lib/fs.js b/lib/fs.js index 6f7a3cf2513bd8..d390335df8c72c 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -587,8 +587,8 @@ fs.openSync = function(path, flags, mode) { fs.read = function(fd, buffer, offset, length, position, callback) { if (!(buffer instanceof Buffer)) { // legacy string interface (fd, length, position, encoding, callback) - var cb = arguments[4], - encoding = arguments[3]; + const cb = arguments[4]; + const encoding = arguments[3]; assertEncoding(encoding); @@ -1481,9 +1481,9 @@ fs.realpathSync = function realpathSync(p, cache) { return cache[p]; } - var original = p, - seenLinks = {}, - knownHard = {}; + const original = p; + const seenLinks = {}; + const knownHard = {}; // current character position in p var pos; @@ -1583,9 +1583,9 @@ fs.realpath = function realpath(p, cache, cb) { return process.nextTick(cb.bind(null, null, cache[p])); } - var original = p, - seenLinks = {}, - knownHard = {}; + const original = p; + const seenLinks = {}; + const knownHard = {}; // current character position in p var pos; @@ -2043,9 +2043,9 @@ util.inherits(SyncWriteStream, Stream); // Export Object.defineProperty(fs, 'SyncWriteStream', { - configurable: true, - writable: true, - value: SyncWriteStream + configurable: true, + writable: true, + value: SyncWriteStream }); SyncWriteStream.prototype.write = function(data, arg1, arg2) { diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 8757a78f05e885..13c4cc642d4105 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -250,11 +250,11 @@ function getHandleWrapType(stream) { ChildProcess.prototype.spawn = function(options) { - var self = this, - ipc, - ipcFd, - // If no `stdio` option was given - use default - stdio = options.stdio || 'pipe'; + const self = this; + var ipc; + var ipcFd; + // If no `stdio` option was given - use default + var stdio = options.stdio || 'pipe'; stdio = _validateStdio(stdio, false); @@ -692,8 +692,8 @@ function handleMessage(target, message, handle) { function nop() { } function _validateStdio(stdio, sync) { - var ipc, - ipcFd; + var ipc; + var ipcFd; // Replace shortcut with an array if (typeof stdio === 'string') { diff --git a/lib/net.js b/lib/net.js index 0ac7d9c7f662af..0e7bb02bb57dff 100644 --- a/lib/net.js +++ b/lib/net.js @@ -722,10 +722,10 @@ function createWriteReq(req, handle, data, encoding) { Socket.prototype.__defineGetter__('bytesWritten', function() { - var bytes = this._bytesDispatched, - state = this._writableState, - data = this._pendingData, - encoding = this._pendingEncoding; + var bytes = this._bytesDispatched; + const state = this._writableState; + const data = this._pendingData; + const encoding = this._pendingEncoding; if (!state) return undefined; @@ -1133,8 +1133,7 @@ function _listen(handle, backlog) { return handle.listen(backlog || 511); } -var createServerHandle = exports._createServerHandle = - function(address, port, addressType, fd) { +function createServerHandle(address, port, addressType, fd) { var err = 0; // assign handle in listen, and clean up if bind or listen fails var handle; @@ -1190,6 +1189,7 @@ var createServerHandle = exports._createServerHandle = return handle; }; +exports._createServerHandle = createServerHandle; Server.prototype._listen2 = function(address, port, addressType, backlog, fd) { @@ -1446,8 +1446,8 @@ Server.prototype.getConnections = function(cb) { } // Poll slaves - var left = this._slaves.length, - total = this._connections; + var left = this._slaves.length; + var total = this._connections; function oncount(err, count) { if (err) { @@ -1489,8 +1489,8 @@ Server.prototype.close = function(cb) { } if (this._usingSlaves) { - var self = this, - left = this._slaves.length; + var self = this; + var left = this._slaves.length; // Increment connections to be sure that, even if all sockets will be closed // during polling of slaves, `close` event will be emitted only once. diff --git a/lib/path.js b/lib/path.js index 0a2c0d6bceb0ec..66a3fa448f30eb 100644 --- a/lib/path.js +++ b/lib/path.js @@ -74,21 +74,21 @@ var win32 = {}; // Function to split a filename into [root, dir, basename, ext] function win32SplitPath(filename) { // Separate device+slash from tail - var result = splitDeviceRe.exec(filename), - device = (result[1] || '') + (result[2] || ''), - tail = result[3]; + const result = splitDeviceRe.exec(filename); + const device = (result[1] || '') + (result[2] || ''); + const tail = result[3]; // Split the tail into dir, basename and extension - var result2 = splitTailRe.exec(tail), - dir = result2[1], - basename = result2[2], - ext = result2[3]; + const result2 = splitTailRe.exec(tail); + const dir = result2[1]; + const basename = result2[2]; + const ext = result2[3]; return [device, dir, basename, ext]; } function win32StatPath(path) { - var result = splitDeviceRe.exec(path), - device = result[1] || '', - isUnc = !!device && device[1] !== ':'; + const result = splitDeviceRe.exec(path); + const device = result[1] || ''; + const isUnc = !!device && device[1] !== ':'; return { device, isUnc, @@ -103,9 +103,9 @@ function normalizeUNCRoot(device) { // path.resolve([from ...], to) win32.resolve = function() { - var resolvedDevice = '', - resolvedTail = '', - resolvedAbsolute = false; + var resolvedDevice = ''; + var resolvedTail = ''; + var resolvedAbsolute = false; for (var i = arguments.length - 1; i >= -1; i--) { var path; @@ -134,11 +134,11 @@ win32.resolve = function() { continue; } - var result = win32StatPath(path), - device = result.device, - isUnc = result.isUnc, - isAbsolute = result.isAbsolute, - tail = result.tail; + const result = win32StatPath(path); + const device = result.device; + var isUnc = result.isUnc; + const isAbsolute = result.isAbsolute; + const tail = result.tail; if (device && resolvedDevice && @@ -182,12 +182,12 @@ win32.resolve = function() { win32.normalize = function(path) { assertPath(path); - var result = win32StatPath(path), - device = result.device, - isUnc = result.isUnc, - isAbsolute = result.isAbsolute, - tail = result.tail, - trailingSlash = /[\\\/]$/.test(tail); + const result = win32StatPath(path); + var device = result.device; + const isUnc = result.isUnc; + const isAbsolute = result.isAbsolute; + var tail = result.tail; + const trailingSlash = /[\\\/]$/.test(tail); // Normalize the tail path tail = normalizeArray(tail.split(/[\\\/]+/), !isAbsolute).join('\\'); @@ -318,9 +318,9 @@ win32._makeLong = function(path) { win32.dirname = function(path) { - var result = win32SplitPath(path), - root = result[0], - dir = result[1]; + const result = win32SplitPath(path); + const root = result[0]; + var dir = result[1]; if (!root && !dir) { // No dirname whatsoever @@ -409,8 +409,8 @@ function posixSplitPath(filename) { // path.resolve([from ...], to) // posix version posix.resolve = function() { - var resolvedPath = '', - resolvedAbsolute = false; + var resolvedPath = ''; + var resolvedAbsolute = false; for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { var path = (i >= 0) ? arguments[i] : process.cwd(); @@ -441,8 +441,8 @@ posix.resolve = function() { posix.normalize = function(path) { assertPath(path); - var isAbsolute = posix.isAbsolute(path), - trailingSlash = path && path[path.length - 1] === '/'; + const isAbsolute = posix.isAbsolute(path); + const trailingSlash = path && path[path.length - 1] === '/'; // Normalize the path path = normalizeArray(path.split('/'), !isAbsolute).join('/'); @@ -519,9 +519,9 @@ posix._makeLong = function(path) { posix.dirname = function(path) { - var result = posixSplitPath(path), - root = result[0], - dir = result[1]; + const result = posixSplitPath(path); + const root = result[0]; + var dir = result[1]; if (!root && !dir) { // No dirname whatsoever diff --git a/lib/querystring.js b/lib/querystring.js index 40677ffb0f0859..5f8df93038921f 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -230,9 +230,9 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { var keys = []; for (var i = 0; i < len; ++i) { - var x = qs[i].replace(regexp, '%20'), - idx = x.indexOf(eq), - k, v; + const x = qs[i].replace(regexp, '%20'); + const idx = x.indexOf(eq); + var k, v; if (idx >= 0) { k = decodeStr(x.substring(0, idx), decode); diff --git a/lib/readline.js b/lib/readline.js index adfb305fb0baa8..5bea6afb950ee0 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -384,8 +384,8 @@ Interface.prototype._tabComplete = function() { return; } - var completions = rv[0], - completeOn = rv[1]; // the text that was completed + const completions = rv[0]; + const completeOn = rv[1]; // the text that was completed if (completions && completions.length) { // Apply/show completions. if (completions.length === 1) { diff --git a/lib/tls.js b/lib/tls.js index 24062832a5b9d3..1abeb77873692b 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -105,12 +105,12 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { return new RegExp('^' + re + '$', 'i'); } - var dnsNames = [], - uriNames = [], - ips = [], - matchCN = true, - valid = false, - reason = 'Unknown reason'; + var dnsNames = []; + var uriNames = []; + const ips = []; + var matchCN = true; + var valid = false; + var reason = 'Unknown reason'; // There're several names to perform check against: // CN and altnames in certificate extension diff --git a/lib/url.js b/lib/url.js index 4de2fab3ff2dee..6b9019f5287d28 100644 --- a/lib/url.js +++ b/lib/url.js @@ -93,11 +93,11 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { // Copy chrome, IE, opera backslash-handling behavior. // Back slashes before the query string get converted to forward slashes // See: https://code.google.com/p/chromium/issues/detail?id=25916 - var queryIndex = url.indexOf('?'), - splitter = - (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#', - uSplit = url.split(splitter), - slashRegex = /\\/g; + const queryIndex = url.indexOf('?'); + const splitter = + (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#'; + const uSplit = url.split(splitter); + const slashRegex = /\\/g; uSplit[0] = uSplit[0].replace(slashRegex, '/'); url = uSplit.join(splitter); @@ -370,11 +370,11 @@ Url.prototype.format = function() { auth += '@'; } - var protocol = this.protocol || '', - pathname = this.pathname || '', - hash = this.hash || '', - host = false, - query = ''; + var protocol = this.protocol || ''; + var pathname = this.pathname || ''; + var hash = this.hash || ''; + var host = false; + var query = ''; if (this.host) { host = auth + this.host; @@ -525,17 +525,17 @@ Url.prototype.resolveObject = function(relative) { return result; } - var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), - isRelAbs = ( - relative.host || - relative.pathname && relative.pathname.charAt(0) === '/' - ), - mustEndAbs = (isRelAbs || isSourceAbs || - (result.host && relative.pathname)), - removeAllDots = mustEndAbs, - srcPath = result.pathname && result.pathname.split('/') || [], - relPath = relative.pathname && relative.pathname.split('/') || [], - psychotic = result.protocol && !slashedProtocol[result.protocol]; + const isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'); + const isRelAbs = ( + relative.host || + relative.pathname && relative.pathname.charAt(0) === '/' + ); + var mustEndAbs = (isRelAbs || isSourceAbs || + (result.host && relative.pathname)); + const removeAllDots = mustEndAbs; + var srcPath = result.pathname && result.pathname.split('/') || []; + var relPath = relative.pathname && relative.pathname.split('/') || []; + const psychotic = result.protocol && !slashedProtocol[result.protocol]; // if the url is a non-slashed url, then relative // links like ../.. should be able