This commit is contained in:
flowmemo 2016-12-24 00:20:46 +08:00
parent 20097d7961
commit e32c62039e
2 changed files with 30 additions and 0 deletions

View File

@ -245,6 +245,9 @@ namespace ts.formatting {
public NoSpaceAfterTypeAssertion: Rule;
public SpaceAfterTypeAssertion: Rule;
// No space before non-null assertion operator
public NoSpaceBeforeNonNullAssertionOperator: Rule;
constructor() {
///
/// Common Rules
@ -410,6 +413,9 @@ namespace ts.formatting {
this.NoSpaceBeforeEqualInJsxAttribute = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.EqualsToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterEqualInJsxAttribute = new Rule(RuleDescriptor.create3(SyntaxKind.EqualsToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
// No space before non-null assertion operator
this.NoSpaceBeforeNonNullAssertionOperator = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.ExclamationToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonNullAssertionContext), RuleAction.Delete));
// These rules are higher in priority than user-configurable rules.
this.HighPriorityCommonRules = [
this.IgnoreBeforeComment, this.IgnoreAfterLineComment,
@ -456,6 +462,7 @@ namespace ts.formatting {
this.SpaceBeforeAt,
this.NoSpaceAfterAt,
this.SpaceAfterDecorator,
this.NoSpaceBeforeNonNullAssertionOperator
];
// These rules are lower in priority than user-configurable rules.
@ -882,5 +889,9 @@ namespace ts.formatting {
static IsYieldOrYieldStarWithOperand(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.YieldExpression && (<YieldExpression>context.contextNode).expression !== undefined;
}
static IsNonNullAssertionContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.NonNullExpression;
}
}
}

View File

@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
/////*1*/'bar'!;
/////*2*/('bar')!;
/////*3*/'bar'[1]!;
/////*4*/var bar = 'bar'.foo!;
/////*5*/var foo = bar!;
format.document();
goTo.marker('1');
verify.currentLineContentIs("'bar'!;");
goTo.marker('2');
verify.currentLineContentIs("('bar')!;");
goTo.marker('3');
verify.currentLineContentIs("'bar'[1]!;");
goTo.marker('4');
verify.currentLineContentIs("var bar = 'bar'.foo!;");
goTo.marker('5');
verify.currentLineContentIs("var foo = bar!;");