ts-codemod-lib 3.3.0 → 3.3.2

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.
Files changed (86) hide show
  1. package/README.md +22 -0
  2. package/dist/entry-point.mjs +2 -24
  3. package/dist/entry-point.mjs.map +1 -1
  4. package/dist/functions/ast-transformers/append-as-const.mjs +330 -292
  5. package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
  6. package/dist/functions/ast-transformers/convert-interface-to-type.mjs +85 -70
  7. package/dist/functions/ast-transformers/convert-interface-to-type.mjs.map +1 -1
  8. package/dist/functions/ast-transformers/convert-to-readonly.d.mts.map +1 -1
  9. package/dist/functions/ast-transformers/convert-to-readonly.mjs +971 -838
  10. package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
  11. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts +32 -9
  12. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts.map +1 -1
  13. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs +299 -134
  14. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -1
  15. package/dist/functions/ast-transformers/index.mjs +10 -12
  16. package/dist/functions/ast-transformers/index.mjs.map +1 -1
  17. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs +14 -7
  18. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs.map +1 -1
  19. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs +12 -15
  20. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs.map +1 -1
  21. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.d.mts.map +1 -1
  22. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs +70 -59
  23. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map +1 -1
  24. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs +5 -5
  25. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs.map +1 -1
  26. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs +15 -20
  27. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs.map +1 -1
  28. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs +30 -34
  29. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs.map +1 -1
  30. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +197 -156
  31. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
  32. package/dist/functions/ast-transformers/transform-source-code.mjs +74 -75
  33. package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
  34. package/dist/functions/ast-transformers/types.mjs +2 -2
  35. package/dist/functions/ast-transformers/types.mjs.map +1 -1
  36. package/dist/functions/constants/ignore-comment-text.mjs +11 -13
  37. package/dist/functions/constants/ignore-comment-text.mjs.map +1 -1
  38. package/dist/functions/constants/index.mjs +2 -2
  39. package/dist/functions/constants/index.mjs.map +1 -1
  40. package/dist/functions/functions/has-call-or-construct-signature.d.mts +18 -0
  41. package/dist/functions/functions/has-call-or-construct-signature.d.mts.map +1 -0
  42. package/dist/functions/functions/has-call-or-construct-signature.mjs +87 -0
  43. package/dist/functions/functions/has-call-or-construct-signature.mjs.map +1 -0
  44. package/dist/functions/functions/has-disable-next-line-comment.mjs +67 -38
  45. package/dist/functions/functions/has-disable-next-line-comment.mjs.map +1 -1
  46. package/dist/functions/functions/index.d.mts +1 -0
  47. package/dist/functions/functions/index.d.mts.map +1 -1
  48. package/dist/functions/functions/index.mjs +12 -11
  49. package/dist/functions/functions/index.mjs.map +1 -1
  50. package/dist/functions/functions/is-as-const-node.mjs +25 -20
  51. package/dist/functions/functions/is-as-const-node.mjs.map +1 -1
  52. package/dist/functions/functions/is-atomic-type-node.mjs +245 -25
  53. package/dist/functions/functions/is-atomic-type-node.mjs.map +1 -1
  54. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs +34 -13
  55. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs.map +1 -1
  56. package/dist/functions/functions/is-readonly-node.mjs +120 -14
  57. package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
  58. package/dist/functions/functions/is-spread-parameter-node.mjs +5 -6
  59. package/dist/functions/functions/is-spread-parameter-node.mjs.map +1 -1
  60. package/dist/functions/functions/remove-parentheses.mjs +4 -4
  61. package/dist/functions/functions/remove-parentheses.mjs.map +1 -1
  62. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs +23 -9
  63. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs.map +1 -1
  64. package/dist/functions/functions/unwrap-readonly.mjs +3 -4
  65. package/dist/functions/functions/unwrap-readonly.mjs.map +1 -1
  66. package/dist/functions/functions/wrap-with-parentheses.d.mts +14 -5
  67. package/dist/functions/functions/wrap-with-parentheses.d.mts.map +1 -1
  68. package/dist/functions/functions/wrap-with-parentheses.mjs +67 -30
  69. package/dist/functions/functions/wrap-with-parentheses.mjs.map +1 -1
  70. package/dist/functions/index.mjs +5 -24
  71. package/dist/functions/index.mjs.map +1 -1
  72. package/dist/functions/utils/index.mjs +2 -2
  73. package/dist/functions/utils/index.mjs.map +1 -1
  74. package/dist/functions/utils/replace-with-debug.mjs +4 -6
  75. package/dist/functions/utils/replace-with-debug.mjs.map +1 -1
  76. package/dist/index.mjs +2 -24
  77. package/dist/index.mjs.map +1 -1
  78. package/package.json +18 -18
  79. package/src/functions/ast-transformers/convert-to-readonly.mts +19 -13
  80. package/src/functions/ast-transformers/convert-to-readonly.test.mts +129 -1
  81. package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.mts +32 -9
  82. package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.test.mts +76 -22
  83. package/src/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mts +8 -1
  84. package/src/functions/functions/has-call-or-construct-signature.mts +120 -0
  85. package/src/functions/functions/index.mts +1 -0
  86. package/src/functions/functions/wrap-with-parentheses.mts +32 -17
@@ -2,31 +2,251 @@ import { ISet } from 'ts-data-forge';
2
2
  import * as tsm from 'ts-morph';
3
3
 
