@@ -47,11 +47,11 @@ function isReservedPropName(name, list) {
47
47
}
48
48
49
49
let attributeMap ;
50
- // attributeMap = [ endrange, true||false if comment in between nodes exists, it needs to be sorted to end]
50
+ // attributeMap = { end: endrange, hasComment: true||false if comment in between nodes exists, it needs to be sorted to end }
51
51
52
52
function shouldSortToEnd ( node ) {
53
53
const attr = attributeMap . get ( node ) ;
54
- return ! ! attr && ! ! attr [ 1 ] ;
54
+ return ! ! attr && ! ! attr . hasComment ;
55
55
}
56
56
57
57
function contextCompare ( a , b , options ) {
@@ -170,35 +170,35 @@ function getGroupsOfSortableAttributes(attributes, context) {
170
170
}
171
171
if ( ! attrIsSpread ) {
172
172
if ( comment . length === 0 ) {
173
- attributeMap . set ( attribute , [ attribute . range [ 1 ] , false ] ) ;
173
+ attributeMap . set ( attribute , { end : attribute . range [ 1 ] , hasComment : false } ) ;
174
174
addtoSortableAttributeGroups ( attribute ) ;
175
175
} else {
176
176
const firstComment = comment [ 0 ] ;
177
177
const commentline = firstComment . loc . start . line ;
178
178
if ( comment . length === 1 ) {
179
179
if ( attributeline + 1 === commentline && nextAttribute ) {
180
- attributeMap . set ( attribute , [ nextAttribute . range [ 1 ] , true ] ) ;
180
+ attributeMap . set ( attribute , { end : nextAttribute . range [ 1 ] , hasComment : true } ) ;
181
181
addtoSortableAttributeGroups ( attribute ) ;
182
182
i += 1 ;
183
183
} else if ( attributeline === commentline ) {
184
184
if ( firstComment . type === 'Block' && nextAttribute ) {
185
- attributeMap . set ( attribute , [ nextAttribute . range [ 1 ] , true ] ) ;
185
+ attributeMap . set ( attribute , { end : nextAttribute . range [ 1 ] , hasComment : true } ) ;
186
186
i += 1 ;
187
187
} else if ( firstComment . type === 'Block' ) {
188
- attributeMap . set ( attribute , [ firstComment . range [ 1 ] , true ] ) ;
188
+ attributeMap . set ( attribute , { end : firstComment . range [ 1 ] , hasComment : true } ) ;
189
189
} else {
190
- attributeMap . set ( attribute , [ firstComment . range [ 1 ] , false ] ) ;
190
+ attributeMap . set ( attribute , { end : firstComment . range [ 1 ] , hasComment : false } ) ;
191
191
}
192
192
addtoSortableAttributeGroups ( attribute ) ;
193
193
}
194
194
} else if ( comment . length > 1 && attributeline + 1 === comment [ 1 ] . loc . start . line && nextAttribute ) {
195
195
const commentNextAttribute = sourceCode . getCommentsAfter ( nextAttribute ) ;
196
- attributeMap . set ( attribute , [ nextAttribute . range [ 1 ] , true ] ) ;
196
+ attributeMap . set ( attribute , { end : nextAttribute . range [ 1 ] , hasComment : true } ) ;
197
197
if (
198
198
commentNextAttribute . length === 1
199
199
&& nextAttribute . loc . start . line === commentNextAttribute [ 0 ] . loc . start . line
200
200
) {
201
- attributeMap . set ( attribute , [ commentNextAttribute [ 0 ] . range [ 1 ] , true ] ) ;
201
+ attributeMap . set ( attribute , { end : commentNextAttribute [ 0 ] . range [ 1 ] , hasComment : true } ) ;
202
202
}
203
203
addtoSortableAttributeGroups ( attribute ) ;
204
204
i += 1 ;
@@ -248,10 +248,9 @@ function generateFixerFunction(node, context, reservedList) {
248
248
sortableAttributeGroups . forEach ( ( sortableGroup , ii ) => {
249
249
sortableGroup . forEach ( ( attr , jj ) => {
250
250
const sortedAttr = sortedAttributeGroups [ ii ] [ jj ] ;
251
- const sortedAttrText = source . substring ( sortedAttr . range [ 0 ] , attributeMap . get ( sortedAttr ) [ 0 ] ) ;
252
- const attrrangeEnd = attributeMap . get ( attr ) [ 0 ] ;
251
+ const sortedAttrText = source . substring ( sortedAttr . range [ 0 ] , attributeMap . get ( sortedAttr ) . end ) ;
253
252
fixers . push ( {
254
- range : [ attr . range [ 0 ] , attrrangeEnd ] ,
253
+ range : [ attr . range [ 0 ] , attributeMap . get ( attr ) . end ] ,
255
254
text : sortedAttrText ,
256
255
} ) ;
257
256
} ) ;
0 commit comments