@@ -431,38 +431,30 @@ module.exports = {
431
431
*/
432
432
executeOnVueComponent ( context , cb ) {
433
433
const filePath = context . getFilename ( )
434
+ const sourceCode = context . getSourceCode ( )
434
435
const _this = this
435
- const componentComments = [ ]
436
+ const componentComments = sourceCode . getAllComments ( ) . filter ( comment => this . isVueComponentComment ( comment . value ) )
436
437
const foundNodes = [ ]
437
438
438
- function isDuplicateNode ( node ) {
439
- return foundNodes . some ( el => el . loc . start . line === node . loc . start . line )
439
+ const isDuplicateNode = ( node ) => {
440
+ if ( foundNodes . some ( el => el . loc . start . line === node . loc . start . line ) ) return true
441
+ foundNodes . push ( node )
442
+ return false
440
443
}
441
444
442
445
return {
443
- LineComment ( node ) {
444
- // line comment with @vue /component
445
- if ( ! _this . isVueComponentComment ( node . value ) ) return
446
- componentComments . push ( node )
447
- } ,
448
- BlockComment ( node ) {
449
- // block comment with @vue /component
450
- if ( ! _this . isVueComponentComment ( node . value ) ) return
451
- componentComments . push ( node )
452
- } ,
453
446
ObjectExpression ( node ) {
454
447
if ( ! componentComments . some ( el => el . loc . end . line === node . loc . start . line - 1 ) || isDuplicateNode ( node ) ) return
455
- foundNodes . push ( node )
456
448
cb ( node )
457
449
} ,
458
450
'ExportDefaultDeclaration:exit' ( node ) {
459
451
// export default {} in .vue || .jsx
460
- if ( ! _this . isVueComponentFile ( node , filePath ) || isDuplicateNode ( node ) ) return
452
+ if ( ! _this . isVueComponentFile ( node , filePath ) || isDuplicateNode ( node . declaration ) ) return
461
453
cb ( node . declaration )
462
454
} ,
463
455
'CallExpression:exit' ( node ) {
464
456
// Vue.component('xxx', {}) || component('xxx', {})
465
- if ( ! _this . isVueComponent ( node ) || isDuplicateNode ( node ) ) return
457
+ if ( ! _this . isVueComponent ( node ) || isDuplicateNode ( node . arguments . slice ( - 1 ) [ 0 ] ) ) return
466
458
cb ( node . arguments . slice ( - 1 ) [ 0 ] )
467
459
}
468
460
}
0 commit comments