From 0d6918e01fffbd23dd55921f8294de5fd60cb7c0 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 22 Jun 2017 10:37:30 +0200 Subject: [PATCH] Convert classes loosely --- build/build.js | 2 +- lib/internal/streams/BufferList.js | 106 ++++++++++------------ test/parallel/test-stream-unpipe-event.js | 31 ++----- 3 files changed, 59 insertions(+), 80 deletions(-) diff --git a/build/build.js b/build/build.js index 44edf874ff..2e7a027fb5 100644 --- a/build/build.js +++ b/build/build.js @@ -64,7 +64,7 @@ function processFile (inputLoc, out, replacements) { 'transform-es2015-template-literals', 'transform-es2015-shorthand-properties', 'transform-es2015-for-of', - 'transform-es2015-classes', + ['transform-es2015-classes', { loose: true }], 'transform-es2015-destructuring', 'transform-es2015-computed-properties', 'transform-es2015-spread' diff --git a/lib/internal/streams/BufferList.js b/lib/internal/streams/BufferList.js index 8546bb06e4..d467615978 100644 --- a/lib/internal/streams/BufferList.js +++ b/lib/internal/streams/BufferList.js @@ -2,8 +2,6 @@ /**/ -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Buffer = require('safe-buffer').Buffer; @@ -22,63 +20,55 @@ module.exports = function () { this.length = 0; } - _createClass(BufferList, [{ - key: 'push', - value: function push(v) { - var entry = { data: v, next: null }; - if (this.length > 0) this.tail.next = entry;else this.head = entry; - this.tail = entry; - ++this.length; - } - }, { - key: 'unshift', - value: function unshift(v) { - var entry = { data: v, next: this.head }; - if (this.length === 0) this.tail = entry; - this.head = entry; - ++this.length; - } - }, { - key: 'shift', - value: function shift() { - if (this.length === 0) return; - var ret = this.head.data; - if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; - --this.length; - return ret; - } - }, { - key: 'clear', - value: function clear() { - this.head = this.tail = null; - this.length = 0; - } - }, { - key: 'join', - value: function join(s) { - if (this.length === 0) return ''; - var p = this.head; - var ret = '' + p.data; - while (p = p.next) { - ret += s + p.data; - }return ret; - } - }, { - key: 'concat', - value: function concat(n) { - if (this.length === 0) return Buffer.alloc(0); - if (this.length === 1) return this.head.data; - var ret = Buffer.allocUnsafe(n >>> 0); - var p = this.head; - var i = 0; - while (p) { - copyBuffer(p.data, ret, i); - i += p.data.length; - p = p.next; - } - return ret; + BufferList.prototype.push = function push(v) { + var entry = { data: v, next: null }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + }; + + BufferList.prototype.unshift = function unshift(v) { + var entry = { data: v, next: this.head }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + }; + + BufferList.prototype.shift = function shift() { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + }; + + BufferList.prototype.clear = function clear() { + this.head = this.tail = null; + this.length = 0; + }; + + BufferList.prototype.join = function join(s) { + if (this.length === 0) return ''; + var p = this.head; + var ret = '' + p.data; + while (p = p.next) { + ret += s + p.data; + }return ret; + }; + + BufferList.prototype.concat = function concat(n) { + if (this.length === 0) return Buffer.alloc(0); + if (this.length === 1) return this.head.data; + var ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + copyBuffer(p.data, ret, i); + i += p.data.length; + p = p.next; } - }]); + return ret; + }; return BufferList; }(); \ No newline at end of file diff --git a/test/parallel/test-stream-unpipe-event.js b/test/parallel/test-stream-unpipe-event.js index 3eb8b28591..2f7ef2567b 100644 --- a/test/parallel/test-stream-unpipe-event.js +++ b/test/parallel/test-stream-unpipe-event.js @@ -1,5 +1,3 @@ -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } @@ -25,15 +23,12 @@ var NullWriteable = function (_Writable) { function NullWriteable() { _classCallCheck(this, NullWriteable); - return _possibleConstructorReturn(this, (NullWriteable.__proto__ || Object.getPrototypeOf(NullWriteable)).apply(this, arguments)); + return _possibleConstructorReturn(this, _Writable.apply(this, arguments)); } - _createClass(NullWriteable, [{ - key: '_write', - value: function _write(chunk, encoding, callback) { - return callback(); - } - }]); + NullWriteable.prototype._write = function _write(chunk, encoding, callback) { + return callback(); + }; return NullWriteable; }(Writable); @@ -44,15 +39,12 @@ var QuickEndReadable = function (_Readable) { function QuickEndReadable() { _classCallCheck(this, QuickEndReadable); - return _possibleConstructorReturn(this, (QuickEndReadable.__proto__ || Object.getPrototypeOf(QuickEndReadable)).apply(this, arguments)); + return _possibleConstructorReturn(this, _Readable.apply(this, arguments)); } - _createClass(QuickEndReadable, [{ - key: '_read', - value: function _read() { - this.push(null); - } - }]); + QuickEndReadable.prototype._read = function _read() { + this.push(null); + }; return QuickEndReadable; }(Readable); @@ -63,13 +55,10 @@ var NeverEndReadable = function (_Readable2) { function NeverEndReadable() { _classCallCheck(this, NeverEndReadable); - return _possibleConstructorReturn(this, (NeverEndReadable.__proto__ || Object.getPrototypeOf(NeverEndReadable)).apply(this, arguments)); + return _possibleConstructorReturn(this, _Readable2.apply(this, arguments)); } - _createClass(NeverEndReadable, [{ - key: '_read', - value: function _read() {} - }]); + NeverEndReadable.prototype._read = function _read() {}; return NeverEndReadable; }(Readable);