diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 6e5e2b963e8..ce0fe7b28be 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -202,6 +202,9 @@ namespace ts.OutliningElementsCollector { case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxOpeningElement: return spanForJSXAttributes((n).attributes); + case SyntaxKind.TemplateExpression: + case SyntaxKind.NoSubstitutionTemplateLiteral: + return spanForTemplateLiteral(n); } function spanForJSXElement(node: JsxElement): OutliningSpan | undefined { @@ -225,6 +228,13 @@ namespace ts.OutliningElementsCollector { return createOutliningSpanFromBounds(node.getStart(sourceFile), node.getEnd(), OutliningSpanKind.Code); } + function spanForTemplateLiteral(node: TemplateExpression | NoSubstitutionTemplateLiteral) { + if (node.kind === SyntaxKind.NoSubstitutionTemplateLiteral && node.text.length === 0) { + return undefined; + } + return createOutliningSpanFromBounds(node.getStart(sourceFile), node.getEnd(), OutliningSpanKind.Code); + } + function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined { // If the block has no leading keywords and is inside an array literal or call expression, // we only want to collapse the span of the block. diff --git a/tests/cases/fourslash/getOutliningSpansForTemplateLiteral.ts b/tests/cases/fourslash/getOutliningSpansForTemplateLiteral.ts new file mode 100644 index 00000000000..f196d6897b6 --- /dev/null +++ b/tests/cases/fourslash/getOutliningSpansForTemplateLiteral.ts @@ -0,0 +1,20 @@ +/// + +//// declare function tag(...args: any[]): void +//// const a = [|`signal line`|] +//// const b = [|`multi +//// line`|] +//// const c = tag[|`signal line`|] +//// const d = tag[|`multi +//// line`|] +//// const e = [|`signal ${1} line`|] +//// const f = [|`multi +//// ${1} +//// line`|] +//// const g = tag[|`signal ${1} line`|] +//// const h = tag[|`multi +//// ${1} +//// line`|] +//// const i = `` + +verify.outliningSpansInCurrentFile(test.ranges());