Skip to content
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

Fix adding trailing comma in TS tuples #6199

Merged
merged 1 commit into from Jun 7, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/language-js/printer-estree.js
Expand Up @@ -2487,7 +2487,7 @@ function printPathNoParens(path, options, print, args) {
printArrayItems(path, options, typesField, print)
])
),
ifBreak(shouldPrintComma(options) ? "," : ""),
ifBreak(shouldPrintComma(options, "all") ? "," : ""),
comments.printDanglingComments(path, options, /* sameIndent */ true),
softline,
"]"
Expand Down
71 changes: 71 additions & 0 deletions tests/typescript_tuple/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -44,6 +44,47 @@ exports[`trailing-comma.ts 2`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "es5"
| printWidth
=====================================input======================================
export interface ShopQueryResult {
chic: boolean;
location: number[];
menus: Menu[];
openingDays: number[];
closingDays: [
{
from: string,
to: string,
}, // <== this one
];
shop: string;
distance: number;
}

=====================================output=====================================
export interface ShopQueryResult {
chic: boolean;
location: number[];
menus: Menu[];
openingDays: number[];
closingDays: [
{
from: string;
to: string;
} // <== this one
];
shop: string;
distance: number;
}

================================================================================
`;

exports[`trailing-comma.ts 3`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
Expand Down Expand Up @@ -114,6 +155,36 @@ exports[`tuple.ts 2`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "es5"
| printWidth
=====================================input======================================

export type SCMRawResource = [
number /*handle*/,
string /*resourceUri*/,
modes.Command /*command*/,
string[] /*icons: light, dark*/,
boolean /*strike through*/,
boolean /*faded*/
];

=====================================output=====================================
export type SCMRawResource = [
number /*handle*/,
string /*resourceUri*/,
modes.Command /*command*/,
string[] /*icons: light, dark*/,
boolean /*strike through*/,
boolean /*faded*/
];

================================================================================
`;

exports[`tuple.ts 3`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
Expand Down
1 change: 1 addition & 0 deletions tests/typescript_tuple/jsfmt.spec.js
@@ -1,2 +1,3 @@
run_spec(__dirname, ["typescript"]);
run_spec(__dirname, ["typescript"], { trailingComma: "es5" });
run_spec(__dirname, ["typescript"], { trailingComma: "all" });