Skip to content

Commit 42e08f5

Browse files
author
Andy
authored
findAllRefs: Find string references inside of template strings (#16723)
1 parent c51c2ae commit 42e08f5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/compiler/utilities.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,19 @@ namespace ts {
47434743
|| kind === SyntaxKind.TemplateTail;
47444744
}
47454745

4746+
export function isStringTextContainingNode(node: Node) {
4747+
switch (node.kind) {
4748+
case SyntaxKind.StringLiteral:
4749+
case SyntaxKind.TemplateHead:
4750+
case SyntaxKind.TemplateMiddle:
4751+
case SyntaxKind.TemplateTail:
4752+
case SyntaxKind.NoSubstitutionTemplateLiteral:
4753+
return true;
4754+
default:
4755+
return false;
4756+
}
4757+
}
4758+
47464759
// Identifiers
47474760

47484761
/* @internal */

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ namespace ts {
787787

788788
export function isInString(sourceFile: SourceFile, position: number): boolean {
789789
const previousToken = findPrecedingToken(position, sourceFile);
790-
if (previousToken && previousToken.kind === SyntaxKind.StringLiteral) {
790+
if (previousToken && isStringTextContainingNode(previousToken)) {
791791
const start = previousToken.getStart();
792792
const end = previousToken.getEnd();
793793

tests/cases/fourslash/renameCommentsAndStrings4.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
///////<reference path="./Bar.ts" />
44

5-
////function /**/[|Bar|]() {
5+
////function [|Bar|]() {
66
//// // This is a reference to [|Bar|] in a comment.
7-
//// "this is a reference to [|Bar|] in a string"
7+
//// "this is a reference to [|Bar|] in a string";
8+
//// `Foo [|Bar|] Baz.`;
9+
//// {
10+
//// const Bar = 0;
11+
//// `[|Bar|] ba ${Bar} bara [|Bar|] berbobo ${Bar} araura [|Bar|] ara!`;
12+
//// }
813
////}
914

1015
const ranges = test.ranges();

0 commit comments

Comments
 (0)