@@ -7,6 +7,7 @@ export type ParsedFileLocation = {
77const FILE_LOCATION_SUFFIX_PATTERN = / ^ ( .* ?) : ( \d + ) (?: : ( \d + ) ) ? $ / ;
88const FILE_LOCATION_RANGE_SUFFIX_PATTERN = / ^ ( .* ?) : ( \d + ) - ( \d + ) $ / ;
99const FILE_LOCATION_HASH_PATTERN = / ^ ( .* ?) # L ( \d + ) (?: C ( \d + ) ) ? $ / i;
10+ const FILE_URL_LOCATION_HASH_PATTERN = / ^ # L ( \d + ) (?: C ( \d + ) ) ? $ / i;
1011
1112export const FILE_LINK_SUFFIX_SOURCE =
1213 "(?:(?::\\d+(?::\\d+)?|:\\d+-\\d+)|(?:#L\\d+(?:C\\d+)?))?" ;
@@ -27,8 +28,21 @@ function decodeURIComponentSafely(value: string) {
2728 }
2829}
2930
30- function normalizeRecognizedFileUrlHash ( hash : string ) {
31- return FILE_LOCATION_HASH_PATTERN . test ( hash ) ? hash : "" ;
31+ function parseRecognizedFileUrlHash ( hash : string ) {
32+ const match = hash . match ( FILE_URL_LOCATION_HASH_PATTERN ) ;
33+ if ( ! match ) {
34+ return {
35+ line : null ,
36+ column : null ,
37+ } ;
38+ }
39+
40+ const [ , lineValue , columnValue ] = match ;
41+ const line = parsePositiveInteger ( lineValue ) ;
42+ return {
43+ line,
44+ column : line === null ? null : parsePositiveInteger ( columnValue ) ,
45+ } ;
3246}
3347
3448function buildLocalPathFromFileUrl ( host : string , pathname : string ) {
@@ -272,15 +286,15 @@ export function fromFileUrl(url: string) {
272286 }
273287
274288 const path = buildLocalPathFromFileUrl ( parsed . host , parsed . pathname ) ;
275- const normalizedHash = normalizeRecognizedFileUrlHash ( parsed . hash ) ;
276- return normalizeFileLinkPath ( ` ${ path } ${ normalizedHash } ` ) ;
289+ const { line , column } = parseRecognizedFileUrlHash ( parsed . hash ) ;
290+ return formatFileLocation ( path , line , column ) ;
277291 } catch {
278292 const manualParts = parseManualFileUrl ( url ) ;
279293 if ( ! manualParts ) {
280294 return null ;
281295 }
282296 const path = buildLocalPathFromFileUrl ( manualParts . host , manualParts . pathname ) ;
283- const normalizedHash = normalizeRecognizedFileUrlHash ( manualParts . hash ) ;
284- return normalizeFileLinkPath ( ` ${ path } ${ normalizedHash } ` ) ;
297+ const { line , column } = parseRecognizedFileUrlHash ( manualParts . hash ) ;
298+ return formatFileLocation ( path , line , column ) ;
285299 }
286300}
0 commit comments