indent inside mapped type

This commit is contained in:
Kagami Sascha Rosylight 2016-12-21 21:01:47 +09:00
parent bc59d6242b
commit f4c33aaec4
3 changed files with 17 additions and 2 deletions

View file

@ -488,14 +488,16 @@ namespace ts.formatting {
// open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent
case SyntaxKind.OpenBraceToken:
case SyntaxKind.CloseBraceToken:
case SyntaxKind.OpenBracketToken:
case SyntaxKind.CloseBracketToken:
case SyntaxKind.OpenParenToken:
case SyntaxKind.CloseParenToken:
case SyntaxKind.ElseKeyword:
case SyntaxKind.WhileKeyword:
case SyntaxKind.AtToken:
return indentation;
case SyntaxKind.OpenBracketToken:
case SyntaxKind.CloseBracketToken:
return (container.kind === SyntaxKind.MappedType) ?
indentation + getEffectiveDelta(delta, container) : indentation;
default:
// if token line equals to the line of containing node (this is a first token in the node) - use node indentation
return nodeStartLine !== line ? indentation + getEffectiveDelta(delta, container) : indentation;

View file

@ -438,6 +438,7 @@ namespace ts.formatting {
case SyntaxKind.ModuleBlock:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.TypeLiteral:
case SyntaxKind.MappedType:
case SyntaxKind.TupleType:
case SyntaxKind.CaseBlock:
case SyntaxKind.DefaultClause:

View file

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />
/////*generic*/type t < T > = {
/////*map*/ [ P in keyof T ] : T [ P ]
////};
format.document();
goTo.marker("generic");
verify.currentLineContentIs("type t<T> = {");
goTo.marker("map");
verify.currentLineContentIs(" [P in keyof T]: T[P]");