Skip to content

Commit

Permalink
Add tests for babel/babel#13655
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Aug 18, 2021
1 parent 09510ab commit c26f73d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
60 changes: 60 additions & 0 deletions 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"
`;
16 changes: 16 additions & 0 deletions 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)
3 changes: 3 additions & 0 deletions tests/format/flow/ternary/jsfmt.spec.js
@@ -0,0 +1,3 @@
run_spec(__dirname, ["flow", "babel-flow"], {
errors: { flow: ["arrows.js"] },
});

0 comments on commit c26f73d

Please sign in to comment.