fix(52177): Wrong space in type assertions when using array (#52184)

This commit is contained in:
Oleksandr T
2023-01-12 00:59:22 +02:00
committed by GitHub
parent a05b7ec01f
commit 6860373c1a
2 changed files with 29 additions and 5 deletions

View File

@@ -240,11 +240,12 @@ export function getAllRules(): RuleSpec[] {
rule("NoSpaceBetweenCloseParenAndAngularBracket", SyntaxKind.CloseParenToken, SyntaxKind.LessThanToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], RuleAction.DeleteSpace),
rule("NoSpaceAfterOpenAngularBracket", SyntaxKind.LessThanToken, anyToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], RuleAction.DeleteSpace),
rule("NoSpaceBeforeCloseAngularBracket", anyToken, SyntaxKind.GreaterThanToken, [isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext], RuleAction.DeleteSpace),
rule("NoSpaceAfterCloseAngularBracket",
SyntaxKind.GreaterThanToken,
[SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken],
[isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext, isNotFunctionDeclContext /*To prevent an interference with the SpaceBeforeOpenParenInFuncDecl rule*/],
RuleAction.DeleteSpace),
rule("NoSpaceAfterCloseAngularBracket", SyntaxKind.GreaterThanToken, [SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken], [
isNonJsxSameLineTokenContext,
isTypeArgumentOrParameterOrAssertionContext,
isNotFunctionDeclContext /*To prevent an interference with the SpaceBeforeOpenParenInFuncDecl rule*/,
isNonTypeAssertionContext
], RuleAction.DeleteSpace),
// decorators
rule("SpaceBeforeAt", [SyntaxKind.CloseParenToken, SyntaxKind.Identifier], SyntaxKind.AtToken, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
@@ -835,6 +836,10 @@ function isTypeAssertionContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.TypeAssertionExpression;
}
function isNonTypeAssertionContext(context: FormattingContext): boolean {
return !isTypeAssertionContext(context);
}
function isVoidOpContext(context: FormattingContext): boolean {
return context.currentTokenSpan.kind === SyntaxKind.VoidKeyword && context.currentTokenParent.kind === SyntaxKind.VoidExpression;
}