Skip to content

Commit

Permalink
Convert classes loosely
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jun 22, 2017
1 parent 46770ab commit 432d4b7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 80 deletions.
2 changes: 1 addition & 1 deletion build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
106 changes: 48 additions & 58 deletions lib/internal/streams/BufferList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

/*<replacement>*/

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;
Expand All @@ -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;
}();
31 changes: 10 additions & 21 deletions test/parallel/test-stream-unpipe-event.js
Original file line number Diff line number Diff line change
@@ -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; }
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 432d4b7

Please sign in to comment.