Fix range for object newline detection (#520)
It turns out that the range is not inclusive. It incorrectly included a \n after and would expand way more objects than we intended to. I found it while running prettier on the codebase. I'll make 0.14.1 for this.master
parent
f88c95031e
commit
cb347378c6
|
@ -160,7 +160,7 @@ function hasNewline(text, index, opts) {
|
|||
}
|
||||
|
||||
function hasNewlineInRange(text, start, end) {
|
||||
for (var i = start; i <= end; ++i) {
|
||||
for (var i = start; i < end; ++i) {
|
||||
if (text.charAt(i) === "\n") {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,11 +20,7 @@ exports[`test object.js 1`] = `
|
|||
"const obj1 = {a:1, b:2, c:3}
|
||||
const obj2 = { a:1, b:2, c:3 };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
const obj1 = {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3
|
||||
};
|
||||
const obj1 = { a: 1, b: 2, c: 3 };
|
||||
const obj2 = { a: 1, b: 2, c: 3 };
|
||||
"
|
||||
`;
|
||||
|
@ -33,11 +29,7 @@ exports[`test object.js 2`] = `
|
|||
"const obj1 = {a:1, b:2, c:3}
|
||||
const obj2 = { a:1, b:2, c:3 };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
const obj1 = {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3
|
||||
};
|
||||
const obj1 = {a: 1, b: 2, c: 3};
|
||||
const obj2 = {a: 1, b: 2, c: 3};
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -73,11 +73,7 @@ var abig2: Array<{ x: number, y: number }> = [
|
|||
{ x: 0, y: 0, a: true },
|
||||
{ x: 0, y: 0, b: \"hey\" },
|
||||
{ x: 0, y: 0, c: 1 },
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
c: \"hey\"
|
||||
}
|
||||
{ x: 0, y: 0, c: \"hey\" }
|
||||
];
|
||||
|
||||
module.exports = \"arrays\";
|
||||
|
|
|
@ -45,9 +45,7 @@ x &= 0;
|
|||
|
||||
// regression tests -- OK to assign consts like this:
|
||||
|
||||
const { foo } = {
|
||||
foo: \"foo\"
|
||||
};
|
||||
const { foo } = { foo: \"foo\" };
|
||||
const [bar] = [\"bar\"];
|
||||
(foo: number); // error: string ~> number
|
||||
(bar: number); // error: string ~> number
|
||||
|
|
|
@ -321,9 +321,7 @@ qux({ a: \"\" });
|
|||
function corge({ b }: { b: string }) {}
|
||||
corge({ b: 0 });
|
||||
|
||||
var { n }: { n: number } = {
|
||||
n: \"\"
|
||||
};
|
||||
var { n }: { n: number } = { n: \"\" };
|
||||
|
||||
function test() {
|
||||
var { foo } = { bar: 123 }; // error on foo
|
||||
|
@ -545,9 +543,7 @@ function bar() {
|
|||
// @flow
|
||||
|
||||
var { x } = {
|
||||
x: {
|
||||
foo: \"foo\"
|
||||
}
|
||||
x: { foo: \"foo\" }
|
||||
};
|
||||
|
||||
function bar() {
|
||||
|
|
|
@ -42,9 +42,7 @@ function foo0(
|
|||
}
|
||||
|
||||
function foo2(
|
||||
x: {
|
||||
[key: string]: number
|
||||
}
|
||||
x: { [key: string]: number }
|
||||
): { [key: string]: number, +toString: () => string } {
|
||||
// x\'s prototype has a toString method
|
||||
return x;
|
||||
|
|
|
@ -1458,10 +1458,7 @@ export const builders: {
|
|||
identifier(name: string): Identifier,
|
||||
literal(
|
||||
value: ?(string | boolean | number | RegExp),
|
||||
regex?: {
|
||||
pattern: string,
|
||||
flags: string
|
||||
}
|
||||
regex?: { pattern: string, flags: string }
|
||||
): Literal,
|
||||
thisExpression(): ThisExpression,
|
||||
arrayExpression(elements: Expression[]): ArrayExpression,
|
||||
|
|
|
@ -59,9 +59,11 @@ let tests = [
|
|||
function(copyProperties: Object$Assign) {
|
||||
let result = {};
|
||||
result.baz = false;
|
||||
(copyProperties(result, { foo: \"a\" }, {
|
||||
bar: 123
|
||||
}): { foo: string, bar: number, baz: boolean });
|
||||
(copyProperties(result, { foo: \"a\" }, { bar: 123 }): {
|
||||
foo: string,
|
||||
bar: number,
|
||||
baz: boolean
|
||||
});
|
||||
},
|
||||
// module from lib
|
||||
function() {
|
||||
|
|
|
@ -41,58 +41,42 @@ function foo7(): {[key: string]: number; foo: number} {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// No indexer should be fine
|
||||
function foo0(): {} {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// Matching indexer should be fine
|
||||
function foo1(): { [key: string]: string } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// Indexer with different key type is an error when it matches
|
||||
function foo2(): { [key: number]: string } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// Matching indexer with different value type is an error
|
||||
function foo3(): { [key: string]: number } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// Indexer with different key type and different value type is twice an error
|
||||
function foo4(): { [key: number]: number } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// If key exists in object type then indexer is not matched
|
||||
function foo5(): { [key: string]: number, foo: string } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// If key exists in object type then indexer is not matched
|
||||
function foo6(): { [key: number]: number, foo: string } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
|
||||
// Should still complain about mistyped properties
|
||||
function foo7(): { [key: string]: number, foo: number } {
|
||||
return {
|
||||
foo: \"bar\"
|
||||
};
|
||||
return { foo: \"bar\" };
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -2,9 +2,7 @@ exports[`test import.js 1`] = `
|
|||
"interface I { x: number }
|
||||
export type J = I; // workaround for export interface
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
interface I {
|
||||
x: number
|
||||
}
|
||||
interface I { x: number }
|
||||
export type J = I; // workaround for export interface
|
||||
"
|
||||
`;
|
||||
|
@ -48,15 +46,11 @@ function testInterfaceName(o: I) {
|
|||
(o.constructor.name: string); // ok
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare class C {
|
||||
x: number
|
||||
}
|
||||
declare class C { x: number }
|
||||
|
||||
var x: string = new C().x;
|
||||
|
||||
interface I {
|
||||
x: number
|
||||
}
|
||||
interface I { x: number }
|
||||
|
||||
var i = new I(); // error
|
||||
function testInterfaceName(o: I) {
|
||||
|
@ -90,12 +84,8 @@ var e: E<number> = { x: \"\", y: \"\", z: \"\" }; // error: x and z should be nu
|
|||
(e.y: string);
|
||||
(e.z: string); // error: z is number
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
interface I {
|
||||
y: string
|
||||
}
|
||||
interface I_ {
|
||||
x: number
|
||||
}
|
||||
interface I { y: string }
|
||||
interface I_ { x: number }
|
||||
interface J extends I, I_ {}
|
||||
interface K extends J {}
|
||||
|
||||
|
@ -103,21 +93,13 @@ var k: K = { x: \"\", y: \"\" }; // error: x should be number
|
|||
(k.x: string); // error: x is number
|
||||
(k.y: string);
|
||||
|
||||
declare class C {
|
||||
x: number
|
||||
}
|
||||
declare class C { x: number }
|
||||
declare class D extends C, Other {} // error: multiple extends
|
||||
//declare class E implements I { } // parse error
|
||||
|
||||
interface A<Y> {
|
||||
y: Y
|
||||
}
|
||||
interface A_<X> {
|
||||
x: X
|
||||
}
|
||||
interface B<Z> extends A<string>, A_<Z> {
|
||||
z: Z
|
||||
}
|
||||
interface A<Y> { y: Y }
|
||||
interface A_<X> { x: X }
|
||||
interface B<Z> extends A<string>, A_<Z> { z: Z }
|
||||
interface E<Z> extends B<Z> {}
|
||||
|
||||
var e: E<number> = { x: \"\", y: \"\", z: \"\" }; // error: x and z should be numbers
|
||||
|
@ -141,9 +123,7 @@ function bar(m: M) { m.x; m.y; m.z; } // OK
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
import type { J } from \"./import\";
|
||||
interface K {}
|
||||
interface L extends J, K {
|
||||
y: string
|
||||
}
|
||||
interface L extends J, K { y: string }
|
||||
|
||||
function foo(l: L) {
|
||||
l.x;
|
||||
|
@ -151,12 +131,7 @@ function foo(l: L) {
|
|||
l.z;
|
||||
} // error: z not found in L
|
||||
// interface + multiple inheritance is similar to object type + intersection
|
||||
type M =
|
||||
& { y: string }
|
||||
& J
|
||||
& {
|
||||
z: boolean
|
||||
};
|
||||
type M = { y: string } & J & { z: boolean };
|
||||
|
||||
function bar(m: M) {
|
||||
m.x;
|
||||
|
@ -175,13 +150,8 @@ function foo(k: K) {
|
|||
(k.y: number); // error: y is string in I
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
interface I {
|
||||
x: number,
|
||||
y: string
|
||||
}
|
||||
interface J {
|
||||
y: number
|
||||
}
|
||||
interface I { x: number, y: string }
|
||||
interface J { y: number }
|
||||
interface K extends I, J { x: string } // error: x is number in I
|
||||
function foo(k: K) {
|
||||
(k.x: number); // error: x is string in K
|
||||
|
@ -201,9 +171,7 @@ declare class C {
|
|||
|
||||
new C().bar((x: string) => { }); // error, number ~/~> string
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
interface I {
|
||||
foo(x: number): void
|
||||
}
|
||||
interface I { foo(x: number): void }
|
||||
(function foo(x: number) {}: I); // error, property \`foo\` not found function
|
||||
declare class C {
|
||||
bar(i: I): void,
|
||||
|
|
|
@ -147,9 +147,7 @@ module.exports = {obj: o};
|
|||
/* @providesModule E */
|
||||
|
||||
function h(x: number) {}
|
||||
var proto = {
|
||||
fn: h
|
||||
};
|
||||
var proto = { fn: h };
|
||||
|
||||
var o = Object.create(proto);
|
||||
o.fn(false);
|
||||
|
|
|
@ -21,9 +21,7 @@ o3.w = o2;
|
|||
module.exports = o3;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
var o1 = { x: 0, y: \"\" };
|
||||
var o2 = {
|
||||
z: o1
|
||||
};
|
||||
var o2 = { z: o1 };
|
||||
|
||||
var o3 = {};
|
||||
o3.w = o2;
|
||||
|
|
|
@ -107,9 +107,7 @@ function goofy() {
|
|||
}
|
||||
|
||||
function goofy2() {
|
||||
var o = {
|
||||
x: 0
|
||||
};
|
||||
var o = { x: 0 };
|
||||
if (typeof o.x == \"function\") {
|
||||
o.x();
|
||||
}
|
||||
|
|
|
@ -174,13 +174,8 @@ class C6 extends React.Component { // OK, recommended
|
|||
var React = require(\"React\");
|
||||
|
||||
type T1 = {};
|
||||
type T2 = {
|
||||
x: number
|
||||
};
|
||||
type T3 = {
|
||||
x: number,
|
||||
y: number
|
||||
};
|
||||
type T2 = { x: number };
|
||||
type T3 = { x: number, y: number };
|
||||
|
||||
class C1
|
||||
extends React.Component<T1, T2, any> {} // error
|
||||
|
@ -561,10 +556,7 @@ var TestProps = React.createClass({
|
|||
z: React.PropTypes.number
|
||||
},
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
x: \"\",
|
||||
y: 0
|
||||
};
|
||||
return { x: \"\", y: 0 };
|
||||
},
|
||||
test: function() {
|
||||
var a: number = this.props.x; // error
|
||||
|
@ -577,9 +569,7 @@ var element = <TestProps x={false} y={false} z={false} />; // 3 errors
|
|||
(element: $jsx<*>);
|
||||
(element: $jsx<TestProps>);
|
||||
var FooProps = React.createClass({
|
||||
propTypes: {
|
||||
w: React.PropTypes.string.isRequired
|
||||
}
|
||||
propTypes: { w: React.PropTypes.string.isRequired }
|
||||
});
|
||||
(element: $jsx<FooProps>);
|
||||
"
|
||||
|
|
|
@ -104,9 +104,7 @@ class C {
|
|||
({ foo: \"foo\" }: C);
|
||||
|
||||
// error, object types don\'t structurally match instances
|
||||
type O = {
|
||||
foo: string
|
||||
};
|
||||
type O = { foo: string };
|
||||
declare var o: O;
|
||||
(o: C);
|
||||
"
|
||||
|
|
|
@ -17,13 +17,9 @@ interface B<X> extends A<X> {
|
|||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
interface Some<X> {}
|
||||
interface Other<X> {
|
||||
x: X
|
||||
}
|
||||
interface Other<X> { x: X }
|
||||
interface None<Y> {}
|
||||
interface Nada<Y> {
|
||||
y: Y
|
||||
}
|
||||
interface Nada<Y> { y: Y }
|
||||
interface A<X> {
|
||||
foo<Y>(s: Some<X>, e: None<Y>): A<Y>,
|
||||
foo<Y>(s: Some<X>, e: Nada<Y>): A<Y>,
|
||||
|
|
|
@ -60,26 +60,11 @@ declare function my_filter<T, P: $Pred<1>>(
|
|||
cb: P
|
||||
): Array<$Refine<T, P, 1>>;
|
||||
|
||||
type A = {
|
||||
kind: \"A\",
|
||||
u: number
|
||||
};
|
||||
type B = {
|
||||
kind: \"B\",
|
||||
v: string
|
||||
};
|
||||
type C = {
|
||||
kind: \"C\",
|
||||
y: boolean
|
||||
};
|
||||
type D = {
|
||||
kind: \"D\",
|
||||
x: boolean
|
||||
};
|
||||
type E = {
|
||||
kind: \"E\",
|
||||
y: boolean
|
||||
};
|
||||
type A = { kind: \"A\", u: number };
|
||||
type B = { kind: \"B\", v: string };
|
||||
type C = { kind: \"C\", y: boolean };
|
||||
type D = { kind: \"D\", x: boolean };
|
||||
type E = { kind: \"E\", y: boolean };
|
||||
|
||||
declare var ab: Array<A | B | C>;
|
||||
|
||||
|
@ -267,26 +252,11 @@ declare function my_filter<T, P: $Pred<1>>(
|
|||
cb: P
|
||||
): Array<$Refine<T, P, 1>>;
|
||||
|
||||
type A = {
|
||||
kind: \"A\",
|
||||
u: number
|
||||
};
|
||||
type B = {
|
||||
kind: \"B\",
|
||||
v: string
|
||||
};
|
||||
type C = {
|
||||
kind: \"C\",
|
||||
y: boolean
|
||||
};
|
||||
type D = {
|
||||
kind: \"D\",
|
||||
x: boolean
|
||||
};
|
||||
type E = {
|
||||
kind: \"E\",
|
||||
y: boolean
|
||||
};
|
||||
type A = { kind: \"A\", u: number };
|
||||
type B = { kind: \"B\", v: string };
|
||||
type C = { kind: \"C\", y: boolean };
|
||||
type D = { kind: \"D\", x: boolean };
|
||||
type E = { kind: \"E\", y: boolean };
|
||||
|
||||
declare var ab: Array<A | B | C>;
|
||||
|
||||
|
|
|
@ -21,9 +21,7 @@ function identity<A>(val: A): Functor<A> {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
|
||||
type F<A> = {
|
||||
foo<B>(x: A): F<B>
|
||||
};
|
||||
type F<A> = { foo<B>(x: A): F<B> };
|
||||
declare function foo(x: any): F<any>;
|
||||
({ foo }: F<any>);
|
||||
|
||||
|
@ -204,9 +202,7 @@ function foo(x: I<number>): J<number> {
|
|||
// I<number> and J<number> both expand to () => () => ...
|
||||
}
|
||||
|
||||
type Q<X> = {
|
||||
x: X
|
||||
};
|
||||
type Q<X> = { x: X };
|
||||
type P<X> = () => Q<P<X>>;
|
||||
|
||||
function bar(x: P<number>): () => P<number> {
|
||||
|
|
|
@ -208,13 +208,7 @@ export const LIFE = 42;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
|
||||
export type Action =
|
||||
| {
|
||||
type: \"FOO\"
|
||||
}
|
||||
| {
|
||||
type: \"BAR\"
|
||||
};
|
||||
export type Action = { type: \"FOO\" } | { type: \"BAR\" };
|
||||
|
||||
export const LIFE = 42;
|
||||
"
|
||||
|
|
|
@ -10,13 +10,7 @@ export const LIFE = 42;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
|
||||
export type Action =
|
||||
| {
|
||||
type: \"QUX\"
|
||||
}
|
||||
| {
|
||||
type: \"BAR\"
|
||||
};
|
||||
export type Action = { type: \"QUX\" } | { type: \"BAR\" };
|
||||
|
||||
export const LIFE = 42;
|
||||
"
|
||||
|
|
|
@ -10,13 +10,7 @@ export const LIFE = 0;
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
|
||||
export type Action =
|
||||
| {
|
||||
type: \"QUX\"
|
||||
}
|
||||
| {
|
||||
type: \"BAR\"
|
||||
};
|
||||
export type Action = { type: \"QUX\" } | { type: \"BAR\" };
|
||||
|
||||
export const LIFE = 0;
|
||||
"
|
||||
|
|
|
@ -318,15 +318,7 @@ let tests = [
|
|||
return x.result; // error
|
||||
},
|
||||
function() {
|
||||
type T =
|
||||
| {
|
||||
foo: Object,
|
||||
bar: string
|
||||
}
|
||||
| {
|
||||
baz: string,
|
||||
quux: string
|
||||
};
|
||||
type T = { foo: Object, bar: string } | { baz: string, quux: string };
|
||||
|
||||
function testAlwaysTruthyProp(t: T) {
|
||||
if (t.foo) {
|
||||
|
@ -615,9 +607,7 @@ function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) {
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// @flow
|
||||
|
||||
type Obj = {
|
||||
p: number | string
|
||||
};
|
||||
type Obj = { p: number | string };
|
||||
|
||||
function f() {}
|
||||
|
||||
|
@ -692,9 +682,7 @@ function def_assign_within_for(b: boolean, obj: Obj) {
|
|||
|
||||
// --- name-sensitive havoc ---
|
||||
|
||||
type Obj2 = {
|
||||
q: number | string
|
||||
};
|
||||
type Obj2 = { q: number | string };
|
||||
|
||||
function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) {
|
||||
obj.p = 10; // (obj.p : number)
|
||||
|
@ -1403,14 +1391,7 @@ let tests = [
|
|||
}
|
||||
return x.foo; // error
|
||||
},
|
||||
function(
|
||||
x:
|
||||
| { kind: 0, foo: number }
|
||||
| {
|
||||
kind: 1,
|
||||
bar: number
|
||||
}
|
||||
): number {
|
||||
function(x: { kind: 0, foo: number } | { kind: 1, bar: number }): number {
|
||||
if (x.kind === 0) {
|
||||
return x.foo;
|
||||
} else {
|
||||
|
@ -1993,12 +1974,7 @@ let tests = [
|
|||
return x.foo; // error
|
||||
},
|
||||
function(
|
||||
x:
|
||||
| { kind: \"foo\", foo: string }
|
||||
| {
|
||||
kind: \"bar\",
|
||||
bar: string
|
||||
}
|
||||
x: { kind: \"foo\", foo: string } | { kind: \"bar\", bar: string }
|
||||
): string {
|
||||
if (x.kind === \"foo\") {
|
||||
return x.foo;
|
||||
|
@ -2493,24 +2469,10 @@ function foo(x: ASTNode) {
|
|||
}
|
||||
|
||||
// example 3
|
||||
type Apple = {
|
||||
kind: \"Fruit\",
|
||||
taste: \"Bad\"
|
||||
};
|
||||
type Orange = {
|
||||
kind: \"Fruit\",
|
||||
taste: \"Good\"
|
||||
};
|
||||
type Broccoli = {
|
||||
kind: \"Veg\",
|
||||
taste: \"Bad\",
|
||||
raw: \"No\"
|
||||
};
|
||||
type Carrot = {
|
||||
kind: \"Veg\",
|
||||
taste: \"Good\",
|
||||
raw: \"Maybe\"
|
||||
};
|
||||
type Apple = { kind: \"Fruit\", taste: \"Bad\" };
|
||||
type Orange = { kind: \"Fruit\", taste: \"Good\" };
|
||||
type Broccoli = { kind: \"Veg\", taste: \"Bad\", raw: \"No\" };
|
||||
type Carrot = { kind: \"Veg\", taste: \"Good\", raw: \"Maybe\" };
|
||||
|
||||
type Breakfast = Apple | Orange | Broccoli | Carrot;
|
||||
|
||||
|
@ -2566,10 +2528,7 @@ kind({ kind: EnumKind.A, A: 1 });
|
|||
|
||||
// example 6
|
||||
type Citizen = { citizen: true };
|
||||
type NonCitizen = {
|
||||
citizen: false,
|
||||
nationality: string
|
||||
};
|
||||
type NonCitizen = { citizen: false, nationality: string };
|
||||
function nationality(x: Citizen | NonCitizen) {
|
||||
if (x.citizen) return \"Shire\";
|
||||
else return x.nationality;
|
||||
|
|
|
@ -182,9 +182,7 @@ declare function map<Tv, TNext>(
|
|||
*/
|
||||
function test(
|
||||
x: { kind: ?string },
|
||||
kinds: {
|
||||
[key: string]: string
|
||||
}
|
||||
kinds: { [key: string]: string }
|
||||
): Array<{ kind: ?string }> {
|
||||
return map(kinds, value => {
|
||||
(value: string); // OK
|
||||
|
|
|
@ -78,9 +78,7 @@ module.exports = o;
|
|||
|
||||
// progressively annotate:
|
||||
|
||||
var o = {
|
||||
x: 0
|
||||
};
|
||||
var o = { x: 0 };
|
||||
//var o: {x: number;} = { x: 0 }
|
||||
|
||||
var x: string = o.x;
|
||||
|
|
|
@ -12,9 +12,7 @@ exports[`test B.js 1`] = `
|
|||
module.exports = { foo: \"\" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* @flow */
|
||||
module.exports = {
|
||||
foo: \"\"
|
||||
};
|
||||
module.exports = { foo: \"\" };
|
||||
"
|
||||
`;
|
||||
|
||||
|
|
|
@ -144,9 +144,7 @@ interface HasOptional {
|
|||
b?: number
|
||||
}
|
||||
|
||||
var test1: HasOptional = {
|
||||
a: \"hello\"
|
||||
};
|
||||
var test1: HasOptional = { a: \"hello\" };
|
||||
|
||||
var test2: HasOptional = {}; // Error: missing property a
|
||||
var test3: HasOptional = { a: \"hello\", b: true }; // Error: boolean ~> number
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
exports[`test bar.js 1`] = `
|
||||
"export type Foo = { x: number; }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
export type Foo = {
|
||||
x: number
|
||||
};
|
||||
export type Foo = { x: number };
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test foo.js 1`] = `
|
||||
"export type Foo = { x: number; }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
export type Foo = {
|
||||
x: number
|
||||
};
|
||||
export type Foo = { x: number };
|
||||
"
|
||||
`;
|
||||
|
||||
|
|
|
@ -267,12 +267,8 @@ class C {
|
|||
function foo(c: C): I { return c; }
|
||||
function bar(c: C): J { return c; }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
interface I {
|
||||
xs: Array<this>
|
||||
}
|
||||
interface J {
|
||||
f(): J
|
||||
}
|
||||
interface I { xs: Array<this> }
|
||||
interface J { f(): J }
|
||||
class C {
|
||||
xs: Array<C>;
|
||||
f(): C {
|
||||
|
|
|
@ -81,15 +81,11 @@ function f(b): React.Element<*> {
|
|||
var React = require(\"react\");
|
||||
|
||||
var A = React.createClass({
|
||||
propTypes: {
|
||||
foo: React.PropTypes.string.isRequired
|
||||
}
|
||||
propTypes: { foo: React.PropTypes.string.isRequired }
|
||||
});
|
||||
|
||||
var B = React.createClass({
|
||||
propTypes: {
|
||||
bar: React.PropTypes.string.isRequired
|
||||
}
|
||||
propTypes: { bar: React.PropTypes.string.isRequired }
|
||||
});
|
||||
|
||||
function f(b): React.Element<*> {
|
||||
|
|
|
@ -121,9 +121,7 @@ var bar: Array<{b: ?boolean, c: number} | {b: boolean}> = [
|
|||
|
||||
var bar: Array<{ b: ?boolean, c: number } | { b: boolean }> = [
|
||||
{ b: true, c: 123 },
|
||||
{
|
||||
b: true
|
||||
}
|
||||
{ b: true }
|
||||
];
|
||||
"
|
||||
`;
|
||||
|
@ -139,12 +137,7 @@ exports[`test issue-1371.js 1`] = `
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function create(
|
||||
a: any
|
||||
):
|
||||
| { type: \"B\", data: number }
|
||||
| {
|
||||
type: \"A\",
|
||||
data: string
|
||||
} {
|
||||
): { type: \"B\", data: number } | { type: \"A\", data: string } {
|
||||
return {
|
||||
type: \"A\",
|
||||
data: a
|
||||
|
@ -692,9 +685,7 @@ type B3 = string;
|
|||
function alias(a: T<number> | T<string>) {}
|
||||
alias({ x: (x: V<B4>) => {} });
|
||||
|
||||
type T<X> = {
|
||||
x: U<X>
|
||||
};
|
||||
type T<X> = { x: U<X> };
|
||||
type U<X> = (x: V<X>) => void;
|
||||
type V<X> = X;
|
||||
|
||||
|
@ -1347,16 +1338,9 @@ function rec(x: F<string>): G | H { return x; }
|
|||
|
||||
// polymorphic recursive types
|
||||
|
||||
type F<X> = {
|
||||
f: F<X>,
|
||||
x: X
|
||||
};
|
||||
type G = {
|
||||
x: number
|
||||
};
|
||||
type H = {
|
||||
x: string
|
||||
};
|
||||
type F<X> = { f: F<X>, x: X };
|
||||
type G = { x: number };
|
||||
type H = { x: string };
|
||||
|
||||
function rec(x: F<string>): G | H {
|
||||
return x;
|
||||
|
@ -1659,15 +1643,7 @@ function str() {
|
|||
|
||||
// annotations for disjoint unions
|
||||
|
||||
type T =
|
||||
| {
|
||||
type: \"FOO\",
|
||||
x: number
|
||||
}
|
||||
| {
|
||||
type: \"BAR\",
|
||||
x: string
|
||||
};
|
||||
type T = { type: \"FOO\", x: number } | { type: \"BAR\", x: string };
|
||||
|
||||
({ type: (bar(): \"BAR\"), x: str() }: T);
|
||||
|
||||
|
@ -2037,15 +2013,7 @@ type ActionType =
|
|||
|
||||
const Constants = require(\"./test30-helper\");
|
||||
|
||||
type ActionType =
|
||||
| {
|
||||
type: \"foo\",
|
||||
x: number
|
||||
}
|
||||
| {
|
||||
type: \"bar\",
|
||||
x: number
|
||||
};
|
||||
type ActionType = { type: \"foo\", x: number } | { type: \"bar\", x: number };
|
||||
|
||||
({ type: Constants.BAR, x: 0 }: ActionType);
|
||||
"
|
||||
|
|
|
@ -4,9 +4,7 @@ exports[`test module.js 1`] = `
|
|||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
declare module X {
|
||||
declare interface Y {
|
||||
x: number
|
||||
}
|
||||
declare interface Y { x: number }
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -50,13 +50,7 @@ const e = classnames({
|
|||
});
|
||||
|
||||
const f = classnames({
|
||||
\"some-prop\": {
|
||||
foo: \"bar\",
|
||||
bar: \"foo\",
|
||||
foo: \"bar\",
|
||||
bar: \"foo\",
|
||||
foo: \"bar\"
|
||||
}
|
||||
\"some-prop\": { foo: \"bar\", bar: \"foo\", foo: \"bar\", bar: \"foo\", foo: \"bar\" }
|
||||
});
|
||||
|
||||
const g = classnames({
|
||||
|
|
|
@ -8,3 +8,34 @@ a = () => ({}).x;
|
|||
a = () => ({}).x;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test range.js 1`] = `
|
||||
"group(
|
||||
concat([
|
||||
\"(\",
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([line, join(concat([\",\", line]), printed)])
|
||||
),
|
||||
options.trailingComma ? \",\" : \"\",
|
||||
line,
|
||||
\")\"
|
||||
]),
|
||||
{shouldBreak: true}
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
group(
|
||||
concat([
|
||||
\"(\",
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([line, join(concat([\",\", line]), printed)])
|
||||
),
|
||||
options.trailingComma ? \",\" : \"\",
|
||||
line,
|
||||
\")\"
|
||||
]),
|
||||
{ shouldBreak: true }
|
||||
);
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
group(
|
||||
concat([
|
||||
"(",
|
||||
indent(
|
||||
options.tabWidth,
|
||||
concat([line, join(concat([",", line]), printed)])
|
||||
),
|
||||
options.trailingComma ? "," : "",
|
||||
line,
|
||||
")"
|
||||
]),
|
||||
{shouldBreak: true}
|
||||
)
|
|
@ -5,8 +5,6 @@ type Bar = { [string]: number }
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
type Foo = (any) => string;
|
||||
|
||||
type Bar = {
|
||||
[string]: number
|
||||
};
|
||||
type Bar = { [string]: number };
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -19,12 +19,7 @@ const obj1 = conditionIsTruthy
|
|||
|
||||
const obj2 = conditionIsTruthy
|
||||
? shortThing
|
||||
: {
|
||||
some: \"long\",
|
||||
object: \"with\",
|
||||
lots: \"of\",
|
||||
stuff
|
||||
};
|
||||
: { some: \"long\", object: \"with\", lots: \"of\", stuff };
|
||||
|
||||
const obj3 = conditionIsTruthy
|
||||
? {
|
||||
|
|
Loading…
Reference in New Issue