@@ -16,19 +16,16 @@ export interface DetectedToken {
1616interface Pattern {
1717 kind : 'url' | 'path' ;
1818 re : RegExp ;
19- /** When true, trailing-punctuation stripping is skipped — the pattern's
20- * trailing characters are significant (e.g. error-location `:line:col`). */
21- skipStrip ?: boolean ;
2219}
2320
2421const PATTERNS : Pattern [ ] = [
25- { kind : 'url' , re : / ^ h t t p s ? : \/ \/ \ S+ $ / } ,
26- { kind : 'url' , re : / ^ f i l e : \/ \/ \ S+ $ / } ,
27- { kind : 'path' , re : / ^ \ S+ : \d + ( : \d + ) ? $ / , skipStrip : true } , // error-location first (so it beats generic path)
28- { kind : 'path' , re : / ^ ~ \/ \ S* $ / } ,
29- { kind : 'path' , re : / ^ \/ \ S+ $ / } ,
30- { kind : 'path' , re : / ^ \. \. ? \/ \ S* $ / } ,
31- { kind : 'path' , re : / ^ [ A - Z a - z ] : \\ \S * $ / } ,
22+ { kind : 'url' , re : new RegExp ( ' ^https?://\\ S+$' ) } ,
23+ { kind : 'url' , re : new RegExp ( ' ^file://\\ S+$' ) } ,
24+ { kind : 'path' , re : new RegExp ( '^\\ S+:\\ d+(:\\ d+)?$' ) } , // error-location first (so it beats generic path)
25+ { kind : 'path' , re : new RegExp ( '^~/\\ S*$' ) } ,
26+ { kind : 'path' , re : new RegExp ( '^/\\ S+$' ) } ,
27+ { kind : 'path' , re : new RegExp ( '^\\.{1,2}/\\ S*$' ) } ,
28+ { kind : 'path' , re : new RegExp ( ' ^[A-Za-z]:\\\\\\ S*$' ) } ,
3229] ;
3330
3431const TRAILING_PUNCT = / [ . , ; : ! ? ' " ] + $ / ;
@@ -88,11 +85,16 @@ export function detectTokenAt(line: string, col: number): DetectedToken | null {
8885 const raw = line . slice ( start , end ) ;
8986 if ( ! raw ) return null ;
9087
91- for ( const { kind, re, skipStrip } of PATTERNS ) {
92- if ( ! re . test ( raw ) ) continue ;
93- const text = skipStrip ? raw : stripTrailing ( raw ) ;
94- if ( ! text ) continue ;
95- return { kind, start, end : start + text . length , text } ;
88+ // Strip trailing punctuation once, then test all patterns against the
89+ // cleaned token. This ensures error-location patterns like `file:42` are
90+ // found even when the original token had a trailing period (e.g. in
91+ // compiler output "Error at src/foo.ts:42.").
92+ const cleaned = stripTrailing ( raw ) ;
93+ if ( ! cleaned ) return null ;
94+
95+ for ( const { kind, re } of PATTERNS ) {
96+ if ( ! re . test ( cleaned ) ) continue ;
97+ return { kind, start, end : start + cleaned . length , text : cleaned } ;
9698 }
9799 return null ;
98100}
0 commit comments