diff --git a/tests/format/flow/import/__snapshots__/jsfmt.spec.js.snap b/tests/format/flow/import/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..18f52fe31bb5 --- /dev/null +++ b/tests/format/flow/import/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`import-as-as.js format 1`] = ` +====================================options===================================== +parsers: ["flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +// @flow +import { foo as as } from "foo"; +import { as as as } from "foo"; +import { as as foo } from "foo"; + +=====================================output===================================== +// @flow +import { foo as as } from "foo"; +import { as as as } from "foo"; +import { as as foo } from "foo"; + +================================================================================ +`; + +exports[`type-import-as-as.js format 1`] = ` +====================================options===================================== +parsers: ["flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +import {type foo as as} from "foo"; + +=====================================output===================================== +import { type foo as as } from "foo"; + +================================================================================ +`; diff --git a/tests/format/flow/import/import-as-as.js b/tests/format/flow/import/import-as-as.js new file mode 100644 index 000000000000..5f3bb61851f8 --- /dev/null +++ b/tests/format/flow/import/import-as-as.js @@ -0,0 +1,4 @@ +// @flow +import { foo as as } from "foo"; +import { as as as } from "foo"; +import { as as foo } from "foo"; diff --git a/tests/format/flow/import/jsfmt.spec.js b/tests/format/flow/import/jsfmt.spec.js new file mode 100644 index 000000000000..b9a908981a50 --- /dev/null +++ b/tests/format/flow/import/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow"]); diff --git a/tests/format/flow/import/type-import-as-as.js b/tests/format/flow/import/type-import-as-as.js new file mode 100644 index 000000000000..4c047ef9e33c --- /dev/null +++ b/tests/format/flow/import/type-import-as-as.js @@ -0,0 +1 @@ +import {type foo as as} from "foo"; diff --git a/tests/format/flow/ternary/__snapshots__/jsfmt.spec.js.snap b/tests/format/flow/ternary/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..8cc73dc36614 --- /dev/null +++ b/tests/format/flow/ternary/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,60 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`arrows.js [babel-flow] format 1`] = ` +====================================options===================================== +parsers: ["flow", "babel-flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +// Test cases from babel +// ref: https://github.com/babel/babel/blob/614b48678095746b83bbe517c4d6b30ba8cd5c04/packages/babel-parser/test/fixtures/flow/arrows-in-ternaries/issue-13644/input.js +// \`flow\` cannot parse below codes +// ref: https://github.com/facebook/flow/issues/8731 + +(a ? (b = c) : d => e); // a ? (b = c) : (d => e) +(a ? (b += c) : d => e); // a ? (b += c) : (d => e) + +(a ? (b = c) : d => e : f); // a ? ((b = c): d => e) : f +(a ? (b += c) : d => e : f); // ((a ? (b += c) : (d => e)) : f) + +(a ? b => (c = d) : e => f); // a ? (b => (c = d)) : (e => f) +(a ? b => (c += d) : e => f); // a ? (b => (c += d)) : (e => f) + +(a ? b => (c = d) : e => f : g); // a ? (b => ((c = d): e => f)) : g +(a ? b => (c += d) : e => f : g); // ((a ? (b => (c += d)) : (e => f)) : g) + +=====================================output===================================== +// Test cases from babel +// ref: https://github.com/babel/babel/blob/614b48678095746b83bbe517c4d6b30ba8cd5c04/packages/babel-parser/test/fixtures/flow/arrows-in-ternaries/issue-13644/input.js +// \`flow\` cannot parse below codes +// ref: https://github.com/facebook/flow/issues/8731 + +a ? (b = c) : (d) => e; // a ? (b = c) : (d => e) +a ? (b += c) : (d) => e; // a ? (b += c) : (d => e) + +a ? (b = c): d => e : f; // a ? ((b = c): d => e) : f +((a ? (b += c) : (d) => e): f); // ((a ? (b += c) : (d => e)) : f) + +a ? (b) => (c = d) : (e) => f; // a ? (b => (c = d)) : (e => f) +a ? (b) => (c += d) : (e) => f; // a ? (b => (c += d)) : (e => f) + +a + ? (b) => + (c = d): e => + f + : g; // a ? (b => ((c = d): e => f)) : g +((a ? (b) => (c += d) : (e) => f): g); // ((a ? (b => (c += d)) : (e => f)) : g) + +================================================================================ +`; + +exports[`arrows.js [flow] format 1`] = ` +"Unexpected token \`)\`, expected the token \`:\` (6:22) + 4 | // ref: https://github.com/facebook/flow/issues/8731 + 5 | +> 6 | (a ? (b = c) : d => e); // a ? (b = c) : (d => e) + | ^ + 7 | (a ? (b += c) : d => e); // a ? (b += c) : (d => e) + 8 | + 9 | (a ? (b = c) : d => e : f); // a ? ((b = c): d => e) : f" +`; diff --git a/tests/format/flow/ternary/arrows.js b/tests/format/flow/ternary/arrows.js new file mode 100644 index 000000000000..12b301f02b98 --- /dev/null +++ b/tests/format/flow/ternary/arrows.js @@ -0,0 +1,16 @@ +// Test cases from babel +// ref: https://github.com/babel/babel/blob/614b48678095746b83bbe517c4d6b30ba8cd5c04/packages/babel-parser/test/fixtures/flow/arrows-in-ternaries/issue-13644/input.js +// `flow` cannot parse below codes +// ref: https://github.com/facebook/flow/issues/8731 + +(a ? (b = c) : d => e); // a ? (b = c) : (d => e) +(a ? (b += c) : d => e); // a ? (b += c) : (d => e) + +(a ? (b = c) : d => e : f); // a ? ((b = c): d => e) : f +(a ? (b += c) : d => e : f); // ((a ? (b += c) : (d => e)) : f) + +(a ? b => (c = d) : e => f); // a ? (b => (c = d)) : (e => f) +(a ? b => (c += d) : e => f); // a ? (b => (c += d)) : (e => f) + +(a ? b => (c = d) : e => f : g); // a ? (b => ((c = d): e => f)) : g +(a ? b => (c += d) : e => f : g); // ((a ? (b => (c += d)) : (e => f)) : g) diff --git a/tests/format/flow/ternary/jsfmt.spec.js b/tests/format/flow/ternary/jsfmt.spec.js new file mode 100644 index 000000000000..824dde386563 --- /dev/null +++ b/tests/format/flow/ternary/jsfmt.spec.js @@ -0,0 +1,3 @@ +run_spec(__dirname, ["flow", "babel-flow"], { + errors: { flow: ["arrows.js"] }, +}); diff --git a/tests/format/misc/errors/babel-flow/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/babel-flow/__snapshots__/jsfmt.spec.js.snap index 770a98581a6e..f3a74f0d3dd0 100644 --- a/tests/format/misc/errors/babel-flow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/babel-flow/__snapshots__/jsfmt.spec.js.snap @@ -17,3 +17,17 @@ exports[`async-arrow-invalid.js [babel-flow] format 1`] = ` | ^ 4 |" `; + +exports[`wrong-arrow-no-parens-jsx.js [babel] format 1`] = ` +"Unterminated JSX contents. (1:4) +> 1 | (a => b); + | ^ + 2 |" +`; + +exports[`wrong-arrow-no-parens-jsx.js [babel-flow] format 1`] = ` +"Unterminated JSX contents. (1:4) +> 1 | (a => b); + | ^ + 2 |" +`; diff --git a/tests/format/misc/errors/babel-flow/wrong-arrow-no-parens-jsx.js b/tests/format/misc/errors/babel-flow/wrong-arrow-no-parens-jsx.js new file mode 100644 index 000000000000..11885587667e --- /dev/null +++ b/tests/format/misc/errors/babel-flow/wrong-arrow-no-parens-jsx.js @@ -0,0 +1 @@ +(a => b);