@@ -7,7 +7,6 @@ const _ = require('lodash');
7
7
const findTarget = require ( './finders' ) . findTarget ;
8
8
const flowDoctrine = require ( '../flow_doctrine' ) ;
9
9
const util = require ( 'util' ) ;
10
- const debuglog = util . debuglog ( 'documentation' ) ;
11
10
12
11
/**
13
12
* Infers param tags by reading function parameter names
@@ -45,17 +44,22 @@ function inferParams(comment /*: Comment */) {
45
44
46
45
function inferAndCombineParams ( params , comment ) {
47
46
var inferredParams = params . map ( ( param , i ) => paramToDoc ( param , '' , i ) ) ;
48
- var mergedParams = mergeTrees ( inferredParams , comment . params ) ;
47
+ var mergedParamsAndErrors = mergeTrees ( inferredParams , comment . params ) ;
49
48
50
49
// Then merge the trees. This is the hard part.
51
50
return _ . assign ( comment , {
52
- params : mergedParams
51
+ params : mergedParamsAndErrors . mergedParams ,
52
+ errors : comment . errors . concat ( mergedParamsAndErrors . errors )
53
53
} ) ;
54
54
}
55
55
56
56
// Utility methods ============================================================
57
57
//
58
58
const PATH_SPLIT_CAPTURING = / ( \[ ] ) ? ( \. ) / g;
59
+ const PATH_SPLIT = / (?: \[ ] ) ? \. / g;
60
+ function tagDepth ( tag /*: CommentTag */ ) /*: number */ {
61
+ return ( tag . name || '' ) . split ( PATH_SPLIT ) . length ;
62
+ }
59
63
60
64
/**
61
65
* Index tags by their `name` property into an ES6 map.
@@ -199,7 +203,7 @@ function paramToDoc(
199
203
} ;
200
204
default :
201
205
// (a)
202
- var newParam /*: CommentTagNamed */ = {
206
+ var newParam /*: CommentTag */ = {
203
207
title : 'param' ,
204
208
name : prefix ? prefixedName : param . name ,
205
209
lineNumber : param . loc . start . line
@@ -261,25 +265,29 @@ function mergeTrees(inferred, explicit) {
261
265
function mergeTopNodes ( inferred , explicit ) {
262
266
const mapExplicit = mapTags ( explicit ) ;
263
267
const inferredNames = new Set ( inferred . map ( tag => tag . name ) ) ;
264
- const explicitTagsWithoutInference = explicit . filter (
265
- tag => ! inferredNames . has ( tag . name )
266
- ) ;
268
+ const explicitTagsWithoutInference = explicit . filter ( tag => {
269
+ return tagDepth ( tag ) === 1 && ! inferredNames . has ( tag . name ) ;
270
+ } ) ;
267
271
268
- if ( explicitTagsWithoutInference . length ) {
269
- debuglog (
270
- `${ explicitTagsWithoutInference . length } tags were specified but didn't match ` +
271
- `inferred information ${ explicitTagsWithoutInference
272
- . map ( t => t . name )
273
- . join ( ', ' ) } `
274
- ) ;
275
- }
272
+ var errors = explicitTagsWithoutInference . map ( tag => {
273
+ return {
274
+ message : `An explicit parameter named ${ tag . name || '' } was specified but didn't match ` +
275
+ `inferred information ${ Array . from ( inferredNames ) . join ( ', ' ) } ` ,
276
+ commentLineNumber : tag . lineNumber
277
+ } ;
278
+ } ) ;
276
279
277
- return inferred
278
- . map ( inferredTag => {
279
- const explicitTag = mapExplicit . get ( inferredTag . name ) ;
280
- return explicitTag ? combineTags ( inferredTag , explicitTag ) : inferredTag ;
281
- } )
282
- . concat ( explicitTagsWithoutInference ) ;
280
+ return {
281
+ errors,
282
+ mergedParams : inferred
283
+ . map ( inferredTag => {
284
+ const explicitTag = mapExplicit . get ( inferredTag . name ) ;
285
+ return explicitTag
286
+ ? combineTags ( inferredTag , explicitTag )
287
+ : inferredTag ;
288
+ } )
289
+ . concat ( explicitTagsWithoutInference )
290
+ } ;
283
291
}
284
292
285
293
// This method is used for _non-root_ properties only - we use mergeTopNodes
0 commit comments