Skip to content

Commit 2346808

Browse files
KingwlDanielRosenwasser
authored andcommitted
add template literal spans (microsoft#34699)
1 parent 9cc0fcd commit 2346808

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ namespace ts.OutliningElementsCollector {
202202
case SyntaxKind.JsxSelfClosingElement:
203203
case SyntaxKind.JsxOpeningElement:
204204
return spanForJSXAttributes((<JsxOpeningLikeElement>n).attributes);
205+
case SyntaxKind.TemplateExpression:
206+
case SyntaxKind.NoSubstitutionTemplateLiteral:
207+
return spanForTemplateLiteral(<TemplateExpression | NoSubstitutionTemplateLiteral>n);
205208
}
206209

207210
function spanForJSXElement(node: JsxElement): OutliningSpan | undefined {
@@ -225,6 +228,13 @@ namespace ts.OutliningElementsCollector {
225228
return createOutliningSpanFromBounds(node.getStart(sourceFile), node.getEnd(), OutliningSpanKind.Code);
226229
}
227230

231+
function spanForTemplateLiteral(node: TemplateExpression | NoSubstitutionTemplateLiteral) {
232+
if (node.kind === SyntaxKind.NoSubstitutionTemplateLiteral && node.text.length === 0) {
233+
return undefined;
234+
}
235+
return createOutliningSpanFromBounds(node.getStart(sourceFile), node.getEnd(), OutliningSpanKind.Code);
236+
}
237+
228238
function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined {
229239
// If the block has no leading keywords and is inside an array literal or call expression,
230240
// we only want to collapse the span of the block.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// declare function tag(...args: any[]): void
4+
//// const a = [|`signal line`|]
5+
//// const b = [|`multi
6+
//// line`|]
7+
//// const c = tag[|`signal line`|]
8+
//// const d = tag[|`multi
9+
//// line`|]
10+
//// const e = [|`signal ${1} line`|]
11+
//// const f = [|`multi
12+
//// ${1}
13+
//// line`|]
14+
//// const g = tag[|`signal ${1} line`|]
15+
//// const h = tag[|`multi
16+
//// ${1}
17+
//// line`|]
18+
//// const i = ``
19+
20+
verify.outliningSpansInCurrentFile(test.ranges());

0 commit comments

Comments
 (0)