Skip to content

Commit 27cb3e3

Browse files
Merge pull request #466 from Meteor-Community-Packages/fix/ambiguous-variables
fix: rename ambiguous variable declarations in destructuring assignments
2 parents 24310c4 + 81078b5 commit 27cb3e3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

package/collection2/main.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,15 @@ function getArgumentsAndValidationContext(methodName, args, async) {
180180
}
181181

182182
let validationContext = {};
183+
let validatedArgs = args;
183184
if (this._c2 && options.bypassCollection2 !== true) {
184185
let userId = null;
185186
try {
186187
// https://github.com/aldeed/meteor-collection2/issues/175
187188
userId = Meteor.userId();
188189
} catch (err) {}
189190

190-
[args, validationContext] = doValidate(
191+
[validatedArgs, validationContext] = doValidate(
191192
this,
192193
methodName,
193194
args,
@@ -197,17 +198,17 @@ function getArgumentsAndValidationContext(methodName, args, async) {
197198
async
198199
);
199200

200-
if (!args) {
201+
if (!validatedArgs) {
201202
// doValidate already called the callback or threw the error, so we're done.
202203
// But insert should always return an ID to match core behavior.
203204
return isInsertType(methodName) ? this._makeNewID() : undefined;
204205
}
205206
} else {
206207
// We still need to adjust args because insert does not take options
207-
if (isInsertType(methodName) && typeof args[1] !== 'function') args.splice(1, 1);
208+
if (isInsertType(methodName) && typeof validatedArgs[1] !== 'function') validatedArgs.splice(1, 1);
208209
}
209210

210-
return [args, validationContext];
211+
return [validatedArgs, validationContext];
211212
}
212213

213214
function _methodMutation(async, methodName) {
@@ -217,13 +218,13 @@ function getArgumentsAndValidationContext(methodName, args, async) {
217218

218219
if (!_super) return;
219220
Mongo.Collection.prototype[methodName] = function (...args) {
220-
[args, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, async);
221+
const [validatedArgs, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, async);
221222

222223
if (async && !Meteor.isFibersDisabled) {
223224
try {
224225
this[methodName.replace('Async', '')].isCalledFromAsync = true;
225226
_super.isCalledFromAsync = true;
226-
return Promise.resolve(_super.apply(this, args));
227+
return Promise.resolve(_super.apply(this, validatedArgs));
227228
} catch (err) {
228229
if (this._c2) {
229230
const addValidationErrorsPropName =
@@ -239,18 +240,18 @@ function getArgumentsAndValidationContext(methodName, args, async) {
239240
}
240241
}
241242
} else {
242-
return _super.apply(this, args);
243+
return _super.apply(this, validatedArgs);
243244
}
244245
};
245246
}
246247

247248
function _methodMutationAsync(methodName) {
248249
const _super = Mongo.Collection.prototype[methodName];
249250
Mongo.Collection.prototype[methodName] = async function (...args) {
250-
[args, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, true);
251+
const [validatedArgs, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, true);
251252

252253
try {
253-
return await _super.apply(this, args);
254+
return await _super.apply(this, validatedArgs);
254255
} catch (err) {
255256
if (this._c2) {
256257
const addValidationErrorsPropName =

0 commit comments

Comments
 (0)