File tree Expand file tree Collapse file tree 6 files changed +44
-5
lines changed Expand file tree Collapse file tree 6 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -1847,6 +1847,10 @@ namespace ts {
1847
1847
return getSourceTextOfNodeFromSourceFile ( sourceFile , str ) . charCodeAt ( 0 ) === CharacterCodes . doubleQuote ;
1848
1848
}
1849
1849
1850
+ export function isSingleOrDoubleQuoteOrBacktick ( charCode : number ) {
1851
+ return charCode === CharacterCodes . singleQuote || charCode === CharacterCodes . doubleQuote || charCode === CharacterCodes . backtick ;
1852
+ }
1853
+
1850
1854
export function getDeclarationOfExpando ( node : Node ) : Node | undefined {
1851
1855
if ( ! node . parent ) {
1852
1856
return undefined ;
@@ -3236,6 +3240,14 @@ namespace ts {
3236
3240
return isSingleOrDoubleQuote ( name . charCodeAt ( 0 ) ) ;
3237
3241
}
3238
3242
3243
+ export function stripQuotesOrBacktics ( name : string ) {
3244
+ const length = name . length ;
3245
+ if ( length >= 2 && name . charCodeAt ( 0 ) === name . charCodeAt ( length - 1 ) && isSingleOrDoubleQuoteOrBacktick ( name . charCodeAt ( 0 ) ) ) {
3246
+ return name . substring ( 1 , length - 1 ) ;
3247
+ }
3248
+ return name ;
3249
+ }
3250
+
3239
3251
function getReplacement ( c : string , offset : number , input : string ) {
3240
3252
if ( c . charCodeAt ( 0 ) === CharacterCodes . nullCharacter ) {
3241
3253
const lookAhead = input . charCodeAt ( offset + c . length ) ;
Original file line number Diff line number Diff line change @@ -448,7 +448,7 @@ namespace ts.FindAllReferences {
448
448
function getTextSpan ( node : Node , sourceFile : SourceFile , endNode ?: Node ) : TextSpan {
449
449
let start = node . getStart ( sourceFile ) ;
450
450
let end = ( endNode || node ) . getEnd ( ) ;
451
- if ( node . kind === SyntaxKind . StringLiteral ) {
451
+ if ( isStringLiteralLike ( node ) ) {
452
452
Debug . assert ( endNode === undefined ) ;
453
453
start += 1 ;
454
454
end -= 1 ;
@@ -1234,8 +1234,9 @@ namespace ts.FindAllReferences.Core {
1234
1234
case SyntaxKind . Identifier :
1235
1235
return ( node as Identifier ) . text . length === searchSymbolName . length ;
1236
1236
1237
+ case SyntaxKind . NoSubstitutionTemplateLiteral :
1237
1238
case SyntaxKind . StringLiteral : {
1238
- const str = node as StringLiteral ;
1239
+ const str = node as StringLiteralLike ;
1239
1240
return ( isLiteralNameOfPropertyDeclarationOrIndexAccess ( str ) || isNameOfModuleDeclaration ( node ) || isExpressionOfExternalModuleImportEqualsDeclaration ( node ) || ( isCallExpression ( node . parent ) && isBindableObjectDefinePropertyCall ( node . parent ) && node . parent . arguments [ 1 ] === node ) ) &&
1240
1241
str . text . length === searchSymbolName . length ;
1241
1242
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ namespace ts.Rename {
31
31
32
32
const kind = SymbolDisplay . getSymbolKind ( typeChecker , symbol , node ) ;
33
33
const specifierName = ( isImportOrExportSpecifierName ( node ) || isStringOrNumericLiteralLike ( node ) && node . parent . kind === SyntaxKind . ComputedPropertyName )
34
- ? stripQuotes ( getTextOfIdentifierOrLiteral ( node ) )
34
+ ? stripQuotesOrBacktics ( getTextOfIdentifierOrLiteral ( node ) )
35
35
: undefined ;
36
36
const displayName = specifierName || typeChecker . symbolToString ( symbol ) ;
37
37
const fullDisplayName = specifierName || typeChecker . getFullyQualifiedName ( symbol ) ;
@@ -81,7 +81,7 @@ namespace ts.Rename {
81
81
function createTriggerSpanForNode ( node : Node , sourceFile : SourceFile ) {
82
82
let start = node . getStart ( sourceFile ) ;
83
83
let width = node . getWidth ( sourceFile ) ;
84
- if ( node . kind === SyntaxKind . StringLiteral ) {
84
+ if ( isStringLiteralLike ( node ) ) {
85
85
// Exclude the quotes
86
86
start += 1 ;
87
87
width -= 2 ;
@@ -93,6 +93,7 @@ namespace ts.Rename {
93
93
switch ( node . kind ) {
94
94
case SyntaxKind . Identifier :
95
95
case SyntaxKind . StringLiteral :
96
+ case SyntaxKind . NoSubstitutionTemplateLiteral :
96
97
case SyntaxKind . ThisKeyword :
97
98
return true ;
98
99
case SyntaxKind . NumericLiteral :
Original file line number Diff line number Diff line change @@ -2227,6 +2227,7 @@ namespace ts {
2227
2227
function getContainingObjectLiteralElementWorker ( node : Node ) : ObjectLiteralElement | undefined {
2228
2228
switch ( node . kind ) {
2229
2229
case SyntaxKind . StringLiteral :
2230
+ case SyntaxKind . NoSubstitutionTemplateLiteral :
2230
2231
case SyntaxKind . NumericLiteral :
2231
2232
if ( node . parent . kind === SyntaxKind . ComputedPropertyName ) {
2232
2233
return isObjectLiteralElement ( node . parent . parent ) ? node . parent . parent : undefined ;
Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ namespace ts {
267
267
isFunctionLike ( node . parent ) && ( < FunctionLikeDeclaration > node . parent ) . name === node ;
268
268
}
269
269
270
- export function isLiteralNameOfPropertyDeclarationOrIndexAccess ( node : StringLiteral | NumericLiteral ) : boolean {
270
+ export function isLiteralNameOfPropertyDeclarationOrIndexAccess ( node : StringLiteral | NumericLiteral | NoSubstitutionTemplateLiteral ) : boolean {
271
271
switch ( node . parent . kind ) {
272
272
case SyntaxKind . PropertyDeclaration :
273
273
case SyntaxKind . PropertySignature :
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ ////var o = {
4
+ //// [|[`[|{| "contextRangeIndex": 0 |}tplProp|]`]: 0|],
5
+ //// [|['[|{| "contextRangeIndex": 2 |}strProp|]']: 0|]
6
+ //// };
7
+ ////
8
+ ////o = {
9
+ //// [|[`[|{| "contextRangeIndex": 4 |}tplProp|]`]: 1|],
10
+ //// [|['[|{| "contextRangeIndex": 6 |}strProp|]']: 1|]
11
+ //// };
12
+ ////
13
+ ////o.[|tplProp|];
14
+ ////o['[|tplProp|]'];
15
+ ////o["[|tplProp|]"];
16
+ ////o[`[|tplProp|]`];
17
+ ////
18
+ ////o.[|strProp|];
19
+ ////o['[|strProp|]'];
20
+ ////o["[|strProp|]"];
21
+ ////o[`[|strProp|]`];
22
+
23
+ verify . rangesWithSameTextAreRenameLocations ( "tplProp" ) ;
24
+ verify . rangesWithSameTextAreRenameLocations ( "strProp" ) ;
You can’t perform that action at this time.
0 commit comments