fix(56665): Improve Outline for template literals (#56667)

This commit is contained in:
Oleksandr T 2023-12-15 19:04:07 +02:00 committed by GitHub
parent 2c7162143b
commit 22bee05d8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 6 deletions

View File

@ -84,6 +84,7 @@ import {
isStatic,
isStringLiteralLike,
isStringOrNumericLiteralLike,
isTemplateLiteral,
isToken,
isVariableDeclaration,
lastOrUndefined,
@ -1057,7 +1058,7 @@ function getFunctionOrClassName(node: FunctionExpression | FunctionDeclaration |
return `${name} callback`;
}
const args = cleanText(mapDefined(parent.arguments, a => isStringLiteralLike(a) ? a.getText(curSourceFile) : undefined).join(", "));
const args = cleanText(mapDefined(parent.arguments, a => isStringLiteralLike(a) || isTemplateLiteral(a) ? a.getText(curSourceFile) : undefined).join(", "));
return `${name}(${args}) callback`;
}
}

View File

@ -18,7 +18,7 @@
//// // These will only show up as childItems.
//// function z() {}
//// console.log(function() {})
//// describe("this", 'function', `is a function`, `but this ${"wont"} show`, () => {});
//// describe("this", 'function', `is a function`, `with template literal ${"a"}`, () => {});
//// [].map(() => {});
////})
////(function classes() {
@ -77,11 +77,11 @@ verify.navigationTree({
"kind": "function"
},
{
"text": `describe("this", 'function', \`is a function\`) callback`,
"text": "describe(\"this\", 'function', `is a function`, `with template literal ${\"a\"}`) callback",
"kind": "function"
},
{
"text": `map() callback`,
"text": "map() callback",
"kind": "function"
},
{
@ -199,11 +199,11 @@ verify.navigationBar([
"kind": "function"
},
{
"text": `describe("this", 'function', \`is a function\`) callback`,
"text": "describe(\"this\", 'function', `is a function`, `with template literal ${\"a\"}`) callback",
"kind": "function"
},
{
"text": `map() callback`,
"text": "map() callback",
"kind": "function"
},
{

View File

@ -0,0 +1,93 @@
/// <reference path="fourslash.ts"/>
////describe('foo', () => {
//// test(`a ${1} b ${2}`, () => {})
////})
////
////const a = 1;
////const b = 2;
////describe('foo', () => {
//// test(`a ${a} b {b}`, () => {})
////})
verify.navigationTree({
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "a",
"kind": "const"
},
{
"text": "b",
"kind": "const"
},
{
"text": "describe('foo') callback",
"kind": "function",
"childItems": [
{
"text": "test(`a ${1} b ${2}`) callback",
"kind": "function"
}
]
},
{
"text": "describe('foo') callback",
"kind": "function",
"childItems": [
{
"text": "test(`a ${a} b {b}`) callback",
"kind": "function"
}
]
}
]
});
verify.navigationBar([
{
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "a",
"kind": "const"
},
{
"text": "b",
"kind": "const"
},
{
"text": "describe('foo') callback",
"kind": "function"
},
{
"text": "describe('foo') callback",
"kind": "function"
}
]
},
{
"text": "describe('foo') callback",
"kind": "function",
"childItems": [
{
"text": "test(`a ${1} b ${2}`) callback",
"kind": "function"
}
],
"indent": 1
},
{
"text": "describe('foo') callback",
"kind": "function",
"childItems": [
{
"text": "test(`a ${a} b {b}`) callback",
"kind": "function"
}
],
"indent": 1
}
]);