@@ -49,8 +49,8 @@ export default class DocFactory {
4949 this . _results . push ( doc . value ) ;
5050
5151 // ast does not child, so only comment.
52- if ( ast . body . length === 0 && ast . leadingComments ) {
53- let results = this . _traverseComments ( ast , null , ast . leadingComments ) ;
52+ if ( ast . program . body . length === 0 && ast . program . innerComments ) {
53+ let results = this . _traverseComments ( ast , null , ast . program . innerComments ) ;
5454 this . _results . push ( ...results ) ;
5555 }
5656 }
@@ -86,7 +86,7 @@ export default class DocFactory {
8686 _inspectExportDefaultDeclaration ( ) {
8787 let pseudoExportNodes = [ ] ;
8888
89- for ( let exportNode of this . _ast . body ) {
89+ for ( let exportNode of this . _ast . program . body ) {
9090 if ( exportNode . type !== 'ExportDefaultDeclaration' ) continue ;
9191
9292 let targetClassName = null ;
@@ -159,7 +159,7 @@ export default class DocFactory {
159159 }
160160 }
161161
162- this . _ast . body . push ( ...pseudoExportNodes ) ;
162+ this . _ast . program . body . push ( ...pseudoExportNodes ) ;
163163 }
164164
165165 /**
@@ -186,7 +186,7 @@ export default class DocFactory {
186186 _inspectExportNamedDeclaration ( ) {
187187 let pseudoExportNodes = [ ] ;
188188
189- for ( let exportNode of this . _ast . body ) {
189+ for ( let exportNode of this . _ast . program . body ) {
190190 if ( exportNode . type !== 'ExportNamedDeclaration' ) continue ;
191191
192192 if ( exportNode . declaration && exportNode . declaration . type === 'VariableDeclaration' ) {
@@ -261,7 +261,7 @@ export default class DocFactory {
261261 }
262262 }
263263
264- this . _ast . body . push ( ...pseudoExportNodes ) ;
264+ this . _ast . program . body . push ( ...pseudoExportNodes ) ;
265265 }
266266
267267 /**
@@ -315,19 +315,6 @@ export default class DocFactory {
315315 node = virtualNode ;
316316 }
317317
318- // hack: leadingComment of MethodDefinition with Literal is not valid by espree(v2.0.2)
319- //if (node.type === 'MethodDefinition' && node.key.type === 'Literal') {
320- // todo: switch espree to acorn
321- if ( node . type === 'MethodDefinition' && ( node . computed || ! node . key . name ) ) {
322- let line = node . loc . start . line - 1 ;
323- for ( let comment of this . _ast . comments || [ ] ) {
324- if ( comment . loc . end . line === line ) {
325- comments = [ comment ] ;
326- break ;
327- }
328- }
329- }
330-
331318 if ( comments && comments . length ) {
332319 let temp = [ ] ;
333320 for ( let comment of comments ) {
@@ -339,7 +326,7 @@ export default class DocFactory {
339326 }
340327
341328 if ( comments . length === 0 ) {
342- comments = [ { type : 'Block ' , value : '* @_undocument' } ] ;
329+ comments = [ { type : 'CommentBlock ' , value : '* @_undocument' } ] ;
343330 }
344331
345332 let results = [ ] ;
@@ -427,7 +414,7 @@ export default class DocFactory {
427414 switch ( node . type ) {
428415 case 'ClassDeclaration' :
429416 return this . _decideClassDeclarationType ( node ) ;
430- case 'MethodDefinition' :
417+ case 'ClassMethod' : // for babylon
431418 return this . _decideMethodDefinitionType ( node ) ;
432419 case 'ExpressionStatement' :
433420 return this . _decideExpressionStatementType ( node ) ;
@@ -449,7 +436,7 @@ export default class DocFactory {
449436 * @private
450437 */
451438 _decideClassDeclarationType ( node ) {
452- if ( ! this . _isTopDepthInBody ( node , this . _ast . body ) ) return { type : null , node : null } ;
439+ if ( ! this . _isTopDepthInBody ( node , this . _ast . program . body ) ) return { type : null , node : null } ;
453440
454441 return { type : 'Class' , node : node } ;
455442 }
@@ -477,7 +464,7 @@ export default class DocFactory {
477464 * @private
478465 */
479466 _decideFunctionDeclarationType ( node ) {
480- if ( ! this . _isTopDepthInBody ( node , this . _ast . body ) ) return { type : null , node : null } ;
467+ if ( ! this . _isTopDepthInBody ( node , this . _ast . program . body ) ) return { type : null , node : null } ;
481468
482469 return { type : 'Function' , node : node } ;
483470 }
@@ -489,7 +476,7 @@ export default class DocFactory {
489476 * @private
490477 */
491478 _decideExpressionStatementType ( node ) {
492- let isTop = this . _isTopDepthInBody ( node , this . _ast . body ) ;
479+ let isTop = this . _isTopDepthInBody ( node , this . _ast . program . body ) ;
493480 Object . defineProperty ( node . expression , 'parent' , { value : node } ) ;
494481 node = node . expression ;
495482 node [ already ] = true ;
@@ -542,7 +529,7 @@ export default class DocFactory {
542529 * @private
543530 */
544531 _decideVariableType ( node ) {
545- if ( ! this . _isTopDepthInBody ( node , this . _ast . body ) ) return { type : null , node : null } ;
532+ if ( ! this . _isTopDepthInBody ( node , this . _ast . program . body ) ) return { type : null , node : null } ;
546533
547534 let innerType = null ;
548535 let innerNode = null ;
@@ -575,7 +562,7 @@ export default class DocFactory {
575562 * @private
576563 */
577564 _decideAssignmentType ( node ) {
578- if ( ! this . _isTopDepthInBody ( node , this . _ast . body ) ) return { type : null , node : null } ;
565+ if ( ! this . _isTopDepthInBody ( node , this . _ast . program . body ) ) return { type : null , node : null } ;
579566
580567 let innerType ;
581568 let innerNode ;
0 commit comments