Skip to content

Commit a16c441

Browse files
authored
fix(37940): add space after parameter decorator (microsoft#37959)
1 parent 6fbaeeb commit a16c441

File tree

8 files changed

+115
-4
lines changed

8 files changed

+115
-4
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4133,7 +4133,7 @@ namespace ts {
41334133
if (closingLineTerminatorCount) {
41344134
writeLine(closingLineTerminatorCount);
41354135
}
4136-
else if (format & ListFormat.SpaceBetweenBraces) {
4136+
else if (format & (ListFormat.SpaceAfterList | ListFormat.SpaceBetweenBraces)) {
41374137
writeSpace();
41384138
}
41394139
}

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6546,6 +6546,7 @@ namespace ts {
65466546

65476547
NoSpaceIfEmpty = 1 << 19, // If the literal is empty, do not add spaces between braces.
65486548
SingleElement = 1 << 20,
6549+
SpaceAfterList = 1 << 21, // Add space after list
65496550

65506551
// Precomputed Formats
65516552
Modifiers = SingleLine | SpaceBetweenSiblings | NoInterveningComments,
@@ -6580,7 +6581,7 @@ namespace ts {
65806581
CaseOrDefaultClauseStatements = Indented | MultiLine | NoTrailingNewLine | OptionalIfEmpty,
65816582
HeritageClauseTypes = CommaDelimited | SpaceBetweenSiblings | SingleLine,
65826583
SourceFileStatements = MultiLine | NoTrailingNewLine,
6583-
Decorators = MultiLine | Optional,
6584+
Decorators = MultiLine | Optional | SpaceAfterList,
65846585
TypeArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional,
65856586
TypeParameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional,
65866587
Parameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,7 @@ declare namespace ts {
32273227
NoInterveningComments = 262144,
32283228
NoSpaceIfEmpty = 524288,
32293229
SingleElement = 1048576,
3230+
SpaceAfterList = 2097152,
32303231
Modifiers = 262656,
32313232
HeritageClauses = 512,
32323233
SingleLineTypeLiteralMembers = 768,
@@ -3258,7 +3259,7 @@ declare namespace ts {
32583259
CaseOrDefaultClauseStatements = 163969,
32593260
HeritageClauseTypes = 528,
32603261
SourceFileStatements = 131073,
3261-
Decorators = 49153,
3262+
Decorators = 2146305,
32623263
TypeArguments = 53776,
32633264
TypeParameters = 53776,
32643265
Parameters = 2576,

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,7 @@ declare namespace ts {
32273227
NoInterveningComments = 262144,
32283228
NoSpaceIfEmpty = 524288,
32293229
SingleElement = 1048576,
3230+
SpaceAfterList = 2097152,
32303231
Modifiers = 262656,
32313232
HeritageClauses = 512,
32323233
SingleLineTypeLiteralMembers = 768,
@@ -3258,7 +3259,7 @@ declare namespace ts {
32583259
CaseOrDefaultClauseStatements = 163969,
32593260
HeritageClauseTypes = 528,
32603261
SourceFileStatements = 131073,
3261-
Decorators = 49153,
3262+
Decorators = 2146305,
32623263
TypeArguments = 53776,
32633264
TypeParameters = 53776,
32643265
Parameters = 2576,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @experimentalDecorators: true
4+
5+
// @Filename: /a.ts
6+
////const decorator1: any = () => {};
7+
////const decorator2: any = () => {};
8+
////[|class Foo {
9+
//// constructor(@decorator1 private readonly x: number,
10+
//// @decorator1 @decorator2 private readonly y: number) { }
11+
////
12+
//// method1(@decorator1 x: number) { }
13+
//// method2(@decorator1 @decorator2 x: number) { }
14+
////}|]
15+
16+
verify.noErrors();
17+
18+
verify.moveToNewFile({
19+
newFileContents: {
20+
"/a.ts":
21+
`const decorator1: any = () => {};
22+
const decorator2: any = () => {};
23+
`,
24+
"/Foo.ts":
25+
`class Foo {
26+
constructor(@decorator1 private readonly x: number,
27+
@decorator1 @decorator2 private readonly y: number) { }
28+
29+
method1(@decorator1 x: number) { }
30+
method2(@decorator1 @decorator2 x: number) { }
31+
}
32+
`
33+
}
34+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @experimentalDecorators: true
4+
5+
// @Filename: /a.ts
6+
////const decorator1: any = () => {};
7+
////const decorator2: any = () => {};
8+
////[|class Foo {
9+
//// @decorator1 method1() { }
10+
//// @decorator1 @decorator2 method2() { }
11+
////}|]
12+
13+
verify.noErrors();
14+
15+
verify.moveToNewFile({
16+
newFileContents: {
17+
"/a.ts":
18+
`const decorator1: any = () => {};
19+
const decorator2: any = () => {};
20+
`,
21+
"/Foo.ts":
22+
`class Foo {
23+
@decorator1 method1() { }
24+
@decorator1 @decorator2 method2() { }
25+
}
26+
`
27+
}
28+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @experimentalDecorators: true
4+
5+
// @Filename: /a.ts
6+
////const decorator1: any = () => {};
7+
////[|@decorator1 class Foo {
8+
////}|]
9+
10+
verify.noErrors();
11+
12+
verify.moveToNewFile({
13+
newFileContents: {
14+
"/a.ts":
15+
`const decorator1: any = () => {};
16+
`,
17+
"/Foo.ts":
18+
`@decorator1 class Foo {
19+
}
20+
`
21+
}
22+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @experimentalDecorators: true
4+
5+
// @Filename: /a.ts
6+
////const decorator1: any = () => {};
7+
////const decorator2: any = () => {};
8+
////[|@decorator1 @decorator2 class Foo {
9+
////}|]
10+
11+
verify.noErrors();
12+
13+
verify.moveToNewFile({
14+
newFileContents: {
15+
"/a.ts":
16+
`const decorator1: any = () => {};
17+
const decorator2: any = () => {};
18+
`,
19+
"/Foo.ts":
20+
`@decorator1 @decorator2 class Foo {
21+
}
22+
`
23+
}
24+
});

0 commit comments

Comments
 (0)