Skip to content

Commit 6b86a9b

Browse files
authored
Merge pull request #12072 from hasezoey/receiverRefactor
Refactor all `@receiver` tags to proper jsdoc tags
2 parents cfdb1d8 + d4e3522 commit 6b86a9b

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

docs/source/api.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,29 @@ function parse() {
126126
ctx.constructorWasUndefined = true;
127127
}
128128

129+
// helper function to keep translating array types to string consistent
130+
function convertTypesToString(types) {
131+
return Array.isArray(types) ? types.join('|') : types
132+
}
133+
129134
for (const tag of prop.tags) {
130135
switch (tag.type) {
131136
case 'receiver':
132-
ctx.constructor = tag.string;
137+
console.warn(`Found "@receiver" tag in ${ctx.constructor} ${ctx.name}`);
133138
break;
134139
case 'property':
135140
ctx.type = 'property';
136141

137-
// somewhere since 6.0 the "string" property came back, which was gone with 4.5
138-
let str = tag.string;
139-
140-
const match = str.match(/^{\w+}/);
141-
if (match != null) {
142-
ctx.type = match[0].substring(1, match[0].length - 1);
143-
str = str.replace(/^{\w+}\s*/, '');
142+
// using "name" over "string" because "string" also contains the type and maybe other stuff
143+
ctx.name = tag.name;
144+
// only assign "type" if there are types
145+
if (tag.types.length > 0) {
146+
ctx.type = convertTypesToString(tag.types);
144147
}
145-
ctx.name = str;
148+
146149
break;
147150
case 'type':
148-
ctx.type = Array.isArray(tag.types) ? tag.types.join('|') : tag.types;
151+
ctx.type = convertTypesToString(tag.types);
149152
break;
150153
case 'static':
151154
ctx.type = 'property';
@@ -184,7 +187,7 @@ function parse() {
184187
tag.types.push('null');
185188
}
186189
if (tag.types) {
187-
tag.types = tag.types.join('|');
190+
tag.types = convertTypesToString(tag.types);
188191
}
189192
ctx[tag.type].push(tag);
190193
if (tag.name != null && tag.name.startsWith('[') && tag.name.endsWith(']') && tag.name.includes('.')) {

lib/error/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Click the "show code" link below to see all defaults.
1818
*
1919
* @static
20-
* @receiver MongooseError
20+
* @memberOf MongooseError
2121
* @api public
2222
*/
2323

lib/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ function _ensureIndexes(model, options, callback) {
18221822
* Schema the model uses.
18231823
*
18241824
* @property schema
1825-
* @receiver Model
1825+
* @static
18261826
* @api public
18271827
* @memberOf Model
18281828
*/

lib/query.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Query.base = mquery.prototype;
170170
* @default true
171171
* @property use$geoWithin
172172
* @memberOf Query
173-
* @receiver Query
173+
* @static
174174
* @api public
175175
*/
176176

@@ -1847,7 +1847,7 @@ Query.prototype.setUpdate = function(val) {
18471847
* @method _fieldsForExec
18481848
* @return {Object}
18491849
* @api private
1850-
* @receiver Query
1850+
* @memberOf Query
18511851
*/
18521852

18531853
Query.prototype._fieldsForExec = function() {
@@ -1859,8 +1859,9 @@ Query.prototype._fieldsForExec = function() {
18591859
* Return an update document with corrected `$set` operations.
18601860
*
18611861
* @method _updateForExec
1862+
* @return {Object}
18621863
* @api private
1863-
* @receiver Query
1864+
* @memberOf Query
18641865
*/
18651866

18661867
Query.prototype._updateForExec = function() {
@@ -1907,10 +1908,12 @@ Query.prototype._updateForExec = function() {
19071908
/**
19081909
* Makes sure _path is set.
19091910
*
1911+
* This method is inherited by `mquery`
1912+
*
19101913
* @method _ensurePath
19111914
* @param {String} method
19121915
* @api private
1913-
* @receiver Query
1916+
* @memberOf Query
19141917
*/
19151918

19161919
/**

lib/schema.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,16 +1870,17 @@ Schema.prototype.get = function(key) {
18701870
return this.options[key];
18711871
};
18721872

1873+
const indexTypes = '2d 2dsphere hashed text'.split(' ');
1874+
18731875
/**
18741876
* The allowed index types
18751877
*
1876-
* @receiver Schema
1878+
* @property {String[]} indexTypes
1879+
* @memberOf Schema
18771880
* @static
18781881
* @api public
18791882
*/
18801883

1881-
const indexTypes = '2d 2dsphere hashed text'.split(' ');
1882-
18831884
Object.defineProperty(Schema, 'indexTypes', {
18841885
get: function() {
18851886
return indexTypes;

lib/schematype.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ SchemaType.prototype.splitPath = function() {
206206
* @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
207207
* @return {Function}
208208
* @static
209-
* @receiver SchemaType
209+
* @memberOf SchemaType
210210
* @function cast
211211
* @api public
212212
*/
@@ -280,7 +280,7 @@ SchemaType.prototype.cast = function cast() {
280280
* @param {Any} value The value of the option you'd like to set.
281281
* @return {void}
282282
* @static
283-
* @receiver SchemaType
283+
* @memberOf SchemaType
284284
* @function set
285285
* @api public
286286
*/
@@ -303,7 +303,7 @@ SchemaType.set = function set(option, value) {
303303
* @param {Function} getter
304304
* @return {this}
305305
* @static
306-
* @receiver SchemaType
306+
* @memberOf SchemaType
307307
* @function get
308308
* @api public
309309
*/
@@ -1634,7 +1634,7 @@ SchemaType.prototype._castForQuery = function(val) {
16341634
* @param {Function} fn
16351635
* @return {Function}
16361636
* @static
1637-
* @receiver SchemaType
1637+
* @memberOf SchemaType
16381638
* @function checkRequired
16391639
* @api public
16401640
*/

lib/types/DocumentArray/methods/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const methods = {
3535
*
3636
* @method _cast
3737
* @api private
38-
* @receiver MongooseDocumentArray
38+
* @memberOf MongooseDocumentArray
3939
*/
4040

4141
_cast(value, index) {

lib/types/subdocument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Subdocument.prototype.isModified = function(paths, modifiedPaths) {
188188
* @param {String} path the field to mark as valid
189189
* @api private
190190
* @method $markValid
191-
* @receiver Subdocument
191+
* @memberOf Subdocument
192192
*/
193193

194194
Subdocument.prototype.$markValid = function(path) {

0 commit comments

Comments
 (0)