@@ -304,9 +304,57 @@ function getBasename(name) {
304
304
return name ;
305
305
}
306
306
307
+ /** @private
308
+ * @memberof module:src/parser.Parser
309
+ */
310
+ function makeEvent ( node , extras ) {
311
+ extras = extras || { } ;
312
+
313
+ // fill in default values as needed. if we're overriding a property, don't execute the default
314
+ // code for that property, since it might blow up.
315
+ var result = {
316
+ id : extras . id || 'astnode' + node . hashCode ( ) ,
317
+ comment : extras . comment || String ( node . getJsDoc ( ) || '@undocumented' ) ,
318
+ lineno : extras . lineno || node . left . getLineno ( ) ,
319
+ filename : extras . filename || currentSourceName ,
320
+ astnode : extras . astnode || node ,
321
+ code : extras . code || aboutNode ( node ) ,
322
+ event : extras . event || 'symbolFound' ,
323
+ finishers : extras . finishers || [ currentParser . addDocletRef ]
324
+ } ;
325
+
326
+ // make sure the result includes extras that don't have default values
327
+ for ( var prop in extras ) {
328
+ if ( hasOwnProp . call ( extras , prop ) ) {
329
+ result [ prop ] = extras [ prop ] ;
330
+ }
331
+ }
332
+
333
+ return result ;
334
+ }
335
+
336
+ /** @private
337
+ * @memberof module:src/parser.Parser
338
+ */
339
+ function trackVars ( node , e ) {
340
+ // keep track of vars in a function or global scope
341
+ var func = "__global__" ;
342
+ var funcDoc = null ;
343
+ if ( node . enclosingFunction ) {
344
+ func = 'astnode' + node . enclosingFunction . hashCode ( ) ;
345
+ }
346
+ funcDoc = currentParser . refs [ func ] ;
347
+ if ( funcDoc ) {
348
+ funcDoc . meta . vars = funcDoc . meta . vars || { } ;
349
+ funcDoc . meta . vars [ e . code . name ] = false ;
350
+ e . finishers . push ( makeVarsFinisher ( funcDoc ) ) ;
351
+ }
352
+ }
353
+
307
354
/** @private */
308
355
function visitNode ( node ) {
309
356
var e ,
357
+ extras ,
310
358
nodeComments ,
311
359
comment ,
312
360
commentSrc ,
@@ -341,16 +389,7 @@ function visitNode(node) {
341
389
e = null ;
342
390
}
343
391
else if ( node . type === Token . ASSIGN ) {
344
- e = {
345
- id : 'astnode' + node . hashCode ( ) , // the id of the ASSIGN node
346
- comment : String ( node . getJsDoc ( ) || '@undocumented' ) ,
347
- lineno : node . left . getLineno ( ) ,
348
- filename : currentSourceName ,
349
- astnode : node ,
350
- code : aboutNode ( node ) ,
351
- event : "symbolFound" ,
352
- finishers : [ currentParser . addDocletRef ]
353
- } ;
392
+ e = makeEvent ( node ) ;
354
393
355
394
basename = getBasename ( e . code . name ) ;
356
395
@@ -359,28 +398,17 @@ function visitNode(node) {
359
398
}
360
399
}
361
400
else if ( node . type === Token . COLON ) { // assignment within an object literal
362
- e = {
363
- id : 'astnode' + node . hashCode ( ) , // the id of the COLON node
364
- comment : String ( node . left . getJsDoc ( ) || '@undocumented' ) ,
365
- lineno : node . left . getLineno ( ) ,
366
- filename : currentSourceName ,
367
- astnode : node ,
368
- code : aboutNode ( node ) ,
369
- event : "symbolFound" ,
401
+ extras = {
402
+ comment : String ( node . left . getJsDoc ( ) || '@undocumented' ) ,
370
403
finishers : [ currentParser . addDocletRef , currentParser . resolveEnum ]
371
404
} ;
405
+ e = makeEvent ( node , extras ) ;
372
406
}
373
407
else if ( node . type === Token . GET || node . type === Token . SET ) { // assignment within an object literal
374
- e = {
375
- id : 'astnode' + node . hashCode ( ) , // the id of the GET/SET node
376
- comment : String ( node . left . getJsDoc ( ) || '@undocumented' ) ,
377
- lineno : node . left . getLineno ( ) ,
378
- filename : currentSourceName ,
379
- astnode : node ,
380
- code : aboutNode ( node ) ,
381
- event : "symbolFound" ,
382
- finishers : [ currentParser . addDocletRef ]
408
+ extras = {
409
+ comment : String ( node . left . getJsDoc ( ) || '@undocumented' )
383
410
} ;
411
+ e = makeEvent ( node , extras ) ;
384
412
}
385
413
else if ( node . type == Token . VAR || node . type == Token . LET || node . type == Token . CONST ) {
386
414
@@ -394,57 +422,22 @@ function visitNode(node) {
394
422
//node.jsDoc = node.parent.jsDoc;
395
423
}
396
424
397
- e = {
398
- id : 'astnode' + node . hashCode ( ) , // the id of the VARIABLE node
399
- comment : String ( node . getJsDoc ( ) || '@undocumented' ) ,
400
- lineno : node . getLineno ( ) ,
401
- filename : currentSourceName ,
402
- astnode : node ,
403
- code : aboutNode ( node ) ,
404
- event : "symbolFound" ,
405
- finishers : [ currentParser . addDocletRef ]
425
+ extras = {
426
+ lineno : node . getLineno ( )
406
427
} ;
428
+ e = makeEvent ( node , extras ) ;
407
429
408
- // keep track of vars in a function or global scope
409
- func = "__global__" ;
410
- funcDoc = null ;
411
- if ( node . enclosingFunction ) {
412
- func = 'astnode' + node . enclosingFunction . hashCode ( ) ;
413
- }
414
- funcDoc = currentParser . refs [ func ] ;
415
- if ( funcDoc ) {
416
- funcDoc . meta . vars = funcDoc . meta . vars || { } ;
417
- funcDoc . meta . vars [ e . code . name ] = false ;
418
- e . finishers . push ( makeVarsFinisher ( funcDoc ) ) ;
419
- }
430
+ trackVars ( node , e ) ;
420
431
}
421
432
else if ( node . type == Token . FUNCTION || node . type == tkn . NAMEDFUNCTIONSTATEMENT ) {
422
- e = {
423
- id : 'astnode' + node . hashCode ( ) , // the id of the COLON node
424
- comment : String ( node . getJsDoc ( ) || '@undocumented' ) ,
425
- lineno : node . getLineno ( ) ,
426
- filename : currentSourceName ,
427
- astnode : node ,
428
- code : aboutNode ( node ) ,
429
- event : "symbolFound" ,
430
- finishers : [ currentParser . addDocletRef ]
433
+ extras = {
434
+ lineno : node . getLineno ( )
431
435
} ;
436
+ e = makeEvent ( node , extras ) ;
432
437
433
438
e . code . name = ( node . type == tkn . NAMEDFUNCTIONSTATEMENT ) ? '' : String ( node . name ) || '' ;
434
- //console.log(':: e.code.name is', e.code.name);
435
439
436
- // keep track of vars in a function or global scope
437
- func = "__global__" ;
438
- funcDoc = null ;
439
- if ( node . enclosingFunction ) {
440
- func = 'astnode' + node . enclosingFunction . hashCode ( ) ;
441
- }
442
- funcDoc = currentParser . refs [ func ] ;
443
- if ( funcDoc ) {
444
- funcDoc . meta . vars = funcDoc . meta . vars || { } ;
445
- funcDoc . meta . vars [ e . code . name ] = false ;
446
- e . finishers . push ( makeVarsFinisher ( funcDoc ) ) ;
447
- }
440
+ trackVars ( node , e ) ;
448
441
449
442
basename = getBasename ( e . code . name ) ;
450
443
e . code . funcscope = currentParser . resolveVar ( node , basename ) ;
0 commit comments