Skip to content

fix(37940): 'Move to new file' refactoring removes spaces between decorator and property modifiers #37959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2020
Merged
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
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4132,7 +4132,7 @@ namespace ts {
if (closingLineTerminatorCount) {
writeLine(closingLineTerminatorCount);
}
else if (format & ListFormat.SpaceBetweenBraces) {
else if (format & (ListFormat.SpaceAfterList | ListFormat.SpaceBetweenBraces)) {
writeSpace();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6545,6 +6545,7 @@ namespace ts {

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

// Precomputed Formats
Modifiers = SingleLine | SpaceBetweenSiblings | NoInterveningComments,
Expand Down Expand Up @@ -6579,7 +6580,7 @@ namespace ts {
CaseOrDefaultClauseStatements = Indented | MultiLine | NoTrailingNewLine | OptionalIfEmpty,
HeritageClauseTypes = CommaDelimited | SpaceBetweenSiblings | SingleLine,
SourceFileStatements = MultiLine | NoTrailingNewLine,
Decorators = MultiLine | Optional,
Decorators = MultiLine | Optional | SpaceAfterList,
TypeArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional,
TypeParameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | AngleBrackets | Optional,
Parameters = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,7 @@ declare namespace ts {
NoInterveningComments = 262144,
NoSpaceIfEmpty = 524288,
SingleElement = 1048576,
SpaceAfterList = 2097152,
Modifiers = 262656,
HeritageClauses = 512,
SingleLineTypeLiteralMembers = 768,
Expand Down Expand Up @@ -3258,7 +3259,7 @@ declare namespace ts {
CaseOrDefaultClauseStatements = 163969,
HeritageClauseTypes = 528,
SourceFileStatements = 131073,
Decorators = 49153,
Decorators = 2146305,
TypeArguments = 53776,
TypeParameters = 53776,
Parameters = 2576,
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,7 @@ declare namespace ts {
NoInterveningComments = 262144,
NoSpaceIfEmpty = 524288,
SingleElement = 1048576,
SpaceAfterList = 2097152,
Modifiers = 262656,
HeritageClauses = 512,
SingleLineTypeLiteralMembers = 768,
Expand Down Expand Up @@ -3258,7 +3259,7 @@ declare namespace ts {
CaseOrDefaultClauseStatements = 163969,
HeritageClauseTypes = 528,
SourceFileStatements = 131073,
Decorators = 49153,
Decorators = 2146305,
TypeArguments = 53776,
TypeParameters = 53776,
Parameters = 2576,
Expand Down
34 changes: 34 additions & 0 deletions tests/cases/fourslash/moveToNewFile_decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// <reference path='fourslash.ts' />

// @experimentalDecorators: true

// @Filename: /a.ts
////const decorator1: any = () => {};
////const decorator2: any = () => {};
////[|class Foo {
//// constructor(@decorator1 private readonly x: number,
//// @decorator1 @decorator2 private readonly y: number) { }
////
//// method1(@decorator1 x: number) { }
//// method2(@decorator1 @decorator2 x: number) { }
////}|]

verify.noErrors();

verify.moveToNewFile({
newFileContents: {
"/a.ts":
`const decorator1: any = () => {};
const decorator2: any = () => {};
`,
"/Foo.ts":
`class Foo {
constructor(@decorator1 private readonly x: number,
@decorator1 @decorator2 private readonly y: number) { }

method1(@decorator1 x: number) { }
method2(@decorator1 @decorator2 x: number) { }
}
`
}
});
28 changes: 28 additions & 0 deletions tests/cases/fourslash/moveToNewFile_decorators1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference path='fourslash.ts' />

// @experimentalDecorators: true

// @Filename: /a.ts
////const decorator1: any = () => {};
////const decorator2: any = () => {};
////[|class Foo {
//// @decorator1 method1() { }
//// @decorator1 @decorator2 method2() { }
////}|]

verify.noErrors();

verify.moveToNewFile({
newFileContents: {
"/a.ts":
`const decorator1: any = () => {};
const decorator2: any = () => {};
`,
"/Foo.ts":
`class Foo {
@decorator1 method1() { }
@decorator1 @decorator2 method2() { }
}
`
}
});
22 changes: 22 additions & 0 deletions tests/cases/fourslash/moveToNewFile_decorators2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path='fourslash.ts' />

// @experimentalDecorators: true

// @Filename: /a.ts
////const decorator1: any = () => {};
////[|@decorator1 class Foo {
////}|]

verify.noErrors();

verify.moveToNewFile({
newFileContents: {
"/a.ts":
`const decorator1: any = () => {};
`,
"/Foo.ts":
`@decorator1 class Foo {
}
`
}
});
24 changes: 24 additions & 0 deletions tests/cases/fourslash/moveToNewFile_decorators3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />

// @experimentalDecorators: true

// @Filename: /a.ts
////const decorator1: any = () => {};
////const decorator2: any = () => {};
////[|@decorator1 @decorator2 class Foo {
////}|]

verify.noErrors();

verify.moveToNewFile({
newFileContents: {
"/a.ts":
`const decorator1: any = () => {};
const decorator2: any = () => {};
`,
"/Foo.ts":
`@decorator1 @decorator2 class Foo {
}
`
}
});