mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
fix #11676
This commit is contained in:
parent
20097d7961
commit
e32c62039e
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
tests/cases/fourslash/formattingNonNullAssertionOperator.ts
Normal file
19
tests/cases/fourslash/formattingNonNullAssertionOperator.ts
Normal 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!;");
|
||||
Loading…
x
Reference in New Issue
Block a user