ts-codemod-lib 3.3.0 → 3.3.1

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 (69) hide show
  1. package/dist/entry-point.mjs +2 -24
  2. package/dist/entry-point.mjs.map +1 -1
  3. package/dist/functions/ast-transformers/append-as-const.mjs +330 -292
  4. package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
  5. package/dist/functions/ast-transformers/convert-interface-to-type.mjs +85 -70
  6. package/dist/functions/ast-transformers/convert-interface-to-type.mjs.map +1 -1
  7. package/dist/functions/ast-transformers/convert-to-readonly.mjs +969 -840
  8. package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
  9. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs +276 -134
  10. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -1
  11. package/dist/functions/ast-transformers/index.mjs +10 -12
  12. package/dist/functions/ast-transformers/index.mjs.map +1 -1
  13. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs +14 -7
  14. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs.map +1 -1
  15. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs +12 -15
  16. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs.map +1 -1
  17. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs +63 -58
  18. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map +1 -1
  19. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs +5 -5
  20. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs.map +1 -1
  21. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs +15 -20
  22. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs.map +1 -1
  23. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs +30 -34
  24. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs.map +1 -1
  25. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +197 -156
  26. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
  27. package/dist/functions/ast-transformers/transform-source-code.mjs +74 -75
  28. package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
  29. package/dist/functions/ast-transformers/types.mjs +2 -2
  30. package/dist/functions/ast-transformers/types.mjs.map +1 -1
  31. package/dist/functions/constants/ignore-comment-text.mjs +11 -13
  32. package/dist/functions/constants/ignore-comment-text.mjs.map +1 -1
  33. package/dist/functions/constants/index.mjs +2 -2
  34. package/dist/functions/constants/index.mjs.map +1 -1
  35. package/dist/functions/functions/has-disable-next-line-comment.mjs +67 -38
  36. package/dist/functions/functions/has-disable-next-line-comment.mjs.map +1 -1
  37. package/dist/functions/functions/index.mjs +11 -11
  38. package/dist/functions/functions/index.mjs.map +1 -1
  39. package/dist/functions/functions/is-as-const-node.mjs +25 -20
  40. package/dist/functions/functions/is-as-const-node.mjs.map +1 -1
  41. package/dist/functions/functions/is-atomic-type-node.mjs +245 -25
  42. package/dist/functions/functions/is-atomic-type-node.mjs.map +1 -1
  43. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs +34 -13
  44. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs.map +1 -1
  45. package/dist/functions/functions/is-readonly-node.mjs +120 -14
  46. package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
  47. package/dist/functions/functions/is-spread-parameter-node.mjs +5 -6
  48. package/dist/functions/functions/is-spread-parameter-node.mjs.map +1 -1
  49. package/dist/functions/functions/remove-parentheses.mjs +4 -4
  50. package/dist/functions/functions/remove-parentheses.mjs.map +1 -1
  51. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs +23 -9
  52. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs.map +1 -1
  53. package/dist/functions/functions/unwrap-readonly.mjs +3 -4
  54. package/dist/functions/functions/unwrap-readonly.mjs.map +1 -1
  55. package/dist/functions/functions/wrap-with-parentheses.d.mts.map +1 -1
  56. package/dist/functions/functions/wrap-with-parentheses.mjs +54 -29
  57. package/dist/functions/functions/wrap-with-parentheses.mjs.map +1 -1
  58. package/dist/functions/index.mjs +5 -24
  59. package/dist/functions/index.mjs.map +1 -1
  60. package/dist/functions/utils/index.mjs +2 -2
  61. package/dist/functions/utils/index.mjs.map +1 -1
  62. package/dist/functions/utils/replace-with-debug.mjs +4 -6
  63. package/dist/functions/utils/replace-with-debug.mjs.map +1 -1
  64. package/dist/index.mjs +2 -24
  65. package/dist/index.mjs.map +1 -1
  66. package/package.json +11 -12
  67. package/src/functions/ast-transformers/convert-to-readonly.test.mts +10 -1
  68. package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.test.mts +76 -22
  69. package/src/functions/functions/wrap-with-parentheses.mts +5 -2
