ts-codemod-lib 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +22 -0
  2. package/dist/entry-point.mjs +2 -24
  3. package/dist/entry-point.mjs.map +1 -1
  4. package/dist/functions/ast-transformers/append-as-const.mjs +330 -292
  5. package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
  6. package/dist/functions/ast-transformers/convert-interface-to-type.mjs +85 -70
  7. package/dist/functions/ast-transformers/convert-interface-to-type.mjs.map +1 -1
  8. package/dist/functions/ast-transformers/convert-to-readonly.d.mts.map +1 -1
  9. package/dist/functions/ast-transformers/convert-to-readonly.mjs +971 -838
  10. package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
  11. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts +32 -9
  12. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts.map +1 -1
  13. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs +299 -134
  14. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -1
  15. package/dist/functions/ast-transformers/index.mjs +10 -12
  16. package/dist/functions/ast-transformers/index.mjs.map +1 -1
  17. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs +14 -7
  18. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs.map +1 -1
  19. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs +12 -15
  20. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs.map +1 -1
  21. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.d.mts.map +1 -1
  22. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs +70 -59
  23. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map +1 -1
  24. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs +5 -5
  25. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs.map +1 -1
  26. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs +15 -20
  27. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs.map +1 -1
  28. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs +30 -34
  29. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs.map +1 -1
  30. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +197 -156
  31. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
  32. package/dist/functions/ast-transformers/transform-source-code.mjs +74 -75
  33. package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
  34. package/dist/functions/ast-transformers/types.mjs +2 -2
  35. package/dist/functions/ast-transformers/types.mjs.map +1 -1
  36. package/dist/functions/constants/ignore-comment-text.mjs +11 -13
  37. package/dist/functions/constants/ignore-comment-text.mjs.map +1 -1
  38. package/dist/functions/constants/index.mjs +2 -2
  39. package/dist/functions/constants/index.mjs.map +1 -1
  40. package/dist/functions/functions/has-call-or-construct-signature.d.mts +18 -0
  41. package/dist/functions/functions/has-call-or-construct-signature.d.mts.map +1 -0
  42. package/dist/functions/functions/has-call-or-construct-signature.mjs +87 -0
  43. package/dist/functions/functions/has-call-or-construct-signature.mjs.map +1 -0
  44. package/dist/functions/functions/has-disable-next-line-comment.mjs +67 -38
  45. package/dist/functions/functions/has-disable-next-line-comment.mjs.map +1 -1
  46. package/dist/functions/functions/index.d.mts +1 -0
  47. package/dist/functions/functions/index.d.mts.map +1 -1
  48. package/dist/functions/functions/index.mjs +12 -11
  49. package/dist/functions/functions/index.mjs.map +1 -1
  50. package/dist/functions/functions/is-as-const-node.mjs +25 -20
  51. package/dist/functions/functions/is-as-const-node.mjs.map +1 -1
  52. package/dist/functions/functions/is-atomic-type-node.mjs +245 -25
  53. package/dist/functions/functions/is-atomic-type-node.mjs.map +1 -1
  54. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs +34 -13
  55. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs.map +1 -1
  56. package/dist/functions/functions/is-readonly-node.mjs +120 -14
  57. package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
  58. package/dist/functions/functions/is-spread-parameter-node.mjs +5 -6
  59. package/dist/functions/functions/is-spread-parameter-node.mjs.map +1 -1
  60. package/dist/functions/functions/remove-parentheses.mjs +4 -4
  61. package/dist/functions/functions/remove-parentheses.mjs.map +1 -1
  62. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs +23 -9
  63. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs.map +1 -1
  64. package/dist/functions/functions/unwrap-readonly.mjs +3 -4
  65. package/dist/functions/functions/unwrap-readonly.mjs.map +1 -1
  66. package/dist/functions/functions/wrap-with-parentheses.d.mts +14 -5
  67. package/dist/functions/functions/wrap-with-parentheses.d.mts.map +1 -1
  68. package/dist/functions/functions/wrap-with-parentheses.mjs +67 -30
  69. package/dist/functions/functions/wrap-with-parentheses.mjs.map +1 -1
  70. package/dist/functions/index.mjs +5 -24
  71. package/dist/functions/index.mjs.map +1 -1
  72. package/dist/functions/utils/index.mjs +2 -2
  73. package/dist/functions/utils/index.mjs.map +1 -1
  74. package/dist/functions/utils/replace-with-debug.mjs +4 -6
  75. package/dist/functions/utils/replace-with-debug.mjs.map +1 -1
  76. package/dist/index.mjs +2 -24
  77. package/dist/index.mjs.map +1 -1
  78. package/package.json +18 -18
  79. package/src/functions/ast-transformers/convert-to-readonly.mts +19 -13
  80. package/src/functions/ast-transformers/convert-to-readonly.test.mts +129 -1
  81. package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.mts +32 -9
  82. package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.test.mts +76 -22
  83. package/src/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mts +8 -1
  84. package/src/functions/functions/has-call-or-construct-signature.mts +120 -0
  85. package/src/functions/functions/index.mts +1 -0
  86. package/src/functions/functions/wrap-with-parentheses.mts +32 -17
