Added flowCommaSeparator option for object types (#3547)

This commit is contained in:
Sam Pepose 2016-11-15 13:43:42 -06:00 committed by Henry Zhu
parent 6a6ec8785b
commit db85bdc3fc
6 changed files with 31 additions and 2 deletions

View File

@ -37,6 +37,7 @@ minified | boolean | `false` | Should the output be minif
concise | boolean | `false` | Set to `true` to reduce whitespace (but not as much as `opts.compact`)
quotes | `'single'` or `'double'` | autodetect based on `ast.tokens` | The type of quote to use in the output
filename | string | | Used in warning messages
flowCommaSeparator | boolean | `false` | Set to `true` to use commas instead of semicolons as Flow property separators
Options for source maps:

View File

@ -274,7 +274,11 @@ export function ObjectTypeAnnotation(node: Object) {
statement: true,
iterator: () => {
if (props.length !== 1) {
this.semicolon();
if (this.format.flowCommaSeparator) {
this.token(",");
} else {
this.semicolon();
}
this.space();
}
}

View File

@ -63,7 +63,8 @@ function normalizeOptions(code, opts, tokens): Format {
adjustMultilineComment: true,
style: style,
base: 0
}
},
flowCommaSeparator: opts.flowCommaSeparator,
};
if (format.minified) {

View File

@ -0,0 +1,10 @@
var a: { numVal: number };
var a: { numVal: number; };
var a: { numVal: number; [indexer: string]: number };
var a: ?{ numVal: number };
var a: { numVal: number; strVal: string }
var a: { subObj: {strVal: string} }
var a: { subObj: ?{strVal: string} }
var a: { param1: number; param2: string }
var a: { param1: number; param2?: string }
var a: { [a: number]: string; [b: number]: string; };

View File

@ -0,0 +1,10 @@
var a: { numVal: number };
var a: { numVal: number };
var a: { numVal: number, [indexer: string]: number, };
var a: ?{ numVal: number };
var a: { numVal: number, strVal: string, };
var a: { subObj: { strVal: string } };
var a: { subObj: ?{ strVal: string } };
var a: { param1: number, param2: string, };
var a: { param1: number, param2?: string, };
var a: { [a: number]: string, [b: number]: string, };

View File

@ -0,0 +1,3 @@
{
"flowCommaSeparator": true
}