add template literal spans (#34699)

This commit is contained in:
Wenlu Wang 2019-10-31 01:54:00 -05:00 committed by Daniel Rosenwasser
parent 9cc0fcd3da
commit 234680851b
2 changed files with 30 additions and 0 deletions

View File

@ -202,6 +202,9 @@ namespace ts.OutliningElementsCollector {
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.JsxOpeningElement:
return spanForJSXAttributes((<JsxOpeningLikeElement>n).attributes);
case SyntaxKind.TemplateExpression:
case SyntaxKind.NoSubstitutionTemplateLiteral:
return spanForTemplateLiteral(<TemplateExpression | NoSubstitutionTemplateLiteral>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.

View File

@ -0,0 +1,20 @@
/// <reference path="fourslash.ts"/>
//// 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());