4
4
  const atomicTypeKeywordKinds = ISet.create([
5
- tsm.SyntaxKind.StringKeyword,
6
- tsm.SyntaxKind.BooleanKeyword,
7
- tsm.SyntaxKind.NumberKeyword,
8
- tsm.SyntaxKind.BigIntKeyword,
9
- tsm.SyntaxKind.SymbolKeyword,
10
- tsm.SyntaxKind.UndefinedKeyword,
11
- tsm.SyntaxKind.VoidKeyword,
12
- tsm.SyntaxKind.AnyKeyword,
13
- tsm.SyntaxKind.UnknownKeyword,
14
- tsm.SyntaxKind.ObjectKeyword,
15
- // Note: 'object' is sometimes considered primitive in TS type system context
16
- tsm.SyntaxKind.NeverKeyword
5
+ tsm.SyntaxKind.StringKeyword,
6
+ tsm.SyntaxKind.BooleanKeyword,
7
+ tsm.SyntaxKind.NumberKeyword,
8
+ tsm.SyntaxKind.BigIntKeyword,
9
+ tsm.SyntaxKind.SymbolKeyword,
10
+ tsm.SyntaxKind.UndefinedKeyword,
11
+ tsm.SyntaxKind.VoidKeyword,
12
+ tsm.SyntaxKind.AnyKeyword,
13
+ tsm.SyntaxKind.UnknownKeyword,
14
+ tsm.SyntaxKind.ObjectKeyword,
15
+ tsm.SyntaxKind.NeverKeyword,
17
16
  ]);
