Added flowCommaSeparator option for object types (#3547)
This commit is contained in:
parent
6a6ec8785b
commit
db85bdc3fc
@ -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`)
|
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
|
quotes | `'single'` or `'double'` | autodetect based on `ast.tokens` | The type of quote to use in the output
|
||||||
filename | string | | Used in warning messages
|
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:
|
Options for source maps:
|
||||||
|
|
||||||
|
|||||||
@ -274,7 +274,11 @@ export function ObjectTypeAnnotation(node: Object) {
|
|||||||
statement: true,
|
statement: true,
|
||||||
iterator: () => {
|
iterator: () => {
|
||||||
if (props.length !== 1) {
|
if (props.length !== 1) {
|
||||||
this.semicolon();
|
if (this.format.flowCommaSeparator) {
|
||||||
|
this.token(",");
|
||||||
|
} else {
|
||||||
|
this.semicolon();
|
||||||
|
}
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,8 @@ function normalizeOptions(code, opts, tokens): Format {
|
|||||||
adjustMultilineComment: true,
|
adjustMultilineComment: true,
|
||||||
style: style,
|
style: style,
|
||||||
base: 0
|
base: 0
|
||||||
}
|
},
|
||||||
|
flowCommaSeparator: opts.flowCommaSeparator,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (format.minified) {
|
if (format.minified) {
|
||||||
|
|||||||
10
packages/babel-generator/test/fixtures/flowUsesCommas/ObjectExpression/actual.js
vendored
Normal file
10
packages/babel-generator/test/fixtures/flowUsesCommas/ObjectExpression/actual.js
vendored
Normal 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; };
|
||||||
10
packages/babel-generator/test/fixtures/flowUsesCommas/ObjectExpression/expected.js
vendored
Normal file
10
packages/babel-generator/test/fixtures/flowUsesCommas/ObjectExpression/expected.js
vendored
Normal 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, };
|
||||||
3
packages/babel-generator/test/fixtures/flowUsesCommas/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/flowUsesCommas/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"flowCommaSeparator": true
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user