@tsrx/prettier-plugin 0.4.5 → 0.4.7

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": "@tsrx/prettier-plugin",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
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.9.6"
28
28
  },
29
29
  "dependencies": {
30
- "@tsrx/core": "0.2.3"
30
+ "@tsrx/core": "0.2.4"
31
31
  },
32
32
  "files": [
33
33
  "src/"
package/src/index.js CHANGED
@@ -2645,6 +2645,10 @@ function printTsrxNode(node, path, options, print, args) {
2645
2645
  /** @type {Doc[]} */
2646
2646
  const parts = [];
2647
2647
 
2648
+ if (node.typeParameters) {
2649
+ parts.push(path.call(print, 'typeParameters'));
2650
+ }
2651
+
2648
2652
  // Handle parameters
2649
2653
  parts.push('(');
2650
2654
  if (node.parameters && node.parameters.length > 0) {
@@ -5167,6 +5171,15 @@ function printTSTypeParameterDeclaration(node, path, options, print) {
5167
5171
  function printTSTypeParameter(node, path, options, print) {
5168
5172
  /** @type {Doc[]} */
5169
5173
  const parts = [];
5174
+ if (node.const) {
5175
+ parts.push('const ');
5176
+ }
5177
+ if (node.in) {
5178
+ parts.push('in ');
5179
+ }
5180
+ if (node.out) {
5181
+ parts.push('out ');
5182
+ }
5170
5183
  parts.push(node.name);
5171
5184
 
5172
5185
  if (node.constraint) {
@@ -6273,6 +6286,9 @@ function printTSConstructorType(node, path, options, print) {
6273
6286
  parts.push('abstract ');
6274
6287
  }
6275
6288
  parts.push('new ');
6289
+ if (node.typeParameters) {
6290
+ parts.push(path.call(print, 'typeParameters'));
6291
+ }
6276
6292
  parts.push('(');
6277
6293
  const hasParameters = Array.isArray(node.parameters) && node.parameters.length > 0;
6278
6294
  if (hasParameters) {
package/src/index.test.js CHANGED
@@ -6846,6 +6846,24 @@ function g() {
6846
6846
  });
6847
6847
 
6848
6848
  describe('type parameter declarations', () => {
6849
+ it.each([
6850
+ 'type Select<T> = <K extends keyof T>(value: T[K]) => T[K];',
6851
+ 'type Mapper = <T, U = T>(value: T) => U;',
6852
+ 'type Factory = <T = unknown>() => <U extends T>(value: U) => U;',
6853
+ `interface Api {
6854
+ select: <T>(value: T) => T;
6855
+ }`,
6856
+ ])('preserves generic function type declarations: %s', async (source) => {
6857
+ expect(await format(source)).toBeWithNewline(source);
6858
+ });
6859
+
6860
+ it.each([
6861
+ 'type Constructor = new <T>(value: T) => Box<T>;',
6862
+ 'type Constructor = abstract new <T, U = T>(value: U) => Box<T>;',
6863
+ ])('preserves generic constructor type declarations: %s', async (source) => {
6864
+ expect(await format(source)).toBeWithNewline(source);
6865
+ });
6866
+
6849
6867
  /**
6850
6868
  * Formats twice and asserts the output is stable (idempotent).
6851
6869
  * @param {string} code
@@ -6987,6 +7005,28 @@ function g() {
6987
7005
  expect(result).toBeWithNewline(source);
6988
7006
  };
6989
7007
 
7008
+ it.each([
7009
+ 'type Setter<in T> = (value: T) => void;',
7010
+ 'type Getter<out T> = () => T;',
7011
+ 'type Cell<in out T> = { value: T };',
7012
+ `interface Cell<in out T extends object = object> {
7013
+ value: T;
7014
+ }`,
7015
+ ])('keeps type parameter variance: %s', async (source) => {
7016
+ await expectUnchanged(source);
7017
+ });
7018
+
7019
+ it.each([
7020
+ `function identity<const T>(value: T): T {
7021
+ return value;
7022
+ }`,
7023
+ 'const identity = <const T,>(value: T): T => value;',
7024
+ 'class Box<const T> {}',
7025
+ 'class Box<const in out T> {}',
7026
+ ])('keeps const type parameters: %s', async (source) => {
7027
+ await expectUnchanged(source);
7028
+ });
7029
+
6990
7030
  it('keeps readonly on interface members', async () => {
6991
7031
  await expectUnchanged(`export interface BenchRow {
6992
7032
  readonly id: number;