Skip to content

Commit

Permalink
Add more tests for satisfies (#13775)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Nov 2, 2022
1 parent 931661a commit 67e121a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions src/language-js/needs-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions tests/format/typescript/satisfies-operators/lhs.ts
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 67e121a

Please sign in to comment.