From 9f1c94daeb237f87e371d23d34b2ba5b60f19fbc Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 7 Feb 2022 13:04:28 +0800 Subject: [PATCH] Add test for Reinterpret << when parsing TS type arguments babel/babel#14145 --- .../type-arguments-bit-shift-left-like/1.ts | 1 + .../type-arguments-bit-shift-left-like/2.ts | 1 + .../type-arguments-bit-shift-left-like/3.ts | 1 + .../type-arguments-bit-shift-left-like/4.ts | 1 + .../type-arguments-bit-shift-left-like/5.tsx | 1 + .../type-arguments-bit-shift-left-like/6.ts | 1 + .../__snapshots__/jsfmt.spec.js.snap | 107 ++++++++++++++++++ .../jsfmt.spec.js | 3 + 8 files changed, 116 insertions(+) create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/1.ts create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/2.ts create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/3.ts create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/4.ts create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/5.tsx create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/6.ts create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/typescript/type-arguments-bit-shift-left-like/jsfmt.spec.js diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/1.ts b/tests/format/typescript/type-arguments-bit-shift-left-like/1.ts new file mode 100644 index 000000000000..22101bcfd01d --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/1.ts @@ -0,0 +1 @@ +f<<(x) diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/2.ts b/tests/format/typescript/type-arguments-bit-shift-left-like/2.ts new file mode 100644 index 000000000000..94b8ba09b57d --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/2.ts @@ -0,0 +1 @@ +f<(v: T) => void>(); diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/3.ts b/tests/format/typescript/type-arguments-bit-shift-left-like/3.ts new file mode 100644 index 000000000000..8db082343420 --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/3.ts @@ -0,0 +1 @@ +(class extends f<(v: T) => void> {}); diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/4.ts b/tests/format/typescript/type-arguments-bit-shift-left-like/4.ts new file mode 100644 index 000000000000..7316ad25571d --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/4.ts @@ -0,0 +1 @@ +(@f<(v: T) => void>() class {}); diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/5.tsx b/tests/format/typescript/type-arguments-bit-shift-left-like/5.tsx new file mode 100644 index 000000000000..5ad697cb46a8 --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/5.tsx @@ -0,0 +1 @@ +(v: T) => void> /> diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/6.ts b/tests/format/typescript/type-arguments-bit-shift-left-like/6.ts new file mode 100644 index 000000000000..7991a4bbd640 --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/6.ts @@ -0,0 +1 @@ +new f<(v: T) => void>(); diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..5108ca955b08 --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,107 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`1.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +f<<(x) + +=====================================output===================================== +f << (x); + +================================================================================ +`; + +exports[`2.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +f<(v: T) => void>(); + +=====================================output===================================== +f<(v: T) => void>(); + +================================================================================ +`; + +exports[`3.ts [babel-ts] format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +(class extends f<(v: T) => void> {}); + +=====================================output===================================== +(class extends f<(v: T) => void> {}); + +================================================================================ +`; + +exports[`3.ts [typescript] format 1`] = ` +"',' expected. (1:17) +> 1 | (class extends f<(v: T) => void> {}); + | ^ + 2 |" +`; + +exports[`4.ts [babel-ts] format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +(@f<(v: T) => void>() class {}); + +=====================================output===================================== +@f<(v: T) => void>() +class {}; + +================================================================================ +`; + +exports[`4.ts [typescript] format 1`] = ` +"Expression expected. (1:2) +> 1 | (@f<(v: T) => void>() class {}); + | ^ + 2 |" +`; + +exports[`5.tsx [babel-ts] format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +(v: T) => void> /> + +=====================================output===================================== +(v: T) => void> />; + +================================================================================ +`; + +exports[`5.tsx [typescript] format 1`] = ` +"Identifier expected. (1:11) +> 1 | (v: T) => void> /> + | ^ + 2 |" +`; + +exports[`6.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +new f<(v: T) => void>(); + +=====================================output===================================== +new f<(v: T) => void>(); + +================================================================================ +`; diff --git a/tests/format/typescript/type-arguments-bit-shift-left-like/jsfmt.spec.js b/tests/format/typescript/type-arguments-bit-shift-left-like/jsfmt.spec.js new file mode 100644 index 000000000000..2775ae27811f --- /dev/null +++ b/tests/format/typescript/type-arguments-bit-shift-left-like/jsfmt.spec.js @@ -0,0 +1,3 @@ +run_spec(__dirname, ["typescript"], { + errors: { typescript: ["3.ts", "4.ts", "5.tsx"] }, +});