@@ -1,15 +1,13 @@
1
- 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"
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
- "transformer-ignore",
9
- "ts-codemod-ignore",
10
- "codemod-ignore",
11
- "transform-ignore"
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"],"sourcesContent":["export const IGNORE_LINE_COMMENT_PREFIXES = [\n 'transformer-ignore-next-line',\n 'ts-codemod-ignore-next-line',\n 'codemod-ignore-next-line',\n 'transform-ignore-next-line',\n] as const;\n\nexport const IGNORE_FILE_COMMENT_PREFIXES = [\n 'transformer-ignore',\n 'ts-codemod-ignore',\n 'codemod-ignore',\n 'transform-ignore',\n] as const;\n"],"names":[],"mappings":"AAAO,MAAM,4BAAA,GAA+B;AAAA,EAC1C,8BAAA;AAAA,EACA,6BAAA;AAAA,EACA,0BAAA;AAAA,EACA;AACF;AAEO,MAAM,4BAAA,GAA+B;AAAA,EAC1C,oBAAA;AAAA,EACA,mBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF;;;;"}
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 { IGNORE_FILE_COMMENT_PREFIXES, IGNORE_LINE_COMMENT_PREFIXES } from './ignore-comment-text.mjs';
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","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/functions/constants/index.mts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import * as tsm from 'ts-morph';
2
+ /**
3
+ * Determines whether a node is a type literal or an interface that declares a
4
+ * call or construct signature.
5
+ *
6
+ * `Readonly<T>` is a mapped type over `keyof T`, and neither signature kind is a
7
+ * property, so neither survives the mapping: wrapping `{ (x: string): void }`
8
+ * with `Readonly` produces a type that is no longer callable. A type mixing
9
+ * properties with a call signature is worse still — the properties come through
10
+ * and only the signature disappears. So a type literal carrying one must not be
11
+ * wrapped; its members are marked `readonly` in place instead.
12
+ *
13
+ * @param node - The node to check
14
+ * @returns true if the node declares at least one call or construct signature,
15
+ * false for any other node kind
16
+ */
17
+ export declare const hasCallOrConstructSignature: (node: tsm.Node) => boolean;
18
+ //# sourceMappingURL=has-call-or-construct-signature.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-call-or-construct-signature.d.mts","sourceRoot":"","sources":["../../../src/functions/functions/has-call-or-construct-signature.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,2BAA2B,SAAU,GAAG,CAAC,IAAI,KAAG,OASxD,CAAC"}
@@ -0,0 +1,87 @@
1
+ import * as tsm from 'ts-morph';
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ export const hasCallOrConstructSignature = (node) => (node.isKind(tsm.SyntaxKind.TypeLiteral) ||
18
+ node.isKind(tsm.SyntaxKind.InterfaceDeclaration)) &&
19
+ node
20
+ .getMembers()
21
+ .some((member) => member.isKind(tsm.SyntaxKind.CallSignature) ||
22
+ member.isKind(tsm.SyntaxKind.ConstructSignature));
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
+
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
+ //# sourceMappingURL=has-call-or-construct-signature.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-call-or-construct-signature.mjs","sourceRoot":"","sources":["../../../src/functions/functions/has-call-or-construct-signature.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,IAAc,EAAW,EAAE,CACrE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC;IACtC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACnD,IAAI;SACD,UAAU,EAAE;SACZ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AI,EAAE,GAAG,CAAC,UAAU,CAAC,gBAAgB;aACtC;SACF,CAAC,CAAC,oBAAoB,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE;YAC1C,MAAM,CAAC,OAAO,CACZ,2BAA2B,CAAC,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAC5D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,43 +1,72 @@
1
1
  import * as tsm from 'ts-morph';
