From cd0982ae7c90c2b26dd017f008a135771ea4920c Mon Sep 17 00:00:00 2001 From: himself65 Date: Mon, 2 Mar 2020 15:29:50 +0800 Subject: [PATCH] lib: change var to let/const PR-URL: https://github.com/nodejs/node/pull/32037 Reviewed-By: Michael Dawson Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- lib/_stream_writable.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index b1dca886bcffe0..c8dbeeaddde8c0 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -187,7 +187,7 @@ function WritableState(options, stream, isDuplex) { } WritableState.prototype.getBuffer = function getBuffer() { - var current = this.bufferedRequest; + let current = this.bufferedRequest; const out = []; while (current) { out.push(current); @@ -205,7 +205,7 @@ ObjectDefineProperty(WritableState.prototype, 'buffer', { // Test _writableState for inheritance to account for Duplex streams, // whose prototype chain only points to Readable. -var realHasInstance; +let realHasInstance; if (typeof Symbol === 'function' && SymbolHasInstance) { realHasInstance = FunctionPrototype[SymbolHasInstance]; ObjectDefineProperty(Writable, SymbolHasInstance, { @@ -357,7 +357,7 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) { state.needDrain = true; if (state.writing || state.corked || state.errored) { - var last = state.lastBufferedRequest; + const last = state.lastBufferedRequest; state.lastBufferedRequest = { chunk, encoding, @@ -428,7 +428,7 @@ function onwrite(stream, er) { } } else { // Check if we're actually ready to finish, but don't emit yet - var finished = needFinish(state) || stream.destroyed; + const finished = needFinish(state) || stream.destroyed; if (!finished && !state.corked && @@ -499,17 +499,17 @@ function errorBuffer(state, err) { // If there's something in the buffer waiting, then process it function clearBuffer(stream, state) { state.bufferProcessing = true; - var entry = state.bufferedRequest; + let entry = state.bufferedRequest; if (stream._writev && entry && entry.next) { // Fast case, write everything using _writev() - var l = state.bufferedRequestCount; - var buffer = new Array(l); - var holder = state.corkedRequestsFree; + const l = state.bufferedRequestCount; + const buffer = new Array(l); + const holder = state.corkedRequestsFree; holder.entry = entry; - var count = 0; - var allBuffers = true; + let count = 0; + let allBuffers = true; while (entry) { buffer[count] = entry; if (entry.encoding !== 'buffer') @@ -529,7 +529,7 @@ function clearBuffer(stream, state) { state.corkedRequestsFree = holder.next; holder.next = null; } else { - var corkReq = { next: null, entry: null, finish: undefined }; + const corkReq = { next: null, entry: null, finish: undefined }; corkReq.finish = onCorkedFinish.bind(undefined, corkReq, state); state.corkedRequestsFree = corkReq; } @@ -537,10 +537,10 @@ function clearBuffer(stream, state) { } else { // Slow case, write chunks one-by-one while (entry) { - var chunk = entry.chunk; - var encoding = entry.encoding; - var cb = entry.callback; - var len = state.objectMode ? 1 : chunk.length; + const chunk = entry.chunk; + const encoding = entry.encoding; + const cb = entry.callback; + const len = state.objectMode ? 1 : chunk.length; doWrite(stream, state, false, len, chunk, encoding, cb); entry = entry.next; @@ -677,10 +677,10 @@ function endWritable(stream, state, cb) { } function onCorkedFinish(corkReq, state, err) { - var entry = corkReq.entry; + let entry = corkReq.entry; corkReq.entry = null; while (entry) { - var cb = entry.callback; + const cb = entry.callback; state.pendingcb--; cb(err); entry = entry.next;