@@ -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,MAAM,2BAAA,GAA8B,CAC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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
@@ -1 +1 @@
1
- {"version":3,"file":"unwrap-readonly.mjs","sources":["../../../src/functions/functions/unwrap-readonly.mts"],"sourcesContent":["import { type ReadonlyTypeReferenceNode } from './is-readonly-node.mjs';\nimport { wrapWithParentheses } from './wrap-with-parentheses.mjs';\n\nexport const unwrapReadonlyTypeArgText = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: ReadonlyTypeReferenceNode,\n): string => wrapWithParentheses(node.getTypeArguments()[0].getFullText());\n"],"names":[],"mappings":";;AAGO,MAAM,yBAAA,GAA4B,CAEvC,IAAA,KACW,mBAAA,CAAoB,IAAA,CAAK,kBAAiB,CAAE,CAAC,CAAA,CAAE,WAAA,EAAa;;;;"}
1
+ {"version":3,"file":"unwrap-readonly.mjs","sourceRoot":"","sources":["../../../src/functions/functions/unwrap-readonly.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,CAAC,MAAM,yBAAyB,GAAG;AACvC,8EAA8E;AAC9E,IAA+B,EACvB,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"wrap-with-parentheses.d.mts","sourceRoot":"","sources":["../../../src/functions/functions/wrap-with-parentheses.mts"],"names":[],"mappings":"AAgDA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MAQrD,CAAC"}
1
+ {"version":3,"file":"wrap-with-parentheses.d.mts","sourceRoot":"","sources":["../../../src/functions/functions/wrap-with-parentheses.mts"],"names":[],"mappings":"AAmDA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MAQrD,CAAC"}
@@ -1,36 +1,61 @@
1
- import { range, asUint32 } from 'ts-data-forge';
2
1
 
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ import { asUint32, range } from 'ts-data-forge';
3
12
  const parenDepthDelta = (char) => {
4
- switch (char) {
5
- case "(":
6
- return 1;
7
- case ")":
8
- return -1;
9
- default:
10
- return 0;
11
- }
13
+ switch (char) {
14
+ case '(':
15
+ return 1;
16
+ case ')':
17
+ return -1;
18
+
19
+
20
+ case undefined:
21
+ default:
22
+ return 0;
23
+ }
12
24
  };
13
25
  const isWrappedWithParentheses = (str) => {
14
- const trimmed = str.trim();
15
- if (!trimmed.startsWith("(") || !trimmed.endsWith(")")) {
16
- return false;
17
- }
18
- let mut_depth = 0;
19
- for (const mut_i of range(0, asUint32(trimmed.length))) {
20
- mut_depth += parenDepthDelta(trimmed.charAt(mut_i));
21
- if (mut_depth === 0 && mut_i < trimmed.length - 1) {
22
- return false;
26
+ const trimmed = str.trim();
27
+ if (!trimmed.startsWith('(') || !trimmed.endsWith(')')) {
28
+ return false;
23
29
  }
24
- }
25
- return true;
26
- };
27
- const wrapWithParentheses = (nodeStr) => {
28
- const trimmed = nodeStr.trim();
29
- if (isWrappedWithParentheses(trimmed)) {
30
- return trimmed;
31
- }
32
- return `(${trimmed})`;
30
+
31
+
32
+ let mut_depth = 0;
33
+ for (const mut_i of range(0, asUint32(trimmed.length))) {
34
+ mut_depth += parenDepthDelta(trimmed.at(mut_i));
35
+
36
+ if (mut_depth === 0 && mut_i < trimmed.length - 1) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
33
41
  };
34
42
 
35
- export { wrapWithParentheses };
36
- //# sourceMappingURL=wrap-with-parentheses.mjs.map
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ export const wrapWithParentheses = (nodeStr) => {
55
+ const trimmed = nodeStr.trim();
56
+ if (isWrappedWithParentheses(trimmed)) {
57
+ return trimmed;
58
+ }
59
+ return `(${trimmed})`;
60
+ };
61
+ //# sourceMappingURL=wrap-with-parentheses.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrap-with-parentheses.mjs","sources":["../../../src/functions/functions/wrap-with-parentheses.mts"],"sourcesContent":["/**\n * Checks if a string is already wrapped with a single pair of balanced parentheses\n * that encompasses the entire expression.\n *\n * @example\n * isWrappedWithParentheses('(A)') // true\n * isWrappedWithParentheses('((A))') // true (outer pair wraps everything)\n * isWrappedWithParentheses('(A) | (B)') // false (outer parens don't wrap everything)\n * isWrappedWithParentheses('A') // false\n */\nimport { asUint32, range } from 'ts-data-forge';\n\nconst parenDepthDelta = (char: string): number => {\n switch (char) {\n case '(':\n return 1;\n\n case ')':\n return -1;\n\n default:\n return 0;\n }\n};\n\nconst isWrappedWithParentheses = (str: string): boolean => {\n const trimmed = str.trim();\n\n if (!trimmed.startsWith('(') || !trimmed.endsWith(')')) {\n return false;\n }\n\n // Check if the opening and closing parentheses are balanced\n // and the opening parenthesis corresponds to the closing one\n let mut_depth = 0;\n\n for (const mut_i of range(0, asUint32(trimmed.length))) {\n mut_depth += parenDepthDelta(trimmed.charAt(mut_i));\n\n // If we reach depth 0 before the end, the outer parentheses don't wrap everything\n if (mut_depth === 0 && mut_i < trimmed.length - 1) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Wraps a string with parentheses if not already wrapped.\n * Avoids adding redundant parentheses when the expression is already\n * fully wrapped with balanced parentheses.\n *\n * @example\n * wrapWithParentheses('A') // '(A)'\n * wrapWithParentheses('(A)') // '(A)' (not '((A))')\n * wrapWithParentheses('A | B') // '(A | B)'\n * wrapWithParentheses('(A | B)') // '(A | B)' (not '((A | B))')\n * wrapWithParentheses('(A) | (B)') // '((A) | (B))' (needs outer parens)\n */\nexport const wrapWithParentheses = (nodeStr: string): string => {\n const trimmed = nodeStr.trim();\n\n if (isWrappedWithParentheses(trimmed)) {\n return trimmed;\n }\n\n return `(${trimmed})` as const;\n};\n"],"names":[],"mappings":";;AAYA,MAAM,eAAA,GAAkB,CAAC,IAAA,KAAyB;AAChD,EAAA,QAAQ,IAAA;AAAM,IACZ,KAAK,GAAA;AACH,MAAA,OAAO,CAAA;AAAA,IAET,KAAK,GAAA;AACH,MAAA,OAAO,EAAA;AAAA,IAET;AACE,MAAA,OAAO,CAAA;AAAA;AAEb,CAAA;AAEA,MAAM,wBAAA,GAA2B,CAAC,GAAA,KAAyB;AACzD,EAAA,MAAM,OAAA,GAAU,IAAI,IAAA,EAAK;AAEzB,EAAA,IAAI,CAAC,QAAQ,UAAA,CAAW,GAAG,KAAK,CAAC,OAAA,CAAQ,QAAA,CAAS,GAAG,CAAA,EAAG;AACtD,IAAA,OAAO,KAAA;AAAA,EACT;AAIA,EAAA,IAAI,SAAA,GAAY,CAAA;AAEhB,EAAA,KAAA,MAAW,SAAS,KAAA,CAAM,CAAA,EAAG,SAAS,OAAA,CAAQ,MAAM,CAAC,CAAA,EAAG;AACtD,IAAA,SAAA,IAAa,eAAA,CAAgB,OAAA,CAAQ,MAAA,CAAO,KAAK,CAAC,CAAA;AAGlD,IAAA,IAAI,SAAA,KAAc,CAAA,IAAK,KAAA,GAAQ,OAAA,CAAQ,SAAS,CAAA,EAAG;AACjD,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT,CAAA;AAcO,MAAM,mBAAA,GAAsB,CAAC,OAAA,KAA4B;AAC9D,EAAA,MAAM,OAAA,GAAU,QAAQ,IAAA,EAAK;AAE7B,EAAA,IAAI,wBAAA,CAAyB,OAAO,CAAA,EAAG;AACrC,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,OAAO,IAAI,OAAO,CAAA,CAAA,CAAA;AACpB;;;;"}
1
+ {"version":3,"file":"wrap-with-parentheses.mjs","sourceRoot":"","sources":["../../../src/functions/functions/wrap-with-parentheses.mts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,eAAe,GAAG,CAAC,IAAwB,EAAU,EAAE;IAC3D,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,GAAG;YACN,OAAO,CAAC,CAAC;QAEX,KAAK,GAAG;YACN,OAAO,CAAC,CAAC,CAAC;QAEZ,sEAAsE;QACtE,0DAA0D;QAC1D,KAAK,SAAS,CAAC;QACf;YACE,OAAO,CAAC,CAAC;IACb,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,GAAW,EAAW,EAAE;IACxD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAE3B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4DAA4D;IAC5D,6DAA6D;IAC7D,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QACvD,SAAS,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAEhD,kFAAkF;QAClF,IAAI,SAAS,KAAK,CAAC,IAAI,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClD,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAE/B,IAAI,wBAAwB,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,IAAI,OAAO,GAAY,CAAC;AACjC,CAAC,CAAC"}
@@ -1,24 +1,5 @@
1
- export { appendAsConstTransformer } from './ast-transformers/append-as-const.mjs';
2
- export { convertInterfaceToTypeTransformer } from './ast-transformers/convert-interface-to-type.mjs';
3
- export { convertToReadonlyTransformer } from './ast-transformers/convert-to-readonly.mjs';
4
- export { enableNoUncheckedIndexedAccessTransformer } from './ast-transformers/enable-no-unchecked-indexed-access.mjs';
5
- export { compareUnionIntersectionTypes } from './ast-transformers/readonly-transformer-helpers/compare-union-types.mjs';
6
- export { invalidDeepReadonlyTypeName } from './ast-transformers/readonly-transformer-helpers/constants.mjs';
7
- export { groupUnionIntersectionTypes } from './ast-transformers/readonly-transformer-helpers/group-union-types.mjs';
8
- export { nextReadonlyContext } from './ast-transformers/readonly-transformer-helpers/readonly-context.mjs';
9
- export { replaceAnyWithUnknownTransformer } from './ast-transformers/replace-any-with-unknown.mjs';
10
- export { replaceRecordWithUnknownRecordTransformer } from './ast-transformers/replace-record-with-unknown-record.mjs';
11
- export { transformSourceCode } from './ast-transformers/transform-source-code.mjs';
12
- export { IGNORE_FILE_COMMENT_PREFIXES, IGNORE_LINE_COMMENT_PREFIXES } from './constants/ignore-comment-text.mjs';
13
- export { hasDisableNextLineComment } from './functions/has-disable-next-line-comment.mjs';
14
- export { isAsConstNode } from './functions/is-as-const-node.mjs';
15
- export { isAtomicTypeNode } from './functions/is-atomic-type-node.mjs';
16
- export { isConditionalTypeDistributionGuard } from './functions/is-conditional-type-distribution-guard.mjs';
17
- export { isReadonlyArrayTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTupleTypeNode, isReadonlyTypeReferenceNode, isShallowReadonlyTypeNode } from './functions/is-readonly-node.mjs';
18
- export { isSpreadNamedTupleMemberNode, isSpreadParameterNode } from './functions/is-spread-parameter-node.mjs';
19
- export { removeParentheses } from './functions/remove-parentheses.mjs';
20
- export { shouldAvoidParenthesesForReadonly } from './functions/should-avoid-parentheses-for-readonly.mjs';
21
- export { unwrapReadonlyTypeArgText } from './functions/unwrap-readonly.mjs';
22
- export { wrapWithParentheses } from './functions/wrap-with-parentheses.mjs';
23
- export { replaceNodeWithDebugPrint } from './utils/replace-with-debug.mjs';
24
- //# sourceMappingURL=index.mjs.map
1
+ export * from './ast-transformers/index.mjs';
2
+ export * from './constants/index.mjs';
3
+ export * from './functions/index.mjs';
4
+ export * from './utils/index.mjs';
5
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/functions/index.mts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
@@ -1,2 +1,2 @@
1
- export { replaceNodeWithDebugPrint } from './replace-with-debug.mjs';
2
- //# sourceMappingURL=index.mjs.map
1
+ export * from './replace-with-debug.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/functions/utils/index.mts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -1,7 +1,5 @@
1
- const replaceNodeWithDebugPrint = (node, newNodeText) => {
2
- console.debug(`${node.getText()} -> ${newNodeText}`);
3
- node.replaceWithText(newNodeText);
1
+ export const replaceNodeWithDebugPrint = (node, newNodeText) => {
2
+ console.debug(`${node.getText()} -> ${newNodeText}`);
3
+ node.replaceWithText(newNodeText);
4
4
  };
5
-
6
- export { replaceNodeWithDebugPrint };
7
- //# sourceMappingURL=replace-with-debug.mjs.map
5
+ //# sourceMappingURL=replace-with-debug.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace-with-debug.mjs","sources":["../../../src/functions/utils/replace-with-debug.mts"],"sourcesContent":["import type * as tsm from 'ts-morph';\n\nexport const replaceNodeWithDebugPrint = (\n node: tsm.Node,\n newNodeText: string,\n): void => {\n console.debug(`${node.getText()} -> ${newNodeText}`);\n\n node.replaceWithText(newNodeText);\n};\n"],"names":[],"mappings":"AAEO,MAAM,yBAAA,GAA4B,CACvC,IAAA,EACA,WAAA,KACS;AACT,EAAA,OAAA,CAAQ,MAAM,CAAA,EAAG,IAAA,CAAK,SAAS,CAAA,IAAA,EAAO,WAAW,CAAA,CAAE,CAAA;AAEnD,EAAA,IAAA,CAAK,gBAAgB,WAAW,CAAA;AAClC;;;;"}
1
+ {"version":3,"file":"replace-with-debug.mjs","sourceRoot":"","sources":["../../../src/functions/utils/replace-with-debug.mts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAc,EACd,WAAmB,EACb,EAAE;IACR,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,WAAW,EAAE,CAAC,CAAC;IAErD,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;AACpC,CAAC,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,24 +1,2 @@
1
- export { appendAsConstTransformer } from './functions/ast-transformers/append-as-const.mjs';
2
- export { convertInterfaceToTypeTransformer } from './functions/ast-transformers/convert-interface-to-type.mjs';
3
- export { convertToReadonlyTransformer } from './functions/ast-transformers/convert-to-readonly.mjs';
4
- export { enableNoUncheckedIndexedAccessTransformer } from './functions/ast-transformers/enable-no-unchecked-indexed-access.mjs';
5
- export { compareUnionIntersectionTypes } from './functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs';
6
- export { invalidDeepReadonlyTypeName } from './functions/ast-transformers/readonly-transformer-helpers/constants.mjs';
7
- export { groupUnionIntersectionTypes } from './functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs';
8
- export { nextReadonlyContext } from './functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs';
9
- export { replaceAnyWithUnknownTransformer } from './functions/ast-transformers/replace-any-with-unknown.mjs';
10
- export { replaceRecordWithUnknownRecordTransformer } from './functions/ast-transformers/replace-record-with-unknown-record.mjs';
11
- export { transformSourceCode } from './functions/ast-transformers/transform-source-code.mjs';
12
- export { IGNORE_FILE_COMMENT_PREFIXES, IGNORE_LINE_COMMENT_PREFIXES } from './functions/constants/ignore-comment-text.mjs';
13
- export { hasDisableNextLineComment } from './functions/functions/has-disable-next-line-comment.mjs';
14
- export { isAsConstNode } from './functions/functions/is-as-const-node.mjs';
15
- export { isAtomicTypeNode } from './functions/functions/is-atomic-type-node.mjs';
16
- export { isConditionalTypeDistributionGuard } from './functions/functions/is-conditional-type-distribution-guard.mjs';
17
- export { isReadonlyArrayTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTupleTypeNode, isReadonlyTypeReferenceNode, isShallowReadonlyTypeNode } from './functions/functions/is-readonly-node.mjs';
18
- export { isSpreadNamedTupleMemberNode, isSpreadParameterNode } from './functions/functions/is-spread-parameter-node.mjs';
19
- export { removeParentheses } from './functions/functions/remove-parentheses.mjs';
20
- export { shouldAvoidParenthesesForReadonly } from './functions/functions/should-avoid-parentheses-for-readonly.mjs';
21
- export { unwrapReadonlyTypeArgText } from './functions/functions/unwrap-readonly.mjs';
22
- export { wrapWithParentheses } from './functions/functions/wrap-with-parentheses.mjs';
23
- export { replaceNodeWithDebugPrint } from './functions/utils/replace-with-debug.mjs';
24
- //# sourceMappingURL=index.mjs.map
1
+ export * from './functions/index.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-codemod-lib",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "typescript",
@@ -38,37 +38,36 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "dependencies": {
41
- "ts-data-forge": "^14.4.0",
41
+ "ts-data-forge": "^14.6.3",
42
42
  "ts-morph": "^28.0.0",
43
43
  "ts-type-forge": "^9.2.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "26.4.0",
46
+ "@types/node": "26.4.1",
47
47
  "@vitest/browser-playwright": "4.1.11",
48
48
  "@vitest/coverage-v8": "4.1.11",
49
49
  "@vitest/ui": "4.1.11",
50
- "cspell": "10.0.1",
50
+ "cspell": "10.1.1",
51
51
  "dedent": "1.7.2",
52
52
  "esbuild": "0.28.2",
53
- "eslint": "10.8.1",
54
- "eslint-config-typed": "5.10.0",
55
- "eslint-plugin-ts-data-forge": "0.5.0",
56
- "eslint-plugin-ts-fortress": "1.0.4",
57
- "eslint-plugin-ts-type-forge": "0.7.0",
53
+ "eslint": "10.9.1",
54
+ "eslint-config-typed": "5.11.2",
55
+ "eslint-plugin-ts-data-forge": "0.7.0",
56
+ "eslint-plugin-ts-fortress": "1.2.0",
57
+ "eslint-plugin-ts-type-forge": "0.8.1",
58
58
  "jiti": "2.7.0",
59
59
  "npm-run-all2": "9.0.3",
60
60
  "playwright": "1.62.1",
61
61
  "prettier": "3.9.6",
62
62
  "prettier-plugin-organize-imports": "4.3.0",
63
63
  "prettier-plugin-packagejson": "3.0.2",
64
- "rollup": "4.62.4",
65
- "ts-repo-utils": "10.3.2",
64
+ "ts-repo-utils": "10.6.0",
66
65
  "tsx": "4.23.12",
67
66
  "typedoc": "0.28.20",
68
67
  "typedoc-github-theme": "0.4.0",
69
68
  "typescript": "6.0.3",
70
69
  "typescript-native": "npm:typescript@7.0.2",
71
- "vite": "8.2.1",
70
+ "vite": "8.2.2",
72
71
  "vitest": "4.1.11"
73
72
  },
74
73
  "engines": {
@@ -6,6 +6,7 @@ import dedent from 'dedent';
6
6
  import * as prettierPluginEstree from 'prettier/plugins/estree';
7
7
  import * as prettierPluginTypeScript from 'prettier/plugins/typescript';
8
8
  import * as prettier from 'prettier/standalone';
9
+ import { isString } from 'ts-data-forge';
9
10
  import {
10
11
  convertToReadonlyTransformer,
11
12
  type ReadonlyTransformerOptions,
@@ -63,7 +64,15 @@ const normalizeWhitespaceForComparison = (code: string): string => {
63
64
  // 1. Protect newlines immediately following line comments
64
65
  const protectedCode = code.replaceAll(
65
66
  /(\/\/.*?)\r?\n/gu,
66
- (_match, comment: string) => `${comment}${placeholder}`,
67
+ // The strict standard library types a capture group as `unknown`: an
68
+ // optional group is `undefined` when it does not participate, so `string`
69
+ // is not something the signature can promise. This group is not optional,
70
+ // so the narrowing never actually fails — it just has to be written.
71
+ (match: string, ...args: readonly unknown[]): string => {
72
+ const comment = args[0];
73
+
74
+ return isString(comment) ? `${comment}${placeholder}` : match;
75
+ },
67
76
  );
68
77
 
69
78
  // 2. Collapse multiple whitespace characters (including unprotected newlines) into a single space