Skip to content

Commit

Permalink
Add tests for @babel/parser 7.15.3 (#11366)
Browse files Browse the repository at this point in the history
* Add tests for babel/babel#13659

* Add tests for babel/babel#13655

* Add tests for babel/babel#13645

* Update tests
  • Loading branch information
sosukesuzuki committed Aug 18, 2021
1 parent c05115d commit 4f1e768
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 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";
================================================================================
`;
4 changes: 4 additions & 0 deletions 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";
1 change: 1 addition & 0 deletions tests/format/flow/import/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["flow"]);
1 change: 1 addition & 0 deletions tests/format/flow/import/type-import-as-as.js
@@ -0,0 +1 @@
import {type foo as as} from "foo";
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"] },
});
Expand Up @@ -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 | <T>(a => b);
| ^
2 |"
`;
exports[`wrong-arrow-no-parens-jsx.js [babel-flow] format 1`] = `
"Unterminated JSX contents. (1:4)
> 1 | <T>(a => b);
| ^
2 |"
`;
@@ -0,0 +1 @@
<T>(a => b);

0 comments on commit 4f1e768

Please sign in to comment.