mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(52177): Wrong space in type assertions when using array (#52184)
This commit is contained in:
parent
a05b7ec01f
commit
6860373c1a
@ -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;
|
||||
}
|
||||
|
||||
19
tests/cases/fourslash/formatInsertSpaceAfterTypeAssertion.ts
Normal file
19
tests/cases/fourslash/formatInsertSpaceAfterTypeAssertion.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////let a = <string> "";
|
||||
////let b = <number> 1;
|
||||
////let c = <any[]> [];
|
||||
////let d = <string[]> [];
|
||||
////let e = <string[]> ["e"];
|
||||
|
||||
format.setFormatOptions({
|
||||
insertSpaceAfterTypeAssertion: true,
|
||||
})
|
||||
format.document();
|
||||
verify.currentFileContentIs(
|
||||
`let a=<string> "";
|
||||
let b=<number> 1;
|
||||
let c=<any[]> [];
|
||||
let d=<string[]> [];
|
||||
let e=<string[]> ["e"];`
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user