@tsrx/prettier-plugin 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/printer.js +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsrx/prettier-plugin",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "TSRX plugin for Prettier",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"prettier-3-6": "npm:prettier@3.6.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tsrx/core": "0.6.
|
|
30
|
+
"@tsrx/core": "0.6.1"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"src/"
|
package/src/printer.js
CHANGED
|
@@ -80,6 +80,9 @@ const TSRX_VISITOR_KEYS = /** @type {Record<string, string[]>} */ ({
|
|
|
80
80
|
/** `@catch (error, reset)` has a second parameter. */
|
|
81
81
|
const CATCH_CLAUSE_KEYS = ['param', 'resetParam', 'body'];
|
|
82
82
|
|
|
83
|
+
/** A plain `try` with a `pending` block (see `printTsrx`). */
|
|
84
|
+
const PENDING_TRY_KEYS = ['block', 'pending', 'handler', 'finalizer'];
|
|
85
|
+
|
|
83
86
|
/**
|
|
84
87
|
* A shorthand attribute (`{name}`) prints only its value: its `name` is the
|
|
85
88
|
* same identifier as the value's expression, so no comment may attach to it.
|
|
@@ -169,6 +172,7 @@ export const printer = {
|
|
|
169
172
|
const keys = TSRX_VISITOR_KEYS[node.tsrxType ?? node.type];
|
|
170
173
|
if (keys) return keys;
|
|
171
174
|
if (node.type === 'CatchClause' && node.resetParam) return CATCH_CLAUSE_KEYS;
|
|
175
|
+
if (node.type === 'TryStatement' && node.pending) return PENDING_TRY_KEYS;
|
|
172
176
|
if (node.type === 'JSXAttribute' && node.shorthand) return SHORTHAND_ATTRIBUTE_KEYS;
|
|
173
177
|
return /** @type {NonNullable<Printer<Node>['getVisitorKeys']>} */ (estree.getVisitorKeys)(
|
|
174
178
|
node,
|
|
@@ -836,6 +840,21 @@ function printTsrx(path, options, print) {
|
|
|
836
840
|
];
|
|
837
841
|
}
|
|
838
842
|
|
|
843
|
+
// A `pending` block on a plain `try`, which the parser reads for
|
|
844
|
+
// `@tsrx/ripple`, and Prettier's `try` would leave out (#1303). It prints
|
|
845
|
+
// as Prettier prints a `try`, with the block after the `try` block.
|
|
846
|
+
case 'TryStatement':
|
|
847
|
+
return node.pending
|
|
848
|
+
? [
|
|
849
|
+
'try ',
|
|
850
|
+
print('block'),
|
|
851
|
+
' pending ',
|
|
852
|
+
print('pending'),
|
|
853
|
+
node.handler ? [' ', print('handler')] : '',
|
|
854
|
+
node.finalizer ? [' finally ', print('finalizer')] : '',
|
|
855
|
+
]
|
|
856
|
+
: null;
|
|
857
|
+
|
|
839
858
|
case 'JSXForExpression':
|
|
840
859
|
return printFor(path, options, print);
|
|
841
860
|
|