diff --git a/package.json b/package.json index 692fc40e3ab1..3d657ab6e2ae 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dependencies": { "@angular/compiler": "12.2.1", "@babel/code-frame": "7.14.5", - "@babel/parser": "7.15.2", + "@babel/parser": "7.15.3", "@glimmer/syntax": "0.80.0", "@iarna/toml": "2.2.5", "@typescript-eslint/typescript-estree": "4.29.1", 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); diff --git a/yarn.lock b/yarn.lock index a7eb3fdec948..c964b14bfa1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -298,15 +298,10 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@7.15.2": - version "7.15.2" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.2.tgz#08d4ffcf90d211bf77e7cc7154c6f02d468d2b1d" - integrity sha512-bMJXql1Ss8lFnvr11TZDH4ArtwlAS5NG9qBmdiFW2UHHm6MVoR+GDc5XE2b9K938cyjc9O6/+vjjcffLDtfuDg== - -"@babel/parser@^7.1.0", "@babel/parser@^7.14.5", "@babel/parser@^7.15.0", "@babel/parser@^7.7.2": - version "7.15.0" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.0.tgz#b6d6e29058ca369127b0eeca2a1c4b5794f1b6b9" - integrity sha512-0v7oNOjr6YT9Z2RAOTv4T9aP+ubfx4Q/OhVtAet7PFDt0t9Oy6Jn+/rfC6b8HJ5zEqrQCiMxJfgtHpmIminmJQ== +"@babel/parser@7.15.3", "@babel/parser@^7.1.0", "@babel/parser@^7.14.5", "@babel/parser@^7.15.0", "@babel/parser@^7.7.2": + version "7.15.3" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.3.tgz#3416d9bea748052cfcb63dbcc27368105b1ed862" + integrity sha512-O0L6v/HvqbdJawj0iBEfVQMc3/6WP+AeOsovsIgBFyJaG+W2w7eqvZB7puddATmWuARlm1SX7DwxJ/JJUnDpEA== "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@^7.14.5": version "7.14.5"