Also skip TemplateHeads

This commit is contained in:
Andrew Branch 2019-04-11 12:47:10 -07:00
parent fd88e52252
commit 039487c84e
No known key found for this signature in database
GPG key ID: 22CCA4B120C427D2
2 changed files with 14 additions and 3 deletions

View file

@ -2136,7 +2136,7 @@ namespace ts.server {
// TemplateSpans, along with the SyntaxLists containing them,
// are a somewhat unintuitive grouping of things that should be
// considered independently. Dive in without pushing a selection range.
if (isBlock(node) || isTemplateSpan(node) || prevNode && isTemplateHead(prevNode)) {
if (isBlock(node) || isTemplateSpan(node) || isTemplateHead(node) || prevNode && isTemplateHead(prevNode)) {
parentNode = node;
break;
}

View file

@ -273,7 +273,10 @@ type X = {
it("works for string literals and template strings", () => {
// tslint:disable-next-line:no-invalid-template-strings
const getSelectionRange = setup("/file.ts", "`a b ${\n 'c'\n} d`");
const locations = getSelectionRange([{ line: 2, offset: 4 }]);
const locations = getSelectionRange([
{ line: 2, offset: 4 },
{ line: 1, offset: 4 },
]);
assert.deepEqual(locations, [
{
textSpan: { // c
@ -298,7 +301,15 @@ type X = {
parent: {
textSpan: { // whole template string
start: { line: 1, offset: 1 },
end: { line: 3, offset: 5 } } } } } } }
end: { line: 3, offset: 5 } } } } } } },
{
textSpan: { // whole template string without backticks
start: { line: 1, offset: 2 },
end: { line: 3, offset: 4 } },
parent: {
textSpan: { // whole template string
start: { line: 1, offset: 1 },
end: { line: 3, offset: 5 } } } },
]);
});