From c26f73d0903eb0b0ab9b3da1e5fd1b1d582f75a3 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Thu, 19 Aug 2021 06:42:31 +0900 Subject: [PATCH] Add tests for babel/babel#13655 --- .../ternary/__snapshots__/jsfmt.spec.js.snap | 60 +++++++++++++++++++ tests/format/flow/ternary/arrows.js | 16 +++++ tests/format/flow/ternary/jsfmt.spec.js | 3 + 3 files changed, 79 insertions(+) create mode 100644 tests/format/flow/ternary/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/flow/ternary/arrows.js create mode 100644 tests/format/flow/ternary/jsfmt.spec.js 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"] }, +});