Skip to content

Commit

Permalink
Merge pull request #11238 from Uzlopak/remove-sliced
Browse files Browse the repository at this point in the history
remove sliced
  • Loading branch information
vkarpov15 committed Jan 20, 2022
2 parents 6af50eb + a08a85d commit c609e5c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Aggregate.prototype.model = function(model) {
Aggregate.prototype.append = function() {
const args = (arguments.length === 1 && Array.isArray(arguments[0]))
? arguments[0]
: utils.args(arguments);
: [...arguments];

if (!args.every(isOperator)) {
throw new Error('Arguments must be aggregate pipeline operators');
Expand Down Expand Up @@ -371,7 +371,7 @@ Aggregate.prototype.near = function(arg) {
*/

Aggregate.prototype.unwind = function() {
const args = utils.args(arguments);
const args = [...arguments];

const res = [];
for (const arg of args) {
Expand Down
6 changes: 3 additions & 3 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ function init(self, obj, doc, opts, prefix) {
*/

Document.prototype.update = function update() {
const args = utils.args(arguments);
const args = [...arguments];
args.unshift({ _id: this._id });
const query = this.constructor.update.apply(this.constructor, args);

Expand Down Expand Up @@ -962,7 +962,7 @@ Document.prototype.updateOne = function updateOne(doc, options, callback) {
*/

Document.prototype.replaceOne = function replaceOne() {
const args = utils.args(arguments);
const args = [...arguments];
args.unshift({ _id: this._id });
return this.constructor.replaceOne.apply(this.constructor, args);
};
Expand Down Expand Up @@ -4136,7 +4136,7 @@ Document.prototype.equals = function(doc) {

Document.prototype.populate = function populate() {
const pop = {};
const args = utils.args(arguments);
const args = [...arguments];
let fn;

if (args.length > 0) {
Expand Down
3 changes: 1 addition & 2 deletions lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const Collection = require('mongodb').Collection;
const ObjectId = require('./objectid');
const get = require('../../helpers/get');
const getConstructorName = require('../../helpers/getConstructorName');
const sliced = require('sliced');
const stream = require('stream');
const util = require('util');

Expand Down Expand Up @@ -173,7 +172,7 @@ function iter(i) {
if (debug) {
if (typeof debug === 'function') {
debug.apply(_this,
[_this.name, i].concat(sliced(args, 0, args.length - 1)));
[_this.name, i].concat(args.slice(0, args.length - 1)));
} else if (debug instanceof stream.Writable) {
this.$printToStream(_this.name, i, args, debug);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3069,10 +3069,10 @@ Model.create = function create(doc, options, callback) {
options = {};
// Handle falsy callbacks re: #5061
if (typeof last === 'function' || (arguments.length > 1 && !last)) {
cb = last;
args = utils.args(arguments, 0, arguments.length - 1);
args = [...arguments];
cb = args.pop();
} else {
args = utils.args(arguments);
args = [...arguments];
}

if (args.length === 2 &&
Expand Down
9 changes: 4 additions & 5 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const sanitizeFilter = require('./helpers/query/sanitizeFilter');
const sanitizeProjection = require('./helpers/query/sanitizeProjection');
const selectPopulatedFields = require('./helpers/query/selectPopulatedFields');
const setDefaultsOnInsert = require('./helpers/setDefaultsOnInsert');
const slice = require('sliced');
const updateValidators = require('./helpers/updateValidators');
const util = require('util');
const utils = require('./utils');
Expand Down Expand Up @@ -379,14 +378,14 @@ Query.prototype.slice = function() {
if ('number' === typeof arguments[0]) {
this._ensurePath('slice');
path = this._path;
val = slice(arguments);
val = [arguments[0], arguments[1]];
} else {
path = arguments[0];
val = arguments[1];
}
} else if (arguments.length === 3) {
path = arguments[0];
val = slice(arguments, 1);
val = [arguments[1], arguments[2]];
}

const p = {};
Expand Down Expand Up @@ -680,10 +679,10 @@ Query.prototype.mod = function() {
path = this._path;
} else if (arguments.length === 2 && !Array.isArray(arguments[1])) {
this._ensurePath('mod');
val = slice(arguments);
val = [arguments[0], arguments[1]];
path = this._path;
} else if (arguments.length === 3) {
val = slice(arguments, 1);
val = [arguments[1], arguments[2]];
path = arguments[0];
} else {
val = arguments[1];
Expand Down
2 changes: 1 addition & 1 deletion lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ SchemaType.prototype.default = function(val) {
this.defaultValue = val;
return this.defaultValue;
} else if (arguments.length > 1) {
this.defaultValue = utils.args(arguments);
this.defaultValue = [...arguments];
}
return this.defaultValue;
};
Expand Down
9 changes: 4 additions & 5 deletions lib/statemachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

const utils = require('./utils');
const utils = require('./utils'); // eslint-disable-line no-unused-vars

/*!
* StateMachine represents a minimal `interface` for the
Expand All @@ -32,7 +32,7 @@ const StateMachine = module.exports = exports = function StateMachine() {
*/

StateMachine.ctor = function() {
const states = utils.args(arguments);
const states = [...arguments];

const ctor = function() {
StateMachine.apply(this, arguments);
Expand Down Expand Up @@ -122,9 +122,8 @@ StateMachine.prototype.some = function some() {

StateMachine.prototype._iter = function _iter(iterMethod) {
return function() {
const numArgs = arguments.length;
let states = utils.args(arguments, 0, numArgs - 1);
const callback = arguments[numArgs - 1];
let states = [...arguments];
const callback = states.pop();

if (!states.length) states = this.stateNames;

Expand Down
8 changes: 0 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

const ms = require('ms');
const mpath = require('mpath');
const sliced = require('sliced');
const Decimal = require('./types/decimal128');
const ObjectId = require('./types/objectid');
const PopulateOptions = require('./options/PopulateOptions');
Expand Down Expand Up @@ -441,13 +440,6 @@ exports.hasKey = function hasKey(obj, key) {
return false;
};

/*!
* A faster Array.prototype.slice.call(arguments) alternative
* @api private
*/

exports.args = sliced;

/*!
* process.nextTick helper.
*
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"mquery": "4.0.0",
"ms": "2.1.2",
"regexp-clone": "1.0.0",
"sift": "13.5.2",
"sliced": "1.0.1"
"sift": "13.5.2"
},
"devDependencies": {
"@babel/core": "7.10.5",
Expand Down

0 comments on commit c609e5c

Please sign in to comment.