ts-codemod-lib 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/entry-point.mjs +2 -24
  2. package/dist/entry-point.mjs.map +1 -1
  3. package/dist/functions/ast-transformers/append-as-const.mjs +330 -292
  4. package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
  5. package/dist/functions/ast-transformers/convert-interface-to-type.mjs +85 -70
  6. package/dist/functions/ast-transformers/convert-interface-to-type.mjs.map +1 -1
  7. package/dist/functions/ast-transformers/convert-to-readonly.mjs +969 -840
  8. package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
  9. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs +276 -134
  10. package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -1
  11. package/dist/functions/ast-transformers/index.mjs +10 -12
  12. package/dist/functions/ast-transformers/index.mjs.map +1 -1
  13. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs +14 -7
  14. package/dist/functions/ast-transformers/readonly-transformer-helpers/compare-union-types.mjs.map +1 -1
  15. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs +12 -15
  16. package/dist/functions/ast-transformers/readonly-transformer-helpers/constants.mjs.map +1 -1
  17. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs +63 -58
  18. package/dist/functions/ast-transformers/readonly-transformer-helpers/group-union-types.mjs.map +1 -1
  19. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs +5 -5
  20. package/dist/functions/ast-transformers/readonly-transformer-helpers/index.mjs.map +1 -1
  21. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs +15 -20
  22. package/dist/functions/ast-transformers/readonly-transformer-helpers/readonly-context.mjs.map +1 -1
  23. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs +30 -34
  24. package/dist/functions/ast-transformers/replace-any-with-unknown.mjs.map +1 -1
  25. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +197 -156
  26. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
  27. package/dist/functions/ast-transformers/transform-source-code.mjs +74 -75
  28. package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
  29. package/dist/functions/ast-transformers/types.mjs +2 -2
  30. package/dist/functions/ast-transformers/types.mjs.map +1 -1
  31. package/dist/functions/constants/ignore-comment-text.mjs +11 -13
  32. package/dist/functions/constants/ignore-comment-text.mjs.map +1 -1
  33. package/dist/functions/constants/index.mjs +2 -2
  34. package/dist/functions/constants/index.mjs.map +1 -1
  35. package/dist/functions/functions/has-disable-next-line-comment.mjs +67 -38
  36. package/dist/functions/functions/has-disable-next-line-comment.mjs.map +1 -1
  37. package/dist/functions/functions/index.mjs +11 -11
  38. package/dist/functions/functions/index.mjs.map +1 -1
  39. package/dist/functions/functions/is-as-const-node.mjs +25 -20
  40. package/dist/functions/functions/is-as-const-node.mjs.map +1 -1
  41. package/dist/functions/functions/is-atomic-type-node.mjs +245 -25
  42. package/dist/functions/functions/is-atomic-type-node.mjs.map +1 -1
  43. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs +34 -13
  44. package/dist/functions/functions/is-conditional-type-distribution-guard.mjs.map +1 -1
  45. package/dist/functions/functions/is-readonly-node.mjs +120 -14
  46. package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
  47. package/dist/functions/functions/is-spread-parameter-node.mjs +5 -6
  48. package/dist/functions/functions/is-spread-parameter-node.mjs.map +1 -1
  49. package/dist/functions/functions/remove-parentheses.mjs +4 -4
  50. package/dist/functions/functions/remove-parentheses.mjs.map +1 -1
  51. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs +23 -9
  52. package/dist/functions/functions/should-avoid-parentheses-for-readonly.mjs.map +1 -1
  53. package/dist/functions/functions/unwrap-readonly.mjs +3 -4
  54. package/dist/functions/functions/unwrap-readonly.mjs.map +1 -1
  55. package/dist/functions/functions/wrap-with-parentheses.d.mts.map +1 -1
  56. package/dist/functions/functions/wrap-with-parentheses.mjs +54 -29
  57. package/dist/functions/functions/wrap-with-parentheses.mjs.map +1 -1
  58. package/dist/functions/index.mjs +5 -24
  59. package/dist/functions/index.mjs.map +1 -1
  60. package/dist/functions/utils/index.mjs +2 -2
  61. package/dist/functions/utils/index.mjs.map +1 -1
  62. package/dist/functions/utils/replace-with-debug.mjs +4 -6
  63. package/dist/functions/utils/replace-with-debug.mjs.map +1 -1
  64. package/dist/index.mjs +2 -24
  65. package/dist/index.mjs.map +1 -1
  66. package/package.json +11 -12
  67. package/src/functions/ast-transformers/convert-to-readonly.test.mts +10 -1
  68. package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.test.mts +76 -22
  69. package/src/functions/functions/wrap-with-parentheses.mts +5 -2
