@@ -205,36 +205,41 @@ export default createRule("valid-compile", {
205205 } {
206206 decoded ??= decode ( JSON . parse ( output . sourceMapText ! ) . mappings )
207207
208- const lineMaps = decoded [ pos . line ]
208+ const lineMaps = decoded [ pos . line - 1 ]
209209
210210 if ( ! lineMaps ?. length ) {
211211 for ( let line = pos . line - 1 ; line >= 0 ; line -- ) {
212212 const prevLineMaps = decoded [ line ]
213213 if ( prevLineMaps ?. length ) {
214- const [ , , remapLine , remapCol ] =
214+ const [ , , sourceCodeLine , sourceCodeColumn ] =
215215 prevLineMaps [ prevLineMaps . length - 1 ]
216216 return {
217- line : remapLine ! ,
218- column : remapCol ! ,
217+ line : sourceCodeLine ! + 1 ,
218+ column : sourceCodeColumn ! ,
219219 }
220220 }
221221 }
222222 return { line : - 1 , column : - 1 }
223223 }
224224
225225 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+ ) {
228232 return {
229- line : remapLine ! ,
230- column : remapCol ! ,
233+ line : sourceCodeLine ! + 1 ,
234+ column : sourceCodeColumn ! + ( pos . column - generateCodeColumn ) ,
231235 }
232236 }
233237 }
234- const [ , , remapLine , remapCol ] = lineMaps [ lineMaps . length - 1 ]
238+ const [ generateCodeColumn , , sourceCodeLine , sourceCodeColumn ] =
239+ lineMaps [ lineMaps . length - 1 ]
235240 return {
236- line : remapLine ! ,
237- column : remapCol ! ,
241+ line : sourceCodeLine ! + 1 ,
242+ column : sourceCodeColumn ! + ( pos . column - generateCodeColumn ) ,
238243 }
239244 }
240245 }
@@ -258,6 +263,7 @@ export default createRule("valid-compile", {
258263 column : number
259264 }
260265 } {
266+ const mapIndexes = this . mapIndexes
261267 const locs = ( this . locs ??= new LinesAndColumns ( this . code ) )
262268 let start :
263269 | {
@@ -273,24 +279,30 @@ export default createRule("valid-compile", {
273279 | undefined = undefined
274280 if ( points . start ) {
275281 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 )
281285 }
282286 }
283287 if ( points . end ) {
284288 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 */ )
290292 }
291293 }
292294
293295 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+ }
294306 }
295307 }
296308
0 commit comments