Skip to content

Commit cb9cacf

Browse files
committed
Merge branch 'master' of https://github.com/gnalck/TypeScript into gnalck-master
2 parents 97d8632 + 2b72751 commit cb9cacf

7 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/harness/fourslash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ namespace FourSlash {
363363
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
364364
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
365365
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
366+
InsertSpaceAfterTypeAssertion: false,
366367
PlaceOpenBraceOnNewLineForFunctions: false,
367368
PlaceOpenBraceOnNewLineForControlBlocks: false,
368369
};

src/server/editorServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,7 @@ namespace ts.server {
15971597
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
15981598
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
15991599
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
1600+
InsertSpaceAfterTypeAssertion: false,
16001601
PlaceOpenBraceOnNewLineForFunctions: false,
16011602
PlaceOpenBraceOnNewLineForControlBlocks: false,
16021603
});

src/services/formatting/rules.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ namespace ts.formatting {
138138
public NoSpaceAfterOpenAngularBracket: Rule;
139139
public NoSpaceBeforeCloseAngularBracket: Rule;
140140
public NoSpaceAfterCloseAngularBracket: Rule;
141-
public NoSpaceAfterTypeAssertion: Rule;
142141

143142
// Remove spaces in empty interface literals. e.g.: x: {}
144143
public NoSpaceBetweenEmptyInterfaceBraceBrackets: Rule;
@@ -240,6 +239,10 @@ namespace ts.formatting {
240239
public NoSpaceBeforeEqualInJsxAttribute: Rule;
241240
public NoSpaceAfterEqualInJsxAttribute: Rule;
242241

242+
// No space after type assertions
243+
public NoSpaceAfterTypeAssertion: Rule;
244+
public SpaceAfterTypeAssertion: Rule;
245+
243246
constructor() {
244247
///
245248
/// Common Rules
@@ -375,7 +378,6 @@ namespace ts.formatting {
375378
this.NoSpaceAfterOpenAngularBracket = new Rule(RuleDescriptor.create3(SyntaxKind.LessThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
376379
this.NoSpaceBeforeCloseAngularBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.GreaterThanToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
377380
this.NoSpaceAfterCloseAngularBracket = new Rule(RuleDescriptor.create3(SyntaxKind.GreaterThanToken, Shared.TokenRange.FromTokens([SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
378-
this.NoSpaceAfterTypeAssertion = new Rule(RuleDescriptor.create3(SyntaxKind.GreaterThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeAssertionContext), RuleAction.Delete));
379381

380382
// Remove spaces in empty interface literals. e.g.: x: {}
381383
this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsObjectTypeContext), RuleAction.Delete));
@@ -447,7 +449,6 @@ namespace ts.formatting {
447449
this.NoSpaceAfterOpenAngularBracket,
448450
this.NoSpaceBeforeCloseAngularBracket,
449451
this.NoSpaceAfterCloseAngularBracket,
450-
this.NoSpaceAfterTypeAssertion,
451452
this.SpaceBeforeAt,
452453
this.NoSpaceAfterAt,
453454
this.SpaceAfterDecorator,
@@ -526,6 +527,11 @@ namespace ts.formatting {
526527
// Insert space after function keyword for anonymous functions
527528
this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
528529
this.NoSpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Delete));
530+
531+
// No space after type assertion
532+
this.NoSpaceAfterTypeAssertion = new Rule(RuleDescriptor.create3(SyntaxKind.GreaterThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeAssertionContext), RuleAction.Delete));
533+
this.SpaceAfterTypeAssertion = new Rule(RuleDescriptor.create3(SyntaxKind.GreaterThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeAssertionContext), RuleAction.Space));
534+
529535
}
530536

531537
///

src/services/formatting/rulesProvider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,16 @@ namespace ts.formatting {
137137
rules.push(this.globalRules.NewLineBeforeOpenBraceInTypeScriptDeclWithBlock);
138138
}
139139

140+
if (options.InsertSpaceAfterTypeAssertion) {
141+
rules.push(this.globalRules.SpaceAfterTypeAssertion);
142+
}
143+
else {
144+
rules.push(this.globalRules.NoSpaceAfterTypeAssertion);
145+
}
146+
140147
rules = rules.concat(this.globalRules.LowPriorityCommonRules);
141148

142149
return rules;
143150
}
144151
}
145-
}
152+
}

src/services/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ namespace ts {
353353
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
354354
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean;
355355
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
356+
InsertSpaceAfterTypeAssertion?: boolean;
356357
PlaceOpenBraceOnNewLineForFunctions: boolean;
357358
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
358359
[s: string]: boolean | number | string | undefined;

tests/cases/fourslash/formattingOptionsChange.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis*/(1 )
99
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets*/[1 ]; [ ]; []; [,];
1010
/////*InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces*/`${1}`;`${ 1 }`
11+
/////*InsertSpaceAfterTypeAssertion*/const bar = <Bar> Thing.getFoo();
1112
/////*PlaceOpenBraceOnNewLineForFunctions*/class foo {
1213
////}
1314
/////*PlaceOpenBraceOnNewLineForControlBlocks*/if (true) {
@@ -22,6 +23,7 @@ runTest("InsertSpaceAfterFunctionKeywordForAnonymousFunctions", "(function () {
2223
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", " ( 1 )", " (1)");
2324
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets", "[ 1 ];[];[];[ , ];", "[1];[];[];[,];");
2425
runTest("InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", "`${ 1 }`; `${ 1 }`", "`${1}`; `${1}`");
26+
runTest("InsertSpaceAfterTypeAssertion", "const bar = <Bar> Thing.getFoo();", "const bar = <Bar>Thing.getFoo();");
2527
runTest("PlaceOpenBraceOnNewLineForFunctions", "class foo", "class foo {");
2628
runTest("PlaceOpenBraceOnNewLineForControlBlocks", "if ( true )", "if ( true ) {");
2729
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces", "{ var t = 1 };", "{var t = 1};");

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ declare namespace FourSlashInterface {
8383
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
8484
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
8585
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean;
86+
InsertSpaceAfterTypeAssertion: boolean;
8687
PlaceOpenBraceOnNewLineForFunctions: boolean;
8788
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
8889
[s: string]: boolean | number | string | undefined;

0 commit comments

Comments
 (0)