18
- const isAtomicTypeNode = (node) => {
19
- if (node.isKind(tsm.SyntaxKind.LiteralType)) {
20
- return true;
21
- }
22
- if (node.isKind(tsm.SyntaxKind.TemplateLiteralType)) {
23
- return true;
24
- }
25
- if (atomicTypeKeywordKinds.has(node.getKind())) {
26
- return true;
27
- }
28
- return false;
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ export const isAtomicTypeNode = (node) => {
27
+
28
+ if (node.isKind(tsm.SyntaxKind.LiteralType)) {
29
+ return true;
30
+ }
31
+
32
+ if (node.isKind(tsm.SyntaxKind.TemplateLiteralType)) {
33
+ return true;
34
+ }
35
+
36
+
37
+
38
+ if (atomicTypeKeywordKinds.has(node.getKind())) {
39
+ return true;
40
+ }
41
+ return false;
29
42
  };
30
43
 
31
- export { isAtomicTypeNode };
32
- //# sourceMappingURL=is-atomic-type-node.mjs.map
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+ //# sourceMappingURL=is-atomic-type-node.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-atomic-type-node.mjs","sources":["../../../src/functions/functions/is-atomic-type-node.mts"],"sourcesContent":["import { ISet } from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { type DeepReadonly } from 'ts-type-forge';\n\n// Define the set of SyntaxKinds that represent primitive type keywords\nconst atomicTypeKeywordKinds = ISet.create<tsm.SyntaxKind>([\n tsm.SyntaxKind.StringKeyword,\n tsm.SyntaxKind.BooleanKeyword,\n tsm.SyntaxKind.NumberKeyword,\n tsm.SyntaxKind.BigIntKeyword,\n tsm.SyntaxKind.SymbolKeyword,\n tsm.SyntaxKind.UndefinedKeyword,\n tsm.SyntaxKind.VoidKeyword,\n tsm.SyntaxKind.AnyKeyword,\n tsm.SyntaxKind.UnknownKeyword,\n tsm.SyntaxKind.ObjectKeyword, // Note: 'object' is sometimes considered primitive in TS type system context\n tsm.SyntaxKind.NeverKeyword,\n]);\n\n// transformer-ignore-next-line convert-to-readonly\nexport type AtomicTypeNode = tsm.Node &\n Readonly<\n | tsm.LiteralTypeNode\n | tsm.TemplateLiteralTypeNode\n | (tsm.TypeNode & {\n kind:\n | tsm.SyntaxKind.StringKeyword\n | tsm.SyntaxKind.BooleanKeyword\n | tsm.SyntaxKind.NumberKeyword\n | tsm.SyntaxKind.BigIntKeyword\n | tsm.SyntaxKind.SymbolKeyword\n | tsm.SyntaxKind.UndefinedKeyword\n | tsm.SyntaxKind.VoidKeyword\n | tsm.SyntaxKind.AnyKeyword\n | tsm.SyntaxKind.UnknownKeyword\n | tsm.SyntaxKind.ObjectKeyword\n | tsm.SyntaxKind.NeverKeyword;\n })\n >;\n\n/**\n * Checks if a given ts-morph node represents a primitive type node.\n * This includes keyword types (string, number, etc.), literal types (null, \"abc\", 123),\n * and template literal types.\n *\n * @param node - The ts-morph node to check.\n * @returns True if the node represents a primitive type node, false otherwise.\n * Acts as a type guard.\n */\nexport const isAtomicTypeNode = (\n node: DeepReadonly<tsm.Node>,\n): node is AtomicTypeNode => {\n // Check for literal types (null, \"aaa\", 1.23, 456n, true, false)\n if (node.isKind(tsm.SyntaxKind.LiteralType)) {\n return true;\n }\n\n // Check for template literal types (`abc${expr}def`)\n if (node.isKind(tsm.SyntaxKind.TemplateLiteralType)) {\n return true;\n }\n\n // Check if it's a TypeNode and its kind is one of the primitive keywords\n // Node.isTypeNode(node) ensures we only check nodes that represent types\n // if (ts.Node.isTypeNode(node) && primitiveKeywordKinds.has(node.getKind())) {\n if (atomicTypeKeywordKinds.has(node.getKind())) {\n return true;\n }\n\n return false;\n};\n\nif (import.meta.vitest !== undefined) {\n // Helper to get a specific type node from source code\n const getTypeNodeFromSource = (\n sourceCode: string,\n typeName: string,\n ): tsm.TypeNode => {\n const project = new tsm.Project({ useInMemoryFileSystem: true });\n\n const sourceFile = project.createSourceFile('test.ts', sourceCode);\n\n const typeAlias = sourceFile.getTypeAliasOrThrow(typeName);\n\n return typeAlias.getTypeNodeOrThrow();\n };\n\n // Helper to get the first node of a specific kind from source code\n const getFirstNodeOfKind = <T extends tsm.Node>(\n sourceCode: string,\n kind: tsm.SyntaxKind,\n ): T | undefined => {\n const project = new tsm.Project({ useInMemoryFileSystem: true });\n\n const sourceFile = project.createSourceFile('test.ts', sourceCode);\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return sourceFile.getFirstDescendantByKind(kind) as T | undefined;\n };\n\n describe('isAtomicTypeNode', () => {\n describe('positive cases', () => {\n test.each([\n {\n name: 'string',\n code: 'type Test = string;',\n kind: tsm.SyntaxKind.StringKeyword,\n },\n {\n name: 'number',\n code: 'type Test = number;',\n kind: tsm.SyntaxKind.NumberKeyword,\n },\n {\n name: 'boolean',\n code: 'type Test = boolean;',\n kind: tsm.SyntaxKind.BooleanKeyword,\n },\n {\n name: 'bigint',\n code: 'type Test = bigint;',\n kind: tsm.SyntaxKind.BigIntKeyword,\n },\n {\n name: 'symbol',\n code: 'type Test = symbol;',\n kind: tsm.SyntaxKind.SymbolKeyword,\n },\n {\n name: 'undefined',\n code: 'type Test = undefined;',\n kind: tsm.SyntaxKind.UndefinedKeyword,\n },\n {\n name: 'void',\n code: 'type Test = void;',\n kind: tsm.SyntaxKind.VoidKeyword,\n },\n {\n name: 'any',\n code: 'type Test = any;',\n kind: tsm.SyntaxKind.AnyKeyword,\n },\n {\n name: 'unknown',\n code: 'type Test = unknown;',\n kind: tsm.SyntaxKind.UnknownKeyword,\n },\n {\n name: 'never',\n code: 'type Test = never;',\n kind: tsm.SyntaxKind.NeverKeyword,\n },\n {\n name: 'object',\n code: 'type Test = object;',\n kind: tsm.SyntaxKind.ObjectKeyword,\n }, // Included based on original code\n {\n name: 'null',\n code: 'type Test = null;',\n kind: tsm.SyntaxKind.LiteralType,\n },\n {\n name: 'string literal (\"hello\")',\n code: 'type Test = \"hello\";',\n kind: tsm.SyntaxKind.LiteralType,\n },\n {\n name: 'number literal (123)',\n code: 'type Test = 123;',\n kind: tsm.SyntaxKind.LiteralType,\n },\n {\n name: 'bigint literal (123n)',\n code: 'type Test = 123n;',\n kind: tsm.SyntaxKind.LiteralType,\n },\n {\n name: 'boolean literal (true)',\n code: 'type Test = true;',\n kind: tsm.SyntaxKind.LiteralType,\n },\n {\n name: 'boolean literal (false)',\n code: 'type Test = false;',\n kind: tsm.SyntaxKind.LiteralType,\n },\n {\n name: 'TemplateLiteral',\n // eslint-disable-next-line no-template-curly-in-string\n code: 'type Test = `a${string}b`;',\n kind: tsm.SyntaxKind.TemplateLiteralType,\n },\n ])('$name', ({ code, kind }) => {\n const node = getTypeNodeFromSource(code, 'Test');\n\n expect(node.getKind()).toBe(kind);\n\n assert.isTrue(isAtomicTypeNode(node));\n });\n });\n\n describe('negative cases', () => {\n test.each([\n {\n name: 'Date TypeReference',\n code: 'type Test = Date;',\n kind: tsm.SyntaxKind.TypeReference,\n },\n {\n name: 'Array Type',\n code: 'type Test = number[];',\n kind: tsm.SyntaxKind.ArrayType,\n },\n {\n name: 'Tuple Type',\n code: 'type Test = [string, number];',\n kind: tsm.SyntaxKind.TupleType,\n },\n {\n name: 'Type Literal',\n code: 'type Test = { a: number };',\n kind: tsm.SyntaxKind.TypeLiteral,\n },\n {\n name: 'Readonly Type Operator',\n code: 'type Test = readonly string[];',\n kind: tsm.SyntaxKind.TypeOperator,\n },\n {\n name: 'Union Type',\n code: 'type Test = string | number;',\n kind: tsm.SyntaxKind.UnionType,\n },\n {\n name: 'Intersection Type',\n code: 'type Test = A & B;',\n kind: tsm.SyntaxKind.IntersectionType,\n },\n {\n name: 'Mapped Type',\n code: 'type Test = { [K in keyof T]: T[K] };',\n kind: tsm.SyntaxKind.MappedType,\n }, // Needs T defined\n {\n name: 'Parenthesized Type',\n code: 'type Test = (string);',\n kind: tsm.SyntaxKind.ParenthesizedType,\n },\n {\n name: 'Conditional Type',\n code: 'type Test = T extends U ? X : Y;',\n kind: tsm.SyntaxKind.ConditionalType,\n }, // Needs T, U, X, Y\n {\n name: 'Indexed Access Type',\n code: 'type Test = T[K];',\n kind: tsm.SyntaxKind.IndexedAccessType,\n }, // Needs T, K\n {\n name: 'Type Query (typeof)',\n code: 'type Test = typeof myVar;',\n kind: tsm.SyntaxKind.TypeQuery,\n },\n ])('$name', ({ code, kind }) => {\n const node = getTypeNodeFromSource(code, 'Test');\n\n expect(node.getKind()).toBe(kind); // Verify node type\n\n assert.isFalse(isAtomicTypeNode(node));\n });\n\n test.each([\n {\n name: 'Type Predicate',\n code: 'function isString(x: any): x is string { return typeof x === \"string\"; }',\n kind: tsm.SyntaxKind.TypePredicate,\n }, // Node is part of function sig\n {\n name: 'This Type',\n code: 'class C { method(): this {} }',\n kind: tsm.SyntaxKind.ThisType,\n }, // Node is part of method sig\n {\n name: 'Infer Type',\n code: 'type Test<T> = T extends Promise<infer R> ? R : T;',\n kind: tsm.SyntaxKind.InferType,\n }, // Needs context\n ])('$name (not a type node)', ({ code, kind }) => {\n const node = getFirstNodeOfKind(code, kind);\n\n expect(node).toBeDefined();\n\n if (node === undefined) {\n throw new Error('Node should be defined');\n }\n\n assert.isFalse(isAtomicTypeNode(node));\n });\n });\n });\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,sBAAA,GAAyB,KAAK,MAAA,CAAuB;AAAA,EACzD,IAAI,UAAA,CAAW,aAAA;AAAA,EACf,IAAI,UAAA,CAAW,cAAA;AAAA,EACf,IAAI,UAAA,CAAW,aAAA;AAAA,EACf,IAAI,UAAA,CAAW,aAAA;AAAA,EACf,IAAI,UAAA,CAAW,aAAA;AAAA,EACf,IAAI,UAAA,CAAW,gBAAA;AAAA,EACf,IAAI,UAAA,CAAW,WAAA;AAAA,EACf,IAAI,UAAA,CAAW,UAAA;AAAA,EACf,IAAI,UAAA,CAAW,cAAA;AAAA,EACf,IAAI,UAAA,CAAW,aAAA;AAAA;AAAA,EACf,IAAI,UAAA,CAAW;AACjB,CAAC,CAAA;AAgCM,MAAM,gBAAA,GAAmB,CAC9B,IAAA,KAC2B;AAE3B,EAAA,IAAI,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3C,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,mBAAmB,CAAA,EAAG;AACnD,IAAA,OAAO,IAAA;AAAA,EACT;AAKA,EAAA,IAAI,sBAAA,CAAuB,GAAA,CAAI,IAAA,CAAK,OAAA,EAAS,CAAA,EAAG;AAC9C,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,KAAA;AACT;;;;"}
1
+ {"version":3,"file":"is-atomic-type-node.mjs","sourceRoot":"","sources":["../../../src/functions/functions/is-atomic-type-node.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAGhC,uEAAuE;AACvE,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAiB;IACzD,GAAG,CAAC,UAAU,CAAC,aAAa;IAC5B,GAAG,CAAC,UAAU,CAAC,cAA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AI,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC;gBACR;oBACE,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,0EAA0E;oBAChF,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,aAAa;iBACnC,EAAE,+BAA+B;gBAClC;oBACE,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,+BAA+B;oBACrC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,QAAQ;iBAC9B,EAAE,6BAA6B;gBAChC;oBACE,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,oDAAoD;oBAC1D,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,SAAS;iBAC/B,EAAE,gBAAgB;aACpB,CAAC,CAAC,yBAAyB,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE;gBAC/C,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE5C,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;gBAE3B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;gBAC5C,CAAC;gBAED,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,16 +1,37 @@
1
1
  import * as tsm from 'ts-morph';
2
2
 
3
- const isConditionalTypeDistributionGuard = (node) => {
4
- const parent = node.getParent();
5
- if (parent?.isKind(tsm.SyntaxKind.ConditionalType) !== true) {
6
- return false;
7
- }
8
- const checkType = parent.getCheckType();
9
- if (!checkType.isKind(tsm.SyntaxKind.TupleType) && !checkType.isKind(tsm.SyntaxKind.ArrayType)) {
10
- return false;
11
- }
12
- return checkType.compilerNode === node.compilerNode || parent.getExtendsType().compilerNode === node.compilerNode;
13
- };
14
3
 
15
- export { isConditionalTypeDistributionGuard };
16
- //# sourceMappingURL=is-conditional-type-distribution-guard.mjs.map
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+ export const isConditionalTypeDistributionGuard = (node) => {
23
+ const parent = node.getParent();
24
+ if (parent?.isKind(tsm.SyntaxKind.ConditionalType) !== true) {
25
+ return false;
26
+ }
27
+ const checkType = parent.getCheckType();
28
+
29
+
30
+ if (!checkType.isKind(tsm.SyntaxKind.TupleType) &&
31
+ !checkType.isKind(tsm.SyntaxKind.ArrayType)) {
32
+ return false;
33
+ }
34
+ return (checkType.compilerNode === node.compilerNode ||
35
+ parent.getExtendsType().compilerNode === node.compilerNode);
36
+ };
37
+ //# sourceMappingURL=is-conditional-type-distribution-guard.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-conditional-type-distribution-guard.mjs","sources":["../../../src/functions/functions/is-conditional-type-distribution-guard.mts"],"sourcesContent":["import * as tsm from 'ts-morph';\n\n/**\n * Determines whether a type node is an operand (check or extends type) of a\n * conditional type whose check type is wrapped to suppress union distribution,\n * i.e. the `X` and `Y` in `X extends Y ? ... : ...` where `X` is itself a tuple\n * or array.\n *\n * Wrapping a naked type parameter so that it is no longer naked is a well-known\n * type-implementation idiom used to suppress union distribution. Both\n * `[A] extends [B] ? ...` (tuple wrapping) and `A[] extends B[] ? ...` (array\n * wrapping) rely on this. Adding a `readonly` modifier to those operands neither\n * makes the type more immutable in any meaningful way nor preserves the idiom's\n * intent, so such operands must be left untouched.\n *\n * A naked check type such as `T extends string[] ? ...` still distributes, so it\n * is not a guard; arrays/tuples in its extends position are converted as usual.\n *\n * @param node - The type node to check\n * @returns true if the node is the check or extends type of a distribution-guarded\n * conditional type\n */\nexport const isConditionalTypeDistributionGuard = (node: tsm.Node): boolean => {\n const parent = node.getParent();\n\n if (parent?.isKind(tsm.SyntaxKind.ConditionalType) !== true) {\n return false;\n }\n\n const checkType = parent.getCheckType();\n\n // The guard is only in effect when the check type itself is wrapped in a tuple\n // or array; otherwise (e.g. a naked `T`) the conditional still distributes.\n if (\n !checkType.isKind(tsm.SyntaxKind.TupleType) &&\n !checkType.isKind(tsm.SyntaxKind.ArrayType)\n ) {\n return false;\n }\n\n return (\n checkType.compilerNode === node.compilerNode ||\n parent.getExtendsType().compilerNode === node.compilerNode\n );\n};\n"],"names":[],"mappings":";;AAsBO,MAAM,kCAAA,GAAqC,CAAC,IAAA,KAA4B;AAC7E,EAAA,MAAM,MAAA,GAAS,KAAK,SAAA,EAAU;AAE9B,EAAA,IAAI,QAAQ,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,eAAe,MAAM,IAAA,EAAM;AAC3D,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,SAAA,GAAY,OAAO,YAAA,EAAa;AAItC,EAAA,IACE,CAAC,SAAA,CAAU,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA,IAC1C,CAAC,SAAA,CAAU,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA,EAC1C;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OACE,SAAA,CAAU,iBAAiB,IAAA,CAAK,YAAA,IAChC,OAAO,cAAA,EAAe,CAAE,iBAAiB,IAAA,CAAK,YAAA;AAElD;;;;"}
1
+ {"version":3,"file":"is-conditional-type-distribution-guard.mjs","sourceRoot":"","sources":["../../../src/functions/functions/is-conditional-type-distribution-guard.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,IAAc,EAAW,EAAE;IAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAEhC,IAAI,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IAExC,+EAA+E;IAC/E,4EAA4E;IAC5E,IACE,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;QAC3C,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAC3C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,SAAS,CAAC,YAAY,KAAK,IAAI,CAAC,YAAY;QAC5C,MAAM,CAAC,cAAc,EAAE,CAAC,YAAY,KAAK,IAAI,CAAC,YAAY,CAC3D,CAAC;AACJ,CAAC,CAAC"}
@@ -1,20 +1,126 @@
1
1
  import { Arr } from 'ts-data-forge';
2
2
  import * as tsm from 'ts-morph';
3
3
  import { isAtomicTypeNode } from './is-atomic-type-node.mjs';
4
+ export const isShallowReadonlyTypeNode = (node) => isReadonlyTupleOrArrayTypeNode(node) ||
5
+ isReadonlyTypeReferenceNode(node) ||
6
+ isAtomicTypeNode(node);
7
+ export const isReadonlyTupleOrArrayTypeNode = (node) => node.isKind(tsm.SyntaxKind.TypeOperator) &&
8
+ node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword &&
9
+ (node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType) ||
10
+ node.getTypeNode().isKind(tsm.SyntaxKind.TupleType));
11
+ export const isReadonlyArrayTypeNode = (node) => node.isKind(tsm.SyntaxKind.TypeOperator) &&
12
+ node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword &&
13
+ node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType);
4
14
 
5
- const isShallowReadonlyTypeNode = (node) => isReadonlyTupleOrArrayTypeNode(node) || isReadonlyTypeReferenceNode(node) || isAtomicTypeNode(node);
6
- const isReadonlyTupleOrArrayTypeNode = (node) => node.isKind(tsm.SyntaxKind.TypeOperator) && node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword && (node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType) || // Use optional chaining and isKind
7
- node.getTypeNode().isKind(tsm.SyntaxKind.TupleType));
8
- const isReadonlyArrayTypeNode = (node) => node.isKind(tsm.SyntaxKind.TypeOperator) && node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword && node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType);
9
- const isReadonlyTupleTypeNode = (node) => node.isKind(tsm.SyntaxKind.TypeOperator) && node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword && node.getTypeNode().isKind(tsm.SyntaxKind.TupleType);
10
- const isReadonlyTypeReferenceNode = (node) => {
11
- if (!node.isKind(tsm.SyntaxKind.TypeReference)) {
12
- return false;
13
- }
14
- const typeName = node.getTypeName();
15
- const typeArguments = node.getTypeArguments();
16
- return typeName.isKind(tsm.SyntaxKind.Identifier) && typeName.getText() === "Readonly" && Arr.isFixedLengthArray(1, typeArguments);
15
+ const getTypeNodeFromSource = (sourceCode, typeName) => {
16
+ const project = new tsm.Project({ useInMemoryFileSystem: true });
17
+ const sourceFile = project.createSourceFile('test.ts', sourceCode);
18
+ const typeAlias = sourceFile.getTypeAliasOrThrow(typeName);
19
+ return typeAlias.getTypeNodeOrThrow();
17
20
  };
18
21
 
19
- export { isReadonlyArrayTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTupleTypeNode, isReadonlyTypeReferenceNode, isShallowReadonlyTypeNode };
20
- //# sourceMappingURL=is-readonly-node.mjs.map
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+ export const isReadonlyTupleTypeNode = (node) => node.isKind(tsm.SyntaxKind.TypeOperator) &&
49
+ node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword &&
50
+ node.getTypeNode().isKind(tsm.SyntaxKind.TupleType);
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ export const isReadonlyTypeReferenceNode = (node) => {
80
+ if (!node.isKind(tsm.SyntaxKind.TypeReference)) {
81
+ return false;
82
+ }
83
+ const typeName = node.getTypeName();
84
+ const typeArguments = node.getTypeArguments();
85
+ return (typeName.isKind(tsm.SyntaxKind.Identifier) &&
86
+ typeName.getText() === 'Readonly' &&
87
+ Arr.isFixedLengthArray(1, typeArguments));
88
+ };
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+ //# sourceMappingURL=is-readonly-node.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-readonly-node.mjs","sources":["../../../src/functions/functions/is-readonly-node.mts"],"sourcesContent":["import { Arr, expectType } from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { type DeepReadonly, type StrictOmit } from 'ts-type-forge';\nimport { isAtomicTypeNode } from './is-atomic-type-node.mjs';\n\nexport const isShallowReadonlyTypeNode = (node: tsm.Node): boolean =>\n isReadonlyTupleOrArrayTypeNode(node) ||\n isReadonlyTypeReferenceNode(node) ||\n isAtomicTypeNode(node);\n\nexport const isReadonlyTupleOrArrayTypeNode = (\n node: DeepReadonly<tsm.Node>,\n): node is ReadonlyArrayTypeNode | ReadonlyTupleTypeNode =>\n node.isKind(tsm.SyntaxKind.TypeOperator) &&\n node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword &&\n (node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType) || // Use optional chaining and isKind\n node.getTypeNode().isKind(tsm.SyntaxKind.TupleType));\n\nexport type ReadonlyArrayTypeNode = tsm.TypeNode &\n StrictOmit<tsm.TypeOperatorTypeNode, 'getOperator' | 'getTypeNode'> &\n Readonly<{\n getOperator: () => tsm.SyntaxKind.ReadonlyKeyword;\n getTypeNode: () => tsm.ArrayTypeNode;\n }>;\n\nexport const isReadonlyArrayTypeNode = (\n node: DeepReadonly<tsm.Node>,\n): node is ReadonlyArrayTypeNode =>\n node.isKind(tsm.SyntaxKind.TypeOperator) &&\n node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword &&\n node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType);\n\n// Helper to get a specific type node from source code\nconst getTypeNodeFromSource = (\n sourceCode: string,\n typeName: string,\n): tsm.Node => {\n const project = new tsm.Project({ useInMemoryFileSystem: true });\n\n const sourceFile = project.createSourceFile('test.ts', sourceCode);\n\n const typeAlias = sourceFile.getTypeAliasOrThrow(typeName);\n\n return typeAlias.getTypeNodeOrThrow();\n};\n\nif (import.meta.vitest !== undefined) {\n describe('isReadonlyArrayTypeNode', () => {\n test('should return true for readonly array type', () => {\n const node = getTypeNodeFromSource(\n 'type Test = readonly number[];',\n 'Test',\n );\n\n if (isReadonlyArrayTypeNode(node)) {\n const _operator = node.getOperator();\n\n expectType<typeof _operator, tsm.SyntaxKind.ReadonlyKeyword>('=');\n\n const _typeNode = node.getTypeNode();\n\n expectType<typeof _typeNode, tsm.ArrayTypeNode>('=');\n }\n\n assert.isTrue(node.isKind(tsm.SyntaxKind.TypeOperator));\n\n if (!isReadonlyArrayTypeNode(node)) {\n throw new Error('node should be ReadonlyArrayTypeNode');\n }\n\n expect(node.getOperator()).toBe(tsm.SyntaxKind.ReadonlyKeyword);\n\n assert.isTrue(node.getTypeNode().isKind(tsm.SyntaxKind.ArrayType));\n });\n\n test('should return false for non-readonly array', () => {\n const node = getTypeNodeFromSource('type Test = string[];', 'Test');\n\n assert.isFalse(isReadonlyArrayTypeNode(node));\n });\n\n test('should return false for readonly tuple', () => {\n const node = getTypeNodeFromSource(\n 'type Test = readonly [string];',\n 'Test',\n );\n\n assert.isFalse(isReadonlyArrayTypeNode(node));\n });\n });\n}\n\nexport type ReadonlyTupleTypeNode = tsm.TypeNode &\n StrictOmit<tsm.TypeOperatorTypeNode, 'getOperator' | 'getTypeNode'> &\n Readonly<{\n getOperator: () => tsm.SyntaxKind.ReadonlyKeyword;\n getTypeNode: () => tsm.TupleTypeNode;\n }>;\n\nexport const isReadonlyTupleTypeNode = (\n node: DeepReadonly<tsm.Node>,\n): node is ReadonlyTupleTypeNode =>\n node.isKind(tsm.SyntaxKind.TypeOperator) &&\n node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword &&\n node.getTypeNode().isKind(tsm.SyntaxKind.TupleType);\n\nif (import.meta.vitest !== undefined) {\n describe('isReadonlyTupleTypeNode', () => {\n test('should return true for readonly tuple type', () => {\n const node = getTypeNodeFromSource(\n 'type Test = readonly [number, string];',\n 'Test',\n );\n\n assert.isTrue(isReadonlyTupleTypeNode(node));\n\n if (isReadonlyTupleTypeNode(node)) {\n const _operator = node.getOperator();\n\n expectType<typeof _operator, tsm.SyntaxKind.ReadonlyKeyword>('=');\n\n const _typeNode = node.getTypeNode();\n\n expectType<typeof _typeNode, tsm.TupleTypeNode>('=');\n }\n\n assert.isTrue(node.isKind(tsm.SyntaxKind.TypeOperator));\n\n if (!isReadonlyTupleTypeNode(node)) {\n throw new Error('node should be ReadonlyTupleTypeNode');\n }\n\n expect(node.getOperator()).toBe(tsm.SyntaxKind.ReadonlyKeyword);\n\n assert.isTrue(node.getTypeNode().isKind(tsm.SyntaxKind.TupleType));\n });\n\n test('should return false for non-readonly tuple', () => {\n const node = getTypeNodeFromSource('type Test = [boolean];', 'Test');\n\n assert.isFalse(isReadonlyTupleTypeNode(node));\n });\n\n test('should return false for readonly array', () => {\n const node = getTypeNodeFromSource(\n 'type Test = readonly number[];',\n 'Test',\n );\n\n assert.isFalse(isReadonlyTupleTypeNode(node));\n });\n });\n}\n\nexport type ReadonlyTypeReferenceNode = tsm.TypeNode &\n StrictOmit<tsm.TypeReferenceNode, 'getTypeName' | 'getTypeArguments'> &\n Readonly<{\n getTypeName: () => StrictOmit<tsm.Identifier, 'getText'> &\n Readonly<{\n getText: () => 'Readonly';\n }>;\n getTypeArguments: () => readonly [tsm.TypeNode];\n }>;\n\nexport const isReadonlyTypeReferenceNode = (\n node: DeepReadonly<tsm.Node>,\n): node is ReadonlyTypeReferenceNode => {\n if (!node.isKind(tsm.SyntaxKind.TypeReference)) {\n return false;\n }\n\n const typeName = node.getTypeName();\n\n const typeArguments = node.getTypeArguments();\n\n return (\n typeName.isKind(tsm.SyntaxKind.Identifier) &&\n typeName.getText() === 'Readonly' &&\n Arr.isFixedLengthArray(1, typeArguments)\n );\n};\n\nif (import.meta.vitest !== undefined) {\n describe('isReadonlyTypeReferenceNode', () => {\n test('should return true for Readonly<T>', () => {\n const node = getTypeNodeFromSource(\n 'type Test = Readonly<{ x: number }>;',\n 'Test',\n );\n\n assert.isTrue(isReadonlyTypeReferenceNode(node));\n\n if (isReadonlyTypeReferenceNode(node)) {\n const _typeNameText = node.getTypeName().getText();\n\n expectType<typeof _typeNameText, 'Readonly'>('=');\n\n const _typeArguments = node.getTypeArguments();\n\n expectType<\n typeof _typeArguments,\n readonly [tsm.TypeNode<tsm.ts.TypeNode>]\n >('=');\n }\n\n assert.isTrue(node.isKind(tsm.SyntaxKind.TypeReference));\n\n if (!isReadonlyTypeReferenceNode(node)) {\n throw new Error('node should be ReadonlyNode');\n }\n\n expect(node.getTypeName().getText()).toBe('Readonly');\n\n expect(node.getTypeArguments()).toHaveLength(1);\n });\n\n test('should return false for other type references', () => {\n const node = getTypeNodeFromSource(\n 'type Test = Partial<{ y: string }>;',\n 'Test',\n );\n\n assert.isFalse(isReadonlyTypeReferenceNode(node));\n });\n\n test('should return false for Readonly without type arguments', () => {\n // Note: This is syntactically incorrect TS, but testing the guard\n const node = getTypeNodeFromSource('type Test = Readonly;', 'Test');\n\n assert.isFalse(isReadonlyTypeReferenceNode(node));\n });\n\n test('should return false for Readonly with multiple type arguments', () => {\n // Note: This is syntactically incorrect TS, but testing the guard\n const project = new tsm.Project({ useInMemoryFileSystem: true });\n\n // Need to create manually as TS parser might reject Readonly<A, B>\n const sourceFile = project.createSourceFile(\n 'test.ts',\n 'type Test = Readonly<string, number>;',\n );\n\n const node = sourceFile.getTypeAliasOrThrow('Test').getTypeNodeOrThrow();\n\n assert.isFalse(isReadonlyTypeReferenceNode(node));\n });\n });\n}\n"],"names":[],"mappings":";;;;MAKa,yBAAA,GAA4B,CAAC,IAAA,KACxC,8BAAA,CAA+B,IAAI,KACnC,2BAAA,CAA4B,IAAI,CAAA,IAChC,gBAAA,CAAiB,IAAI;MAEV,8BAAA,GAAiC,CAC5C,IAAA,KAEA,IAAA,CAAK,OAAO,GAAA,CAAI,UAAA,CAAW,YAAY,CAAA,IACvC,IAAA,CAAK,aAAY,KAAM,GAAA,CAAI,WAAW,eAAA,KACrC,IAAA,CAAK,aAAY,CAAE,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA;AACjD,IAAA,CAAK,WAAA,EAAY,CAAE,MAAA,CAAO,GAAA,CAAI,WAAW,SAAS,CAAA;MASzC,uBAAA,GAA0B,CACrC,IAAA,KAEA,IAAA,CAAK,OAAO,GAAA,CAAI,UAAA,CAAW,YAAY,CAAA,IACvC,IAAA,CAAK,aAAY,KAAM,GAAA,CAAI,WAAW,eAAA,IACtC,IAAA,CAAK,aAAY,CAAE,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS;MAqEvC,uBAAA,GAA0B,CACrC,IAAA,KAEA,IAAA,CAAK,OAAO,GAAA,CAAI,UAAA,CAAW,YAAY,CAAA,IACvC,IAAA,CAAK,aAAY,KAAM,GAAA,CAAI,WAAW,eAAA,IACtC,IAAA,CAAK,aAAY,CAAE,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS;AA4D7C,MAA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AAO,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import * as tsm from 'ts-morph';
2
-
3
- const isSpreadParameterNode = (node) => node.isKind(tsm.SyntaxKind.Parameter) && node.getDotDotDotToken() !== void 0;
4
- const isSpreadNamedTupleMemberNode = (node) => node.isKind(tsm.SyntaxKind.NamedTupleMember) && node.getDotDotDotToken() !== void 0;
5
-
6
- export { isSpreadNamedTupleMemberNode, isSpreadParameterNode };
7
- //# sourceMappingURL=is-spread-parameter-node.mjs.map
2
+ export const isSpreadParameterNode = (node) => node.isKind(tsm.SyntaxKind.Parameter) &&
3
+ node.getDotDotDotToken() !== undefined;
4
+ export const isSpreadNamedTupleMemberNode = (node) => node.isKind(tsm.SyntaxKind.NamedTupleMember) &&
5
+ node.getDotDotDotToken() !== undefined;
6
+ //# sourceMappingURL=is-spread-parameter-node.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-spread-parameter-node.mjs","sources":["../../../src/functions/functions/is-spread-parameter-node.mts"],"sourcesContent":["import * as tsm from 'ts-morph';\n\nexport const isSpreadParameterNode = (\n node: tsm.Node,\n): node is tsm.ParameterDeclaration =>\n node.isKind(tsm.SyntaxKind.Parameter) &&\n node.getDotDotDotToken() !== undefined;\n\nexport const isSpreadNamedTupleMemberNode = (\n node: tsm.Node,\n): node is tsm.NamedTupleMember =>\n node.isKind(tsm.SyntaxKind.NamedTupleMember) &&\n node.getDotDotDotToken() !== undefined;\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAA,GAAwB,CACnC,IAAA,KAEA,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA,IACpC,IAAA,CAAK,iBAAA,EAAkB,KAAM;AAExB,MAAM,4BAAA,GAA+B,CAC1C,IAAA,KAEA,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,gBAAgB,CAAA,IAC3C,IAAA,CAAK,iBAAA,EAAkB,KAAM;;;;"}
1
+ {"version":3,"file":"is-spread-parameter-node.mjs","sourceRoot":"","sources":["../../../src/functions/functions/is-spread-parameter-node.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAAc,EACoB,EAAE,CACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;IACrC,IAAI,CAAC,iBAAiB,EAAE,KAAK,SAAS,CAAC;AAEzC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,IAAc,EACgB,EAAE,CAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,gBAAgB,CAAC;IAC5C,IAAI,CAAC,iBAAiB,EAAE,KAAK,SAAS,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import * as tsm from 'ts-morph';
2
2
 
3
- const removeParentheses = (node) => node.isKind(tsm.SyntaxKind.ParenthesizedType) ? removeParentheses(node.getTypeNode()) : node;
4
-
5
- export { removeParentheses };
6
- //# sourceMappingURL=remove-parentheses.mjs.map
3
+ export const removeParentheses = (node) => node.isKind(tsm.SyntaxKind.ParenthesizedType)
4
+ ? removeParentheses(node.getTypeNode())
5
+ : node;
6
+ //# sourceMappingURL=remove-parentheses.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"remove-parentheses.mjs","sources":["../../../src/functions/functions/remove-parentheses.mts"],"sourcesContent":["import * as tsm from 'ts-morph';\n\n// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\nexport const removeParentheses = (node: tsm.TypeNode): tsm.TypeNode =>\n node.isKind(tsm.SyntaxKind.ParenthesizedType)\n ? removeParentheses(node.getTypeNode())\n : node;\n"],"names":[],"mappings":";;AAGO,MAAM,iBAAA,GAAoB,CAAC,IAAA,KAChC,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,iBAAiB,CAAA,GACxC,iBAAA,CAAkB,IAAA,CAAK,WAAA,EAAa,CAAA,GACpC;;;;"}
1
+ {"version":3,"file":"remove-parentheses.mjs","sourceRoot":"","sources":["../../../src/functions/functions/remove-parentheses.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAkB,EAAgB,EAAE,CACpE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC;IAC3C,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC,CAAC,IAAI,CAAC"}
@@ -1,12 +1,26 @@
1
1
  import * as tsm from 'ts-morph';
2
2
 
3
- const shouldAvoidParenthesesForReadonly = (node) => {
4
- const parent = node.getParent();
5
- if (parent === void 0) {
6
- return false;
7
- }
8
- return parent.isKind(tsm.SyntaxKind.TypePredicate);
9
- };
10
3
 
11
- export { shouldAvoidParenthesesForReadonly };
12
- //# sourceMappingURL=should-avoid-parentheses-for-readonly.mjs.map
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ export const shouldAvoidParenthesesForReadonly = (node) => {
16
+ const parent = node.getParent();
17
+ if (parent === undefined) {
18
+ return false;
19
+ }
20
+
21
+
22
+
23
+
24
+ return parent.isKind(tsm.SyntaxKind.TypePredicate);
25
+ };
26
+ //# sourceMappingURL=should-avoid-parentheses-for-readonly.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"should-avoid-parentheses-for-readonly.mjs","sources":["../../../src/functions/functions/should-avoid-parentheses-for-readonly.mts"],"sourcesContent":["import * as tsm from 'ts-morph';\n\n/**\n * Determines if parentheses should be avoided when adding 'readonly' prefix to a type.\n *\n * Parentheses should be AVOIDED in these specific contexts:\n * - Type predicates: `x is [T, U]` -> `x is readonly [T, U]` (not `x is (readonly [T, U])`)\n * because parentheses around the type in a type predicate cause syntax errors\n *\n * For all other contexts, we keep parentheses for safety to avoid precedence issues,\n * relying on prettier to remove unnecessary ones.\n *\n * @param node - The type node to check\n * @returns true if parentheses should be avoided, false otherwise (keep parentheses)\n */\nexport const shouldAvoidParenthesesForReadonly = (node: tsm.Node): boolean => {\n const parent = node.getParent();\n\n if (parent === undefined) {\n return false;\n }\n\n // Check if parent is TypePredicate: x is T\n // In this case, we MUST avoid parentheses: x is readonly T (not x is (readonly T))\n // because `x is (readonly T)` is a syntax error\n // For all other cases, keep parentheses for safety\n return parent.isKind(tsm.SyntaxKind.TypePredicate);\n};\n"],"names":[],"mappings":";;AAeO,MAAM,iCAAA,GAAoC,CAAC,IAAA,KAA4B;AAC5E,EAAA,MAAM,MAAA,GAAS,KAAK,SAAA,EAAU;AAE9B,EAAA,IAAI,WAAW,MAAA,EAAW;AACxB,IAAA,OAAO,KAAA;AAAA,EACT;AAMA,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,aAAa,CAAA;AACnD;;;;"}
1
+ {"version":3,"file":"should-avoid-parentheses-for-readonly.mjs","sourceRoot":"","sources":["../../../src/functions/functions/should-avoid-parentheses-for-readonly.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,IAAc,EAAW,EAAE;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAEhC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2CAA2C;IAC3C,mFAAmF;IACnF,gDAAgD;IAChD,mDAAmD;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AACrD,CAAC,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { wrapWithParentheses } from './wrap-with-parentheses.mjs';
2
+ export const unwrapReadonlyTypeArgText = (
2
3
 
3
- const unwrapReadonlyTypeArgText = (node) => wrapWithParentheses(node.getTypeArguments()[0].getFullText());
4
-
5
- export { unwrapReadonlyTypeArgText };
6
- //# sourceMappingURL=unwrap-readonly.mjs.map
4
+ node) => wrapWithParentheses(node.getTypeArguments()[0].getFullText());
5
+ //# sourceMappingURL=unwrap-readonly.mjs.map