mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-27 04:48:33 -05:00
Fixed formatting on script blocks, added regrestion tests, fixed minor bugs
This commit is contained in:
@@ -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<true>();
|
||||
/* 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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
31
tests/cases/fourslash/formatSimulatingScriptBlocks.ts
Normal file
31
tests/cases/fourslash/formatSimulatingScriptBlocks.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
/////* 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 */");
|
||||
@@ -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');
|
||||
verify.currentLineContentIs(' // This is a comment');
|
||||
Reference in New Issue
Block a user