@@ -205,36 +205,41 @@ export default createRule("valid-compile", {
205
205
} {
206
206
decoded ??= decode ( JSON . parse ( output . sourceMapText ! ) . mappings )
207
207
208
- const lineMaps = decoded [ pos . line ]
208
+ const lineMaps = decoded [ pos . line - 1 ]
209
209
210
210
if ( ! lineMaps ?. length ) {
211
211
for ( let line = pos . line - 1 ; line >= 0 ; line -- ) {
212
212
const prevLineMaps = decoded [ line ]
213
213
if ( prevLineMaps ?. length ) {
214
- const [ , , remapLine , remapCol ] =
214
+ const [ , , sourceCodeLine , sourceCodeColumn ] =
215
215
prevLineMaps [ prevLineMaps . length - 1 ]
216
216
return {
217
- line : remapLine ! ,
218
- column : remapCol ! ,
217
+ line : sourceCodeLine ! + 1 ,
218
+ column : sourceCodeColumn ! ,
219
219
}
220
220
}
221
221
}
222
222
return { line : - 1 , column : - 1 }
223
223
}
224
224
225
225
for ( let index = 0 ; index < lineMaps . length - 1 ; index ++ ) {
226
- const [ col , , remapLine , remapCol ] = lineMaps [ index ]
227
- if ( col <= pos . column && pos . column < lineMaps [ index + 1 ] [ 0 ] ) {
226
+ const [ generateCodeColumn , , sourceCodeLine , sourceCodeColumn ] =
227
+ lineMaps [ index ]
228
+ if (
229
+ generateCodeColumn <= pos . column &&
230
+ pos . column < lineMaps [ index + 1 ] [ 0 ]
231
+ ) {
228
232
return {
229
- line : remapLine ! ,
230
- column : remapCol ! ,
233
+ line : sourceCodeLine ! + 1 ,
234
+ column : sourceCodeColumn ! + ( pos . column - generateCodeColumn ) ,
231
235
}
232
236
}
233
237
}
234
- const [ , , remapLine , remapCol ] = lineMaps [ lineMaps . length - 1 ]
238
+ const [ generateCodeColumn , , sourceCodeLine , sourceCodeColumn ] =
239
+ lineMaps [ lineMaps . length - 1 ]
235
240
return {
236
- line : remapLine ! ,
237
- column : remapCol ! ,
241
+ line : sourceCodeLine ! + 1 ,
242
+ column : sourceCodeColumn ! + ( pos . column - generateCodeColumn ) ,
238
243
}
239
244
}
240
245
}
@@ -258,6 +263,7 @@ export default createRule("valid-compile", {
258
263
column : number
259
264
}
260
265
} {
266
+ const mapIndexes = this . mapIndexes
261
267
const locs = ( this . locs ??= new LinesAndColumns ( this . code ) )
262
268
let start :
263
269
| {
@@ -273,24 +279,30 @@ export default createRule("valid-compile", {
273
279
| undefined = undefined
274
280
if ( points . start ) {
275
281
const index = locs . getIndexFromLoc ( points . start )
276
- for ( const mapIndex of this . mapIndexes ) {
277
- if ( mapIndex . range [ 0 ] <= index && index < mapIndex . range [ 1 ] ) {
278
- start = sourceCode . getLocFromIndex ( mapIndex . remap ( index ) )
279
- break
280
- }
282
+ const remapped = remapIndex ( index )
283
+ if ( remapped ) {
284
+ start = sourceCode . getLocFromIndex ( remapped )
281
285
}
282
286
}
283
287
if ( points . end ) {
284
288
const index = locs . getIndexFromLoc ( points . end )
285
- for ( const mapIndex of this . mapIndexes ) {
286
- if ( mapIndex . range [ 0 ] <= index && index <= mapIndex . range [ 1 ] ) {
287
- end = sourceCode . getLocFromIndex ( mapIndex . remap ( index ) )
288
- break
289
- }
289
+ const remapped = remapIndex ( index - 1 /* include index */ )
290
+ if ( remapped ) {
291
+ end = sourceCode . getLocFromIndex ( remapped + 1 /* restore */ )
290
292
}
291
293
}
292
294
293
295
return { start, end }
296
+
297
+ /** remap index */
298
+ function remapIndex ( index : number ) {
299
+ for ( const mapIndex of mapIndexes ) {
300
+ if ( mapIndex . range [ 0 ] <= index && index < mapIndex . range [ 1 ] ) {
301
+ return mapIndex . remap ( index )
302
+ }
303
+ }
304
+ return null
305
+ }
294
306
}
295
307
}
296
308
0 commit comments