forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#22849 from aozgaa/dev/aozgaa/cSharpObjLi…
…teralFormatting CSharp Style Object Literal Formatting
- Loading branch information
Showing
11 changed files
with
206 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/cases/fourslash/codeFixClassImplementInterfaceObjectLiteral.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// interface IPerson { | ||
//// coordinate: { | ||
//// x: number; | ||
//// y: number; | ||
//// } | ||
//// } | ||
//// class Person implements IPerson { } | ||
|
||
verify.codeFix({ | ||
description: "Implement interface 'IPerson'", | ||
newFileContent: | ||
`interface IPerson { | ||
coordinate: { | ||
x: number; | ||
y: number; | ||
} | ||
} | ||
class Person implements IPerson { | ||
coordinate: { x: number; y: number; }; | ||
}`, | ||
}); |
50 changes: 50 additions & 0 deletions
50
tests/cases/fourslash/extract-method-formatting-objectliteral.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// | ||
//// namespace M { | ||
//// class C { | ||
//// foo() { | ||
//// /*a*/let x = {a:1}; | ||
//// let y = { | ||
//// b: 2 | ||
//// }; | ||
//// let z = | ||
//// { | ||
//// c: 3 | ||
//// };/*b*/ | ||
//// return x.a + y.b + z.c; | ||
//// } | ||
//// } | ||
//// } | ||
//// | ||
|
||
goTo.select('a', 'b'); | ||
edit.applyRefactor({ | ||
refactorName: "Extract Symbol", | ||
actionName: "function_scope_1", | ||
actionDescription: "Extract to method in class 'C'", | ||
newContent: | ||
` | ||
namespace M { | ||
class C { | ||
foo() { | ||
let { x, y, z } = this./*RENAME*/newMethod(); | ||
return x.a + y.b + z.c; | ||
} | ||
private newMethod() { | ||
let x = { a: 1 }; | ||
let y = { | ||
b: 2 | ||
}; | ||
let z = { | ||
c: 3 | ||
}; | ||
return { x, y, z }; | ||
} | ||
} | ||
} | ||
` | ||
}); | ||
|
||
|
44 changes: 44 additions & 0 deletions
44
tests/cases/fourslash/formattingObjectLiteralOpenCurlyNewline.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// | ||
//// var clear = | ||
//// { | ||
//// outerKey: | ||
//// { | ||
//// innerKey: 1, | ||
//// innerKey2: | ||
//// 2 | ||
//// } | ||
//// }; | ||
//// | ||
|
||
format.document(); | ||
verify.currentFileContentIs( | ||
` | ||
var clear = | ||
{ | ||
outerKey: | ||
{ | ||
innerKey: 1, | ||
innerKey2: | ||
2 | ||
} | ||
}; | ||
` | ||
); | ||
|
||
format.setOption("indentMultiLineObjectLiteralBeginningOnBlankLine", true); | ||
format.document(); | ||
verify.currentFileContentIs( | ||
` | ||
var clear = | ||
{ | ||
outerKey: | ||
{ | ||
innerKey: 1, | ||
innerKey2: | ||
2 | ||
} | ||
}; | ||
` | ||
); |
36 changes: 36 additions & 0 deletions
36
tests/cases/fourslash/formattingObjectLiteralOpenCurlyNewlineTyping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// | ||
//// var varName =/**/ | ||
//// | ||
|
||
goTo.marker(); | ||
edit.insert("\n{"); | ||
verify.currentFileContentIs( | ||
` | ||
var varName = | ||
{ | ||
` | ||
); | ||
|
||
edit.insert("\na: 1"); | ||
format.document(); | ||
verify.currentFileContentIs( | ||
` | ||
var varName = | ||
{ | ||
a: 1 | ||
` | ||
); | ||
|
||
edit.insert("\n};"); | ||
|
||
format.document(); | ||
verify.currentFileContentIs( | ||
` | ||
var varName = | ||
{ | ||
a: 1 | ||
}; | ||
` | ||
); |
22 changes: 22 additions & 0 deletions
22
tests/cases/fourslash/formattingObjectLiteralOpenCurlySingleLine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
//// | ||
//// let obj1 = | ||
//// { x: 10 }; | ||
//// | ||
//// let obj2 = | ||
//// // leading trivia | ||
//// { y: 10 }; | ||
//// | ||
|
||
format.document(); | ||
verify.currentFileContentIs( | ||
` | ||
let obj1 = | ||
{ x: 10 }; | ||
let obj2 = | ||
// leading trivia | ||
{ y: 10 }; | ||
` | ||
); |