From fc16db79b7ee7d0cda252c302e1bff13221ed435 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 29 Mar 2021 21:51:03 +0800 Subject: [PATCH] Add tests from https://github.com/babel/babel/pull/12933 --- .../__snapshots__/jsfmt.spec.js.snap | 25 +++++++++++++++++++ tests/misc/errors/js/assignment/jsfmt.spec.js | 7 ++++++ .../__snapshots__/jsfmt.spec.js.snap | 24 ++++++++++++++++++ tests/typescript/assignment/parenthesized.ts | 6 +++++ 4 files changed, 62 insertions(+) create mode 100644 tests/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/misc/errors/js/assignment/jsfmt.spec.js create mode 100644 tests/typescript/assignment/parenthesized.ts diff --git a/tests/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..0a7e2a259209 --- /dev/null +++ b/tests/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 [babel] format 1`] = ` +"Invalid parenthesized assignment pattern (1:1) +> 1 | ({}) = x; + | ^" +`; + +exports[`snippet: #0 [babel-ts] format 1`] = ` +"Invalid parenthesized assignment pattern (1:1) +> 1 | ({}) = x; + | ^" +`; + +exports[`snippet: #0 [espree] format 1`] = ` +"Parenthesized pattern (1:1) +> 1 | ({}) = x; + | ^" +`; + +exports[`snippet: #0 [meriyah] format 1`] = ` +"[1:6]: Invalid left-hand side in assignment (1:6) +> 1 | ({}) = x; + | ^" +`; diff --git a/tests/misc/errors/js/assignment/jsfmt.spec.js b/tests/misc/errors/js/assignment/jsfmt.spec.js new file mode 100644 index 000000000000..f987b21113fe --- /dev/null +++ b/tests/misc/errors/js/assignment/jsfmt.spec.js @@ -0,0 +1,7 @@ +run_spec( + { + dirname: __dirname, + snippets: ["({}) = x;"], + }, + ["babel", "babel-ts", "espree", "meriyah"] +); diff --git a/tests/typescript/assignment/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/assignment/__snapshots__/jsfmt.spec.js.snap index c2bbfff352a5..21ffd8bcfd40 100644 --- a/tests/typescript/assignment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/assignment/__snapshots__/jsfmt.spec.js.snap @@ -179,3 +179,27 @@ const firestorePersonallyIdentifiablePaths: Array = ================================================================================ `; + +exports[`parenthesized.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// https://github.com/babel/babel/pull/12933/files +(x) = null; +(x!) = null; +(a as any) = null; +(a as number) = 42; +((a as any) as string) = null; + +=====================================output===================================== +// https://github.com/babel/babel/pull/12933/files +(x) = null; +x! = null; +(a as any) = null; +(a as number) = 42; +((a as any) as string) = null; + +================================================================================ +`; diff --git a/tests/typescript/assignment/parenthesized.ts b/tests/typescript/assignment/parenthesized.ts new file mode 100644 index 000000000000..27511999df7d --- /dev/null +++ b/tests/typescript/assignment/parenthesized.ts @@ -0,0 +1,6 @@ +// https://github.com/babel/babel/pull/12933/files +(x) = null; +(x!) = null; +(a as any) = null; +(a as number) = 42; +((a as any) as string) = null;