Skip to content

Commit 99b958f

Browse files
committed
Merge branch 'flowmemo-fix-11676'
2 parents e4b81d0 + 914bcfd commit 99b958f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/services/formatting/rules.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ namespace ts.formatting {
245245
public NoSpaceAfterTypeAssertion: Rule;
246246
public SpaceAfterTypeAssertion: Rule;
247247

248+
// No space before non-null assertion operator
249+
public NoSpaceBeforeNonNullAssertionOperator: Rule;
250+
248251
constructor() {
249252
///
250253
/// Common Rules
@@ -410,6 +413,9 @@ namespace ts.formatting {
410413
this.NoSpaceBeforeEqualInJsxAttribute = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.EqualsToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
411414
this.NoSpaceAfterEqualInJsxAttribute = new Rule(RuleDescriptor.create3(SyntaxKind.EqualsToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
412415

416+
// No space before non-null assertion operator
417+
this.NoSpaceBeforeNonNullAssertionOperator = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.ExclamationToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonNullAssertionContext), RuleAction.Delete));
418+
413419
// These rules are higher in priority than user-configurable rules.
414420
this.HighPriorityCommonRules = [
415421
this.IgnoreBeforeComment, this.IgnoreAfterLineComment,
@@ -456,6 +462,7 @@ namespace ts.formatting {
456462
this.SpaceBeforeAt,
457463
this.NoSpaceAfterAt,
458464
this.SpaceAfterDecorator,
465+
this.NoSpaceBeforeNonNullAssertionOperator
459466
];
460467

461468
// These rules are lower in priority than user-configurable rules.
@@ -882,5 +889,9 @@ namespace ts.formatting {
882889
static IsYieldOrYieldStarWithOperand(context: FormattingContext): boolean {
883890
return context.contextNode.kind === SyntaxKind.YieldExpression && (<YieldExpression>context.contextNode).expression !== undefined;
884891
}
892+
893+
static IsNonNullAssertionContext(context: FormattingContext): boolean {
894+
return context.contextNode.kind === SyntaxKind.NonNullExpression;
895+
}
885896
}
886897
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////*1*/'bar'!;
4+
/////*2*/('bar')!;
5+
/////*3*/'bar'[1]!;
6+
/////*4*/var bar = 'bar'.foo!;
7+
/////*5*/var foo = bar!;
8+
9+
format.document();
10+
goTo.marker("1");
11+
verify.currentLineContentIs("'bar'!;");
12+
goTo.marker("2");
13+
verify.currentLineContentIs("('bar')!;");
14+
goTo.marker("3");
15+
verify.currentLineContentIs("'bar'[1]!;");
16+
goTo.marker("4");
17+
verify.currentLineContentIs("var bar = 'bar'.foo!;");
18+
goTo.marker("5");
19+
verify.currentLineContentIs("var foo = bar!;");

0 commit comments

Comments
 (0)