Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace ts.formatting {
RuleAction.Delete),

// decorators
rule("SpaceBeforeAt", anyToken, SyntaxKind.AtToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
rule("SpaceBeforeAt", anyToken, SyntaxKind.AtToken, [isNonJsxSameLineTokenContext, isNotDecoratorWithFirstParameterContext], RuleAction.Space),
rule("NoSpaceAfterAt", SyntaxKind.AtToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
// Insert space after @ in decorator
rule("SpaceAfterDecorator",
Expand Down Expand Up @@ -720,4 +720,13 @@ namespace ts.formatting {
function isNonNullAssertionContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.NonNullExpression;
}

function isDecoratorWithFirstParameterContext(context: FormattingContext): boolean {
return context.currentTokenSpan.kind === SyntaxKind.OpenParenToken && context.nextTokenParent.kind === SyntaxKind.Decorator &&
context.nextTokenParent.parent && context.nextTokenParent.parent.kind === SyntaxKind.Parameter;
}

function isNotDecoratorWithFirstParameterContext(context: FormattingContext): boolean {
return !isDecoratorWithFirstParameterContext(context);
}
}
12 changes: 12 additions & 0 deletions tests/cases/fourslash/formattingParameterWithDecorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts' />

/////*1*/function (@foo a: any, @bar b: any) { }
/////*2*/class Test { constructor(@foo props: any, @bar b: any) { } }

format.document();

goTo.marker('1');
verify.currentLineContentIs('function (@foo a: any, @bar b: any) { }');

goTo.marker('2');
verify.currentLineContentIs('class Test { constructor(@foo props: any, @bar b: any) { } }');