diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 7c4ccc7c960..429362ab6cb 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -2066,8 +2066,8 @@ namespace Harness { export function runMultifileBaseline(relativeFileBase: string, extension: string, generateContent: () => IterableIterator<[string, string, number]> | IterableIterator<[string, string]>, opts?: BaselineOptions, referencedExtensions?: string[]): void { const gen = generateContent(); const writtenFiles = ts.createMap(); - /* tslint:disable-next-line:no-null-keyword */ const errors: Error[] = []; + // tslint:disable-next-line:no-null-keyword if (gen !== null) { for (let {done, value} = gen.next(); !done; { done, value } = gen.next()) { const [name, content, count] = value as [string, string, number | undefined]; diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 5f26990d3a4..1d1deb57fc8 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -663,9 +663,9 @@ namespace ts.formatting { undecoratedChildStartLine = sourceFile.getLineAndCharacterOfPosition(getNonDecoratorTokenPosOfNode(child, sourceFile)).line; } - // if child is a list item - try to get its indentation + // if child is a list item - try to get its indentation, only if parent is within the original range. let childIndentationAmount = Constants.Unknown; - if (isListItem) { + if (isListItem && parent.pos >= originalRange.pos && parent.end <= originalRange.end) { childIndentationAmount = tryComputeIndentationForListItem(childStartPos, child.end, parentStartLine, originalRange, inheritedIndentation); if (childIndentationAmount !== Constants.Unknown) { inheritedIndentation = childIndentationAmount; diff --git a/tests/cases/fourslash/formatSimulatingScriptBlocks.ts b/tests/cases/fourslash/formatSimulatingScriptBlocks.ts new file mode 100644 index 00000000000..dd64f587a98 --- /dev/null +++ b/tests/cases/fourslash/formatSimulatingScriptBlocks.ts @@ -0,0 +1,31 @@ +/// + +/////* BEGIN EXTERNAL SOURCE */ +/////*begin5*/ +//// var a = 1; +//// alert("/*end5*//********//*begin4*/"); +//// /*end4*/ +/////* END EXTERNAL SOURCE */ +//// +/////* BEGIN EXTERNAL SOURCE */ +/////*begin3*/ +//// var b = 1; +//// +//// var c = "/*end3*//********//*begin2*/"; +//// var d = 1; +//// +//// var e = "/*end2*//********//*begin1*/"; +//// var f = 1; +//// /*end1*/ +/////* END EXTERNAL SOURCE */ + +format.setOption("BaseIndentSize", 12); +format.selection("begin1", "end1"); +format.selection("begin2", "end2"); +format.selection("begin3", "end3"); + +format.setOption("BaseIndentSize", 24); +format.selection("begin4", "end4"); +format.selection("begin5", "end5"); + +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 */"); diff --git a/tests/cases/fourslash/formattingAfterMultiLineIfCondition.ts b/tests/cases/fourslash/formattingAfterMultiLineIfCondition.ts index 21812b0b2b3..c19c3e76fea 100644 --- a/tests/cases/fourslash/formattingAfterMultiLineIfCondition.ts +++ b/tests/cases/fourslash/formattingAfterMultiLineIfCondition.ts @@ -3,7 +3,7 @@ //// var foo; //// if (foo && //// foo) { -/////*comment*/ // This is a comment +/////*comment*/ // This is a comment //// foo.toString(); //// /**/ @@ -11,4 +11,4 @@ goTo.marker(); edit.insert('}'); goTo.marker('comment'); // Comment below multi-line 'if' condition formatting -verify.currentLineContentIs(' // This is a comment'); \ No newline at end of file +verify.currentLineContentIs(' // This is a comment'); \ No newline at end of file