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.
- package/dist/entry-point.mjs +2 -24
- 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.mjs +276 -134
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -1
- package/dist/functions/ast-transformers/index.mjs +10 -12
- 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 -24
- 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 -24
- 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.test.mts +76 -22
- package/src/functions/functions/wrap-with-parentheses.mts +5 -2
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
const IGNORE_LINE_COMMENT_PREFIXES = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const IGNORE_LINE_COMMENT_PREFIXES = [
|
|
2
|
+
'transformer-ignore-next-line',
|
|
3
|
+
'ts-codemod-ignore-next-line',
|
|
4
|
+
'codemod-ignore-next-line',
|
|
5
|
+
'transform-ignore-next-line',
|
|
6
6
|
];
|
|
7
|
-
const IGNORE_FILE_COMMENT_PREFIXES = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export const IGNORE_FILE_COMMENT_PREFIXES = [
|
|
8
|
+
'transformer-ignore',
|
|
9
|
+
'ts-codemod-ignore',
|
|
10
|
+
'codemod-ignore',
|
|
11
|
+
'transform-ignore',
|
|
12
12
|
];
|
|
13
|
-
|
|
14
|
-
export { IGNORE_FILE_COMMENT_PREFIXES, IGNORE_LINE_COMMENT_PREFIXES };
|
|
15
|
-
//# sourceMappingURL=ignore-comment-text.mjs.map
|
|
13
|
+
//# sourceMappingURL=ignore-comment-text.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ignore-comment-text.mjs","sources":["../../../src/functions/constants/ignore-comment-text.mts"],"
|
|
1
|
+
{"version":3,"file":"ignore-comment-text.mjs","sourceRoot":"","sources":["../../../src/functions/constants/ignore-comment-text.mts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,8BAA8B;IAC9B,6BAA6B;IAC7B,0BAA0B;IAC1B,4BAA4B;CACpB,CAAC;AAEX,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,oBAAoB;IACpB,mBAAmB;IACnB,gBAAgB;IAChB,kBAAkB;CACV,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './ignore-comment-text.mjs';
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/functions/constants/index.mts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,43 +1,72 @@
|
|
|
1
1
|
import * as tsm from 'ts-morph';
|
|
2
|
-
import { IGNORE_LINE_COMMENT_PREFIXES } from '../constants/
|
|
2
|
+
import { IGNORE_LINE_COMMENT_PREFIXES } from '../constants/index.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (transformerName === void 0) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
const afterPrefix = commentText.slice(commentText.indexOf(matchedPrefix)).replace(matchedPrefix, "").trim();
|
|
26
|
-
if (afterPrefix === "") {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
const targetTransformers = afterPrefix.split(",").map((name) => name.trim());
|
|
30
|
-
return targetTransformers.includes(transformerName);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const hasDisableNextLineComment = (node, transformerName) => {
|
|
18
|
+
const nodeStartLine = node.getStartLineNumber();
|
|
19
|
+
|
|
20
|
+
if (nodeStartLine <= 1) {
|
|
21
|
+
return false;
|
|
34
22
|
}
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
const sourceFile = node.getSourceFile();
|
|
24
|
+
const leadingCommentRanges = node.getLeadingCommentRanges();
|
|
25
|
+
|
|
26
|
+
for (let mut_i = leadingCommentRanges.length - 1; mut_i >= 0; mut_i--) {
|
|
27
|
+
|
|
28
|
+
const commentRange = leadingCommentRanges[mut_i];
|
|
29
|
+
|
|
30
|
+
const commentEndPos = commentRange.getEnd();
|
|
31
|
+
const commentEndLine = sourceFile.getLineAndColumnAtPos(commentEndPos).line;
|
|
32
|
+
|
|
33
|
+
if (nodeStartLine === commentEndLine + 1) {
|
|
34
|
+
|
|
35
|
+
if (commentRange.getKind() === tsm.SyntaxKind.SingleLineCommentTrivia) {
|
|
36
|
+
const commentText = commentRange.getText().trim();
|
|
37
|
+
|
|
38
|
+
const matchedPrefix = IGNORE_LINE_COMMENT_PREFIXES.find((prefix) => commentText.includes(prefix));
|
|
39
|
+
if (matchedPrefix !== undefined) {
|
|
40
|
+
|
|
41
|
+
if (transformerName === undefined) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const afterPrefix = commentText
|
|
46
|
+
.slice(commentText.indexOf(matchedPrefix))
|
|
47
|
+
.replace(matchedPrefix, '')
|
|
48
|
+
.trim();
|
|
49
|
+
|
|
50
|
+
if (afterPrefix === '') {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const targetTransformers = afterPrefix
|
|
55
|
+
.split(',')
|
|
56
|
+
.map((name) => name.trim());
|
|
57
|
+
return targetTransformers.includes(transformerName);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (commentEndLine < nodeStartLine - 1) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
37
69
|
}
|
|
38
|
-
|
|
39
|
-
return false;
|
|
70
|
+
return false;
|
|
40
71
|
};
|
|
41
|
-
|
|
42
|
-
export { hasDisableNextLineComment };
|
|
43
|
-
//# sourceMappingURL=has-disable-next-line-comment.mjs.map
|
|
72
|
+
//# sourceMappingURL=has-disable-next-line-comment.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-disable-next-line-comment.mjs","sources":["../../../src/functions/functions/has-disable-next-line-comment.mts"],"
|
|
1
|
+
{"version":3,"file":"has-disable-next-line-comment.mjs","sourceRoot":"","sources":["../../../src/functions/functions/has-disable-next-line-comment.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAEtE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAAc,EACd,eAAwB,EACf,EAAE;IACX,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAEhD,8CAA8C;IAC9C,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,qBAAqB;IAE9D,MAAM,oBAAoB,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;IAE5D,yEAAyE;IACzE,KAAK,IAAI,KAAK,GAAG,oBAAoB,CAAC,MAAM,G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AC,IAAI,EAAE,CAAC,CAAC;oBAE9B,OAAO,kBAAkB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;YAED,iEAAiE;YACjE,8DAA8D;YAC9D,6EAA6E;YAC7E,OAAO,KAAK,CAAC;QACf,CAAC;QAED,6EAA6E;QAC7E,IAAI,cAAc,GAAG,aAAa,GAAG,CAAC,EAAE,CAAC;YACvC,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './has-disable-next-line-comment.mjs';
|
|
2
|
+
export * from './is-as-const-node.mjs';
|
|
3
|
+
export * from './is-atomic-type-node.mjs';
|
|
4
|
+
export * from './is-conditional-type-distribution-guard.mjs';
|
|
5
|
+
export * from './is-readonly-node.mjs';
|
|
6
|
+
export * from './is-spread-parameter-node.mjs';
|
|
7
|
+
export * from './remove-parentheses.mjs';
|
|
8
|
+
export * from './should-avoid-parentheses-for-readonly.mjs';
|
|
9
|
+
export * from './unwrap-readonly.mjs';
|
|
10
|
+
export * from './wrap-with-parentheses.mjs';
|
|
11
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/functions/functions/index.mts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8CAA8C,CAAC;AAC7D,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { Arr } from 'ts-data-forge';
|
|
2
|
-
import * as
|
|
2
|
+
import * as ts from 'ts-morph';
|
|
3
|
+
export const isAsConstNode = (node) => {
|
|
4
|
+
if (!node.isKind(ts.SyntaxKind.AsExpression)) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
3
7
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!typeNameNode.isKind(tsm.SyntaxKind.Identifier)) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return typeNameNode.getText() === "const" && Arr.isEmpty(typeNode.getTypeArguments());
|
|
20
|
-
};
|
|
8
|
+
const typeNode = node.getTypeNode();
|
|
9
|
+
if (typeNode === undefined) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!typeNode.isKind(ts.SyntaxKind.TypeReference)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const typeNameNode = typeNode.getTypeName();
|
|
18
|
+
|
|
19
|
+
if (!typeNameNode.isKind(ts.SyntaxKind.Identifier)) {
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
return (typeNameNode.getText() === 'const' &&
|
|
26
|
+
Arr.isEmpty(typeNode.getTypeArguments()));
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=is-as-const-node.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-as-const-node.mjs","sources":["../../../src/functions/functions/is-as-const-node.mts"],"
|
|
1
|
+
{"version":3,"file":"is-as-const-node.mjs","sourceRoot":"","sources":["../../../src/functions/functions/is-as-const-node.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAa,EAWV,EAAE;IACL,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC7C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAEpC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,CAAC,yCAAyC;IACzD,CAAC;IAED,iDAAiD;IACjD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IAC/C,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAE5C,8CAA8C;IAC9C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACnD,mEAAmE;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IAC/C,uEAAuE;IACvE,OAAO,CACL,YAAY,CAAC,OAAO,EAAE,KAAK,OAAO;QAClC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CACzC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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;A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
|
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
|
-
|
|
16
|
-
|
|
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"],"
|
|
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"}
|