@@ -109,10 +109,12 @@ function get_comment_handlers(source) {
109
109
if ( parent === undefined || node . end !== parent . end ) {
110
110
const slice = source . slice ( node . end , comments [ 0 ] . start ) ;
111
111
const is_last_in_body =
112
- // BlockStatement and Program nodes have a body property
113
- parent ?. body ?. length &&
114
- Array . isArray ( parent ?. body ) &&
115
- parent . body . indexOf ( node ) === parent . body . length - 1 ;
112
+ ( ( parent ?. type === 'BlockStatement' || parent ?. type === 'Program' ) &&
113
+ parent . body . indexOf ( node ) === parent . body . length - 1 ) ||
114
+ ( parent ?. type === 'ArrayExpression' &&
115
+ parent . elements . indexOf ( node ) === parent . elements . length - 1 ) ||
116
+ ( parent ?. type === 'ObjectExpression' &&
117
+ parent . properties . indexOf ( node ) === parent . properties . length - 1 ) ;
116
118
117
119
if ( is_last_in_body ) {
118
120
// Special case: There can be multiple trailing comments after the last node in a block,
@@ -121,10 +123,7 @@ function get_comment_handlers(source) {
121
123
122
124
while ( comments . length ) {
123
125
const comment = comments [ 0 ] ;
124
- if ( parent && comment . start > parent . end ) break ;
125
-
126
- const slice = source . slice ( end , comment . start ) ;
127
- if ( node . end === end ? ! / ^ [ , ) \s ] * $ / . test ( slice ) : slice . trim ( ) !== '' ) break ;
126
+ if ( parent && comment . start >= parent . end ) break ;
128
127
129
128
( node . trailingComments ||= [ ] ) . push ( comment ) ;
130
129
comments . shift ( ) ;
0 commit comments