@ripple-ts/prettier-plugin 0.2.155 → 0.2.157

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ripple-ts/prettier-plugin",
3
- "version": "0.2.155",
3
+ "version": "0.2.157",
4
4
  "description": "Ripple plugin for Prettier",
5
5
  "type": "module",
6
6
  "module": "src/index.js",
@@ -11,7 +11,7 @@
11
11
  "ripple",
12
12
  "formatter"
13
13
  ],
14
- "homepage": "https://ripple-ts.com",
14
+ "homepage": "https://ripplejs.com",
15
15
  "author": "Dominic Gannaway",
16
16
  "license": "MIT",
17
17
  "repository": {
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "prettier": "^3.6.2",
28
- "ripple": "0.2.155"
28
+ "ripple": "0.2.157"
29
29
  },
30
30
  "dependencies": {},
31
31
  "files": [
package/src/index.js CHANGED
@@ -1163,10 +1163,14 @@ function printRippleNode(node, path, options, print, args) {
1163
1163
  break;
1164
1164
  }
1165
1165
 
1166
+ case 'TSNonNullExpression': {
1167
+ nodeContent = concat([path.call(print, 'expression'), '!']);
1168
+ break;
1169
+ }
1170
+
1166
1171
  case 'NewExpression':
1167
1172
  nodeContent = printNewExpression(node, path, options, print);
1168
1173
  break;
1169
-
1170
1174
  case 'TemplateLiteral':
1171
1175
  nodeContent = printTemplateLiteral(node, path, options, print);
1172
1176
  break;
@@ -1324,8 +1328,10 @@ function printRippleNode(node, path, options, print, args) {
1324
1328
  const trackedPrefix = node.tracked ? '@' : '';
1325
1329
  let identifierContent;
1326
1330
  if (node.typeAnnotation) {
1331
+ const optionalMarker = node.optional ? '?' : '';
1327
1332
  identifierContent = concat([
1328
1333
  trackedPrefix + node.name,
1334
+ optionalMarker,
1329
1335
  ': ',
1330
1336
  path.call(print, 'typeAnnotation'),
1331
1337
  ]);
@@ -1348,7 +1354,6 @@ function printRippleNode(node, path, options, print, args) {
1348
1354
  }
1349
1355
  break;
1350
1356
  }
1351
-
1352
1357
  case 'Literal':
1353
1358
  // Handle regex literals specially
1354
1359
  if (node.regex) {
@@ -1645,10 +1650,13 @@ function printRippleNode(node, path, options, print, args) {
1645
1650
  nodeContent = printTSPropertySignature(node, path, options, print);
1646
1651
  break;
1647
1652
 
1653
+ case 'TSMethodSignature':
1654
+ nodeContent = printTSMethodSignature(node, path, options, print);
1655
+ break;
1656
+
1648
1657
  case 'TSEnumMember':
1649
1658
  nodeContent = printTSEnumMember(node, path, options, print);
1650
1659
  break;
1651
-
1652
1660
  case 'TSLiteralType':
1653
1661
  nodeContent = path.call(print, 'literal');
1654
1662
  break;
@@ -3863,6 +3871,47 @@ function printTSPropertySignature(node, path, options, print) {
3863
3871
  return concat(parts);
3864
3872
  }
3865
3873
 
3874
+ function printTSMethodSignature(node, path, options, print) {
3875
+ const parts = [];
3876
+
3877
+ // Print the method name/key
3878
+ parts.push(path.call(print, 'key'));
3879
+
3880
+ // Add optional marker if present
3881
+ if (node.optional) {
3882
+ parts.push('?');
3883
+ }
3884
+
3885
+ // Add TypeScript generics/type parameters if present
3886
+ if (node.typeParameters) {
3887
+ const typeParams = path.call(print, 'typeParameters');
3888
+ if (Array.isArray(typeParams)) {
3889
+ parts.push(...typeParams);
3890
+ } else {
3891
+ parts.push(typeParams);
3892
+ }
3893
+ }
3894
+
3895
+ // Print parameters - use 'parameters' property for TypeScript signature nodes
3896
+ parts.push('(');
3897
+ if (node.parameters && node.parameters.length > 0) {
3898
+ const params = path.map(print, 'parameters');
3899
+ for (let i = 0; i < params.length; i++) {
3900
+ if (i > 0) parts.push(', ');
3901
+ parts.push(params[i]);
3902
+ }
3903
+ }
3904
+ parts.push(')');
3905
+
3906
+ // Return type annotation
3907
+ if (node.typeAnnotation) {
3908
+ parts.push(': ');
3909
+ parts.push(path.call(print, 'typeAnnotation'));
3910
+ }
3911
+
3912
+ return concat(parts);
3913
+ }
3914
+
3866
3915
  function printTSTypeReference(node, path, options, print) {
3867
3916
  const parts = [path.call(print, 'typeName')];
3868
3917
 
package/src/index.test.js CHANGED
@@ -2282,6 +2282,44 @@ const items = [] as unknown[];`;
2282
2282
  expect(result).toBeWithNewline(expected);
2283
2283
  });
2284
2284
 
2285
+ it('should format TSMethodSignature in interfaces', async () => {
2286
+ const input = `interface API{get(path:string):Promise<Response>;post<T>(path:string,data:T):Promise<Response>;delete?(id:number):void}`;
2287
+ const expected = `interface API {
2288
+ get(path: string): Promise<Response>;
2289
+ post<T>(path: string, data: T): Promise<Response>;
2290
+ delete?(id: number): void;
2291
+ }`;
2292
+ const result = await format(input);
2293
+ expect(result).toBeWithNewline(expected);
2294
+ });
2295
+
2296
+ it('should format TSMethodSignature with type parameters', async () => {
2297
+ const input = `interface Collection{map<U>(fn:(item:T)=>U):U[];filter(predicate:(item:T)=>boolean):T[]}`;
2298
+ const expected = `interface Collection {\n map<U>(fn: (item: T) => U): U[];\n filter(predicate: (item: T) => boolean): T[];\n}`;
2299
+ const result = await format(input);
2300
+ expect(result).toBeWithNewline(expected);
2301
+ });
2302
+
2303
+ it('should format TSNonNullExpression', async () => {
2304
+ const input = `component Test(){let value:string|null=null;let length=value!.length;<div>{length}</div>}`;
2305
+ const expected = `component Test() {
2306
+ let value: string | null = null;
2307
+ let length = value!.length;
2308
+ <div>{length}</div>
2309
+ }`;
2310
+ const result = await format(input);
2311
+ expect(result).toBeWithNewline(expected);
2312
+ });
2313
+
2314
+ it('should format TSNonNullExpression in complex expressions', async () => {
2315
+ const input = `function getValue(x?:string){return x!.toUpperCase()}`;
2316
+ const expected = `function getValue(x?: string) {
2317
+ return x!.toUpperCase();
2318
+ }`;
2319
+ const result = await format(input);
2320
+ expect(result).toBeWithNewline(expected);
2321
+ });
2322
+
2285
2323
  it('should retain templated declarations', async () => {
2286
2324
  const expected = `function Wrapper() {
2287
2325
  return {