Skip to content

Commit a39110a

Browse files
author
Armando Aguirre
authored
Merge pull request #18806 from armanio123/FixScriptBlockFormatting
Fixed formatting on script blocks
2 parents 1a2de72 + 5225b40 commit a39110a

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,8 +2066,8 @@ namespace Harness {
20662066
export function runMultifileBaseline(relativeFileBase: string, extension: string, generateContent: () => IterableIterator<[string, string, number]> | IterableIterator<[string, string]>, opts?: BaselineOptions, referencedExtensions?: string[]): void {
20672067
const gen = generateContent();
20682068
const writtenFiles = ts.createMap<true>();
2069-
/* tslint:disable-next-line:no-null-keyword */
20702069
const errors: Error[] = [];
2070+
// tslint:disable-next-line:no-null-keyword
20712071
if (gen !== null) {
20722072
for (let {done, value} = gen.next(); !done; { done, value } = gen.next()) {
20732073
const [name, content, count] = value as [string, string, number | undefined];

src/services/formatting/formatting.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,10 @@ namespace ts.formatting {
663663
undecoratedChildStartLine = sourceFile.getLineAndCharacterOfPosition(getNonDecoratorTokenPosOfNode(child, sourceFile)).line;
664664
}
665665

666-
// if child is a list item - try to get its indentation
666+
// if child is a list item - try to get its indentation, only if parent is within the original range.
667667
let childIndentationAmount = Constants.Unknown;
668-
if (isListItem) {
668+
669+
if (isListItem && rangeContainsRange(originalRange, parent)) {
669670
childIndentationAmount = tryComputeIndentationForListItem(childStartPos, child.end, parentStartLine, originalRange, inheritedIndentation);
670671
if (childIndentationAmount !== Constants.Unknown) {
671672
inheritedIndentation = childIndentationAmount;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
/////* BEGIN EXTERNAL SOURCE */
4+
/////*begin5*/
5+
//// var a = 1;
6+
//// alert("/*end5*//********//*begin4*/");
7+
//// /*end4*/
8+
/////* END EXTERNAL SOURCE */
9+
////
10+
/////* BEGIN EXTERNAL SOURCE */
11+
/////*begin3*/
12+
//// var b = 1;
13+
////
14+
//// var c = "/*end3*//********//*begin2*/";
15+
//// var d = 1;
16+
////
17+
//// var e = "/*end2*//********//*begin1*/";
18+
//// var f = 1;
19+
//// /*end1*/
20+
/////* END EXTERNAL SOURCE */
21+
22+
format.setOption("BaseIndentSize", 12);
23+
format.selection("begin1", "end1");
24+
format.selection("begin2", "end2");
25+
format.selection("begin3", "end3");
26+
27+
format.setOption("BaseIndentSize", 24);
28+
format.selection("begin4", "end4");
29+
format.selection("begin5", "end5");
30+
31+
verify.currentFileContentIs("/* BEGIN EXTERNAL SOURCE */\n\n var a = 1;\n alert(\"/********/\");\n\n/* END EXTERNAL SOURCE */\n\n/* BEGIN EXTERNAL SOURCE */\n\n var b = 1;\n\n var c = \"/********/\";\n var d = 1;\n\n var e = \"/********/\";\n var f = 1;\n\n/* END EXTERNAL SOURCE */");

tests/cases/fourslash/formattingAfterMultiLineIfCondition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
//// var foo;
44
//// if (foo &&
55
//// foo) {
6-
/////*comment*/ // This is a comment
6+
/////*comment*/ // This is a comment
77
//// foo.toString();
88
//// /**/
99

1010
goTo.marker();
1111
edit.insert('}');
1212
goTo.marker('comment');
1313
// Comment below multi-line 'if' condition formatting
14-
verify.currentLineContentIs(' // This is a comment');
14+
verify.currentLineContentIs(' // This is a comment');

0 commit comments

Comments
 (0)