[RFC] Do not put spacing inside of arrays with bracketSpacing option enabled (#446)

Given the discussion on #296, it seems like there's debate between spaces around `{}` but no one puts spaces around `[]`. So changing the behavior to respect this.
This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-01-24 11:38:12 -08:00
1 parent 45f1dc8a01
commit e13bb7dbba
49 files changed
+183 -183

No files matched your search

+2 -2
View File
@@ -674,7 +674,7 @@ function genericPrintNoParens(path, options, print) {
indent(
options.tabWidth,
concat([
options.bracketSpacing ? line : softline,
softline,
join(concat([ ",", line ]), path.map(print, "elements"))
])
),
@@ -686,7 +686,7 @@ function genericPrintNoParens(path, options, print) {
? ","
: ""
),
options.bracketSpacing ? line : softline,
softline,
"]"
])
)
+7 -7
View File
@@ -75,20 +75,20 @@ var obj: { str: string, i: number, j: boolean } = {
k: false
};
var arr: Array<number> = [ 1, 2, \"...\" ];
var arr: Array<number> = [1, 2, \"...\"];
// array sugar
var array: number[] = [ 1, 2, \"...\" ];
var array: number[] = [1, 2, \"...\"];
var matrix: number[][] = [ [ 1, 2 ], [ 3, 4 ] ];
var matrix: number[][] = [[1, 2], [3, 4]];
var matrix_parens: number[][] = matrix;
var nullable_array: ?(number[]) = null;
var nullable_array_parens: ?(number[]) = nullable_array;
var array_of_nullable: (?number)[] = [ null, 3 ];
var array_of_nullable: (?number)[] = [null, 3];
var array_of_tuple: [number, string][] = [ [ 0, \"foo\" ], [ 1, \"bar\" ] ];
var array_of_tuple: [number, string][] = [[0, \"foo\"], [1, \"bar\"]];
var array_of_tuple_parens: [number, string][] = array_of_tuple;
type ObjType = { \"bar-foo\": string, \"foo-bar\": number };
@@ -279,7 +279,7 @@ function insertMany<K, V>(
vs: [K, V][],
m: Map<K, V>
): Map<K, V> {
function f([ k, v ]: [K, V], m: Map<K, V>): Map<K, V> {
function f([k, v]: [K, V], m: Map<K, V>): Map<K, V> {
return m.insertWith(merge, k, v);
}
return foldr(f, m, vs);
@@ -288,7 +288,7 @@ function insertMany<K, V>(
class Foo<A> {
bar<B>() {
return function<C>(a: A, b: B, c: C): void {
([ a, b, c ]: [A, B, C]);
([a, b, c]: [A, B, C]);
};
}
}
@@ -50,7 +50,7 @@ function filterItems(items: Array<string | number>): Array<string | number> {
}).filter(Boolean);
}
const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]);
const filteredItems = filterItems([\"foo\", \"b\", 1, 2]);
console.log(filteredItems);
"
@@ -2,8 +2,8 @@ exports[`test multiple.js 1`] = `
"[...a, ...b,];
[...a, ...b];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ ...a, ...b ];
[ ...a, ...b ];
[...a, ...b];
[...a, ...b];
"
`;
@@ -11,8 +11,8 @@ exports[`test multiple.js 2`] = `
"[...a, ...b,];
[...a, ...b];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ ...a, ...b ];
[ ...a, ...b ];
[...a, ...b];
[...a, ...b];
"
`;
@@ -26,14 +26,14 @@ C.sort((a, b) => a - b);
var x: Array<string> = [\'1\', \'2\'];
var y: Array<string> = [\'3\', ...x];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = [ 1, 2, 3 ];
var B = [ ...A ];
var C = [ 1, 2, 3 ];
var A = [1, 2, 3];
var B = [...A];
var C = [1, 2, 3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [ \"1\", \"2\" ];
var y: Array<string> = [ \"3\", ...x ];
var x: Array<string> = [\"1\", \"2\"];
var y: Array<string> = [\"3\", ...x];
"
`;
@@ -47,13 +47,13 @@ C.sort((a, b) => a - b);
var x: Array<string> = [\'1\', \'2\'];
var y: Array<string> = [\'3\', ...x];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var A = [ 1, 2, 3 ];
var B = [ ...A ];
var C = [ 1, 2, 3 ];
var A = [1, 2, 3];
var B = [...A];
var C = [1, 2, 3];
B.sort((a, b) => a - b);
C.sort((a, b) => a - b);
var x: Array<string> = [ \"1\", \"2\" ];
var y: Array<string> = [ \"3\", ...x ];
var x: Array<string> = [\"1\", \"2\"];
var y: Array<string> = [\"3\", ...x];
"
`;
+12 -12
View File
@@ -60,7 +60,7 @@ function from_test() {
/* @flow */
function foo(x: string) {}
var a = [ 0 ];
var a = [0];
var b = a.map(function(x) {
foo(x);
@@ -72,13 +72,13 @@ var d: number = b[0];
var e: Array<string> = a.reverse();
var f = [ \"\" ];
var f = [\"\"];
var g: number = f.map(function() {
return 0;
})[0];
var h: Array<number> = [ 1, 2, 3 ];
var i: Array<string> = [ \"a\", \"b\", \"c\" ];
var h: Array<number> = [1, 2, 3];
var i: Array<string> = [\"a\", \"b\", \"c\"];
var j: Array<number | string> = h.concat(i);
var k: Array<number> = h.concat(h);
var l: Array<number> = h.concat(1, 2, 3);
@@ -90,37 +90,37 @@ function reduce_test() {
/* Adapted from the following source:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
*/
[ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) {
[0, 1, 2, 3, 4].reduce(function(previousValue, currentValue, index, array) {
return previousValue + currentValue + array[index];
});
[ 0, 1, 2, 3, 4 ].reduce(
[0, 1, 2, 3, 4].reduce(
function(previousValue, currentValue, index, array) {
return previousValue + currentValue + array[index];
},
10
);
var total = [ 0, 1, 2, 3 ].reduce(function(a, b) {
var total = [0, 1, 2, 3].reduce(function(a, b) {
return a + b;
});
var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(function(a, b) {
var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
return a.concat(b);
});
/* Added later, because the above is insufficient */
// acc is element type of array when no init is provided
[ \"\" ].reduce((acc, str) => acc * str.length);
[\"\"].reduce((acc, str) => acc * str.length);
// error, string ~> number
[ \"\" ].reduceRight((acc, str) => acc * str.length); // error, string ~> number
[\"\"].reduceRight((acc, str) => acc * str.length); // error, string ~> number
}
function from_test() {
var a: Array<string> = Array.from([ 1, 2, 3 ], function(val, index) {
var a: Array<string> = Array.from([1, 2, 3], function(val, index) {
return index % 2 ? \"foo\" : String(val);
});
var b: Array<string> = Array.from([ 1, 2, 3 ], function(val) {
var b: Array<string> = Array.from([1, 2, 3], function(val) {
return String(val);
});
}
@@ -53,8 +53,8 @@ a.forEach(x => y = x);
// for literals, composite element type is union of individuals
// note: test both tuple and non-tuple inferred literals
var alittle: Array<?number> = [ 0, 1, 2, 3, null ];
var abig: Array<?number> = [ 0, 1, 2, 3, 4, 5, 6, 8, null ];
var alittle: Array<?number> = [0, 1, 2, 3, null];
var abig: Array<?number> = [0, 1, 2, 3, 4, 5, 6, 8, null];
var abig2: Array<{ x: number, y: number }> = [
{ x: 0, y: 0 },
@@ -86,10 +86,10 @@ exports[`test last.js 1`] = `
[,,1,];
[,,1,1];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ , ];
[ , , ];
[ , , 1 ];
[ , , 1, 1 ];
[,];
[, ,];
[, , 1];
[, , 1, 1];
"
`;
@@ -45,7 +45,7 @@ x &= 0;
// regression tests -- OK to assign consts like this:
const { foo } = { foo: \"foo\" };
const [ bar ] = [ \"bar\" ];
const [bar] = [\"bar\"];
(foo: number);
// error: string ~> number
(bar: number);
+6 -6
View File
@@ -174,19 +174,19 @@ for (let x: string | File | Blob of a.values()) {
// incorrect
// entries
for (let [ x, y ]: [string, string | File] of a.entries()) {
for (let [x, y]: [string, string | File] of a.entries()) {
}
// correct
for (let [ x, y ]: [string, string | File | Blob] of a.entries()) {
for (let [x, y]: [string, string | File | Blob] of a.entries()) {
}
// incorrect
for (let [ x, y ]: [number, string] of a.entries()) {
for (let [x, y]: [number, string] of a.entries()) {
}
// incorrect
for (let [ x, y ]: [string, number] of a.entries()) {
for (let [x, y]: [string, number] of a.entries()) {
}
// incorrect
for (let [ x, y ]: [number, number] of a.entries()) {
for (let [x, y]: [number, number] of a.entries()) {
} // incorrect
"
`;
@@ -246,7 +246,7 @@ new MutationObserver((n: number) => {});
// incorrect
// observe
const div = document.createElement(\"div\");
o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] });
o.observe(div, { attributes: true, attributeFilter: [\"style\"] });
// correct
o.observe(div, { characterData: true, invalid: true });
// correct
@@ -2,8 +2,8 @@ exports[`test array.js 1`] = `
"const arr1 = [1,2,3,4];
const arr2 = [1, 2, 3, 4];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const arr1 = [ 1, 2, 3, 4 ];
const arr2 = [ 1, 2, 3, 4 ];
const arr1 = [1, 2, 3, 4];
const arr2 = [1, 2, 3, 4];
"
`;
@@ -17,7 +17,7 @@ function g() {
foo = foo1;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var a = [ \"...\" ];
var a = [\"...\"];
var b = a.map(function(x) {
return 0;
});
@@ -122,7 +122,7 @@ let tests = [
function* generator(): Iterable<[string, number]> {
while (true) {
yield [ \"foo\", 123 ];
yield [\"foo\", 123];
}
}
@@ -131,17 +131,17 @@ let tests = [
function() {
let w = new Map();
let x = new Map(null);
let y = new Map([ [ \"foo\", 123 ] ]);
let y = new Map([[\"foo\", 123]]);
let z = new Map(generator());
let a: Map<string, number> = new Map();
let b: Map<string, number> = new Map([ [ \"foo\", 123 ] ]);
let b: Map<string, number> = new Map([[\"foo\", 123]]);
let c: Map<string, number> = new Map(generator());
},
// bad constructors
function() {
let x = new Map([ \"foo\", 123 ]);
let x = new Map([\"foo\", 123]);
// error
let y: Map<number, string> = new Map([ [ \"foo\", 123 ] ]); // error
let y: Map<number, string> = new Map([[\"foo\", 123]]); // error
},
// get()
function(x: Map<string, number>) {
@@ -271,9 +271,9 @@ ws.delete(window);
ws.delete(obj);
ws.delete(dict);
let ws2 = new WeakSet([ obj, dict ]);
let ws2 = new WeakSet([obj, dict]);
let ws3 = new WeakSet([ 1, 2, 3 ]);
let ws3 = new WeakSet([1, 2, 3]);
// error, must be objects
function* generator(): Iterable<{ foo: string }> {
@@ -63,7 +63,7 @@ class NVerbose<E, I: E> {
}
var nv: NVerbose<number, *> = new NVerbose();
nv.x = [ 0 ];
nv.x = [0];
(nv.x[0]: string);
// error
(nv.foo()[0]: string); // error
@@ -12,9 +12,9 @@ let d = zs[1]; // run off the end
let [...e] = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let xs = [ 0, \"\", true ];
let [ a, ...ys ] = xs;
let [ b, ...zs ] = ys;
let xs = [0, \"\", true];
let [a, ...ys] = xs;
let [b, ...zs] = ys;
let c = zs[0];
// retain tuple info
let d = zs[1];
@@ -29,7 +29,7 @@ let d = zs[1];
(d: void);
// error: number|string|boolean ~> void
let [ ...e ] = 0;
let [...e] = 0;
"
`;
@@ -222,9 +222,9 @@ function obj_prop_err({ x: { y } } = null) {}
// error: property \`x\` cannot be accessed on null
function obj_rest_err({ ...o } = 0) {}
// error: expected object instead of number
function arr_elem_err([ x ] = null) {}
function arr_elem_err([x] = null) {}
// error: element 0 cannot be accessed on null
function arr_rest_err([ ...a ] = null) {}
function arr_rest_err([...a] = null) {}
// error: expected array instead of null
function gen<T>(x: T, { p = x }: { p: T }): T {
@@ -325,23 +325,23 @@ var cp2_err: string = others.childprop2; // Error: number ~> string
declare var a: string;
declare var b: string;
declare var c: string;
[ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ];
[{ a1: a, b }, c] = [{ a1: 0, b: 1 }, 2];
var { m } = { m: 0 };
({ m } = { m: m });
var obj;
({ n: obj.x } = { n: 3 });
[ obj.x ] = [ \"foo\" ];
[obj.x] = [\"foo\"];
function foo({ p, z: [ r ] }) {
function foo({ p, z: [r] }) {
a = p;
b = z;
c = r;
}
foo({ p: 0, z: [ 1, 2 ] });
foo({ p: 0, z: [1, 2] });
[ a, , b, ...c ] = [ 0, 1, true, 3 ];
[a, , b, ...c] = [0, 1, true, 3];
function bar({ x, ...z }) {
var o: { x: string, y: number } = z;
@@ -479,16 +479,16 @@ type Prop<X> = { prop: X };
function obj_pattern2<X>({ prop }: Prop<X>) {}
// prop: X
function arr_pattern<X>([ elem ]: X[]) {}
function arr_pattern<X>([elem]: X[]) {}
// elem: X
type Elem<X> = X[];
function arr_pattern2<X>([ elem ]: Elem<X>) {}
function arr_pattern2<X>([elem]: Elem<X>) {}
// elem: X
function tup_pattern<X>([ proj ]: [X]) {}
function tup_pattern<X>([proj]: [X]) {}
// proj: X
type Proj<X> = [X];
function tup_pattern2<X>([ proj ]: Proj<X>) {}
function tup_pattern2<X>([proj]: Proj<X>) {}
// proj: X
function rest_antipattern<T>(...t: T) {}
@@ -506,12 +506,12 @@ function obj_rest_pattern<X>({ _, ...o }: ObjRest<X>) {
o.x;
}
function arr_rest_pattern<X>([ _, ...a ]: [any, X]) {
function arr_rest_pattern<X>([_, ...a]: [any, X]) {
// a: [X]
a[0];
}
type ArrRest<X> = [any, X];
function arr_rest_pattern<X>([ _, ...a ]: ArrRest<X>) {
function arr_rest_pattern<X>([_, ...a]: ArrRest<X>) {
// a: [X]
a[0];
}
@@ -545,11 +545,11 @@ var { x: o } = o;
// Make sure that destructuring doesn\'t cause infinite loops when combined with
// funny doses of repositioning
let foo = (i: number) => [ i ];
let foo = (i: number) => [i];
const bar = (i: number) => {
[ i ] = foo(i);
return [ i ];
[i] = foo(i);
return [i];
};
foo = (i: number) => {
@@ -541,7 +541,7 @@ export class NumberGenerator {
export var varDeclNumber1 = 1, varDeclNumber2 = 2;
export var { destructuredObjNumber } = { destructuredObjNumber: 1 };
export var [ destructuredArrNumber ] = [ 1 ];
export var [destructuredArrNumber] = [1];
"
`;
@@ -592,7 +592,7 @@ export class NumberGenerator2 {
export var varDeclNumber3 = 1, varDeclNumber4 = 2;
export var { destructuredObjNumber2 } = { destructuredObjNumber2: 1 };
export var [ destructuredArrNumber2 ] = [ 1 ];
export var [destructuredArrNumber2] = [1];
"
`;
+6 -6
View File
@@ -85,7 +85,7 @@ e.getAll(\'content-type\').forEach((v: string) => {}); // correct
const a = new Headers(\"\'Content-Type\': \'image/jpeg\'\");
// not correct
const b = new Headers([ \"Content-Type\", \"image/jpeg\" ]);
const b = new Headers([\"Content-Type\", \"image/jpeg\"]);
// not correct
const c = new Headers({ \"Content-Type\", \"image/jpeg\" });
// correct
@@ -115,11 +115,11 @@ const h: number = e.get(\"Content-Type\");
// not correct
for (let v of e) {
const [ i, j ]: [string, string] = v; // correct
const [i, j]: [string, string] = v; // correct
}
for (let v of e.entries()) {
const [ i, j ]: [string, string] = v; // correct
const [i, j]: [string, string] = v; // correct
}
e.getAll(\"content-type\").forEach((v: string) => {}); // correct
@@ -374,7 +374,7 @@ e.getAll(\'key1\').forEach((v: string) => {}); // correct
const a = new URLSearchParams(\"key1=value1\");
// correct
const b = new URLSearchParams([ \"key1\", \"value1\" ]);
const b = new URLSearchParams([\"key1\", \"value1\"]);
// not correct
const c = new URLSearchParams({ \"key1\", \"value1\" });
// not correct
@@ -404,11 +404,11 @@ const h: number = e.get(\"key1\");
// not correct
for (let v of e) {
const [ i, j ]: [string, string] = v; // correct
const [i, j]: [string, string] = v; // correct
}
for (let v of e.entries()) {
const [ i, j ]: [string, string] = v; // correct
const [i, j]: [string, string] = v; // correct
}
e.getAll(\"key1\").forEach((v: string) => {}); // correct
+2 -2
View File
@@ -235,7 +235,7 @@ function corge(x: boolean) {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x: boolean) {
var arr = [ 1, 2, 3 ];
var arr = [1, 2, 3];
for (var elem of arr) {
if (x) {
continue;
@@ -260,7 +260,7 @@ function baz(x: boolean) {
}
function bliffl(x: boolean) {
var arr = [ 1, 2, 3 ];
var arr = [1, 2, 3];
loop1:
for (var elem of arr) {
loop2:
+14 -14
View File
@@ -47,31 +47,31 @@ function test(a: string, b: number): number {
}
// tuples flow correctly into params
test.apply(\"\", [ \"\", 0 ]);
test.apply(\"\", [\"\", 0]);
// wrong this is an error
test.apply(0, [ \"\", 0 ]);
test.apply(0, [\"\", 0]);
// error: lookup \`length\` on Number
// not enough arguments is an error (via incompatible RestT)
test.apply(\"\", [ \"\" ]);
test.apply(\"\", [\"\"]);
// error: string ~> number
// mistyped arguments is an error
test.apply(\"\", [ \"\", \"\" ]);
test.apply(\"\", [\"\", \"\"]);
// error: string ~> number (2nd arg)
test.apply(\"\", [ 0, 0 ]);
test.apply(\"\", [0, 0]);
// error: number ~> string (1st arg)
// resolve args array from tvar
function f(args) {
test.apply(\"\", args);
}
f([ \"\", 0 ]);
f([\"\", 0]);
// OK
f([ \"\", \"\" ]);
f([\"\", \"\"]);
// error: string ~> number (2nd arg)
f([ 0, 0 ]);
f([0, 0]);
// error: number ~> string (1st arg)
// expect array
@@ -83,12 +83,12 @@ test.apply(\"\", \"not array\");
// - 123 is not a string
// - \'foo\' is not a number
// - return type (number) is not void
(test.call.apply(test, [ 0, 123, \"foo\" ]): void);
(test.call.apply(test, [0, 123, \"foo\"]): void);
// expect 2 errors:
// - lookup length on number (0 is used as \`this\`)
// - 123 is not a string
(test.bind.apply(test, [ 0, 123 ]): (b: number) => number);
(test.bind.apply(test, [0, 123]): (b: number) => number);
// args are optional
function test2(): number {
@@ -187,18 +187,18 @@ test.call(\"\", 0, 0);
function f(args) {
test.call(\"\", args[0], args[1]);
}
f([ \"\", 0 ]);
f([\"\", 0]);
// OK
f([ \"\", \"\" ]);
f([\"\", \"\"]);
// error: string ~> number (2nd arg)
f([ 0, 0 ]);
f([0, 0]);
// error: number ~> string (1st arg)
// expect 3 errors:
// - lookup length on Number (0 used as \`this\`)
// - number !~> string (param a)
// - string !~> number (param b)
(test.apply.call(test, 0, [ 0, \"foo\" ]): number);
(test.apply.call(test, 0, [0, \"foo\"]): number);
// args are optional
function test2(): number {
@@ -92,7 +92,7 @@ class H<Z> extends G<Array<Z>> {
}
var h1 = new H();
h1.foo([ \"...\" ]);
h1.foo([\"...\"]);
var h2: F<Array<Array<Array<number>>>> = h1;
var obj: Object<string, string> = {};
+4 -4
View File
@@ -619,7 +619,7 @@ function for_in_post_init() {
// local use of annotated var in for-of is ok
function for_of_scoped_init() {
for (var x of [ 1, 2, 3 ]) {
for (var x of [1, 2, 3]) {
var x: number = 0;
var y: number = x;
}
@@ -629,14 +629,14 @@ function for_of_scoped_init() {
function for_in_pre_init() {
var y: number = x;
// error
for (var x of [ 1, 2, 3 ]) {
for (var x of [1, 2, 3]) {
var x: number = 0;
}
}
// ...and after
function for_in_post_init() {
for (var x of [ 1, 2, 3 ]) {
for (var x of [1, 2, 3]) {
var x: number = 0;
}
var y: number = x; // error
@@ -975,6 +975,6 @@ exports[`test nullable-init.js 1`] = `
var a: Array<?number> = [null,null];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o: { x: ?number } = { x: null };
var a: Array<?number> = [ null, null ];
var a: Array<?number> = [null, null];
"
`;
+1 -1
View File
@@ -37,7 +37,7 @@ for (var y in this) {
// allowed, even though we can\'t actually enumerate all the keys on \`this\`.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var a = [ true, false ];
var a = [true, false];
function foo(x) {}
for (var i = 0; i < 3; i++) {
@@ -12,14 +12,14 @@ var arrayTest5: Iterable<string> = [\"hi\", 1];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
var arrayTest1: Iterable<number> = ([ 1, 2 ]: Array<number>);
var arrayTest2: Iterable<number | string> = [ 1, 2, \"hi\" ];
var arrayTest3: Iterable<*> = [ 1, 2, 3 ];
var arrayTest1: Iterable<number> = ([1, 2]: Array<number>);
var arrayTest2: Iterable<number | string> = [1, 2, \"hi\"];
var arrayTest3: Iterable<*> = [1, 2, 3];
// Error string ~> number
var arrayTest4: Iterable<number> = [ \"hi\" ];
var arrayTest4: Iterable<number> = [\"hi\"];
// Error string ~> number
var arrayTest5: Iterable<string> = [ \"hi\", 1 ];
var arrayTest5: Iterable<string> = [\"hi\", 1];
"
`;
@@ -36,7 +36,7 @@ export const log = y => {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const formatData = pipe(
zip,
map(([ ref, data ]) => ({
map(([ref, data]) => ({
nodeId: ref.nodeId.toString(),
...attributeFromDataValue(ref.attributeId, data)
})),
@@ -59,7 +59,7 @@ var name: number = object[APIKeys.NAME];
// error: object.name is a string
var indices = { red: 0, green: 1, blue: 2 };
var tuple = [ 42, \"hello\", false ];
var tuple = [42, \"hello\", false];
var red: string = tuple[indices.red]; // error: tuple[0] is a number
"
`;
@@ -580,7 +580,7 @@ function logical2f(): string {
* A literal on the left side of &&
*/
function logical2g(): string {
return [ 1, 2, 3 ] && \"foo\";
return [1, 2, 3] && \"foo\";
}
/**
+1 -1
View File
@@ -188,7 +188,7 @@ var a = { length: \"duck\" };
a.length = 123;
a.length();
var b = [ 123 ];
var b = [123];
b.length = \"duck\";
b.length();
"
@@ -9,7 +9,7 @@ export var arr = [f];
type Foo = {};
var f: Foo = {};
export var arr = [ f ];
export var arr = [f];
"
`;
@@ -42,8 +42,8 @@ function bar<U, V>(x: U, f: Map<U, V>): V {
var y: number = bar(0, x => \"\");
type Seq = number | Array<Seq>;
var s1: Seq = [ 0, [ 0 ] ];
var s2: Seq = [ [ \"\" ] ];
var s1: Seq = [0, [0]];
var s2: Seq = [[\"\"]];
module.exports = { foo: (\"\": number) };
"
@@ -116,8 +116,8 @@ num = buffer.indexOf(3);
num = buffer.indexOf(3, 4);
// static methods
buffer = Buffer.from([ 0x62, 0x75, 0x66, 0x66, 0x65, 0x72 ]);
const typedArray = new Uint8Array([ 0x34 ]);
buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const typedArray = new Uint8Array([0x34]);
buffer = Buffer.from(
typedArray.buffer,
typedArray.byteOffset,
@@ -131,7 +131,7 @@ buffer = Buffer.from(\"foo\", \"utf8\");
// flow doesn\'t support a subclass hiding a superclass member, so this checks out as
// ok, even though it is not correct.
buffer = Buffer.from(
[ 0x62, 0x75, 0x66, 0x66, 0x65, 0x72 ],
[0x62, 0x75, 0x66, 0x66, 0x65, 0x72],
(a: number) => a + 1,
{}
); // should error but doesn\'t
@@ -69,7 +69,7 @@ execFile(\'ls\', [\'-l\'], {timeout: 250}, function(error, stdout, stderr) {
var execFile = require(\"child_process\").execFile;
// args only.
execFile(\"ls\", [ \"-lh\" ]);
execFile(\"ls\", [\"-lh\"]);
// callback only.
execFile(\"ls\", function(error, stdout, stderr) {
@@ -80,15 +80,15 @@ execFile(\"ls\", function(error, stdout, stderr) {
execFile(\"wc\", { timeout: 250 });
// args + callback.
execFile(\"ls\", [ \"-l\" ], function(error, stdout, stderr) {
execFile(\"ls\", [\"-l\"], function(error, stdout, stderr) {
console.info(stdout);
});
// args + options.
execFile(\"ls\", [ \"-l\" ], { timeout: 250 });
execFile(\"ls\", [\"-l\"], { timeout: 250 });
// Put it all together.
execFile(\"ls\", [ \"-l\" ], { timeout: 250 }, function(error, stdout, stderr) {
execFile(\"ls\", [\"-l\"], { timeout: 250 }, function(error, stdout, stderr) {
console.info(stdout);
});
"
@@ -120,7 +120,7 @@ execSync(\"ls\", { timeout: \"250\" });
// error, no signatures match
execSync(\"ls\", { stdio: \"inherit\" });
// error, no signatures match
execSync(\"ls\", { stdio: [ \"inherit\" ] }); // error, no signatures match
execSync(\"ls\", { stdio: [\"inherit\"] }); // error, no signatures match
"
`;
@@ -161,10 +161,10 @@ wc.stderr.pipe(process.stderr);
var child_process = require(\"child_process\");
var ls = child_process.spawn(\"ls\");
var wc = child_process.spawn(\"wc\", [ \"-l\" ]);
var wc = child_process.spawn(\"wc\", [\"-l\"]);
// args + options.
child_process.spawn(\"echo\", [ \"-n\", \'\"Testing...\"\' ], { env: { TEST: \"foo\" } });
child_process.spawn(\"echo\", [\"-n\", \'\"Testing...\"\'], { env: { TEST: \"foo\" } });
// options only.
child_process.spawn(\"echo\", { env: { FOO: 2 } });
@@ -61,7 +61,7 @@ if (x != null) {
qux(x);
}
var array_of_nullable: Array<?number> = [ null, 3 ];
var array_of_nullable: Array<?number> = [null, 3];
"
`;
@@ -105,11 +105,11 @@ exports[`test apply.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
(Object.assign.apply(null, [ {}, { a: 1 }, { b: \"foo\" } ]): {
(Object.assign.apply(null, [{}, { a: 1 }, { b: \"foo\" }]): {
a: number,
b: string
});
(Object.assign({}, ...[ { a: 1 }, { b: \"foo\" } ]): { a: number, b: string });
(Object.assign({}, ...[{ a: 1 }, { b: \"foo\" }]): { a: number, b: string });
"
`;
@@ -15,7 +15,7 @@ exports[`test default.js 1`] = `
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f<T>(foo, bar = foo): [T, T] {
return [ foo, bar ];
return [foo, bar];
}
"
`;
@@ -178,7 +178,7 @@ function qux(x = \"hello\", ...y): string {
}
qux(0, 0);
qux(0, ...[ \"\", 42 ]);
qux(0, ...[\"\", 42]);
module.exports = qux;
"
@@ -324,7 +324,7 @@ foo(123, true); // ERROR boolean ~> string
/* @flow */
function foo(x?: number, ...y: Array<string>): [?number, Array<string>] {
return [ x, y ];
return [x, y];
}
foo();
@@ -199,6 +199,6 @@ function foo<U>(x: $Either<Array<U>, U>): Array<U> {
}
var x1: number = foo(0)[0];
var x2: string = foo([ \"\" ])[0];
var x2: string = foo([\"\"])[0];
"
`;
@@ -5,10 +5,10 @@ var [n, b, s] = foo(42);
n * s.length;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo(x) {
return [ x, x > 0, \"number \" + x ];
return [x, x > 0, \"number \" + x];
}
var [ n, b, s ] = foo(42);
var [n, b, s] = foo(42);
n * s.length;
"
`;
@@ -51,7 +51,7 @@ Promise.all([
true
]).then(xs => {
// tuple information is preserved
let [ a, b, c ] = xs;
let [a, b, c] = xs;
(a: number);
// Error: string ~> number
(b: boolean);
+3 -3
View File
@@ -167,10 +167,10 @@ var Example = React.createClass({
});
var ok_empty = <Example arr={[]} />;
var ok_numbers = <Example arr={[ 1, 2 ]} />;
var ok_numbers = <Example arr={[1, 2]} />;
var fail_not_array = <Example arr={2} />;
var fail_mistyped_elems = <Example arr={[ 1, \"foo\" ]} />;
var fail_mistyped_elems = <Example arr={[1, \"foo\"]} />;
"
`;
@@ -350,7 +350,7 @@ var ex2 = <Example literal=\"bar\" />;
var React = require(\"react\");
var Example = React.createClass({
propTypes: { literal: React.PropTypes.oneOf([ \"foo\" ]).isRequired }
propTypes: { literal: React.PropTypes.oneOf([\"foo\"]).isRequired }
});
var ex1 = <Example literal=\"foo\" />;
+2 -2
View File
@@ -429,7 +429,7 @@ var tests = [
var y: string = x.p || \"\"; // ok
},
function() {
var x: { p: string | string[] } = { p: [ \"xxx\" ] };
var x: { p: string | string[] } = { p: [\"xxx\"] };
if (Array.isArray(x.p)) {
var y: string[] = x.p; // ok
} else {
@@ -806,7 +806,7 @@ var paths = [
var y: string = x || \"\"; // ok
},
function() {
var x: string | string[] = [ \"xxx\" ];
var x: string | string[] = [\"xxx\"];
if (Array.isArray(x)) {
var y: string[] = x; // ok
} else {
@@ -66,7 +66,7 @@ requireLazy([\'A\']); // Error: No calback expression
* @flow
*/
requireLazy([ \"A\", \"B\" ], function(A, B) {
requireLazy([\"A\", \"B\"], function(A, B) {
var num1: number = A.numberValueA;
var str1: string = A.stringValueA;
var num2: number = A.stringValueA;
@@ -86,8 +86,8 @@ var notB: Object = B;
requireLazy();
// Error: No args
requireLazy([ nope ], function() {});
requireLazy([nope], function() {});
// Error: Non-stringliteral args
requireLazy([ \"A\" ]); // Error: No calback expression
requireLazy([\"A\"]); // Error: No calback expression
"
`;
@@ -120,7 +120,7 @@ test(0, ...[1, 2, 3]);
/* @flow */
function test(...nums: Array<number>) {}
test(0, ...[ 1, 2, 3 ]);
test(0, ...[1, 2, 3]);
"
`;
@@ -35,7 +35,7 @@ function foo(z: number) {
return bar(z);
}
var array = [ \"foo\", \"bar\" ];
var array = [\"foo\", \"bar\"];
array;
module.exports = { foo: foo };
@@ -106,7 +106,7 @@ class Invariant {
inout_object: { _: this };
out_array(): Array<this> {
return [ this ];
return [this];
}
in_array(_: Array<this>) {}
inout_array: Array<this>;
@@ -16,7 +16,7 @@ function foo(x: Array<number>): [number, ?number] {
}
function foo(x: Array<number>): [number, ?number] {
return [ x[0], x[1] ]; // OK. This is unsound, but at least arity is enforced
return [x[0], x[1]]; // OK. This is unsound, but at least arity is enforced
}
"
`;
@@ -31,9 +31,9 @@ exports[`test optional.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
([ 0, undefined ]: [number, ?string]);
([0, undefined]: [number, ?string]);
// Ok, correct arity
([ 0 ]: [number, ?string]);
([0]: [number, ?string]);
// Error, arity is enforced
([]: [?number, string]); // error, since second element is not marked optional
@@ -51,7 +51,7 @@ foo([ {} ]); // error, too few elements in array passed to a tuple
function foo(a: [Object, Object]) {}
foo([ {} ]); // error, too few elements in array passed to a tuple
foo([{}]); // error, too few elements in array passed to a tuple
"
`;
@@ -64,12 +64,12 @@ var e: [number, string,] = [123,\'duck\'];
var f: [number, string] = [123, 456];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var a: [] = [];
var b: [] = [ 123 ];
var b: [] = [123];
// Error - arity mismatch
var c: [number] = [];
// nope
var d: [number, string] = [ 123, \"duck\" ];
var e: [number, string] = [ 123, \"duck\" ];
var f: [number, string] = [ 123, 456 ];
var d: [number, string] = [123, \"duck\"];
var e: [number, string] = [123, \"duck\"];
var f: [number, string] = [123, 456];
"
`;
@@ -21,7 +21,7 @@ export const X = {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
let [ x, y ] = [ 1, 2 ];
let [x, y] = [1, 2];
/**
* Test what happens when the destructuring is unevaluated. In this case,
@@ -31,10 +31,10 @@ let [ x, y ] = [ 1, 2 ];
*/
export const X = {
returnsATuple: function(): [number, number] {
return [ 1, 2 ];
return [1, 2];
},
test: function() {
let [ a, b ] = this.returnsATuple();
let [a, b] = this.returnsATuple();
}
};
"
@@ -255,7 +255,7 @@ foo();
str;
type Point = [number, string];
const x: Point = [ 1, \"foo\" ];
const x: Point = [1, \"foo\"];
type MyStr = \"cool\";
const y: MyStr = \"cool\";
type MyBool = true;
@@ -138,7 +138,7 @@ class MySubclass extends MyClass {
// no arity error in call of polymorphic function
function singleton<T>(x: T): Array<T> {
return [ x ];
return [x];
}
var num_array: Array<number> = singleton(0); // ok, type arg inferred
@@ -136,7 +136,7 @@ class MySubclass extends MyClass {
// *no* arity error in call of polymorphic function
function singleton<T>(x: T): Array<T> {
return [ x ];
return [x];
}
var num_array: Array<number> = singleton(0); // ok, type arg inferred
@@ -175,7 +175,7 @@ var x = Foo;
// But using it in a type should still work
var a: Foo = 123;
var b: Array<Foo> = [ 123 ];
var b: Array<Foo> = [123];
type c = Foo;
"
`;
@@ -97,7 +97,7 @@ let tests = [
(name: boolean);
// error, string or void
const bar = [ undefined, \"bar\" ];
const bar = [undefined, \"bar\"];
(bar[x]: boolean); // error, string or void
},
function(x: number) {
@@ -110,7 +110,7 @@ let tests = [
x[0]; // should error, could be void
}
const bar = [ undefined, \"bar\" ];
const bar = [undefined, \"bar\"];
(bar[x]: boolean); // error, string only
}
];
+5 -5
View File
@@ -110,8 +110,8 @@ myclass.myfun([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function (ar) {}
declare class Myclass { myfun(myarray: Array<Function | string>): any }
declare var myclass: Myclass;
myclass.myfun([ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", function(ar) {} ]);
myclass.myfun([ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function(ar) {} ]);
myclass.myfun([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", function(ar) {}]);
myclass.myfun([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function(ar) {}]);
"
`;
@@ -184,7 +184,7 @@ class Tag {
type Node = Tag_ | string;
class Tag_ {
constructor() {
var a1: Array<Node> = [ new Tag_() ];
var a1: Array<Node> = [new Tag_()];
var a2: Array<Node> = a1;
}
}
@@ -197,8 +197,8 @@ var stringArr:Array<string> = [\'a\',\'b\'];
var result = numberAndStringArr.concat(stringArr); // no error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var numberAndStringArr: Array<number | string> = [ 1, 2 ];
var stringArr: Array<string> = [ \"a\", \"b\" ];
var numberAndStringArr: Array<number | string> = [1, 2];
var stringArr: Array<string> = [\"a\", \"b\"];
var result = numberAndStringArr.concat(stringArr); // no error
"
@@ -493,7 +493,7 @@ function inst(a: A5 | A6) {}
class B5 {}
class B6 {}
inst([ new B6() ]);
inst([new B6()]);
type A5 = B5[];
type A6 = B6[];
@@ -647,7 +647,7 @@ type B5 = string;
// tuples
function tup(a: [number, boolean] | [string, boolean]) {}
tup(([ \"\", false ]: A6));
tup(([\"\", false]: A6));
type A6 = [B6, boolean];
type B6 = string;
@@ -1198,10 +1198,10 @@ check_obj({ x: id(\"\") });
function check_arr(_: number[] | string[]) {}
// ok
check_arr([ \"\" ]);
check_arr([\"\"]);
// help!
check_arr([ id(\"\") ]);
check_arr([id(\"\")]);
//////////////////////////////////////
// generic class instance annotations
@@ -1443,7 +1443,7 @@ exports[`test test17.js 1`] = `
[].concat([]);
([].concat([ 0, 1 ])[1]: string);
([].concat([0, 1])[1]: string);
"
`;
@@ -1521,16 +1521,16 @@ exports[`test test20.js 1`] = `
// Array#reduce
[ 0, 1 ].reduce((x, y, i) => y);
[0, 1].reduce((x, y, i) => y);
[ \"a\", \"b\" ].reduce(
[\"a\", \"b\"].reduce(
(regex, representation, index) => {
return regex + (index ? \"|\" : \"\") + \"(\" + representation + \")\";
},
\"\"
);
[ \"\" ].reduce((acc, str) => acc * str.length);
[\"\"].reduce((acc, str) => acc * str.length);
"
`;