prettier/tests/flow/type-at-pos/__snapshots__/jsfmt.spec.js.snap

283 lines
4.9 KiB
Plaintext
Raw Normal View History

exports[`test destructuring.js 1`] = `
"// @flow
let [x, y] = [1, 2];
/**
* Test what happens when the destructuring is unevaluated. In this case,
* \`this\` in a function is unbound, so we never actually find out the type of
* \`this.returnsATuple()\` is; thus, we never evaluate \`b\` and so type-at-pos
* returns EmptyT.
*/
export const X = {
returnsATuple: function(): [number, number] {
return [1, 2];
},
test: function() {
let [a, b] = this.returnsATuple();
}
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
let [x, y] = [1, 2];
/**
* Test what happens when the destructuring is unevaluated. In this case,
* \`this\` in a function is unbound, so we never actually find out the type of
* \`this.returnsATuple()\` is; thus, we never evaluate \`b\` and so type-at-pos
* returns EmptyT.
*/
export const X = {
returnsATuple: function(): [number, number] {
return [1, 2];
},
test: function() {
let [a, b] = this.returnsATuple();
}
2017-01-11 18:16:38 +03:00
};
"
`;
exports[`test function_expressions.js 1`] = `
"// @flow
// TODO: type-at-pos between the ()\'s should be () => void
// class X {
// foo(): void {}
// }
const y = {
bar(): void {}
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
// TODO: type-at-pos between the ()\'s should be () => void
// class X {
// foo(): void {}
// }
const y = { bar(): void {} };
2017-01-11 18:16:38 +03:00
"
`;
exports[`test generics.js 1`] = `
"// @flow
class C<X> { }
var cn: C<number> = new C;
cn;
function foo() { return C; }
var D = foo();
var dn: D<number> = new C;
dn;
type E<X> = C<X>;
var en: E<number> = new C;
en;
type F<X> = C<void>;
var fn: F<number> = new C;
fn;
type O<X> = { x: X };
var on: O<number> = { x: 0 };
on;
type Mono = C<void>;
var mn: Mono<number> = new C; // error: application of non-poly type
mn;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
class C<X> {}
var cn: C<number> = new C();
cn;
function foo() {
return C;
}
var D = foo();
var dn: D<number> = new C();
dn;
type E<X> = C<X>;
var en: E<number> = new C();
en;
type F<X> = C<void>;
var fn: F<number> = new C();
fn;
type O<X> = { x: X };
var on: O<number> = { x: 0 };
on;
type Mono = C<void>;
var mn: Mono<number> = new C();
// error: application of non-poly type
2017-01-11 18:16:38 +03:00
mn;
"
`;
exports[`test import.js 1`] = `
"// @flow
var num = 42;
function bar() { }
bar();
module.exports = num;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var num = 42;
function bar() {}
bar();
2017-01-11 18:16:38 +03:00
module.exports = num;
"
`;
exports[`test object_special_cases.js 1`] = `
"/* @flow */
let tests = [
function() {
let x = {};
Object.defineProperty(x, \'foo\', { value: \'\' });
},
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
let tests = [
function() {
let x = {};
Object.defineProperty(x, \"foo\", { value: \"\" });
}
2017-01-11 18:16:38 +03:00
];
"
`;
exports[`test optional.js 1`] = `
"// @flow
function foo(x?: string) {
return x;
}
foo();
function bar(obj: { x?: string }) {
return obj.x;
}
function qux(x?) {
return x;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
function foo(x?: string) {
return x;
}
foo();
function bar(obj: { x?: string }) {
return obj.x;
}
function qux(x?) {
return x;
2017-01-11 18:16:38 +03:00
}
"
`;
exports[`test predicates.js 1`] = `
"/* @flow */
let x = 0;
if (x == null) {}
if (x == undefined) {}
if (Array.isArray(x)) {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
let x = 0;
if (x == null) {
}
if (x == undefined) {
}
if (Array.isArray(x)) {
}
2017-01-11 18:16:38 +03:00
"
`;
exports[`test react.js 1`] = `
"import React from \"react\";
React.createElement;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import React from \"react\";
2017-01-11 18:16:38 +03:00
React.createElement;
"
`;
exports[`test templates.js 1`] = `
"/* @flow */
\`foo bar\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
2017-01-11 18:16:38 +03:00
\`foo bar\`;
"
`;
exports[`test test.js 1`] = `
"// @flow
var str = require(\'./import\');
function foo() { }
foo();
str
type Point = [number, string];
const x:Point = [1, \"foo\"];
type MyStr = \"cool\";
const y:MyStr = \"cool\";
type MyBool = true;
const z:MyBool = true;
type MyNum = 42;
const w:MyNum = 42;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
var str = require(\"./import\");
function foo() {}
foo();
str;
type Point = [number, string];
const x: Point = [1, \"foo\"];
type MyStr = \"cool\";
const y: MyStr = \"cool\";
type MyBool = true;
const z: MyBool = true;
type MyNum = 42;
2017-01-11 18:16:38 +03:00
const w: MyNum = 42;
"
`;
exports[`test trycatch.js 1`] = `
"// @flow
try {
throw \"foo\";
} catch (e) {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
try {
throw \"foo\";
} catch (e) {
}
2017-01-11 18:16:38 +03:00
"
`;