Skip to content

Commit

Permalink
Merge pull request #466 from Meteor-Community-Packages/fix/ambiguous-…
Browse files Browse the repository at this point in the history
…variables

fix: rename ambiguous variable declarations in destructuring assignments
  • Loading branch information
StorytellerCZ authored Feb 13, 2025
2 parents 24310c4 + 81078b5 commit 27cb3e3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions package/collection2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ function getArgumentsAndValidationContext(methodName, args, async) {
}

let validationContext = {};
let validatedArgs = args;
if (this._c2 && options.bypassCollection2 !== true) {
let userId = null;
try {
// https://github.com/aldeed/meteor-collection2/issues/175
userId = Meteor.userId();
} catch (err) {}

[args, validationContext] = doValidate(
[validatedArgs, validationContext] = doValidate(
this,
methodName,
args,
Expand All @@ -197,17 +198,17 @@ function getArgumentsAndValidationContext(methodName, args, async) {
async
);

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

return [args, validationContext];
return [validatedArgs, validationContext];
}

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

if (!_super) return;
Mongo.Collection.prototype[methodName] = function (...args) {
[args, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, async);
const [validatedArgs, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, async);

if (async && !Meteor.isFibersDisabled) {
try {
this[methodName.replace('Async', '')].isCalledFromAsync = true;
_super.isCalledFromAsync = true;
return Promise.resolve(_super.apply(this, args));
return Promise.resolve(_super.apply(this, validatedArgs));
} catch (err) {
if (this._c2) {
const addValidationErrorsPropName =
Expand All @@ -239,18 +240,18 @@ function getArgumentsAndValidationContext(methodName, args, async) {
}
}
} else {
return _super.apply(this, args);
return _super.apply(this, validatedArgs);
}
};
}

function _methodMutationAsync(methodName) {
const _super = Mongo.Collection.prototype[methodName];
Mongo.Collection.prototype[methodName] = async function (...args) {
[args, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, true);
const [validatedArgs, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, true);

try {
return await _super.apply(this, args);
return await _super.apply(this, validatedArgs);
} catch (err) {
if (this._c2) {
const addValidationErrorsPropName =
Expand Down

0 comments on commit 27cb3e3

Please sign in to comment.