mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
fix(35179): formatter incorrectly remove spaces (#35979)
This commit is contained in:
parent
a8944e6844
commit
4585f448a9
@ -70,8 +70,8 @@ namespace ts.formatting {
|
||||
rule("NoSpaceAfterUnaryPrefixOperator", unaryPrefixOperators, unaryPrefixExpressions, [isNonJsxSameLineTokenContext, isNotBinaryOpContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceAfterUnaryPreincrementOperator", SyntaxKind.PlusPlusToken, unaryPreincrementExpressions, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceAfterUnaryPredecrementOperator", SyntaxKind.MinusMinusToken, unaryPredecrementExpressions, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceBeforeUnaryPostincrementOperator", unaryPostincrementExpressions, SyntaxKind.PlusPlusToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceBeforeUnaryPostdecrementOperator", unaryPostdecrementExpressions, SyntaxKind.MinusMinusToken, [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceBeforeUnaryPostincrementOperator", unaryPostincrementExpressions, SyntaxKind.PlusPlusToken, [isNonJsxSameLineTokenContext, isNotStatementConditionContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceBeforeUnaryPostdecrementOperator", unaryPostdecrementExpressions, SyntaxKind.MinusMinusToken, [isNonJsxSameLineTokenContext, isNotStatementConditionContext], RuleAction.DeleteSpace),
|
||||
|
||||
// More unary operator special-casing.
|
||||
// DevDiv 181814: Be careful when removing leading whitespace
|
||||
@ -790,6 +790,25 @@ namespace ts.formatting {
|
||||
return context.contextNode.kind === SyntaxKind.NonNullExpression;
|
||||
}
|
||||
|
||||
function isNotStatementConditionContext(context: FormattingContext): boolean {
|
||||
return !isStatementConditionContext(context);
|
||||
}
|
||||
|
||||
function isStatementConditionContext(context: FormattingContext): boolean {
|
||||
switch (context.contextNode.kind) {
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForOfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isSemicolonDeletionContext(context: FormattingContext): boolean {
|
||||
let nextTokenKind = context.nextTokenSpan.kind;
|
||||
let nextTokenStart = context.nextTokenSpan.pos;
|
||||
|
||||
49
tests/cases/fourslash/spaceAfterStatementConditions.ts
Normal file
49
tests/cases/fourslash/spaceAfterStatementConditions.ts
Normal file
@ -0,0 +1,49 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////let i = 0;
|
||||
////
|
||||
////if(i<0) ++i;
|
||||
////if(i<0) --i;
|
||||
////
|
||||
////while(i<0) ++i;
|
||||
////while(i<0) --i;
|
||||
////
|
||||
////do ++i;
|
||||
////while(i<0)
|
||||
////do --i;
|
||||
////while(i<0)
|
||||
////
|
||||
////for(let prop in { foo: 1 }) ++i;
|
||||
////for(let prop in { foo: 1 }) --i;
|
||||
////
|
||||
////for(let foo of [1, 2]) ++i;
|
||||
////for(let foo of [1, 2]) --i;
|
||||
////
|
||||
////for(let j = 0; j < 10; j++) ++i;
|
||||
////for(let j = 0; j < 10; j++) --i;
|
||||
////
|
||||
|
||||
format.document();
|
||||
verify.currentFileContentIs(
|
||||
`let i = 0;
|
||||
|
||||
if (i < 0) ++i;
|
||||
if (i < 0) --i;
|
||||
|
||||
while (i < 0) ++i;
|
||||
while (i < 0) --i;
|
||||
|
||||
do ++i;
|
||||
while (i < 0)
|
||||
do --i;
|
||||
while (i < 0)
|
||||
|
||||
for (let prop in { foo: 1 }) ++i;
|
||||
for (let prop in { foo: 1 }) --i;
|
||||
|
||||
for (let foo of [1, 2]) ++i;
|
||||
for (let foo of [1, 2]) --i;
|
||||
|
||||
for (let j = 0; j < 10; j++) ++i;
|
||||
for (let j = 0; j < 10; j++) --i;
|
||||
`);
|
||||
Loading…
x
Reference in New Issue
Block a user