Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/services/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ namespace ts.formatting {

processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta);

if (child.kind === SyntaxKind.JsxText) {
const range: TextRange = { pos: child.getStart(), end: child.getEnd() };
indentMultilineCommentOrJsxText(range, childIndentation.indentation, /*firstLineIsIndented*/ true, /*indentFinalLine*/ false);
}

childContextNode = node;

if (isFirstListItem && parent.kind === SyntaxKind.ArrayLiteralExpression && inheritedIndentation === Constants.Unknown) {
Expand Down Expand Up @@ -833,7 +838,7 @@ namespace ts.formatting {
switch (triviaItem.kind) {
case SyntaxKind.MultiLineCommentTrivia:
if (triviaInRange) {
indentMultilineComment(triviaItem, commentIndentation, /*firstLineIsIndented*/ !indentNextTokenOrTrivia);
indentMultilineCommentOrJsxText(triviaItem, commentIndentation, /*firstLineIsIndented*/ !indentNextTokenOrTrivia);
}
indentNextTokenOrTrivia = false;
break;
Expand Down Expand Up @@ -985,7 +990,7 @@ namespace ts.formatting {
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
}

function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
function indentMultilineCommentOrJsxText(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean, indentFinalLine = true) {
// split comment in lines
let startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line;
const endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line;
Expand All @@ -1006,7 +1011,9 @@ namespace ts.formatting {
startPos = getStartPositionOfLine(line + 1, sourceFile);
}

parts.push({ pos: startPos, end: commentRange.end });
if (indentFinalLine) {
parts.push({ pos: startPos, end: commentRange.end });
}
}

const startLinePos = getStartPositionOfLine(startLine, sourceFile);
Expand Down
35 changes: 35 additions & 0 deletions tests/cases/fourslash/indentationInJsx3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference path='fourslash.ts' />

//@Filename: file.tsx
////function foo() {
//// return (
//// <div>
////hello
////goodbye
//// </div>
//// )
////}

verify.currentFileContentIs(
`function foo() {
return (
<div>
hello
goodbye
</div>
)
}`
);

format.document();

verify.currentFileContentIs(
`function foo() {
return (
<div>
hello
goodbye
</div>
)
}`
);