mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
add template literal spans (#34699)
This commit is contained in:
parent
9cc0fcd3da
commit
234680851b
@ -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.
|
||||
|
||||
20
tests/cases/fourslash/getOutliningSpansForTemplateLiteral.ts
Normal file
20
tests/cases/fourslash/getOutliningSpansForTemplateLiteral.ts
Normal 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());
|
||||
Loading…
x
Reference in New Issue
Block a user