@@ -98,7 +98,7 @@ export default function typescriptProvider({negotiateProtocol}) {
9898 path . join ( protocol . projectDir , from ) ,
9999 path . join ( protocol . projectDir , to ) ,
100100 ] ) ;
101- const testFileExtension = new RegExp ( `\\ .(${ extensions . map ( extension => escapeStringRegexp ( extension ) ) . join ( '|' ) } )$`) ;
101+ const testFileExtension = new RegExp ( String . raw `\ .(${ extensions . map ( extension => escapeStringRegexp ( extension ) ) . join ( '|' ) } )$`, 'v' ) ;
102102
103103 const watchMode = {
104104 changeInterpretations,
@@ -128,7 +128,7 @@ export default function typescriptProvider({negotiateProtocol}) {
128128 }
129129
130130 // Only recognize .cjs, .mjs and .js files.
131- if ( ! / \. ( c | m ) ? j s $ / . test ( filePath ) ) {
131+ if ( ! / \. ( c | m ) ? j s $ / v . test ( filePath ) ) {
132132 return null ;
133133 }
134134
@@ -142,11 +142,11 @@ export default function typescriptProvider({negotiateProtocol}) {
142142
143143 if ( filePath . endsWith ( '.cjs' ) ) {
144144 if ( extensions . includes ( 'cjs' ) ) {
145- possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cjs' } ) ;
145+ possibleExtensions . push ( { replace : / \. c j s $ / v , extension : 'cjs' } ) ;
146146 }
147147
148148 if ( extensions . includes ( 'cts' ) ) {
149- possibleExtensions . push ( { replace : / \. c j s $ / , extension : 'cts' } ) ;
149+ possibleExtensions . push ( { replace : / \. c j s $ / v , extension : 'cts' } ) ;
150150 }
151151
152152 if ( possibleExtensions . length === 0 ) {
@@ -156,11 +156,11 @@ export default function typescriptProvider({negotiateProtocol}) {
156156
157157 if ( filePath . endsWith ( '.mjs' ) ) {
158158 if ( extensions . includes ( 'mjs' ) ) {
159- possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mjs' } ) ;
159+ possibleExtensions . push ( { replace : / \. m j s $ / v , extension : 'mjs' } ) ;
160160 }
161161
162162 if ( extensions . includes ( 'mts' ) ) {
163- possibleExtensions . push ( { replace : / \. m j s $ / , extension : 'mts' } ) ;
163+ possibleExtensions . push ( { replace : / \. m j s $ / v , extension : 'mts' } ) ;
164164 }
165165
166166 if ( possibleExtensions . length === 0 ) {
@@ -170,15 +170,15 @@ export default function typescriptProvider({negotiateProtocol}) {
170170
171171 if ( filePath . endsWith ( '.js' ) ) {
172172 if ( extensions . includes ( 'js' ) ) {
173- possibleExtensions . push ( { replace : / \. j s $ / , extension : 'js' } ) ;
173+ possibleExtensions . push ( { replace : / \. j s $ / v , extension : 'js' } ) ;
174174 }
175175
176176 if ( extensions . includes ( 'ts' ) ) {
177- possibleExtensions . push ( { replace : / \. j s $ / , extension : 'ts' } ) ;
177+ possibleExtensions . push ( { replace : / \. j s $ / v , extension : 'ts' } ) ;
178178 }
179179
180180 if ( extensions . includes ( 'tsx' ) ) {
181- possibleExtensions . push ( { replace : / \. j s $ / , extension : 'tsx' } ) ;
181+ possibleExtensions . push ( { replace : / \. j s $ / v , extension : 'tsx' } ) ;
182182 }
183183
184184 if ( possibleExtensions . length === 0 ) {
@@ -245,7 +245,7 @@ export default function typescriptProvider({negotiateProtocol}) {
245245
246246 worker ( { extensionsToLoadAsModules, state : { extensions, rewritePaths} } ) {
247247 const importJs = extensionsToLoadAsModules . includes ( 'js' ) ;
248- const testFileExtension = new RegExp ( `\\ .(${ extensions . map ( extension => escapeStringRegexp ( extension ) ) . join ( '|' ) } )$`) ;
248+ const testFileExtension = new RegExp ( String . raw `\ .(${ extensions . map ( extension => escapeStringRegexp ( extension ) ) . join ( '|' ) } )$`, 'v' ) ;
249249
250250 return {
251251 canLoad ( reference ) {
@@ -257,10 +257,10 @@ export default function typescriptProvider({negotiateProtocol}) {
257257 let rewritten = `${ to } ${ reference . slice ( from . length ) } ` ;
258258 let useImport = true ;
259259 if ( reference . endsWith ( '.cts' ) ) {
260- rewritten = rewritten . replace ( / \. c t s $ / , '.cjs' ) ;
260+ rewritten = rewritten . replace ( / \. c t s $ / v , '.cjs' ) ;
261261 useImport = false ;
262262 } else if ( reference . endsWith ( '.mts' ) ) {
263- rewritten = rewritten . replace ( / \. m t s $ / , '.mjs' ) ;
263+ rewritten = rewritten . replace ( / \. m t s $ / v , '.mjs' ) ;
264264 } else {
265265 rewritten = rewritten . replace ( testFileExtension , '.js' ) ;
266266 useImport = importJs ;
0 commit comments