ts-codemod-lib 3.4.1 → 3.4.3
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 +4 -4
- package/dist/functions/ast-transformers/convert-to-readonly.d.mts.map +1 -1
- package/dist/functions/ast-transformers/convert-to-readonly.mjs +183 -34
- package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.d.mts +32 -2
- package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.d.mts.map +1 -1
- package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs +88 -2
- package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map +1 -1
- package/package.json +16 -16
- package/src/functions/ast-transformers/convert-to-readonly.mts +279 -45
- package/src/functions/ast-transformers/convert-to-readonly.test.mts +534 -7
- package/src/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mts +124 -3
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import * as tsm from 'ts-morph';
|
|
2
2
|
import { hasCallOrConstructSignature, isAtomicTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTypeReferenceNode, removeParentheses, } from '../../functions/index.mjs';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
export const groupUnionIntersectionTypes = (
|
|
4
16
|
|
|
5
|
-
types) => {
|
|
17
|
+
types, { operator, underReadonly, deepReadonlyTypeName, }) => {
|
|
6
18
|
const mut_grouped = {
|
|
7
19
|
primitives: undefined,
|
|
8
20
|
arraysAndTuples: undefined,
|
|
@@ -45,7 +57,8 @@ types) => {
|
|
|
45
57
|
|
|
46
58
|
if ((t.isKind(tsm.SyntaxKind.TypeLiteral) &&
|
|
47
59
|
!hasCallOrConstructSignature(t)) ||
|
|
48
|
-
|
|
60
|
+
isMergeableReadonlyTypeReferenceNode(t, operator) ||
|
|
61
|
+
(underReadonly && !staysOutsideReadonly(t, deepReadonlyTypeName))) {
|
|
49
62
|
if (mut_grouped.typeLiterals === undefined) {
|
|
50
63
|
mut_grouped.typeLiterals = {
|
|
51
64
|
firstPosition: i,
|
|
@@ -70,4 +83,77 @@ types) => {
|
|
|
70
83
|
}
|
|
71
84
|
return mut_grouped;
|
|
72
85
|
};
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export const isMergeableReadonlyTypeReferenceNode = (
|
|
100
|
+
|
|
101
|
+
node, operator) => isReadonlyTypeReferenceNode(node) &&
|
|
102
|
+
(operator === '|' || isObjectTypeLiteral(node.getTypeArguments()[0]));
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
const isObjectTypeLiteral = (
|
|
108
|
+
|
|
109
|
+
node) => {
|
|
110
|
+
const t = removeParentheses(node);
|
|
111
|
+
if (t.isKind(tsm.SyntaxKind.TypeLiteral)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if (t.isKind(tsm.SyntaxKind.MappedType)) {
|
|
117
|
+
const constraint = t.getTypeParameter().getConstraint();
|
|
118
|
+
return !(constraint?.isKind(tsm.SyntaxKind.TypeOperator) === true &&
|
|
119
|
+
constraint.getOperator() === tsm.SyntaxKind.KeyOfKeyword);
|
|
120
|
+
}
|
|
121
|
+
if (isReadonlyTypeReferenceNode(t)) {
|
|
122
|
+
return isObjectTypeLiteral(t.getTypeArguments()[0]);
|
|
123
|
+
}
|
|
124
|
+
if (t.isKind(tsm.SyntaxKind.UnionType) ||
|
|
125
|
+
t.isKind(tsm.SyntaxKind.IntersectionType)) {
|
|
126
|
+
return t.getTypeNodes().every(isObjectTypeLiteral);
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
const staysOutsideReadonly = (
|
|
142
|
+
|
|
143
|
+
node, deepReadonlyTypeName) => {
|
|
144
|
+
if (node.isKind(tsm.SyntaxKind.FunctionType) ||
|
|
145
|
+
node.isKind(tsm.SyntaxKind.ConstructorType) ||
|
|
146
|
+
node.isKind(tsm.SyntaxKind.TypeLiteral) ||
|
|
147
|
+
node.isKind(tsm.SyntaxKind.TypeOperator)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (node.isKind(tsm.SyntaxKind.TypeReference)) {
|
|
151
|
+
const typeName = node.getTypeName().getText();
|
|
152
|
+
return (typeName === deepReadonlyTypeName ||
|
|
153
|
+
typeName === 'ReadonlyMap' ||
|
|
154
|
+
typeName === 'ReadonlySet' ||
|
|
155
|
+
typeName === 'ReadonlyRecord');
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
};
|
|
73
159
|
//# sourceMappingURL=group-union-types.mjs.map
|
package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-union-types.mjs","sourceRoot":"","sources":["../../../../src/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,8BAA8B,EAC9B,2BAA2B,EAC3B,iBAAiB,GAKlB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,CAAC,MAAM,2BAA2B,GAAG;AACzC,8EAA8E;AAC9E,KAA8B,
|
|
1
|
+
{"version":3,"file":"group-union-types.mjs","sourceRoot":"","sources":["../../../../src/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,8BAA8B,EAC9B,2BAA2B,EAC3B,iBAAiB,GAKlB,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;AACzC,8EAA8E;AAC9E,KAA8B,EAC9B,EACE,QAAQ,EACR,aAAa,EACb,oBAAoB,GAKpB,EAkCD,EAAE;IACH,MAAM,WAAW,GAiCb;QACF,UAAU,EAAE,SAAS;QACrB,eAAe,EAAE,SAAS;QAC1B,YAAY,EAAE,SAAS;QACvB,MAAM,EAAE,SAAS;KAClB,CAAC;IAEF,KAAK,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;QAEhC,8BAA8B;QAC9B,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;YACxB,IAAI,WAAW,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;gBACzC,WAAW,CAAC,UAAU,GAAG;oBACvB,aAAa,EAAE,CAAC;oBAChB,KAAK,EAAE,CAAC,CAAC,CAAC;iBACF,CAAC;YACb,CAAC;iBAAM,CAAC;gBACN,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC;YAED,SAAS;QACX,CAAC;QAED,IACE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;YAClC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;YAClC,8BAA8B,CAAC,CAAC,CAAC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C,YAAY,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,oBAAoB,GAAG;AAC3B,8EAA8E;AAC9E,IAAkB,EAClB,oBAA4B,EACnB,EAAE;IACX,IACE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,EACxC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC;QAE9C,OAAO,CACL,QAAQ,KAAK,oBAAoB;YACjC,QAAQ,KAAK,aAAa;YAC1B,QAAQ,KAAK,aAAa;YAC1B,QAAQ,KAAK,gBAAgB,CAC9B,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-codemod-lib",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
"ts-type-forge": "^9.2.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "26.6.
|
|
47
|
-
"@vitest/browser-playwright": "5.0.
|
|
48
|
-
"@vitest/coverage-v8": "5.0.
|
|
49
|
-
"@vitest/ui": "5.0.
|
|
50
|
-
"cspell": "10.3.
|
|
46
|
+
"@types/node": "26.6.4",
|
|
47
|
+
"@vitest/browser-playwright": "5.0.3",
|
|
48
|
+
"@vitest/coverage-v8": "5.0.3",
|
|
49
|
+
"@vitest/ui": "5.0.3",
|
|
50
|
+
"cspell": "10.3.6",
|
|
51
51
|
"dedent": "1.7.2",
|
|
52
52
|
"esbuild": "0.28.2",
|
|
53
|
-
"eslint": "10.
|
|
54
|
-
"eslint-config-typed": "5.17.
|
|
55
|
-
"eslint-plugin-ts-data-forge": "0.8.
|
|
56
|
-
"eslint-plugin-ts-fortress": "1.3.
|
|
57
|
-
"eslint-plugin-ts-type-forge": "0.8.
|
|
53
|
+
"eslint": "10.12.0",
|
|
54
|
+
"eslint-config-typed": "5.17.2",
|
|
55
|
+
"eslint-plugin-ts-data-forge": "0.8.4",
|
|
56
|
+
"eslint-plugin-ts-fortress": "1.3.1",
|
|
57
|
+
"eslint-plugin-ts-type-forge": "0.8.6",
|
|
58
58
|
"jiti": "2.7.0",
|
|
59
59
|
"npm-run-all2": "9.0.3",
|
|
60
60
|
"playwright": "1.63.0",
|
|
@@ -67,15 +67,15 @@
|
|
|
67
67
|
"typedoc-github-theme": "0.4.0",
|
|
68
68
|
"typescript": "6.0.3",
|
|
69
69
|
"typescript-native": "npm:typescript@7.0.2",
|
|
70
|
-
"vite": "8.3.
|
|
71
|
-
"vitest": "5.0.
|
|
70
|
+
"vite": "8.3.2",
|
|
71
|
+
"vitest": "5.0.3"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
74
|
"node": ">=22.22.2",
|
|
75
75
|
"pnpm": ">=9.0.0"
|
|
76
76
|
},
|
|
77
77
|
"volta": {
|
|
78
|
-
"node": "26.
|
|
78
|
+
"node": "26.11.1"
|
|
79
79
|
},
|
|
80
80
|
"publishConfig": {
|
|
81
81
|
"access": "public",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"check:cspell": "cspell \"**\" --gitignore --gitignore-root ../../ --no-progress",
|
|
87
87
|
"check:dist": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/check-dist.mts",
|
|
88
88
|
"check:ext": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/check-ext.mts",
|
|
89
|
-
"check:lint": "eslint .",
|
|
89
|
+
"check:lint": "oxlint . && eslint .",
|
|
90
90
|
"check:test": "pnpm run z:vitest:node run",
|
|
91
91
|
"check:test:browser": "pnpm run z:vitest --project='Browser' run",
|
|
92
92
|
"check:test:cov": "pnpm run z:vitest:node run --coverage",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"fix:fmt": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-repo-utils/src/cmd/format-uncommitted.mts --cwd .",
|
|
103
103
|
"fix:fmt:diff": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-repo-utils/src/cmd/format-diff-from.mts origin/main --cwd .",
|
|
104
104
|
"fix:fmt:full": "prettier --write .",
|
|
105
|
-
"fix:lint": "eslint . --fix",
|
|
105
|
+
"fix:lint": "oxlint . --fix && eslint . --fix",
|
|
106
106
|
"fmt": "pnpm run fix:fmt",
|
|
107
107
|
"gen": "run-s gen:index gen:readme gen:jsdoc",
|
|
108
108
|
"gen:index": "run-s gen:index:src fix:fmt",
|