findAllRefs: Find string references inside of template strings (#16723)

This commit is contained in:
Andy 2017-06-28 12:53:12 -07:00 committed by GitHub
parent c51c2aecca
commit 42e08f5578
3 changed files with 21 additions and 3 deletions

View File

@ -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 */

View File

@ -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();

View File

@ -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();