2
- import { IGNORE_LINE_COMMENT_PREFIXES } from '../constants/ignore-comment-text.mjs';
2
+ import { IGNORE_LINE_COMMENT_PREFIXES } from '../constants/index.mjs';
3
3
 
4
- const hasDisableNextLineComment = (node, transformerName) => {
5
- const nodeStartLine = node.getStartLineNumber();
6
- if (nodeStartLine <= 1) {
7
- return false;
8
- }
9
- const sourceFile = node.getSourceFile();
10
- const leadingCommentRanges = node.getLeadingCommentRanges();
11
- for (let mut_i = leadingCommentRanges.length - 1; mut_i >= 0; mut_i--) {
12
- const commentRange = leadingCommentRanges[mut_i];
13
- const commentEndPos = commentRange.getEnd();
14
- const commentEndLine = sourceFile.getLineAndColumnAtPos(commentEndPos).line;
15
- if (nodeStartLine === commentEndLine + 1) {
16
- if (commentRange.getKind() === tsm.SyntaxKind.SingleLineCommentTrivia) {
17
- const commentText = commentRange.getText().trim();
18
- const matchedPrefix = IGNORE_LINE_COMMENT_PREFIXES.find(
19
- (prefix) => commentText.includes(prefix)
20
- );
21
- if (matchedPrefix !== void 0) {
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
- if (commentEndLine < nodeStartLine - 1) {
36
- break;
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"],"sourcesContent":["import * as tsm from 'ts-morph';\nimport { IGNORE_LINE_COMMENT_PREFIXES } from '../constants/index.mjs';\n\n/**\n * Checks if a given ts-morph Node is immediately preceded by an ignore-next-line comment,\n * optionally filtered by transformer name(s).\n *\n * @param node - The ts-morph Node to check.\n * @param transformerName - Optional transformer name to check for specific ignore directive.\n * If provided, only ignores if the comment specifies this transformer.\n * Supports ESLint-style syntax like:\n * - `// transformer-ignore-next-line` (ignores all transformers)\n * - `// transformer-ignore-next-line append-as-const` (specific transformer)\n * - `// transformer-ignore-next-line append-as-const, replace-any-with-unknown` (multiple transformers)\n * - Also accepts `ts-codemod-ignore-next-line`, `codemod-ignore-next-line`, `transform-ignore-next-line`\n * @returns True if the node is preceded by the ignore comment on the immediately previous line, false otherwise.\n */\nexport const hasDisableNextLineComment = (\n node: tsm.Node,\n transformerName?: string,\n): boolean => {\n const nodeStartLine = node.getStartLineNumber();\n\n // Cannot be ignored if it's on the first line\n if (nodeStartLine <= 1) {\n return false;\n }\n\n const sourceFile = node.getSourceFile(); // Get the SourceFile\n\n const leadingCommentRanges = node.getLeadingCommentRanges();\n\n // Iterate backwards through comments as the closest one is most relevant\n for (let mut_i = leadingCommentRanges.length - 1; mut_i >= 0; mut_i--) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const commentRange = leadingCommentRanges[mut_i]!;\n\n // Get the end position and convert it to line number\n const commentEndPos = commentRange.getEnd();\n\n const commentEndLine = sourceFile.getLineAndColumnAtPos(commentEndPos).line;\n\n // Check if the comment is on the immediately preceding line\n if (nodeStartLine === commentEndLine + 1) {\n // Check if it's a single-line comment containing the specific ignore text\n if (commentRange.getKind() === tsm.SyntaxKind.SingleLineCommentTrivia) {\n const commentText = commentRange.getText().trim();\n\n // Check if the comment contains any of the supported ignore prefixes\n const matchedPrefix = IGNORE_LINE_COMMENT_PREFIXES.find((prefix) =>\n commentText.includes(prefix),\n );\n\n if (matchedPrefix !== undefined) {\n // If no transformer name specified, check if comment applies to all transformers\n if (transformerName === undefined) {\n return true;\n }\n\n // Extract the part after the prefix\n const afterPrefix = commentText\n .slice(commentText.indexOf(matchedPrefix))\n .replace(matchedPrefix, '')\n .trim();\n\n // If no specific transformers listed in comment, it applies to all\n if (afterPrefix === '') {\n return true;\n }\n\n // Check if the transformer name is in the comma-separated list\n const targetTransformers = afterPrefix\n .split(',')\n .map((name) => name.trim());\n\n return targetTransformers.includes(transformerName);\n }\n }\n\n // If we found *any* comment on the preceding line, but it wasn't\n // the correct ignore comment, then the node is not ignored by\n // a comment on the *immediately* preceding line. Stop checking further back.\n return false;\n }\n\n // If the comment ends before the preceding line, stop checking further back.\n if (commentEndLine < nodeStartLine - 1) {\n break;\n }\n }\n\n return false;\n};\n"],"names":[],"mappings":";;;AAiBO,MAAM,yBAAA,GAA4B,CACvC,IAAA,EACA,eAAA,KACY;AACZ,EAAA,MAAM,aAAA,GAAgB,KAAK,kBAAA,EAAmB;AAG9C,EAAA,IAAI,iBAAiB,CAAA,EAAG;AACtB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,UAAA,GAAa,KAAK,aAAA,EAAc;AAEtC,EAAA,MAAM,oBAAA,GAAuB,KAAK,uBAAA,EAAwB;AAG1D,EAAA,KAAA,IAAS,QAAQ,oBAAA,CAAqB,MAAA,GAAS,CAAA,EAAG,KAAA,IAAS,GAAG,KAAA,EAAA,EAAS;AAErE,IAAA,MAAM,YAAA,GAAe,qBAAqB,KAAK,CAAA;AAG/C,IAAA,MAAM,aAAA,GAAgB,aAAa,MAAA,EAAO;AAE1C,IAAA,MAAM,cAAA,GAAiB,UAAA,CAAW,qBAAA,CAAsB,aAAa,CAAA,CAAE,IAAA;AAGvE,IAAA,IAAI,aAAA,KAAkB,iBAAiB,CAAA,EAAG;AAExC,MAAA,IAAI,YAAA,CAAa,OAAA,EAAQ,KAAM,GAAA,CAAI,WAAW,uBAAA,EAAyB;AACrE,QAAA,MAAM,WAAA,GAAc,YAAA,CAAa,OAAA,EAAQ,CAAE,IAAA,EAAK;AAGhD,QAAA,MAAM,gBAAgB,4BAAA,CAA6B,IAAA;AAAA,UAAK,CAAC,MAAA,KACvD,WAAA,CAAY,QAAA,CAAS,MAAM;AAAA,SAC7B;AAEA,QAAA,IAAI,kBAAkB,MAAA,EAAW;AAE/B,UAAA,IAAI,oBAAoB,MAAA,EAAW;AACjC,YAAA,OAAO,IAAA;AAAA,UACT;AAGA,UAAA,MAAM,WAAA,GAAc,WAAA,CACjB,KAAA,CAAM,WAAA,CAAY,OAAA,CAAQ,aAAa,CAAC,CAAA,CACxC,OAAA,CAAQ,aAAA,EAAe,EAAE,CAAA,CACzB,IAAA,EAAK;AAGR,UAAA,IAAI,gBAAgB,EAAA,EAAI;AACtB,YAAA,OAAO,IAAA;AAAA,UACT;AAGA,UAAA,MAAM,kBAAA,GAAqB,WAAA,CACxB,KAAA,CAAM,GAAG,CAAA,CACT,IAAI,CAAC,IAAA,KAAS,IAAA,CAAK,IAAA,EAAM,CAAA;AAE5B,UAAA,OAAO,kBAAA,CAAmB,SAAS,eAAe,CAAA;AAAA,QACpD;AAAA,MACF;AAKA,MAAA,OAAO,KAAA;AAAA,IACT;AAGA,IAAA,IAAI,cAAA,GAAiB,gBAAgB,CAAA,EAAG;AACtC,MAAA;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;;;;"}
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,O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AmE;oBACnE,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;wBACvB,OAAO,IAAI,CAAC;oBACd,CAAC;oBAED,+DAA+D;oBAC/D,MAAM,kBAAkB,GAAG,WAAW;yBACnC,KAAK,CAAC,GAAG,CAAC;yBACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,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,3 +1,4 @@
1
+ export * from './has-call-or-construct-signature.mjs';
1
2
  export * from './has-disable-next-line-comment.mjs';
2
3
  export * from './is-as-const-node.mjs';
3
4
  export * from './is-atomic-type-node.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","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
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/functions/functions/index.mts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,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,11 +1,12 @@
1
- export { hasDisableNextLineComment } from './has-disable-next-line-comment.mjs';
2
- export { isAsConstNode } from './is-as-const-node.mjs';
3
- export { isAtomicTypeNode } from './is-atomic-type-node.mjs';
4
- export { isConditionalTypeDistributionGuard } from './is-conditional-type-distribution-guard.mjs';
5
- export { isReadonlyArrayTypeNode, isReadonlyTupleOrArrayTypeNode, isReadonlyTupleTypeNode, isReadonlyTypeReferenceNode, isShallowReadonlyTypeNode } from './is-readonly-node.mjs';
6
- export { isSpreadNamedTupleMemberNode, isSpreadParameterNode } from './is-spread-parameter-node.mjs';
7
- export { removeParentheses } from './remove-parentheses.mjs';
8
- export { shouldAvoidParenthesesForReadonly } from './should-avoid-parentheses-for-readonly.mjs';
9
- export { unwrapReadonlyTypeArgText } from './unwrap-readonly.mjs';
10
- export { wrapWithParentheses } from './wrap-with-parentheses.mjs';
11
- //# sourceMappingURL=index.mjs.map
1
+ export * from './has-call-or-construct-signature.mjs';
2
+ export * from './has-disable-next-line-comment.mjs';
3
+ export * from './is-as-const-node.mjs';
4
+ export * from './is-atomic-type-node.mjs';
5
+ export * from './is-conditional-type-distribution-guard.mjs';
6
+ export * from './is-readonly-node.mjs';
7
+ export * from './is-spread-parameter-node.mjs';
8
+ export * from './remove-parentheses.mjs';
9
+ export * from './should-avoid-parentheses-for-readonly.mjs';
10
+ export * from './unwrap-readonly.mjs';
11
+ export * from './wrap-with-parentheses.mjs';
12
+ //# 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/functions/index.mts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,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 tsm from 'ts-morph';
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 isAsConstNode = (node) => {
5
- if (!node.isKind(tsm.SyntaxKind.AsExpression)) {
6
- return false;
7
- }
8
- const typeNode = node.getTypeNode();
9
- if (typeNode === void 0) {
10
- return false;
11
- }
12
- if (!typeNode.isKind(tsm.SyntaxKind.TypeReference)) {
13
- return false;
14
- }
15
- const typeNameNode = typeNode.getTypeName();
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
- export { isAsConstNode };
23
- //# sourceMappingURL=is-as-const-node.mjs.map
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"],"sourcesContent":["import { Arr } from 'ts-data-forge';\nimport * as ts from 'ts-morph';\n\nexport const isAsConstNode = (\n node: ts.Node,\n): node is ts.AsExpression &\n Readonly<{\n type: ts.TypeReferenceNode &\n Readonly<{\n typeName: ts.Identifier &\n Readonly<{\n text: 'const';\n }>;\n typeArguments: undefined;\n }>;\n }> => {\n if (!node.isKind(ts.SyntaxKind.AsExpression)) {\n return false;\n }\n\n // 2. Get the 'type' node from the AsExpression\n const typeNode = node.getTypeNode();\n\n if (typeNode === undefined) {\n return false; // Should have a type node for 'as const'\n }\n\n // 3. Check if the 'type' node is a TypeReference\n if (!typeNode.isKind(ts.SyntaxKind.TypeReference)) {\n return false;\n }\n\n // 4. Get the 'typeName' from the TypeReference\n const typeNameNode = typeNode.getTypeName();\n\n // 5. Check if the 'typeName' is an Identifier\n if (!typeNameNode.isKind(ts.SyntaxKind.Identifier)) {\n // 'as const' uses a simple Identifier 'const', not a QualifiedName\n return false;\n }\n\n // 6. Check if the Identifier's text is 'const'\n // and that there are no type arguments (as const doesn't have them)\n return (\n typeNameNode.getText() === 'const' &&\n Arr.isEmpty(typeNode.getTypeArguments())\n );\n};\n"],"names":["ts"],"mappings":";;;AAGO,MAAM,aAAA,GAAgB,CAC3B,IAAA,KAWM;AACN,EAAA,IAAI,CAAC,IAAA,CAAK,MAAA,CAAOA,GAAA,CAAG,UAAA,CAAW,YAAY,CAAA,EAAG;AAC5C,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,QAAA,GAAW,KAAK,WAAA,EAAY;AAElC,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,IAAI,CAAC,QAAA,CAAS,MAAA,CAAOA,GAAA,CAAG,UAAA,CAAW,aAAa,CAAA,EAAG;AACjD,IAAA,OAAO,KA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