mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 15:25:54 -06:00
findAllRefs: Find string references inside of template strings (#16723)
This commit is contained in:
parent
c51c2aecca
commit
42e08f5578
@ -4743,6 +4743,19 @@ namespace ts {
|
||||
|| kind === SyntaxKind.TemplateTail;
|
||||
}
|
||||
|
||||
export function isStringTextContainingNode(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Identifiers
|
||||
|
||||
/* @internal */
|
||||
|
||||
@ -787,7 +787,7 @@ namespace ts {
|
||||
|
||||
export function isInString(sourceFile: SourceFile, position: number): boolean {
|
||||
const previousToken = findPrecedingToken(position, sourceFile);
|
||||
if (previousToken && previousToken.kind === SyntaxKind.StringLiteral) {
|
||||
if (previousToken && isStringTextContainingNode(previousToken)) {
|
||||
const start = previousToken.getStart();
|
||||
const end = previousToken.getEnd();
|
||||
|
||||
|
||||
@ -2,9 +2,14 @@
|
||||
|
||||
///////<reference path="./Bar.ts" />
|
||||
|
||||
////function /**/[|Bar|]() {
|
||||
////function [|Bar|]() {
|
||||
//// // This is a reference to [|Bar|] in a comment.
|
||||
//// "this is a reference to [|Bar|] in a string"
|
||||
//// "this is a reference to [|Bar|] in a string";
|
||||
//// `Foo [|Bar|] Baz.`;
|
||||
//// {
|
||||
//// const Bar = 0;
|
||||
//// `[|Bar|] ba ${Bar} bara [|Bar|] berbobo ${Bar} araura [|Bar|] ara!`;
|
||||
//// }
|
||||
////}
|
||||
|
||||
const ranges = test.ranges();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user