Merge pull request #8364 from zhengbli/i7503
Fix indentation for array items
This commit is contained in:
commit
3fb16f5930
|
@ -567,7 +567,8 @@ namespace ts.formatting {
|
|||
parentDynamicIndentation: DynamicIndentation,
|
||||
parentStartLine: number,
|
||||
undecoratedParentStartLine: number,
|
||||
isListItem: boolean): number {
|
||||
isListItem: boolean,
|
||||
isFirstListItem?: boolean): number {
|
||||
|
||||
let childStartPos = child.getStart(sourceFile);
|
||||
|
||||
|
@ -626,6 +627,10 @@ namespace ts.formatting {
|
|||
|
||||
childContextNode = node;
|
||||
|
||||
if (isFirstListItem && parent.kind === SyntaxKind.ArrayLiteralExpression && inheritedIndentation === Constants.Unknown) {
|
||||
inheritedIndentation = childIndentation.indentation;
|
||||
}
|
||||
|
||||
return inheritedIndentation;
|
||||
}
|
||||
|
||||
|
@ -665,8 +670,9 @@ namespace ts.formatting {
|
|||
}
|
||||
|
||||
let inheritedIndentation = Constants.Unknown;
|
||||
for (let child of nodes) {
|
||||
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true)
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const child = nodes[i];
|
||||
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true, /*isFirstListItem*/ i === 0);
|
||||
}
|
||||
|
||||
if (listEndToken !== SyntaxKind.Unknown) {
|
||||
|
|
43
tests/cases/fourslash/formatArrayLiteralExpression.ts
Normal file
43
tests/cases/fourslash/formatArrayLiteralExpression.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
///<reference path='fourslash.ts' />
|
||||
|
||||
////export let Things = [{
|
||||
//// Hat: 'hat', /*1*/
|
||||
//// Glove: 'glove',
|
||||
//// Umbrella: 'umbrella'
|
||||
////},{/*2*/
|
||||
//// Salad: 'salad', /*3*/
|
||||
//// Burrito: 'burrito',
|
||||
//// Pie: 'pie'
|
||||
//// }];/*4*/
|
||||
////
|
||||
////export let Things2 = [
|
||||
////{
|
||||
//// Hat: 'hat', /*5*/
|
||||
//// Glove: 'glove',
|
||||
//// Umbrella: 'umbrella'
|
||||
////}/*6*/,
|
||||
//// {
|
||||
//// Salad: 'salad', /*7*/
|
||||
//// Burrito: 'burrito',
|
||||
//// Pie: 'pie'
|
||||
//// }];/*8*/
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("1");
|
||||
verify.currentLineContentIs(" Hat: 'hat',");
|
||||
goTo.marker("2");
|
||||
verify.currentLineContentIs("}, {");
|
||||
goTo.marker("3");
|
||||
verify.currentLineContentIs(" Salad: 'salad',");
|
||||
goTo.marker("4");
|
||||
verify.currentLineContentIs("}];");
|
||||
|
||||
goTo.marker("5");
|
||||
verify.currentLineContentIs(" Hat: 'hat',");
|
||||
goTo.marker("6");
|
||||
verify.currentLineContentIs(" },");
|
||||
goTo.marker("7");
|
||||
verify.currentLineContentIs(" Salad: 'salad',");
|
||||
goTo.marker("8");
|
||||
verify.currentLineContentIs(" }];");
|
Loading…
Reference in a new issue