Skip to content

Commit 22bee05

Browse files
authored
fix(56665): Improve Outline for template literals (microsoft#56667)
1 parent 2c71621 commit 22bee05

File tree

3 files changed

+100
-6
lines changed

3 files changed

+100
-6
lines changed

src/services/navigationBar.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import {
8484
isStatic,
8585
isStringLiteralLike,
8686
isStringOrNumericLiteralLike,
87+
isTemplateLiteral,
8788
isToken,
8889
isVariableDeclaration,
8990
lastOrUndefined,
@@ -1057,7 +1058,7 @@ function getFunctionOrClassName(node: FunctionExpression | FunctionDeclaration |
10571058
return `${name} callback`;
10581059
}
10591060

1060-
const args = cleanText(mapDefined(parent.arguments, a => isStringLiteralLike(a) ? a.getText(curSourceFile) : undefined).join(", "));
1061+
const args = cleanText(mapDefined(parent.arguments, a => isStringLiteralLike(a) || isTemplateLiteral(a) ? a.getText(curSourceFile) : undefined).join(", "));
10611062
return `${name}(${args}) callback`;
10621063
}
10631064
}

tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//// // These will only show up as childItems.
1919
//// function z() {}
2020
//// console.log(function() {})
21-
//// describe("this", 'function', `is a function`, `but this ${"wont"} show`, () => {});
21+
//// describe("this", 'function', `is a function`, `with template literal ${"a"}`, () => {});
2222
//// [].map(() => {});
2323
////})
2424
////(function classes() {
@@ -77,11 +77,11 @@ verify.navigationTree({
7777
"kind": "function"
7878
},
7979
{
80-
"text": `describe("this", 'function', \`is a function\`) callback`,
80+
"text": "describe(\"this\", 'function', `is a function`, `with template literal ${\"a\"}`) callback",
8181
"kind": "function"
8282
},
8383
{
84-
"text": `map() callback`,
84+
"text": "map() callback",
8585
"kind": "function"
8686
},
8787
{
@@ -199,11 +199,11 @@ verify.navigationBar([
199199
"kind": "function"
200200
},
201201
{
202-
"text": `describe("this", 'function', \`is a function\`) callback`,
202+
"text": "describe(\"this\", 'function', `is a function`, `with template literal ${\"a\"}`) callback",
203203
"kind": "function"
204204
},
205205
{
206-
"text": `map() callback`,
206+
"text": "map() callback",
207207
"kind": "function"
208208
},
209209
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////describe('foo', () => {
4+
//// test(`a ${1} b ${2}`, () => {})
5+
////})
6+
////
7+
////const a = 1;
8+
////const b = 2;
9+
////describe('foo', () => {
10+
//// test(`a ${a} b {b}`, () => {})
11+
////})
12+
13+
verify.navigationTree({
14+
"text": "<global>",
15+
"kind": "script",
16+
"childItems": [
17+
{
18+
"text": "a",
19+
"kind": "const"
20+
},
21+
{
22+
"text": "b",
23+
"kind": "const"
24+
},
25+
{
26+
"text": "describe('foo') callback",
27+
"kind": "function",
28+
"childItems": [
29+
{
30+
"text": "test(`a ${1} b ${2}`) callback",
31+
"kind": "function"
32+
}
33+
]
34+
},
35+
{
36+
"text": "describe('foo') callback",
37+
"kind": "function",
38+
"childItems": [
39+
{
40+
"text": "test(`a ${a} b {b}`) callback",
41+
"kind": "function"
42+
}
43+
]
44+
}
45+
]
46+
});
47+
48+
verify.navigationBar([
49+
{
50+
"text": "<global>",
51+
"kind": "script",
52+
"childItems": [
53+
{
54+
"text": "a",
55+
"kind": "const"
56+
},
57+
{
58+
"text": "b",
59+
"kind": "const"
60+
},
61+
{
62+
"text": "describe('foo') callback",
63+
"kind": "function"
64+
},
65+
{
66+
"text": "describe('foo') callback",
67+
"kind": "function"
68+
}
69+
]
70+
},
71+
{
72+
"text": "describe('foo') callback",
73+
"kind": "function",
74+
"childItems": [
75+
{
76+
"text": "test(`a ${1} b ${2}`) callback",
77+
"kind": "function"
78+
}
79+
],
80+
"indent": 1
81+
},
82+
{
83+
"text": "describe('foo') callback",
84+
"kind": "function",
85+
"childItems": [
86+
{
87+
"text": "test(`a ${a} b {b}`) callback",
88+
"kind": "function"
89+
}
90+
],
91+
"indent": 1
92+
}
93+
]);

0 commit comments

Comments
 (0)