@@ -1,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"}
@@ -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 < node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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,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,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACtE,oEAAoE;QACpE,MAAM,YAAY,GAAG,oBAAoB,CAAC,KAAK,CAAE,CAAC;QAElD,qDAAqD;QACrD,MAAM,a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AAO,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 { 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-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","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
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 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,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,YAAA,GAAe,SAAS,WAAA,EAAY;AAG1C,EAAA,IAA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AC,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
- 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
- // Note: 'object' is sometimes considered primitive in TS type system context
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
- const isAtomicTypeNode = (node) => {
19
- if (node.isKind(tsm.SyntaxKind.LiteralType)) {
20
- return true;
21
- }
22
- if (node.isKind(tsm.SyntaxKind.TemplateLiteralType)) {
23
- return true;
24
- }
25
- if (atomicTypeKeywordKinds.has(node.getKind())) {
26
- return true;
27
- }
28
- return false;
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
- export { isAtomicTypeNode };
32
- //# sourceMappingURL=is-atomic-type-node.mjs.map
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;AACrC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAGhC,uEAAuE;AACvE,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAiB;IACzD,GAAG,CAAC,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mB;gBAEtD,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC;gBACR;oBACE,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,0EAA0E;oBAChF,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,aAAa;iBACnC,EAAE,+BAA+B;gBAClC;oBACE,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,+BAA+B;oBACrC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,QAAQ;iBAC9B,EAAE,6BAA6B;gBAChC;oBACE,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,oDAAoD;oBAC1D,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,SAAS;iBAC/B,EAAE,gBAAgB;aACpB,CAAC,CAAC,yBAAyB,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE;gBAC/C,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE5C,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;gBAE3B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;gBAC5C,CAAC;gBAED,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,16 +1,37 @@
1
1
  import * as tsm from 'ts-morph';
2
2
 
3
- const isConditionalTypeDistributionGuard = (node) => {
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
- export { isConditionalTypeDistributionGuard };
16
- //# sourceMappingURL=is-conditional-type-distribution-guard.mjs.map
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"],"sourcesContent":["import * as tsm from 'ts-morph';\n\n/**\n * Determines whether a type node is an operand (check or extends type) of a\n * conditional type whose check type is wrapped to suppress union distribution,\n * i.e. the `X` and `Y` in `X extends Y ? ... : ...` where `X` is itself a tuple\n * or array.\n *\n * Wrapping a naked type parameter so that it is no longer naked is a well-known\n * type-implementation idiom used to suppress union distribution. Both\n * `[A] extends [B] ? ...` (tuple wrapping) and `A[] extends B[] ? ...` (array\n * wrapping) rely on this. Adding a `readonly` modifier to those operands neither\n * makes the type more immutable in any meaningful way nor preserves the idiom's\n * intent, so such operands must be left untouched.\n *\n * A naked check type such as `T extends string[] ? ...` still distributes, so it\n * is not a guard; arrays/tuples in its extends position are converted as usual.\n *\n * @param node - The type node to check\n * @returns true if the node is the check or extends type of a distribution-guarded\n * conditional type\n */\nexport const isConditionalTypeDistributionGuard = (node: tsm.Node): boolean => {\n const parent = node.getParent();\n\n if (parent?.isKind(tsm.SyntaxKind.ConditionalType) !== true) {\n return false;\n }\n\n const checkType = parent.getCheckType();\n\n // The guard is only in effect when the check type itself is wrapped in a tuple\n // or array; otherwise (e.g. a naked `T`) the conditional still distributes.\n if (\n !checkType.isKind(tsm.SyntaxKind.TupleType) &&\n !checkType.isKind(tsm.SyntaxKind.ArrayType)\n ) {\n return false;\n }\n\n return (\n checkType.compilerNode === node.compilerNode ||\n parent.getExtendsType().compilerNode === node.compilerNode\n );\n};\n"],"names":[],"mappings":";;AAsBO,MAAM,kCAAA,GAAqC,CAAC,IAAA,KAA4B;AAC7E,EAAA,MAAM,MAAA,GAAS,KAAK,SAAA,EAAU;AAE9B,EAAA,IAAI,QAAQ,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,eAAe,MAAM,IAAA,EAAM;AAC3D,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,SAAA,GAAY,OAAO,YAAA,EAAa;AAItC,EAAA,IACE,CAAC,SAAA,CAAU,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA,IAC1C,CAAC,SAAA,CAAU,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,SAAS,CAAA,EAC1C;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OACE,SAAA,CAAU,iBAAiB,IAAA,CAAK,YAAA,IAChC,OAAO,cAAA,EAAe,CAAE,iBAAiB,IAAA,CAAK,YAAA;AAElD;;;;"}
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"}