@tsrx/prettier-plugin 0.3.101 → 0.3.103
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/index.js +14 -0
- package/src/index.test.js +20 -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.103",
|
|
4
4
|
"description": "Ripple plugin for Prettier",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"prettier": "^3.8.4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tsrx/core": "0.1.
|
|
30
|
+
"@tsrx/core": "0.1.44"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"src/"
|
package/src/index.js
CHANGED
|
@@ -2297,6 +2297,20 @@ function printRippleNode(node, path, options, print, args) {
|
|
|
2297
2297
|
break;
|
|
2298
2298
|
}
|
|
2299
2299
|
|
|
2300
|
+
case 'TSTypePredicate': {
|
|
2301
|
+
/** @type {Doc[]} */
|
|
2302
|
+
const predicateParts = [];
|
|
2303
|
+
if (node.asserts) predicateParts.push('asserts ');
|
|
2304
|
+
predicateParts.push(
|
|
2305
|
+
node.parameterName.type === 'TSThisType' ? 'this' : node.parameterName.name,
|
|
2306
|
+
);
|
|
2307
|
+
if (node.typeAnnotation) {
|
|
2308
|
+
predicateParts.push(' is ', path.call(print, 'typeAnnotation'));
|
|
2309
|
+
}
|
|
2310
|
+
nodeContent = predicateParts;
|
|
2311
|
+
break;
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2300
2314
|
case 'TSTypeLiteral':
|
|
2301
2315
|
nodeContent = printTSTypeLiteral(node, path, options, print);
|
|
2302
2316
|
break;
|
package/src/index.test.js
CHANGED
|
@@ -1522,6 +1522,26 @@ export { type Extra, realValue } from './mixed.js';`;
|
|
|
1522
1522
|
|
|
1523
1523
|
// Regressed in 0.3.97: `declare module 'name' { … }` lost its `declare`
|
|
1524
1524
|
// keyword, leaving invalid `module 'name' { … }` output.
|
|
1525
|
+
// Regression: TSTypePredicate had no printer case, so predicate return
|
|
1526
|
+
// types (`(v): v is string =>`, `asserts x is T`) printed as
|
|
1527
|
+
// `/* Unknown: TSTypePredicate */`.
|
|
1528
|
+
it('should print type predicate return types', async () => {
|
|
1529
|
+
const input = `const isString = (value: unknown): value is string => typeof value === 'string';
|
|
1530
|
+
function assertUser(x: unknown): asserts x is User {}
|
|
1531
|
+
function isSelf(this: Node): this is Element {
|
|
1532
|
+
return true;
|
|
1533
|
+
}
|
|
1534
|
+
function assertTruthy(x: unknown): asserts x {}`;
|
|
1535
|
+
const expected = `const isString = (value: unknown): value is string => typeof value === 'string';
|
|
1536
|
+
function assertUser(x: unknown): asserts x is User {}
|
|
1537
|
+
function isSelf(this: Node): this is Element {
|
|
1538
|
+
return true;
|
|
1539
|
+
}
|
|
1540
|
+
function assertTruthy(x: unknown): asserts x {}`;
|
|
1541
|
+
const result = await format(input, { singleQuote: true });
|
|
1542
|
+
expect(result).toBeWithNewline(expected);
|
|
1543
|
+
});
|
|
1544
|
+
|
|
1525
1545
|
it('should keep the declare keyword on ambient module declarations', async () => {
|
|
1526
1546
|
const input = `declare module 'some-module' {
|
|
1527
1547
|
interface Thing {
|