@tsrx/prettier-plugin 0.3.32 → 0.3.34
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 +4 -4
- package/src/index.js +30 -1
- package/src/index.test.js +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsrx/prettier-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.34",
|
|
4
4
|
"description": "Ripple plugin for Prettier",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^24.3.0",
|
|
28
28
|
"prettier": "^3.8.3",
|
|
29
|
-
"ripple": "0.3.
|
|
29
|
+
"ripple": "0.3.34"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tsrx/core": "0.0.
|
|
33
|
-
"@tsrx/ripple": "0.0.
|
|
32
|
+
"@tsrx/core": "0.0.14",
|
|
33
|
+
"@tsrx/ripple": "0.0.16"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"src/"
|
package/src/index.js
CHANGED
|
@@ -2117,6 +2117,18 @@ function printRippleNode(node, path, options, print, args) {
|
|
|
2117
2117
|
nodeContent = printTSTupleType(node, path, options, print);
|
|
2118
2118
|
break;
|
|
2119
2119
|
|
|
2120
|
+
case 'TSNamedTupleMember':
|
|
2121
|
+
nodeContent = printTSNamedTupleMember(node, path, options, print);
|
|
2122
|
+
break;
|
|
2123
|
+
|
|
2124
|
+
case 'TSRestType':
|
|
2125
|
+
nodeContent = ['...', path.call(print, 'typeAnnotation')];
|
|
2126
|
+
break;
|
|
2127
|
+
|
|
2128
|
+
case 'TSOptionalType':
|
|
2129
|
+
nodeContent = [path.call(print, 'typeAnnotation'), '?'];
|
|
2130
|
+
break;
|
|
2131
|
+
|
|
2120
2132
|
case 'TSIndexSignature':
|
|
2121
2133
|
nodeContent = printTSIndexSignature(node, path, options, print);
|
|
2122
2134
|
break;
|
|
@@ -5262,6 +5274,23 @@ function printTSTupleType(node, path, options, print) {
|
|
|
5262
5274
|
return parts;
|
|
5263
5275
|
}
|
|
5264
5276
|
|
|
5277
|
+
/**
|
|
5278
|
+
* Print a TypeScript named tuple member
|
|
5279
|
+
* @param {AST.TSNamedTupleMember} node - The named tuple member node
|
|
5280
|
+
* @param {AstPath<AST.TSNamedTupleMember>} path - The AST path
|
|
5281
|
+
* @param {RippleFormatOptions} options - Prettier options
|
|
5282
|
+
* @param {PrintFn} print - Print callback
|
|
5283
|
+
* @returns {Doc[]}
|
|
5284
|
+
*/
|
|
5285
|
+
function printTSNamedTupleMember(node, path, options, print) {
|
|
5286
|
+
return [
|
|
5287
|
+
path.call(print, 'label'),
|
|
5288
|
+
node.optional ? '?' : '',
|
|
5289
|
+
': ',
|
|
5290
|
+
path.call(print, 'elementType'),
|
|
5291
|
+
];
|
|
5292
|
+
}
|
|
5293
|
+
|
|
5265
5294
|
/**
|
|
5266
5295
|
* Print a TypeScript index signature
|
|
5267
5296
|
* @param {AST.TSIndexSignature} node - The index signature node
|
|
@@ -5734,7 +5763,7 @@ function printJSXElement(node, path, options, print) {
|
|
|
5734
5763
|
'attributes',
|
|
5735
5764
|
i,
|
|
5736
5765
|
);
|
|
5737
|
-
} else if (attr.type === 'JSXSpreadAttribute') {
|
|
5766
|
+
} else if (attr.type === 'JSXSpreadAttribute' || attr.type === 'SpreadAttribute') {
|
|
5738
5767
|
return ['{...', path.call(print, 'openingElement', 'attributes', i, 'argument'), '}'];
|
|
5739
5768
|
}
|
|
5740
5769
|
return '';
|
package/src/index.test.js
CHANGED
|
@@ -741,6 +741,17 @@ import { Something, type Props, track } from 'ripple';`;
|
|
|
741
741
|
expect(result).toBeWithNewline(expected);
|
|
742
742
|
});
|
|
743
743
|
|
|
744
|
+
it('should preserve JSX spread attributes inside explicit tsx blocks', async () => {
|
|
745
|
+
const input = `const props = {};
|
|
746
|
+
const foo = <tsx><Bar {...props} /></tsx>;`;
|
|
747
|
+
|
|
748
|
+
const expected = `const props = {};
|
|
749
|
+
const foo = <tsx><Bar {...props} /></tsx>;`;
|
|
750
|
+
|
|
751
|
+
const result = await format(input, { singleQuote: true });
|
|
752
|
+
expect(result).toBeWithNewline(expected);
|
|
753
|
+
});
|
|
754
|
+
|
|
744
755
|
it('should handle type annotations in object params', async () => {
|
|
745
756
|
const input = `interface Props {
|
|
746
757
|
a: number;
|
|
@@ -3287,6 +3298,13 @@ const items = [] as unknown[];`;
|
|
|
3287
3298
|
expect(result).toBeWithNewline(expected);
|
|
3288
3299
|
});
|
|
3289
3300
|
|
|
3301
|
+
it('should preserve named optional TypeScript tuple members', async () => {
|
|
3302
|
+
const input = `export type OptionalTuple = [bar: string, baz?: string];`;
|
|
3303
|
+
const expected = `export type OptionalTuple = [bar: string, baz?: string];`;
|
|
3304
|
+
const result = await format(input);
|
|
3305
|
+
expect(result).toBeWithNewline(expected);
|
|
3306
|
+
});
|
|
3307
|
+
|
|
3290
3308
|
it('should format TypeScript index signatures (TSIndexSignature)', async () => {
|
|
3291
3309
|
const input = `interface Dict { [key: string]: number; readonly [id: number]: string }`;
|
|
3292
3310
|
const expected = `interface Dict {\n [key: string]: number;\n readonly [id: number]: string;\n}`;
|