ts-codemod-lib 3.2.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.
- package/README.md +68 -0
- package/dist/entry-point.mjs +2 -23
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functions/ast-transformers/append-as-const.mjs +330 -292
- package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
- package/dist/functions/ast-transformers/convert-interface-to-type.mjs +85 -70
- package/dist/functions/ast-transformers/convert-interface-to-type.mjs.map +1 -1
- package/dist/functions/ast-transformers/convert-to-readonly.mjs +969 -840
- package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts +65 -0
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts.map +1 -0
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs +297 -0
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -0
- package/dist/functions/ast-transformers/index.d.mts +1 -0
- package/dist/functions/ast-transformers/index.d.mts.map +1 -1
- package/dist/functions/ast-transformers/index.mjs +10 -11
- package/dist/functions/ast-transformers/index.mjs.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs +14 -7
- package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs +12 -15
- package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs +63 -58
- package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs +5 -5
- package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs +15 -20
- package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs.map +1 -1
- package/dist/functions/ast-transformers/replace-any-with-unknown.mjs +30 -34
- package/dist/functions/ast-transformers/replace-any-with-unknown.mjs.map +1 -1
- package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +197 -156
- package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
- package/dist/functions/ast-transformers/transform-source-code.mjs +74 -75
- package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
- package/dist/functions/ast-transformers/types.mjs +2 -2
- package/dist/functions/ast-transformers/types.mjs.map +1 -1
- package/dist/functions/constants/ignore-comment-text.mjs +11 -13
- package/dist/functions/constants/ignore-comment-text.mjs.map +1 -1
- package/dist/functions/constants/index.mjs +2 -2
- package/dist/functions/constants/index.mjs.map +1 -1
- package/dist/functions/functions/has-disable-next-line-comment.mjs +67 -38
- package/dist/functions/functions/has-disable-next-line-comment.mjs.map +1 -1
- package/dist/functions/functions/index.mjs +11 -11
- package/dist/functions/functions/index.mjs.map +1 -1
- package/dist/functions/functions/is-as-const-node.mjs +25 -20
- package/dist/functions/functions/is-as-const-node.mjs.map +1 -1
- package/dist/functions/functions/is-atomic-type-node.mjs +245 -25
- package/dist/functions/functions/is-atomic-type-node.mjs.map +1 -1
- package/dist/functions/functions/is-conditional-type-distribution-guard.mjs +34 -13
- package/dist/functions/functions/is-conditional-type-distribution-guard.mjs.map +1 -1
- package/dist/functions/functions/is-readonly-node.mjs +120 -14
- package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
- package/dist/functions/functions/is-spread-parameter-node.mjs +5 -6
- package/dist/functions/functions/is-spread-parameter-node.mjs.map +1 -1
- package/dist/functions/functions/remove-parentheses.mjs +4 -4
- package/dist/functions/functions/remove-parentheses.mjs.map +1 -1
- package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs +23 -9
- package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs.map +1 -1
- package/dist/functions/functions/unwrap-readonly.mjs +3 -4
- package/dist/functions/functions/unwrap-readonly.mjs.map +1 -1
- package/dist/functions/functions/wrap-with-parentheses.d.mts.map +1 -1
- package/dist/functions/functions/wrap-with-parentheses.mjs +54 -29
- package/dist/functions/functions/wrap-with-parentheses.mjs.map +1 -1
- package/dist/functions/index.mjs +5 -23
- package/dist/functions/index.mjs.map +1 -1
- package/dist/functions/utils/index.mjs +2 -2
- package/dist/functions/utils/index.mjs.map +1 -1
- package/dist/functions/utils/replace-with-debug.mjs +4 -6
- package/dist/functions/utils/replace-with-debug.mjs.map +1 -1
- package/dist/index.mjs +2 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -12
- package/src/functions/ast-transformers/convert-to-readonly.test.mts +10 -1
- package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.mts +438 -0
- package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.test.mts +619 -0
- package/src/functions/ast-transformers/index.mts +1 -0
- 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
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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"],"
|
|
1
|
+
{"version":3,"file":"is-readonly-node.mjs","sourceRoot":"","sources":["../../../src/funct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G,qBAAqB,CAChC,qCAAqC,EACrC,MAAM,CACP,CAAC;YAEF,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,yDAAyD,EAAE,GAAG,EAAE;YACnE,kEAAkE;YAClE,MAAM,IAAI,GAAG,qBAAqB,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;YAEpE,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,+DAA+D,EAAE,GAAG,EAAE;YACzE,kEAAkE;YAClE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC,CAAC;YAEjE,mEAAmE;YACnE,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CACzC,SAAS,EACT,uCAAuC,CACxC,CAAC;YAEF,MAAM,IAAI,GAAG,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,kBAAkB,EAAE,CAAC;YAEzE,MAAM,CAAC,OAAO,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
|
-
|
|
4
|
-
const isSpreadNamedTupleMemberNode = (node) => node.isKind(tsm.SyntaxKind.NamedTupleMember) &&
|
|
5
|
-
|
|
6
|
-
|
|
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"],"
|
|
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)
|
|
4
|
-
|
|
5
|
-
|
|
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"],"
|
|
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
|
-
|
|
12
|
-
|
|
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"],"
|
|
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
|
-
|
|
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"],"
|
|
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":"
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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"],"
|
|
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"}
|
package/dist/functions/index.mjs
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
export { groupUnionIntersectionTypes } from './ast-transformers/readonly-transformer-helpers/group-union-types.mjs';
|
|
7
|
-
export { nextReadonlyContext } from './ast-transformers/readonly-transformer-helpers/readonly-context.mjs';
|
|
8
|
-
export { replaceAnyWithUnknownTransformer } from './ast-transformers/replace-any-with-unknown.mjs';
|
|
9
|
-
export { replaceRecordWithUnknownRecordTransformer } from './ast-transformers/replace-record-with-unknown-record.mjs';
|
|
10
|
-
export { transformSourceCode } from './ast-transformers/transform-source-code.mjs';
|
|
11
|
-
export { IGNORE_FILE_COMMENT_PREFIXES, IGNORE_LINE_COMMENT_PREFIXES } from './constants/ignore-comment-text.mjs';
|
|
12
|
-
export { hasDisableNextLineComment } from './functions/has-disable-next-line-comment.mjs';
|
|
13
|
-
export { isAsConstNode } from './functions/is-as-const-node.mjs';
|
|
14
|
-
export { isAtomicTypeNode } from './functions/is-atomic-type-node.mjs';
|
|
15
|
-
export { isConditionalTypeDistributionGuard } from './functions/is-conditional-type-distribution-guard.mjs';
|
|
16
|
-
export { isReadonlyArrayTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTupleTypeNode, isReadonlyTypeReferenceNode, isShallowReadonlyTypeNode } from './functions/is-readonly-node.mjs';
|
|
17
|
-
export { isSpreadNamedTupleMemberNode, isSpreadParameterNode } from './functions/is-spread-parameter-node.mjs';
|
|
18
|
-
export { removeParentheses } from './functions/remove-parentheses.mjs';
|
|
19
|
-
export { shouldAvoidParenthesesForReadonly } from './functions/should-avoid-parentheses-for-readonly.mjs';
|
|
20
|
-
export { unwrapReadonlyTypeArgText } from './functions/unwrap-readonly.mjs';
|
|
21
|
-
export { wrapWithParentheses } from './functions/wrap-with-parentheses.mjs';
|
|
22
|
-
export { replaceNodeWithDebugPrint } from './utils/replace-with-debug.mjs';
|
|
23
|
-
//# 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","
|
|
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
|
|
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","
|
|
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
|
-
|
|
3
|
-
|
|
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"],"
|
|
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,23 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export { convertToReadonlyTransformer } from './functions/ast-transformers/convert-to-readonly.mjs';
|
|
4
|
-
export { compareUnionIntersectionTypes } from './functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs';
|
|
5
|
-
export { invalidDeepReadonlyTypeName } from './functions/ast-transformers/readonly-transformer-helpers/constants.mjs';
|
|
6
|
-
export { groupUnionIntersectionTypes } from './functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs';
|
|
7
|
-
export { nextReadonlyContext } from './functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs';
|
|
8
|
-
export { replaceAnyWithUnknownTransformer } from './functions/ast-transformers/replace-any-with-unknown.mjs';
|
|
9
|
-
export { replaceRecordWithUnknownRecordTransformer } from './functions/ast-transformers/replace-record-with-unknown-record.mjs';
|
|
10
|
-
export { transformSourceCode } from './functions/ast-transformers/transform-source-code.mjs';
|
|
11
|
-
export { IGNORE_FILE_COMMENT_PREFIXES, IGNORE_LINE_COMMENT_PREFIXES } from './functions/constants/ignore-comment-text.mjs';
|
|
12
|
-
export { hasDisableNextLineComment } from './functions/functions/has-disable-next-line-comment.mjs';
|
|
13
|
-
export { isAsConstNode } from './functions/functions/is-as-const-node.mjs';
|
|
14
|
-
export { isAtomicTypeNode } from './functions/functions/is-atomic-type-node.mjs';
|
|
15
|
-
export { isConditionalTypeDistributionGuard } from './functions/functions/is-conditional-type-distribution-guard.mjs';
|
|
16
|
-
export { isReadonlyArrayTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTupleTypeNode, isReadonlyTypeReferenceNode, isShallowReadonlyTypeNode } from './functions/functions/is-readonly-node.mjs';
|
|
17
|
-
export { isSpreadNamedTupleMemberNode, isSpreadParameterNode } from './functions/functions/is-spread-parameter-node.mjs';
|
|
18
|
-
export { removeParentheses } from './functions/functions/remove-parentheses.mjs';
|
|
19
|
-
export { shouldAvoidParenthesesForReadonly } from './functions/functions/should-avoid-parentheses-for-readonly.mjs';
|
|
20
|
-
export { unwrapReadonlyTypeArgText } from './functions/functions/unwrap-readonly.mjs';
|
|
21
|
-
export { wrapWithParentheses } from './functions/functions/wrap-with-parentheses.mjs';
|
|
22
|
-
export { replaceNodeWithDebugPrint } from './functions/utils/replace-with-debug.mjs';
|
|
23
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './functions/index.mjs';
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","
|
|
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
|
+
"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.
|
|
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.
|
|
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.
|
|
50
|
+
"cspell": "10.1.1",
|
|
51
51
|
"dedent": "1.7.2",
|
|
52
52
|
"esbuild": "0.28.2",
|
|
53
|
-
"eslint": "10.
|
|
54
|
-
"eslint-config-typed": "5.
|
|
55
|
-
"eslint-plugin-ts-data-forge": "0.
|
|
56
|
-
"eslint-plugin-ts-fortress": "1.0
|
|
57
|
-
"eslint-plugin-ts-type-forge": "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
|
-
"
|
|
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.
|
|
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
|
-
|
|
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
|