@@ -7,7 +7,13 @@ import {
7
7
isInHTMLTagRange ,
8
8
getNodeIfIsInHTMLStartTag
9
9
} from '../../../lib/documents' ;
10
- import { filterAsync , isNotNullOrUndefined , pathToUrl , unique } from '../../../utils' ;
10
+ import {
11
+ createGetCanonicalFileName ,
12
+ filterAsync ,
13
+ isNotNullOrUndefined ,
14
+ pathToUrl ,
15
+ unique
16
+ } from '../../../utils' ;
11
17
import { RenameProvider } from '../../interfaces' ;
12
18
import { DocumentSnapshot , SvelteDocumentSnapshot } from '../DocumentSnapshot' ;
13
19
import { convertRange } from '../utils' ;
@@ -18,7 +24,6 @@ import {
18
24
isAfterSvelte2TsxPropsReturn ,
19
25
isTextSpanInGeneratedCode ,
20
26
SnapshotMap ,
21
- findContainingNode ,
22
27
isStoreVariableIn$storeDeclaration ,
23
28
get$storeOffsetOf$storeDeclaration ,
24
29
getStoreOffsetOf$storeDeclaration ,
@@ -113,7 +118,8 @@ export class RenameProviderImpl implements RenameProvider {
113
118
: await this . getAdditionalLocationsForRenameOfPropInsideOtherComponent (
114
119
convertedRenameLocations ,
115
120
docs ,
116
- lang
121
+ lang ,
122
+ tsDoc . filePath
117
123
) ;
118
124
convertedRenameLocations = [
119
125
...convertedRenameLocations ,
@@ -211,7 +217,7 @@ export class RenameProviderImpl implements RenameProvider {
211
217
if (
212
218
isStoreVariableIn$storeDeclaration ( snapshot . getFullText ( ) , loc . textSpan . start )
213
219
) {
214
- // User renamed store, also rename correspondig $store locations
220
+ // User renamed store, also rename corresponding $store locations
215
221
const storeRenameLocations = lang . findRenameLocations (
216
222
snapshot . filePath ,
217
223
get$storeOffsetOf$storeDeclaration (
@@ -268,8 +274,14 @@ export class RenameProviderImpl implements RenameProvider {
268
274
) {
269
275
// First find out if it's really the "rename prop inside component with that prop" case
270
276
// Use original document for that because only there the `export` is present.
277
+ // ':' for typescript's type operator (`export let bla: boolean`)
278
+ // '//' and '/*' for comments (`export let bla// comment` or `export let bla/* comment */`)
271
279
const regex = new RegExp (
272
- `export\\s+let\\s+${ this . getVariableAtPosition ( tsDoc , lang , position ) } ($|\\s|;|:)` // ':' for typescript's type operator (`export let bla: boolean`)
280
+ `export\\s+let\\s+${ this . getVariableAtPosition (
281
+ tsDoc ,
282
+ lang ,
283
+ position
284
+ ) } ($|\\s|;|:|\/\*|\/\/)`
273
285
) ;
274
286
const isRenameInsideComponentWithProp = regex . test (
275
287
getLineAtPosition ( position , document . getText ( ) )
@@ -395,7 +407,8 @@ export class RenameProviderImpl implements RenameProvider {
395
407
private async getAdditionalLocationsForRenameOfPropInsideOtherComponent (
396
408
convertedRenameLocations : TsRenameLocation [ ] ,
397
409
snapshots : SnapshotMap ,
398
- lang : ts . LanguageService
410
+ lang : ts . LanguageService ,
411
+ requestedFileName : string
399
412
) {
400
413
// Check if it's a prop rename
401
414
const updatePropLocation = this . findLocationWhichWantsToUpdatePropName (
@@ -405,6 +418,13 @@ export class RenameProviderImpl implements RenameProvider {
405
418
if ( ! updatePropLocation ) {
406
419
return [ ] ;
407
420
}
421
+ const getCanonicalFileName = createGetCanonicalFileName ( ts . sys . useCaseSensitiveFileNames ) ;
422
+ if (
423
+ getCanonicalFileName ( updatePropLocation . fileName ) ===
424
+ getCanonicalFileName ( requestedFileName )
425
+ ) {
426
+ return [ ] ;
427
+ }
408
428
// Find generated `export let`
409
429
const doc = < SvelteDocumentSnapshot > snapshots . get ( updatePropLocation . fileName ) ;
410
430
const match = this . matchGeneratedExportLet ( doc , updatePropLocation ) ;
@@ -430,12 +450,13 @@ export class RenameProviderImpl implements RenameProvider {
430
450
) {
431
451
const regex = new RegExp (
432
452
// no 'export let', only 'let', because that's what it's translated to in svelte2tsx
453
+ // '//' and '/*' for comments (`let bla/*Ωignore_startΩ*/`)
433
454
`\\s+let\\s+(${ snapshot
434
455
. getFullText ( )
435
456
. substring (
436
457
updatePropLocation . textSpan . start ,
437
458
updatePropLocation . textSpan . start + updatePropLocation . textSpan . length
438
- ) } )($|\\s|;|:)`
459
+ ) } )($|\\s|;|:|\/\*|\/\/ )`
439
460
) ;
440
461
const match = snapshot . getFullText ( ) . match ( regex ) ;
441
462
return match ;
@@ -585,7 +606,7 @@ export class RenameProviderImpl implements RenameProvider {
585
606
let rangeStart = parent . offsetAt ( location . range . start ) ;
586
607
let prefixText = location . prefixText ?. trimRight ( ) ;
587
608
588
- // rename needs to be prefixed in case of a bind shortand on a HTML element
609
+ // rename needs to be prefixed in case of a bind shorthand on a HTML element
589
610
if ( ! prefixText ) {
590
611
const original = parent . getText ( {
591
612
start : Position . create (
@@ -634,7 +655,7 @@ export class RenameProviderImpl implements RenameProvider {
634
655
suffixText : '}'
635
656
} ;
636
657
637
- // rename range needs to be adjusted in case of an attribute shortand
658
+ // rename range needs to be adjusted in case of an attribute shorthand
638
659
if ( snapshot . getOriginalText ( ) . charAt ( rangeStart - 1 ) === '{' ) {
639
660
rangeStart -- ;
640
661
const rangeEnd = parent . offsetAt ( location . range . end ) + 1 ;
0 commit comments