1
1
'use strict' ;
2
2
3
- // require('time-require');
4
- const assign = Object . assign ;
5
3
const Emitter = require ( 'events' ) ;
6
4
const extract = require ( 'extract-comments' ) ;
7
5
const tokenize = require ( 'tokenize-comment' ) ;
8
- const { expects , allows , format , validate , normalize , utils , parse } = require ( './lib' ) ;
9
- const { typeOf , get , set } = utils ;
6
+ const lib = require ( './lib' ) ;
7
+ const { utils } = lib ;
10
8
11
9
/**
12
10
* Create an instance of `Comments` with the given `options`.
@@ -19,7 +17,7 @@ const { typeOf, get, set } = utils;
19
17
class Comments extends Emitter {
20
18
constructor ( options ) {
21
19
super ( ) ;
22
- this . options = assign ( { } , options ) ;
20
+ this . options = Object . assign ( { } , options ) ;
23
21
this . comments = [ ] ;
24
22
this . ast = { } ;
25
23
this . cache = {
@@ -235,7 +233,7 @@ class Comments extends Emitter {
235
233
*/
236
234
237
235
tokenize ( str , options ) {
238
- return tokenize ( str , assign ( { } , this . options , options ) ) ;
236
+ return tokenize ( str , Object . assign ( { } , this . options , options ) ) ;
239
237
}
240
238
241
239
/**
@@ -272,8 +270,8 @@ class Comments extends Emitter {
272
270
*/
273
271
274
272
parseComment ( comment , options ) {
275
- const opts = assign ( { } , this . options , options ) ;
276
- const parsers = assign ( { } , this . plugins . middleware , opts . parse ) ;
273
+ const opts = Object . assign ( { } , this . options , options ) ;
274
+ const parsers = Object . assign ( { } , this . plugins . middleware , opts . parse ) ;
277
275
278
276
if ( typeof parsers . comment === 'function' ) {
279
277
comment = parsers . comment . call ( this , comment , opts ) ;
@@ -285,8 +283,8 @@ class Comments extends Emitter {
285
283
let tok = this . tokenize ( comment . value , opts ) ;
286
284
this . tokens . push ( tok ) ;
287
285
288
- comment = assign ( { } , comment , tok ) ;
289
- normalize . examples ( comment , opts ) ;
286
+ comment = Object . assign ( { } , comment , tok ) ;
287
+ lib . normalize . examples ( comment , opts ) ;
290
288
comment . tags = this . parseTags ( comment , options ) ;
291
289
292
290
// let name = get(comment, 'code.context.name');
@@ -306,7 +304,7 @@ class Comments extends Emitter {
306
304
307
305
// optionally format comment object
308
306
if ( opts . format === true ) {
309
- comment = format . call ( this , comment , opts ) ;
307
+ comment = lib . format . call ( this , comment , opts ) ;
310
308
}
311
309
312
310
this . emit ( 'comment' , comment ) ;
@@ -330,8 +328,8 @@ class Comments extends Emitter {
330
328
*/
331
329
332
330
parseTags ( comment , options ) {
333
- let opts = assign ( { } , this . options , options ) ;
334
- let parsers = assign ( { } , this . plugins . middleware , opts . parse ) ;
331
+ let opts = Object . assign ( { } , this . options , options ) ;
332
+ let parsers = Object . assign ( { } , this . plugins . middleware , opts . parse ) ;
335
333
let tags = [ ] ;
336
334
337
335
if ( typeof parsers . parseTags === 'function' ) {
@@ -366,8 +364,8 @@ class Comments extends Emitter {
366
364
*/
367
365
368
366
parseTag ( tok , options ) {
369
- const opts = assign ( { } , this . options , options ) ;
370
- const parsers = assign ( { } , this . plugins . middleware , opts . parse ) ;
367
+ const opts = Object . assign ( { } , this . options , options ) ;
368
+ const parsers = Object . assign ( { } , this . plugins . middleware , opts . parse ) ;
371
369
let tag ;
372
370
373
371
if ( typeof tok === 'string' ) {
@@ -379,33 +377,33 @@ class Comments extends Emitter {
379
377
}
380
378
381
379
try {
382
- tag = parse . tag ( tok ) ;
380
+ tag = lib . parse . tag ( tok ) ;
383
381
} catch ( err ) {
384
382
if ( opts . strict ) throw err ;
385
383
return null ;
386
384
}
387
385
388
- if ( ! tag || tag . rawType && ! allows . type ( tok ) ) {
386
+ if ( ! tag || tag . rawType && ! lib . allows . type ( tok ) ) {
389
387
return null ;
390
388
}
391
389
392
390
if ( tag . rawType ) {
393
391
tag . type = this . parseType ( tag . rawType . slice ( 1 , - 1 ) , tag , options ) ;
394
392
}
395
393
396
- if ( tag && expects . type ( tag ) && ! tag . type ) {
394
+ if ( tag && lib . expects . type ( tag ) && ! tag . type ) {
397
395
if ( opts . strict === true ) {
398
396
return null ;
399
397
}
400
398
tag . type = null ;
401
399
}
402
400
403
- tag = normalize . tag ( tag , opts ) ;
401
+ tag = lib . normalize . tag ( tag , opts ) ;
404
402
if ( ! tag ) {
405
403
return null ;
406
404
}
407
405
408
- tag = validate . tag ( tag , opts ) ;
406
+ tag = lib . validate . tag ( tag , opts ) ;
409
407
if ( ! tag ) {
410
408
return null ;
411
409
}
@@ -453,7 +451,7 @@ class Comments extends Emitter {
453
451
return parsers . inlineTag . call ( this , str , opts ) ;
454
452
}
455
453
456
- return parse . inline ( str , opts ) ;
454
+ return lib . parse . inline ( str , opts ) ;
457
455
}
458
456
459
457
/**
@@ -482,8 +480,8 @@ class Comments extends Emitter {
482
480
return parsers . type . call ( this , str , tag , opts ) ;
483
481
}
484
482
485
- return parse . type ( str , tag , opts ) ;
486
- } ;
483
+ return lib . parse . type ( str , tag , opts ) ;
484
+ }
487
485
488
486
parseParamType ( str , options ) {
489
487
if ( typeof str !== 'string' ) {
@@ -514,11 +512,11 @@ class Comments extends Emitter {
514
512
}
515
513
516
514
let comments = [ ] ;
517
- const opts = assign ( { } , this . options , options ) ;
515
+ const opts = Object . assign ( { } , this . options , options ) ;
518
516
const res = [ ] ;
519
517
520
518
if ( typeof opts . extract === 'function' ) {
521
- comments = utils . arrayify ( opts . extract . call ( this , str , opts ) ) ;
519
+ comments = [ ] . concat ( opts . extract . call ( this , str , opts ) || [ ] ) ;
522
520
} else {
523
521
comments = extract . block ( str , opts ) ;
524
522
}
@@ -531,8 +529,6 @@ class Comments extends Emitter {
531
529
let comment = this . preprocess ( comments [ i ] , options ) ;
532
530
if ( typeof fn === 'function' ) {
533
531
comment = fn . call ( this , comment ) || comment ;
534
- } else {
535
- comment = comment ;
536
532
}
537
533
538
534
res . push ( comment ) ;
@@ -542,7 +538,7 @@ class Comments extends Emitter {
542
538
}
543
539
544
540
preprocess ( comment , options ) {
545
- let opts = assign ( { } , this . options , options ) ;
541
+ let opts = Object . assign ( { } , this . options , options ) ;
546
542
547
543
if ( typeof opts . preprocess === 'function' ) {
548
544
return opts . preprocess . call ( this , comment , opts ) ;
@@ -571,7 +567,7 @@ class Comments extends Emitter {
571
567
throw new TypeError ( 'expected comment to be an object' ) ;
572
568
}
573
569
574
- let opts = assign ( { } , this . options , options ) ;
570
+ let opts = Object . assign ( { } , this . options , options ) ;
575
571
if ( typeof opts . isValid === 'function' ) {
576
572
return opts . isValid ( comment ) ;
577
573
}
0 commit comments