From 67e121a20b9d5d983970bdc2dcba5de2bd0f7beb Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 2 Nov 2022 10:45:34 +0900 Subject: [PATCH] Add more tests for `satisfies` (#13775) --- package.json | 2 +- src/language-js/needs-parens.js | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 55 +++++++++++++++++++ .../typescript/satisfies-operators/lhs.ts | 5 ++ yarn.lock | 10 ++-- 5 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 tests/format/typescript/satisfies-operators/lhs.ts diff --git a/package.json b/package.json index 552863c1c..814478eb7 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "@angular/compiler": "14.2.8", "@babel/code-frame": "7.18.6", - "@babel/parser": "7.20.0", + "@babel/parser": "7.20.1", "@babel/types": "7.20.0", "@glimmer/syntax": "0.84.2", "@iarna/toml": "2.2.5", diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 20d2e0f78..e293ff3c4 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -272,11 +272,7 @@ function needsParens(path, options) { case "AssignmentPattern": return ( key === "left" && - (node.type === "TSTypeAssertion" || - // babel-parser cannot parse `satisfies` operator in left side of assignment - // https://github.com/babel/babel/issues/15095 - // TODO: Add tests after the bug is fixed - isTSTypeExpression(node)) + (node.type === "TSTypeAssertion" || isTSTypeExpression(node)) ); case "LogicalExpression": diff --git a/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap index 2a4c951f3..027458b92 100644 --- a/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap @@ -576,6 +576,61 @@ window.postMessage({ ================================================================================ `; +exports[`lhs.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = this.multiselectWidget = this.initialValues = undefined; +(this.configuration satisfies any) = (this.editor satisfies any) = (this + .editorBody satisfies any) = undefined; + +=====================================output===================================== +;(a satisfies number) = 42 +;({ a: (b satisfies any) = 2000 } = x) +;(this.selectorElem satisfies any) = + this.multiselectWidget = + this.initialValues = + undefined +;(this.configuration satisfies any) = + (this.editor satisfies any) = + (this.editorBody satisfies any) = + undefined + +================================================================================ +`; + +exports[`lhs.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = this.multiselectWidget = this.initialValues = undefined; +(this.configuration satisfies any) = (this.editor satisfies any) = (this + .editorBody satisfies any) = undefined; + +=====================================output===================================== +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = + this.multiselectWidget = + this.initialValues = + undefined; +(this.configuration satisfies any) = + (this.editor satisfies any) = + (this.editorBody satisfies any) = + undefined; + +================================================================================ +`; + exports[`nested-await-and-satisfies.ts - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["babel-ts"] diff --git a/tests/format/typescript/satisfies-operators/lhs.ts b/tests/format/typescript/satisfies-operators/lhs.ts new file mode 100644 index 000000000..fbdbe1c91 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/lhs.ts @@ -0,0 +1,5 @@ +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = this.multiselectWidget = this.initialValues = undefined; +(this.configuration satisfies any) = (this.editor satisfies any) = (this + .editorBody satisfies any) = undefined; diff --git a/yarn.lock b/yarn.lock index db95a38c3..f022cf7af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -228,12 +228,12 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:7.20.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.18.10, @babel/parser@npm:^7.18.11": - version: 7.20.0 - resolution: "@babel/parser@npm:7.20.0" +"@babel/parser@npm:7.20.1, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.18.10, @babel/parser@npm:^7.18.11": + version: 7.20.1 + resolution: "@babel/parser@npm:7.20.1" bin: parser: ./bin/babel-parser.js - checksum: d54d68e45ff1b9a0c50a3f79d9031f482eb58f18928525949dc20da5b1658ee79167e756129371fd75d3e8fc7e218ab707727145a68958636be9672c7b71768e + checksum: 2db7ba692b8b3054df129876b115ed8b265d5c138dee5e1db56a999209df3dd3d508e0985bf3cc44fc432498da094c164906b531d049608e55e208dae0678d42 languageName: node linkType: hard @@ -6612,7 +6612,7 @@ __metadata: "@angular/compiler": 14.2.8 "@babel/code-frame": 7.18.6 "@babel/generator": 7.20.0 - "@babel/parser": 7.20.0 + "@babel/parser": 7.20.1 "@babel/types": 7.20.0 "@esbuild-plugins/node-modules-polyfill": 0.1.4 "@glimmer/reference": 0.84.2