ts-codemod-lib 2.2.2 → 2.2.4

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 (42) hide show
  1. package/README.md +0 -12
  2. package/dist/cmd/append-as-const.mjs +1 -1
  3. package/dist/cmd/append-as-const.mjs.map +1 -1
  4. package/dist/cmd/convert-interface-to-type.mjs +1 -1
  5. package/dist/cmd/convert-interface-to-type.mjs.map +1 -1
  6. package/dist/cmd/convert-to-readonly.mjs +1 -1
  7. package/dist/cmd/convert-to-readonly.mjs.map +1 -1
  8. package/dist/cmd/replace-any-with-unknown.mjs +1 -1
  9. package/dist/cmd/replace-any-with-unknown.mjs.map +1 -1
  10. package/dist/cmd/replace-record-with-unknown-record.mjs +1 -1
  11. package/dist/cmd/replace-record-with-unknown-record.mjs.map +1 -1
  12. package/dist/cmd/run-transformer-cli.mjs +1 -1
  13. package/dist/cmd/run-transformer-cli.mjs.map +1 -1
  14. package/dist/functions/ast-transformers/append-as-const.mjs +1 -1
  15. package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
  16. package/dist/functions/ast-transformers/convert-interface-to-type.mjs +4 -4
  17. package/dist/functions/ast-transformers/convert-interface-to-type.mjs.map +1 -1
  18. package/dist/functions/ast-transformers/convert-to-readonly.mjs +10 -10
  19. package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
  20. package/dist/functions/ast-transformers/replace-record-with-unknown-record.d.mts.map +1 -1
  21. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +13 -13
  22. package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
  23. package/dist/functions/ast-transformers/transform-source-code.mjs +2 -2
  24. package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
  25. package/dist/functions/functions/is-as-const-node.mjs +1 -1
  26. package/dist/functions/functions/is-as-const-node.mjs.map +1 -1
  27. package/dist/functions/functions/is-readonly-node.mjs +1 -1
  28. package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
  29. package/package.json +47 -40
  30. package/src/cmd/append-as-const.mts +1 -1
  31. package/src/cmd/convert-interface-to-type.mts +1 -1
  32. package/src/cmd/convert-to-readonly.mts +1 -1
  33. package/src/cmd/replace-any-with-unknown.mts +1 -1
  34. package/src/cmd/replace-record-with-unknown-record.mts +1 -1
  35. package/src/cmd/run-transformer-cli.mts +1 -1
  36. package/src/functions/ast-transformers/append-as-const.mts +1 -1
  37. package/src/functions/ast-transformers/convert-interface-to-type.mts +4 -4
  38. package/src/functions/ast-transformers/convert-to-readonly.mts +11 -16
  39. package/src/functions/ast-transformers/replace-record-with-unknown-record.mts +18 -29
  40. package/src/functions/ast-transformers/transform-source-code.mts +2 -2
  41. package/src/functions/functions/is-as-const-node.mts +1 -1
  42. package/src/functions/functions/is-readonly-node.mts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"convert-to-readonly.mjs","sources":["../../../src/functions/ast-transformers/convert-to-readonly.mts"],"sourcesContent":["import {\n Arr,\n expectType,\n ISet,\n isString,\n mapNullable,\n match,\n pipe,\n} from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { type DeepReadonly, type SafeUintWithSmallInt } from 'ts-type-forge';\nimport {\n hasDisableNextLineComment,\n isAtomicTypeNode,\n isConditionalTypeDistributionGuard,\n isReadonlyArrayTypeNode,\n isReadonlyTupleOrArrayTypeNode,\n isReadonlyTupleTypeNode,\n isReadonlyTypeReferenceNode,\n removeParentheses,\n shouldAvoidParenthesesForReadonly,\n unwrapReadonlyTypeArgText,\n wrapWithParentheses,\n type ReadonlyTypeReferenceNode,\n} from '../functions/index.mjs';\nimport { replaceNodeWithDebugPrint } from '../utils/index.mjs';\nimport {\n groupUnionIntersectionTypes,\n invalidDeepReadonlyTypeName,\n nextReadonlyContext,\n type ReadonlyContext,\n} from './readonly-transformer-helpers/index.mjs';\nimport { type TsMorphTransformer } from './types.mjs';\n\nconst TRANSFORMER_NAME = 'convert-to-readonly';\n\nexport const convertToReadonlyTransformer = (\n options?: ReadonlyTransformerOptions,\n): TsMorphTransformer => {\n if (\n options?.DeepReadonly?.typeName !== undefined &&\n invalidDeepReadonlyTypeName.has(options.DeepReadonly.typeName)\n ) {\n throw new Error(\n `Invalid DeepReadonly typeName \"${options.DeepReadonly.typeName}\" passed to convertToReadonlyType`,\n );\n }\n\n const DeepReadonlyTypeName =\n options?.DeepReadonly?.typeName ?? 'DeepReadonly';\n\n const ignorePrefixes = ISet.create(\n options?.ignorePrefixes ?? ['mut_', '#mut_', '_mut_', 'draft'],\n );\n\n const optionsInternal: ReadonlyTransformerOptionsInternal = {\n DeepReadonly: {\n typeName: DeepReadonlyTypeName,\n applyLevel: 'keep',\n },\n ignoreEmptyObjectTypes: options?.ignoreEmptyObjectTypes ?? true,\n ignoredPrefixes: ignorePrefixes,\n debugPrint: options?.debug === true ? console.debug : () => {},\n replaceNode:\n options?.debug === true\n ? replaceNodeWithDebugPrint\n : (node, newNodeText) => node.replaceWithText(newNodeText),\n } as const;\n\n return {\n name: TRANSFORMER_NAME,\n transform: (sourceAst) => {\n for (const node of sourceAst.getChildren()) {\n transformNode(node, initialReadonlyContext, optionsInternal);\n }\n },\n };\n};\n\nexport type ReadonlyTransformerOptions = DeepReadonly<{\n /**\n * Options for a type utility `DeepReadonly` that recursively applies readonly.\n */\n DeepReadonly?: {\n /**\n * The name of a type utility that recursively applies `Readonly`.\n *\n * @default \"DeepReadonly\"\n */\n typeName?: string;\n\n /**\n * Whether to apply `DeepReadonly` aggressively or remove `DeepReadonly` as\n * possible.\n *\n * If `applyLevel` is `\"applyAggressively\"`, it applies `DeepReadonly` to all\n * nested type literals without external type references. For example, the\n * following conversions are applied:\n *\n * - `number[][]` to be `DeepReadonly<number[][]>`\n * - `number[]` to be `readonly number[]`\n * - `<T>(arg: T[][]) => void` to be `<T>(arg: readonly (readonly T[])[]>) =>\n * void`\n *\n * If `applyLevel` is `\"removeAsPossible\"`, the following conversions are applied:\n *\n * - `DeepReadonly<number[][]>` to be `readonly (readonly number[])[]`\n * - `DeepReadonly<{ a: number[] }>` to be `Readonly<{ a: readonly number[]\n * }>`\n * - `<T>(arg: DeepReadonly<T[][]>) => void` to be `<T>(arg:\n * DeepReadonly<T[][]>) => void`\n *\n * @default 'keep'\n */\n // TODO\n // applyLevel?: 'applyAggressively' | 'keep' | 'removeAsPossible';\n };\n\n /**\n * Ignore the readonly conversion for `{}`.\n *\n * @default true\n */\n ignoreEmptyObjectTypes?: boolean;\n\n /**\n * A mute keywords to ignore the readonly conversion.\n *\n * (e.g. `\"mut_\"`)\n *\n * @default ['mut_', '#mut_', '_mut_', 'draft']\n */\n ignorePrefixes?: string[];\n\n debug?: boolean;\n}>;\n\ntype ReadonlyTransformerOptionsInternal = Readonly<{\n DeepReadonly: Readonly<{\n typeName: string;\n\n // removeAsPossible: 正規化後、 DeepReadonly の子ノードが typeLiteral かまたはその union or intersection であり、 それぞれの TypeLiteral がプリミティブ値のメンバーしか持たない場合。\n applyLevel: 'applyAggressively' | 'keep' | 'removeAsPossible';\n }>;\n\n ignoreEmptyObjectTypes: boolean;\n\n ignoredPrefixes: ISet<string>;\n\n debugPrint: (...args: readonly unknown[]) => void;\n replaceNode: (node: tsm.Node, newNodeText: string) => void;\n}>;\n\nconst initialReadonlyContext: ReadonlyContext = {\n type: 'none',\n indexedAccessDepth: 0,\n} as const;\n\nconst transformNode = (\n node: tsm.Node,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (\n tsm.Node.isTypeNode(node) ||\n node.isKind(tsm.SyntaxKind.InterfaceDeclaration) ||\n node.isKind(tsm.SyntaxKind.ClassDeclaration)\n ) {\n options.debugPrint();\n\n options.debugPrint(`transformNode [${node.getKindName()}] `);\n\n options.debugPrint(node.getFullText());\n\n options.debugPrint({ readonlyContext });\n\n options.debugPrint();\n }\n\n if (hasDisableNextLineComment(node, TRANSFORMER_NAME)) {\n options.debugPrint('skipped by disable-next-line comment');\n\n return;\n }\n\n // check for ignorePrefix\n if (node.isKind(tsm.SyntaxKind.VariableDeclaration)) {\n const nodeName = node.getName();\n\n if (options.ignoredPrefixes.some((p) => nodeName.startsWith(p))) {\n // Skip conversion for variable declarations with ignored prefixes\n // Example: const mut_foo: string[] = []; -> remains as is, without appending `as const`\n options.debugPrint('skipped variable declaration by ignorePrefixes');\n\n return;\n }\n\n // TODO: Support ignoredPrefixes in ArrayBindingPattern\n // if (ts.isArrayBindingPattern(nodeName)) {\n // // for (const [i, el] of nodeName.elements.entries())\n // }\n\n // TODO: Support ignoredPrefixes in ObjectBindingPattern\n // if (ts.isObjectBindingPattern(nodeName)) {\n // // for (const [i, el] of nodeName.elements.entries())\n // }\n }\n\n // Skip readonly conversion for function declarations with ignored prefixes\n // Example: function mut_foo() {} -> parameters and return types remain as is\n if (\n (node.isKind(tsm.SyntaxKind.FunctionDeclaration) ||\n node.isKind(tsm.SyntaxKind.FunctionExpression)) &&\n options.ignoredPrefixes.some((p) => node.getName()?.startsWith(p) === true)\n ) {\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.Parameter)) {\n const nodeName = node.getName();\n\n if (options.ignoredPrefixes.some((p) => nodeName.startsWith(p))) {\n // Skip readonly conversion for variable declarations with ignored prefixes\n // Example: const mut_foo: string[] = []; -> remains as is, without readonly conversion\n return;\n }\n\n // TODO: Support ignoredPrefixes in ArrayBindingPattern\n // if (ts.isArrayBindingPattern(nodeName)) {\n // }\n\n // TODO: Support ignoredPrefixes in ObjectBindingPattern\n // if (ts.isObjectBindingPattern(nodeName)) {\n // }\n }\n\n // Skip readonly conversion for type alias declarations with ignored prefixes\n // Example: type mut_Foo = number[]; -> remains as number[] without readonly\n if (\n node.isKind(tsm.SyntaxKind.TypeAliasDeclaration) &&\n options.ignoredPrefixes.some((p) => node.getName().startsWith(p))\n ) {\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TypeReference)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to TypeReferenceNode',\n );\n }\n\n transformTypeReferenceNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.ArrayType)) {\n transformArrayTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TupleType)) {\n transformTupleTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.RestType)) {\n transformRestTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TypeOperator)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to TypeOperatorNode',\n );\n }\n\n transformTypeOperatorNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TypeLiteral)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to TypeLiteralNode',\n );\n }\n\n transformTypeLiteralNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.IndexedAccessType)) {\n transformIndexedAccessTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.MappedType)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to MappedTypeNode',\n );\n }\n\n transformMappedTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.InterfaceDeclaration)) {\n // Skip readonly conversion for interface declarations with ignored prefixes\n // Example: interface mut_Interface {...} -> properties remain without readonly\n if (options.ignoredPrefixes.some((p) => node.getName().startsWith(p))) {\n return;\n }\n\n transformInterfaceDeclarationNode(node, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.ClassDeclaration)) {\n // Skip readonly conversion for class declarations with ignored prefixes\n // Example: class mut_Class {...} -> properties remain without readonly\n if (\n options.ignoredPrefixes.some(\n (p) => node.getName()?.startsWith(p) === true,\n )\n ) {\n return;\n }\n\n transformClassDeclarationNode(node, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.IntersectionType)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to IntersectionTypeNode',\n );\n }\n\n transformIntersectionTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.UnionType)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to UnionTypeNode',\n );\n }\n\n transformUnionTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.ParenthesizedType)) {\n // NOTE: readonlyContext を不変のままバケツリレーさせるためにこのケースも必要\n transformParenthesizedTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n for (const child of node.getChildren()) {\n transformNode(child, initialReadonlyContext, options);\n }\n};\n\n//\n// Transformer implementation for each node type\n//\n\n/**\n * - `tr(ReadonlyArray<E>) |-> readonly tr(E)[]`\n * - `tr(Readonly<Readonly<E>>) |-> Readonly<tr(E)>`\n * - `tr(DeepReadonly<Readonly<E>>) |-> DeepReadonly<tr(E)>`\n * - `tr(Readonly<number>) |-> number`\n * - `tr(Readonly<E[]>) |-> readonly tr(E)[]`\n * - `tr(Readonly<[E1, E2, E3]>) |-> readonly [tr(E1), tr(E2), tr(E3)]`\n * - `tr(Readonly<readonly E[]>) |-> readonly tr(E)[]`\n * - `tr(Readonly<readonly [E1, E2, E3]>) |-> readonly [tr(E1), tr(E2), tr(E3)]`\n * - `tr(Readonly<A | readonly E[]>) |-> Readonly<tr(A)> | readonly tr(E)[]>`\n */\nconst transformTypeReferenceNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TypeReferenceNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n const typeNameStr = node.getTypeName().getText();\n\n const typeArguments = node.getTypeArguments();\n\n // Array<T> / ReadonlyArray<T> to readonly T[]\n if (typeNameStr === 'Array' || typeNameStr === 'ReadonlyArray') {\n if (!Arr.isArrayOfLength(typeArguments, 1)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for ${typeNameStr}.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n {\n type: 'none',\n indexedAccessDepth: readonlyContext.indexedAccessDepth,\n },\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = node.getTypeArguments()[0]!;\n\n options.replaceNode(\n node,\n readonlyContext.type === 'DeepReadonly'\n ? wrapWithParentheses(`${wrapWithParentheses(T.getFullText())}[]`)\n : wrapWithParentheses(\n `readonly ${wrapWithParentheses(T.getFullText())}[]`,\n ),\n );\n\n return;\n }\n\n // Set<T> to ReadonlySet<T>\n if (typeNameStr === 'Set') {\n if (!Arr.isArrayOfLength(typeArguments, 1)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Set.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n {\n type: 'none',\n indexedAccessDepth: readonlyContext.indexedAccessDepth,\n },\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = node.getTypeArguments()[0]!;\n\n options.replaceNode(node, `ReadonlySet<${T.getFullText()}>`);\n\n return;\n }\n\n // Map<T> to ReadonlyMap<T>\n if (typeNameStr === 'Map') {\n if (!Arr.isArrayOfLength(typeArguments, 2)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Map.`,\n );\n }\n\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'keep',\n });\n\n // Recursive processing\n for (const t of typeArguments) {\n transformNode(t, nextReadonlyContextValue, options);\n }\n\n const [K, V] = node.getTypeArguments();\n\n options.replaceNode(\n node,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n `ReadonlyMap<${K!.getFullText()}, ${V!.getFullText()}>`,\n );\n\n return;\n }\n\n // remove unnecessary `Readonly` wrapper or convert to readonly operator\n if (typeNameStr === 'Readonly') {\n if (!Arr.isArrayOfLength(typeArguments, 1)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Readonly.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'Readonly',\n indexedAccessDepthChange: 'keep',\n }),\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = removeParentheses(node.getTypeArguments()[0]!);\n\n // DeepReadonly<Readonly<T>> -> DeepReadonly<T>\n if (readonlyContext.type === 'DeepReadonly') {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<{ ... }>[I] -> { ... }[I]\n if (readonlyContext.indexedAccessDepth > 0) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<Readonly<T>> -> Readonly<T>\n if (isReadonlyTypeReferenceNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<number> -> number\n if (isAtomicTypeNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // T = E[]\n // Readonly<E[]> -> readonly E[]\n //\n // T = [E1, E2, E3]\n // Readonly<[E1, E2, E3]> -> readonly [E1, E2, E3]\n if (\n T.isKind(tsm.SyntaxKind.ArrayType) ||\n T.isKind(tsm.SyntaxKind.TupleType)\n ) {\n const readonlyText = `readonly ${T.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n\n return;\n }\n\n // T = readonly E[] or readonly [E1, E2, E3]\n // Readonly<readonly E[]> -> readonly E[]\n // Readonly<readonly [E1, E2, E3]> -> readonly [E1, E2, E3]\n if (isReadonlyTupleOrArrayTypeNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // T = A | B | C\n // T = A & B & C\n if (\n T.isKind(tsm.SyntaxKind.UnionType) ||\n T.isKind(tsm.SyntaxKind.IntersectionType)\n ) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n return;\n }\n\n // DeepReadonly\n if (typeNameStr === options.DeepReadonly.typeName) {\n if (!Arr.isArrayOfLength(typeArguments, 1)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Readonly.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'DeepReadonly',\n }),\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = node.getTypeArguments()[0]!;\n\n // DeepReadonly<DeepReadonly<T>> -> DeepReadonly<T>\n if (readonlyContext.type === 'DeepReadonly') {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<number> -> number\n if (isAtomicTypeNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // T = P[]\n // DeepReadonly<P[]> -> readonly P[] (for primitive type arrays, convert to readonly P[] form)\n // DeepReadonly<O[]> -> DeepReadonly<O[]> (for object type arrays, keep as is to recursively apply Readonly)\n // DeepReadonly<P[][]> -> DeepReadonly<P[][]>\n if (\n T.isKind(tsm.SyntaxKind.ArrayType) &&\n isAtomicTypeNode(T.getElementTypeNode())\n ) {\n const readonlyText = `readonly ${T.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n\n return;\n }\n\n // T = [P1, P2, P3]\n // DeepReadonly<[P1, P2, P3]> -> readonly [P1, P2, P3]\n if (\n T.isKind(tsm.SyntaxKind.TupleType) &&\n T.getElements().every(isAtomicTypeNode)\n ) {\n const readonlyText = `readonly ${T.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n\n return;\n }\n\n return;\n }\n\n {\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'keep',\n });\n\n // Recursive processing\n for (const t of node.getTypeArguments()) {\n transformNode(t, nextReadonlyContextValue, options);\n }\n }\n};\n\n/** `tr(E[]) |-> tr(E)[]` */\nconst transformArrayTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.ArrayTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getElementTypeNode(),\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n switch (readonlyContext.type) {\n case 'DeepReadonly':\n case 'readonly':\n return; // remain tr(E)[] as is\n\n // Unnecessary `Readonly` wrapper will be remove in transformTypeReferenceNode\n case 'Readonly':\n case 'none':\n // Skip the `A[] extends B[] ? ...` union-distribution-guard idiom: adding\n // `readonly` there does not improve immutability and breaks the idiom.\n if (\n readonlyContext.indexedAccessDepth === 0 &&\n !isConditionalTypeDistributionGuard(node)\n ) {\n const readonlyText = `readonly ${node.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n }\n }\n};\n\n/** `tr([E1, E2, E3])` |-> `[tr(E1), tr(E2), tr(E3)]` */\nconst transformTupleTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TupleTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n {\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n });\n\n for (const el of node.getElements()) {\n if (el.isKind(tsm.SyntaxKind.NamedTupleMember)) {\n if (options.ignoredPrefixes.every((p) => !el.getName().startsWith(p))) {\n transformNode(el.getTypeNode(), nextReadonlyContextValue, options);\n }\n } else {\n transformNode(el, nextReadonlyContextValue, options);\n }\n }\n }\n\n switch (readonlyContext.type) {\n case 'DeepReadonly':\n case 'readonly':\n return; // remain tr(E)[] as is\n\n // Unnecessary `Readonly` wrapper will be remove in transformTypeReferenceNode\n case 'Readonly':\n case 'none':\n // Skip the `[A] extends [B] ? ...` union-distribution-guard idiom: adding\n // `readonly` there does not improve immutability and breaks the idiom.\n if (\n readonlyContext.indexedAccessDepth === 0 &&\n !isConditionalTypeDistributionGuard(node)\n ) {\n const readonlyText = `readonly ${node.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n }\n }\n};\n\n/** `tr(\"...T\")` |-> `...tr(T)` */\nconst transformRestTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.RestTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getTypeNode() /* = T */,\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n const R = removeParentheses(node.getTypeNode());\n\n // `tr(\"...readonly E[]\") |-> ...tr(E)[]`\n // `tr(\"...readonly [E1, E2]\") |-> ...[tr(E1), tr(E2)]`\n if (isReadonlyArrayTypeNode(R) || isReadonlyTupleTypeNode(R)) {\n options.replaceNode(\n node,\n `...${R.getTypeNode().getFullText()}` /* = tr(E)[] or [tr(E1), tr(E2)] */,\n );\n }\n};\n\n/**\n * - `readonly T[][] |-> readonly (readonly T[])[]`\n * - `keyof { a: number[] } |-> keyof Readonly<{ a: readonly number[] }>`\n */\nconst transformTypeOperatorNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TypeOperatorTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getTypeNode(),\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType:\n node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword\n ? 'readonly'\n : 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n switch (readonlyContext.type) {\n // DeepReadonly<readonly E[]> -> DeepReadonly<E[]>\n case 'DeepReadonly':\n options.replaceNode(node, node.getTypeNode().getFullText());\n\n return;\n\n case 'Readonly':\n case 'none':\n if (readonlyContext.indexedAccessDepth > 0) {\n options.replaceNode(node, node.getTypeNode().getFullText());\n }\n }\n};\n\n// `{ readonly member: V } |-> Readonly<{ member: V }>`\nconst transformTypeLiteralNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TypeLiteralNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (\n options.ignoreEmptyObjectTypes &&\n Arr.isArrayOfLength(node.getMembers(), 0)\n ) {\n return;\n }\n\n // Recursive processing\n transformMembers(\n node.getMembers(),\n 'remove',\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n switch (readonlyContext.type) {\n case 'DeepReadonly':\n case 'Readonly':\n // Don't wrap with Readonly if already readonly\n return;\n\n case 'none': {\n if (readonlyContext.indexedAccessDepth === 0) {\n // `{ readonly x: X, readonly y: Y } |-> Readonly<{ x: X, y: Y }>`\n options.replaceNode(node, `Readonly<${node.getFullText()}>`);\n }\n }\n }\n};\n\n/** `tr([A, B, C][I])` |-> `[tr(A), tr(B), tr(C)][I]` */\nconst transformIndexedAccessTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IndexedAccessTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getObjectTypeNode(),\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'incr',\n }),\n options,\n );\n\n transformNode(\n node.getIndexTypeNode() /* = I */,\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'Readonly',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n};\n\n/**\n * - `{ [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n * - `{ -readonly [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n * - `{ readonly [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n * - `{ +readonly [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n */\nconst transformMappedTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.MappedTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n const typeNode = node.getTypeNode();\n\n if (typeNode !== undefined) {\n transformNode(\n typeNode,\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n }\n\n const questionTokenText =\n pipe(node.getQuestionToken()?.getText()).mapNullable((t) =>\n t === '?' ? '?' : t === '-' ? '-?' : t === '+' ? '+?' : undefined,\n ).value ?? '';\n\n const result: string = pipe(\n // remove readonlyToken\n `{ [${node.getTypeParameter().getFullText()}]${questionTokenText}: ${node.getTypeNode()?.getFullText()} }`,\n ).map((mpt) =>\n match(readonlyContext.type, {\n // Don't wrap with Readonly if already readonly or unnecessary\n DeepReadonly: mpt,\n Readonly: mpt,\n none: readonlyContext.indexedAccessDepth > 0 ? mpt : `Readonly<${mpt}>`,\n }),\n ).value;\n\n options.replaceNode(node, result);\n};\n\n// Making interface members readonly\nconst transformInterfaceDeclarationNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.InterfaceDeclaration,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n for (const param of node.getTypeParameters()) {\n transformNode(param, initialReadonlyContext, options);\n }\n\n for (const n of node.getHeritageClauses()) {\n transformNode(n, initialReadonlyContext, options);\n }\n\n transformMembers(node.getMembers(), 'add', initialReadonlyContext, options);\n};\n\nconst transformClassDeclarationNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.ClassDeclaration,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n for (const n of node.getTypeParameters()) {\n transformNode(n, initialReadonlyContext, options);\n }\n\n for (const n of node.getHeritageClauses()) {\n transformNode(n, initialReadonlyContext, options);\n }\n\n for (const mb of node.getMembers()) {\n if (hasDisableNextLineComment(mb)) {\n options.debugPrint('skipped member by disable-next-line comment');\n\n continue;\n }\n\n if (mb.isKind(tsm.SyntaxKind.PropertyDeclaration)) {\n if (!checkIfPropertyNameShouldBeIgnored(mb.getNameNode(), options)) {\n mb.setIsReadonly(true);\n\n const type = mb.getTypeNode();\n\n if (type !== undefined) {\n transformNode(type, initialReadonlyContext, options);\n }\n\n const initializer = mb.getInitializer();\n\n if (initializer !== undefined) {\n transformNode(initializer, initialReadonlyContext, options);\n }\n }\n\n continue;\n }\n\n // MethodDeclaration, GetAccessorDeclaration, SetAccessorDeclaration\n // Check if method name has ignored prefix (e.g., mut_)\n if (\n (mb.isKind(tsm.SyntaxKind.MethodDeclaration) ||\n mb.isKind(tsm.SyntaxKind.GetAccessor) ||\n mb.isKind(tsm.SyntaxKind.SetAccessor)) &&\n checkIfPropertyNameShouldBeIgnored(mb.getNameNode(), options)\n ) {\n options.debugPrint('skipped method by ignored prefix');\n\n continue;\n }\n\n transformNode(mb, initialReadonlyContext, options);\n }\n\n for (const mb of node.getChildrenOfKind(tsm.SyntaxKind.IndexSignature)) {\n transformIndexSignatureDeclaration(\n mb,\n 'add',\n initialReadonlyContext,\n options,\n );\n }\n\n for (const ctor of node.getConstructors()) {\n for (const param of ctor.getParameters()) {\n transformConstructorParameter(param, options);\n }\n\n const body = ctor.getBody();\n\n if (body !== undefined) {\n transformNode(body, initialReadonlyContext, options);\n }\n }\n};\n\nconst transformConstructorParameter = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n param: tsm.ParameterDeclaration,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (hasDisableNextLineComment(param)) {\n options.debugPrint(\n 'skipped class constructor parameter by disable-next-line comment',\n );\n\n return;\n }\n\n const name = param.getName();\n\n if (options.ignoredPrefixes.some((p) => name.startsWith(p))) {\n return;\n }\n\n // Check if parameter is a property declaration (public/protected/private)\n const scope = param.getScope();\n\n // public -> public readonly\n // protected -> protected readonly\n // private -> private readonly\n if (\n scope === tsm.Scope.Public ||\n scope === tsm.Scope.Protected ||\n scope === tsm.Scope.Private\n ) {\n param.setIsReadonly(true);\n }\n\n const type = param.getTypeNode();\n\n if (type !== undefined) {\n transformNode(type, initialReadonlyContext, options);\n }\n};\n\n/**\n * - `tr(A & B) -> tr(A) & tr(B)`\n * - `tr(Readonly<A> & Readonly<B>) -> Readonly<tr(A) & tr(B)>`\n */\nconst transformIntersectionTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IntersectionTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n transformUnionOrIntersectionTypeNodeImpl(node, readonlyContext, options, '&');\n};\n\n/**\n * - `tr(A | B) |-> tr(A) | tr(B)`\n * - `tr(Readonly<A> | Readonly<B>) |-> Readonly<tr(A) | tr(B)>`\n */\nconst transformUnionTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.UnionTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n transformUnionOrIntersectionTypeNodeImpl(node, readonlyContext, options, '|');\n};\n\nconst transformUnionOrIntersectionTypeNodeImpl = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IntersectionTypeNode | tsm.UnionTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n operator: '&' | '|',\n): void => {\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'keep',\n });\n\n // Recursive processing\n for (const n of node.getTypeNodes() /* = [A, B] */) {\n transformNode(n, nextReadonlyContextValue, options);\n }\n\n const newTypes = node.getTypeNodes();\n\n const { primitives, arraysAndTuples, typeLiterals, others } =\n groupUnionIntersectionTypes(newTypes);\n\n options.debugPrint({ primitives, arraysAndTuples, typeLiterals, others });\n\n // Separate empty type literals from non-empty ones when ignoreEmptyObjectTypes is true\n const isEmptyTypeLiteral = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n n: tsm.TypeLiteralNode | ReadonlyTypeReferenceNode,\n ): boolean =>\n n.isKind(tsm.SyntaxKind.TypeLiteral) &&\n Arr.isArrayOfLength(n.getMembers(), 0);\n\n const nonEmptyTypeLiterals =\n typeLiterals === undefined\n ? undefined\n : options.ignoreEmptyObjectTypes\n ? typeLiterals.nodes.filter((n) => !isEmptyTypeLiteral(n))\n : typeLiterals.nodes;\n\n const emptyTypeLiterals =\n typeLiterals === undefined || !options.ignoreEmptyObjectTypes\n ? undefined\n : typeLiterals.nodes.filter((n) => isEmptyTypeLiteral(n));\n\n const typeLiteralsWrappedWithReadonly: readonly [] | readonly [string] =\n nonEmptyTypeLiterals === undefined ||\n Arr.isArrayOfLength(nonEmptyTypeLiterals, 0)\n ? ([] as const)\n : ([\n unionToString({\n types: nonEmptyTypeLiterals.map((n) =>\n isReadonlyTypeReferenceNode(n)\n ? // NOTE: Readonly<A & B> -> (A & B)\n unwrapReadonlyTypeArgText(n)\n : (n satisfies tsm.TypeLiteralNode).getFullText(),\n ),\n op: operator,\n wrapWithReadonly:\n nextReadonlyContextValue.type !== 'DeepReadonly' &&\n nextReadonlyContextValue.indexedAccessDepth === 0,\n }),\n ] as const);\n\n // Sort by first occurrence (preserving the original union order as much as possible)\n const sorted: readonly string[] = [\n mapNullable(\n primitives,\n (a) => [a.nodes.map((n) => n.getFullText()), a.firstPosition] as const,\n ),\n mapNullable(\n arraysAndTuples,\n (a) => [a.nodes.map((n) => n.getFullText()), a.firstPosition] as const,\n ),\n nonEmptyTypeLiterals !== undefined && Arr.isNonEmpty(nonEmptyTypeLiterals)\n ? mapNullable(\n typeLiterals,\n (a) => [typeLiteralsWrappedWithReadonly, a.firstPosition] as const,\n )\n : undefined,\n emptyTypeLiterals !== undefined && Arr.isNonEmpty(emptyTypeLiterals)\n ? mapNullable(\n typeLiterals,\n (a) =>\n [\n emptyTypeLiterals.map((n) => n.getFullText()),\n // Use a position after non-empty type literals if they exist\n a.firstPosition +\n (nonEmptyTypeLiterals !== undefined &&\n Arr.isNonEmpty(nonEmptyTypeLiterals)\n ? 0.5\n : 0),\n ] as const,\n )\n : undefined,\n mapNullable(\n others,\n (a) =>\n [\n a.nodes.map((n) => wrapWithParentheses(n.getFullText())),\n a.firstPosition,\n ] as const,\n ),\n ]\n .filter((x) => x !== undefined)\n .toSorted((a, b) => a[1] - b[1])\n .flatMap((a) => a[0]);\n\n // Readonly<number & { x: X } & { y: Y } & readonly E[]>\n // -> number & readonly E[] & Readonly<{ x: X } & { y: Y }>\n\n // Readonly<number | { x: X } | { y: Y } | readonly E[]>\n // -> number | readonly E[] | Readonly<{ x: X } | { y: Y }>\n // Readonly<number & { x: X } & { y: Y } & readonly E[]>\n // -> number & readonly E[] & Readonly<{ x: X } & { y: Y }>\n\n // Readonly<number | { x: X } | { y: Y } | readonly E[]>\n // -> number | readonly E[] | Readonly<{ x: X } | { y: Y }>\n //\n // NOTE: The result is wrapped in parentheses (via `unionToString`). This is\n // intentional and required for precedence safety: without it, a member such\n // as a function type (`() => T`), or a mix of `&` and `|`, or a `readonly`\n // operator would produce invalid syntax when this node is spliced back in.\n // Idempotency is guaranteed by `transformParenthesizedTypeNode`, which\n // collapses the redundant nesting (`((X))` -> `(X)`) this wrapping can create\n // — see the note there. That prevents the parentheses from growing without\n // bound when a union/intersection sits inside a `ParenthesizedType`.\n options.replaceNode(\n node,\n unionToString({ types: sorted, op: operator, wrapWithReadonly: false }),\n );\n};\n\nconst unionToString = ({\n types,\n op,\n wrapWithReadonly,\n}: Readonly<{\n types: readonly string[];\n op: '&' | '|';\n wrapWithReadonly: boolean | string;\n}>): string =>\n Arr.isArrayOfLength(types, 0)\n ? 'never'\n : Arr.isArrayOfLength(types, 1)\n ? wrapWithReadonly === false\n ? wrapWithParentheses(types[0])\n : (`${isString(wrapWithReadonly) ? wrapWithReadonly : 'Readonly'}<${types[0]}>` as const)\n : wrapWithReadonly === false\n ? wrapWithParentheses(types.join(` ${op} `))\n : (`${isString(wrapWithReadonly) ? wrapWithReadonly : 'Readonly'}<${types.join(` ${op} `)}>` as const);\n\n/** Convert ((T)) -> (T) recursively */\nconst transformParenthesizedTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.ParenthesizedTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n const typeNode = node.getTypeNode();\n\n if (typeNode.isKind(tsm.SyntaxKind.ParenthesizedType)) {\n // Recursive processing\n transformParenthesizedTypeNode(typeNode, readonlyContext, options);\n }\n\n transformNode(node.getTypeNode(), readonlyContext, options);\n\n const T = node.getTypeNode();\n\n if (\n // remove () if T is TypeReferenceNode\n // e.g. `(Readonly<A>) |-> Readonly<A>`\n T.isKind(tsm.SyntaxKind.TypeReference) ||\n // remove () if T is ArrayTypeNode\n // e.g. `(A[]) |-> A[]`\n T.isKind(tsm.SyntaxKind.ArrayType) ||\n // remove () if T is TupleTypeNode\n // e.g. `([A]) |-> [A]`\n T.isKind(tsm.SyntaxKind.TupleType) ||\n // remove () if T is PrimitiveTypeNode\n // e.g. `(number) |-> number`\n isAtomicTypeNode(T) ||\n // remove () if T is TypeLiteralNode\n // e.g. `({ member: V }) |-> { member: V }`\n T.isKind(tsm.SyntaxKind.TypeLiteral) ||\n // collapse redundant nested parentheses if T is itself a ParenthesizedType\n // e.g. `((X)) |-> (X)`\n //\n // This is what makes the transform terminate on nested parentheses. The\n // union/intersection handler defensively wraps its result in parentheses\n // for precedence safety, which turns `(A | B)` into `((A | B))` when the\n // union already sits inside a `ParenthesizedType`. Collapsing the redundant\n // outer layer here means each pass removes exactly the layer the wrapping\n // added, so the parentheses no longer grow without bound (which previously\n // overflowed the parser stack on inputs like `type T = (('a' | 'b'))`).\n T.isKind(tsm.SyntaxKind.ParenthesizedType)\n ) {\n options.replaceNode(node, T.getFullText());\n }\n};\n\n/**\n * `tr([\"member1: V1\", \"member2: V2\", \"member3: V3\"])`\n *\n * -> `[\"member1: tr(V1)\", \"member2: tr(V2)\", \"member3: tr(V3)\"]`\n */\nconst transformMembers = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n members: readonly tsm.TypeElementTypes[],\n readonlyModifier: 'add' | 'remove',\n readonlyContext: Extract<\n ReadonlyContext,\n Readonly<{\n type: 'DeepReadonly' | 'none';\n indexedAccessDepth: SafeUintWithSmallInt;\n }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n for (const mb of members) {\n if (hasDisableNextLineComment(mb)) {\n options.debugPrint('skipped by member disable-next-line comment');\n\n continue;\n }\n\n if (mb.isKind(tsm.SyntaxKind.PropertySignature)) {\n if (!checkIfPropertyNameShouldBeIgnored(mb.getNameNode(), options)) {\n transformPropertySignature(\n mb,\n readonlyModifier,\n readonlyContext,\n options,\n );\n }\n\n continue;\n }\n\n if (mb.isKind(tsm.SyntaxKind.IndexSignature)) {\n transformIndexSignatureDeclaration(\n mb,\n readonlyModifier,\n readonlyContext,\n options,\n );\n\n continue;\n }\n\n transformNode(mb, readonlyContext, options);\n\n continue;\n }\n};\n\nconst transformPropertySignature = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.PropertySignature,\n readonlyModifier: 'add' | 'remove',\n readonlyContext: Extract<\n ReadonlyContext,\n Readonly<{\n type: 'DeepReadonly' | 'none';\n indexedAccessDepth: SafeUintWithSmallInt;\n }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (\n readonlyContext.type === 'DeepReadonly' ||\n readonlyModifier === 'remove'\n ) {\n node.setIsReadonly(false);\n } else {\n node.setIsReadonly(true);\n }\n\n {\n const type = node.getTypeNode();\n\n if (type !== undefined) {\n transformNode(type, readonlyContext, options);\n }\n }\n};\n\nconst transformIndexSignatureDeclaration = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IndexSignatureDeclaration,\n readonlyModifier: 'add' | 'remove',\n readonlyContext: Extract<\n ReadonlyContext,\n Readonly<{\n type: 'DeepReadonly' | 'none';\n indexedAccessDepth: SafeUintWithSmallInt;\n }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (hasDisableNextLineComment(node, TRANSFORMER_NAME)) {\n options.debugPrint('skipped index signature by disable-next-line comment');\n\n return;\n }\n\n if (\n readonlyContext.type === 'DeepReadonly' ||\n readonlyModifier === 'remove'\n ) {\n // node.setIsReadonly(false);\n node.toggleModifier('readonly', false);\n } else {\n node.toggleModifier('readonly', true);\n // node.setIsReadonly(true);\n }\n\n {\n const key = node.getKeyTypeNode();\n\n transformNode(key, readonlyContext, options);\n }\n\n {\n const ret = node.getReturnTypeNode();\n\n if (ret !== undefined) {\n transformNode(ret, readonlyContext, options);\n }\n }\n};\n\nconst checkIfPropertyNameShouldBeIgnored = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n nameNode: tsm.PropertyName,\n options: ReadonlyTransformerOptionsInternal,\n): boolean => {\n expectType<typeof nameNode, tsm.PropertyName>('=');\n\n expectType<\n tsm.PropertyName,\n | tsm.NumericLiteral\n | tsm.BigIntLiteral\n | tsm.NoSubstitutionTemplateLiteral\n | tsm.Identifier\n | tsm.StringLiteral\n | tsm.PrivateIdentifier\n | tsm.ComputedPropertyName // [`mut_x`]: number[]\n >('=');\n\n return (\n // mut_x: number[]\n (nameNode.isKind(tsm.SyntaxKind.Identifier) &&\n pipe(nameNode.getText()).map((nm) =>\n options.ignoredPrefixes.some((p) => nm.startsWith(p)),\n ).value) ||\n // \"mut_x\": number[]\n (nameNode.isKind(tsm.SyntaxKind.StringLiteral) &&\n pipe(nameNode.getLiteralValue()).map((nm) =>\n options.ignoredPrefixes.some((p) => nm.startsWith(p)),\n ).value) ||\n // #memberName: number[] (class only)\n (nameNode.isKind(tsm.SyntaxKind.PrivateIdentifier) &&\n pipe(nameNode.getText()).map((nm) =>\n options.ignoredPrefixes.some((p) => nm.startsWith(`#${p}`)),\n ).value) ||\n // [`mut_x`]: number[]\n (nameNode.isKind(tsm.SyntaxKind.ComputedPropertyName) &&\n pipe(nameNode.getExpression()).map((exp) => {\n if (exp.isKind(tsm.SyntaxKind.StringLiteral)) {\n const nm = exp.getLiteralValue();\n\n return options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AQ,eAAA,CAAgB,IAAA,CAAK,CAAC,CAAA,KAAM,EAAA,CAAG,UAAA,CAAW,CAAC,CAAC;AAAA,KACtD,CAAE,KAAA;AAAA,IAEH,QAAA,CAAS,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,iBAAiB,KAC/C,IAAA,CAAK,QAAA,CAAS,OAAA,EAAS,CAAA,CAAE,GAAA;AAAA,MAAI,CAAC,EAAA,KAC5B,OAAA,CAAQ,eAAA,CAAgB,IAAA,CAAK,CAAC,CAAA,KAAM,EAAA,CAAG,UAAA,CAAW,CAAA,CAAA,EAAI,CAAC,CAAA,CAAE,CAAC;AAAA,KAC5D,CAAE,KAAA;AAAA,IAEH,QAAA,CAAS,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,oBAAoB,CAAA,IAClD,IAAA,CAAK,QAAA,CAAS,aAAA,EAAe,CAAA,CAAE,GAAA,CAAI,CAAC,GAAA,KAAQ;AAC1C,MAAA,IAAI,GAAA,CAAI,MAAA,CAAO,GAAA,CAAI,UAAA,CAAW,aAAa,CAAA,EAAG;AAC5C,QAAA,MAAM,EAAA,GAAK,IAAI,eAAA,EAAgB;AAE/B,QAAA,OAAO,OAAA,CAAQ,gBAAgB,IAAA,CAAK,CAAC,MAAM,EAAA,CAAG,UAAA,CAAW,CAAC,CAAC,CAAA;AAAA,MAAA;AAG7D,MAAA,OAAO,KAAA;AAAA,IAAA,CACR,CAAA,CAAE;AAAA;AAET,CAAA;;;;"}
1
+ {"version":3,"file":"convert-to-readonly.mjs","sources":["../../../src/functions/ast-transformers/convert-to-readonly.mts"],"sourcesContent":["import {\n Arr,\n expectType,\n ISet,\n isString,\n mapNullable,\n match,\n pipe,\n} from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { type DeepReadonly, type SafeUintWithSmallInt } from 'ts-type-forge';\nimport {\n hasDisableNextLineComment,\n isAtomicTypeNode,\n isConditionalTypeDistributionGuard,\n isReadonlyArrayTypeNode,\n isReadonlyTupleOrArrayTypeNode,\n isReadonlyTupleTypeNode,\n isReadonlyTypeReferenceNode,\n removeParentheses,\n shouldAvoidParenthesesForReadonly,\n unwrapReadonlyTypeArgText,\n wrapWithParentheses,\n type ReadonlyTypeReferenceNode,\n} from '../functions/index.mjs';\nimport { replaceNodeWithDebugPrint } from '../utils/index.mjs';\nimport {\n groupUnionIntersectionTypes,\n invalidDeepReadonlyTypeName,\n nextReadonlyContext,\n type ReadonlyContext,\n} from './readonly-transformer-helpers/index.mjs';\nimport { type TsMorphTransformer } from './types.mjs';\n\nconst TRANSFORMER_NAME = 'convert-to-readonly';\n\nexport const convertToReadonlyTransformer = (\n options?: ReadonlyTransformerOptions,\n): TsMorphTransformer => {\n if (\n options?.DeepReadonly?.typeName !== undefined &&\n invalidDeepReadonlyTypeName.has(options.DeepReadonly.typeName)\n ) {\n throw new Error(\n `Invalid DeepReadonly typeName \"${options.DeepReadonly.typeName}\" passed to convertToReadonlyType`,\n );\n }\n\n const DeepReadonlyTypeName =\n options?.DeepReadonly?.typeName ?? 'DeepReadonly';\n\n const ignorePrefixes = ISet.create(\n options?.ignorePrefixes ?? ['mut_', '#mut_', '_mut_', 'draft'],\n );\n\n const optionsInternal: ReadonlyTransformerOptionsInternal = {\n DeepReadonly: {\n typeName: DeepReadonlyTypeName,\n applyLevel: 'keep',\n },\n ignoreEmptyObjectTypes: options?.ignoreEmptyObjectTypes ?? true,\n ignoredPrefixes: ignorePrefixes,\n debugPrint: options?.debug === true ? console.debug : () => {},\n replaceNode:\n options?.debug === true\n ? replaceNodeWithDebugPrint\n : (node, newNodeText) => node.replaceWithText(newNodeText),\n } as const;\n\n return {\n name: TRANSFORMER_NAME,\n transform: (sourceAst) => {\n for (const node of sourceAst.getChildren()) {\n transformNode(node, initialReadonlyContext, optionsInternal);\n }\n },\n };\n};\n\nexport type ReadonlyTransformerOptions = DeepReadonly<{\n /**\n * Options for a type utility `DeepReadonly` that recursively applies readonly.\n */\n DeepReadonly?: {\n /**\n * The name of a type utility that recursively applies `Readonly`.\n *\n * @default \"DeepReadonly\"\n */\n typeName?: string;\n\n /**\n * Whether to apply `DeepReadonly` aggressively or remove `DeepReadonly` as\n * possible.\n *\n * If `applyLevel` is `\"applyAggressively\"`, it applies `DeepReadonly` to all\n * nested type literals without external type references. For example, the\n * following conversions are applied:\n *\n * - `number[][]` to be `DeepReadonly<number[][]>`\n * - `number[]` to be `readonly number[]`\n * - `<T>(arg: T[][]) => void` to be `<T>(arg: readonly (readonly T[])[]>) =>\n * void`\n *\n * If `applyLevel` is `\"removeAsPossible\"`, the following conversions are applied:\n *\n * - `DeepReadonly<number[][]>` to be `readonly (readonly number[])[]`\n * - `DeepReadonly<{ a: number[] }>` to be `Readonly<{ a: readonly number[]\n * }>`\n * - `<T>(arg: DeepReadonly<T[][]>) => void` to be `<T>(arg:\n * DeepReadonly<T[][]>) => void`\n *\n * @default 'keep'\n */\n // TODO\n // applyLevel?: 'applyAggressively' | 'keep' | 'removeAsPossible';\n };\n\n /**\n * Ignore the readonly conversion for `{}`.\n *\n * @default true\n */\n ignoreEmptyObjectTypes?: boolean;\n\n /**\n * A mute keywords to ignore the readonly conversion.\n *\n * (e.g. `\"mut_\"`)\n *\n * @default ['mut_', '#mut_', '_mut_', 'draft']\n */\n ignorePrefixes?: string[];\n\n debug?: boolean;\n}>;\n\ntype ReadonlyTransformerOptionsInternal = Readonly<{\n DeepReadonly: Readonly<{\n typeName: string;\n\n // removeAsPossible: 正規化後、 DeepReadonly の子ノードが typeLiteral かまたはその union or intersection であり、 それぞれの TypeLiteral がプリミティブ値のメンバーしか持たない場合。\n applyLevel: 'applyAggressively' | 'keep' | 'removeAsPossible';\n }>;\n\n ignoreEmptyObjectTypes: boolean;\n\n ignoredPrefixes: ISet<string>;\n\n debugPrint: (...args: readonly unknown[]) => void;\n replaceNode: (node: tsm.Node, newNodeText: string) => void;\n}>;\n\nconst initialReadonlyContext: ReadonlyContext = {\n type: 'none',\n indexedAccessDepth: 0,\n} as const;\n\nconst transformNode = (\n node: tsm.Node,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (\n tsm.Node.isTypeNode(node) ||\n node.isKind(tsm.SyntaxKind.InterfaceDeclaration) ||\n node.isKind(tsm.SyntaxKind.ClassDeclaration)\n ) {\n options.debugPrint();\n\n options.debugPrint(`transformNode [${node.getKindName()}] `);\n\n options.debugPrint(node.getFullText());\n\n options.debugPrint({ readonlyContext });\n\n options.debugPrint();\n }\n\n if (hasDisableNextLineComment(node, TRANSFORMER_NAME)) {\n options.debugPrint('skipped by disable-next-line comment');\n\n return;\n }\n\n // check for ignorePrefix\n if (node.isKind(tsm.SyntaxKind.VariableDeclaration)) {\n const nodeName = node.getName();\n\n if (options.ignoredPrefixes.some((p) => nodeName.startsWith(p))) {\n // Skip conversion for variable declarations with ignored prefixes\n // Example: const mut_foo: string[] = []; -> remains as is, without appending `as const`\n options.debugPrint('skipped variable declaration by ignorePrefixes');\n\n return;\n }\n\n // TODO: Support ignoredPrefixes in ArrayBindingPattern\n // if (ts.isArrayBindingPattern(nodeName)) {\n // // for (const [i, el] of nodeName.elements.entries())\n // }\n\n // TODO: Support ignoredPrefixes in ObjectBindingPattern\n // if (ts.isObjectBindingPattern(nodeName)) {\n // // for (const [i, el] of nodeName.elements.entries())\n // }\n }\n\n // Skip readonly conversion for function declarations with ignored prefixes\n // Example: function mut_foo() {} -> parameters and return types remain as is\n if (\n (node.isKind(tsm.SyntaxKind.FunctionDeclaration) ||\n node.isKind(tsm.SyntaxKind.FunctionExpression)) &&\n options.ignoredPrefixes.some((p) => node.getName()?.startsWith(p) === true)\n ) {\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.Parameter)) {\n const nodeName = node.getName();\n\n if (options.ignoredPrefixes.some((p) => nodeName.startsWith(p))) {\n // Skip readonly conversion for variable declarations with ignored prefixes\n // Example: const mut_foo: string[] = []; -> remains as is, without readonly conversion\n return;\n }\n\n // TODO: Support ignoredPrefixes in ArrayBindingPattern\n // if (ts.isArrayBindingPattern(nodeName)) {\n // }\n\n // TODO: Support ignoredPrefixes in ObjectBindingPattern\n // if (ts.isObjectBindingPattern(nodeName)) {\n // }\n }\n\n // Skip readonly conversion for type alias declarations with ignored prefixes\n // Example: type mut_Foo = number[]; -> remains as number[] without readonly\n if (\n node.isKind(tsm.SyntaxKind.TypeAliasDeclaration) &&\n options.ignoredPrefixes.some((p) => node.getName().startsWith(p))\n ) {\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TypeReference)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to TypeReferenceNode',\n );\n }\n\n transformTypeReferenceNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.ArrayType)) {\n transformArrayTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TupleType)) {\n transformTupleTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.RestType)) {\n transformRestTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TypeOperator)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to TypeOperatorNode',\n );\n }\n\n transformTypeOperatorNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.TypeLiteral)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to TypeLiteralNode',\n );\n }\n\n transformTypeLiteralNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.IndexedAccessType)) {\n transformIndexedAccessTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.MappedType)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to MappedTypeNode',\n );\n }\n\n transformMappedTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.InterfaceDeclaration)) {\n // Skip readonly conversion for interface declarations with ignored prefixes\n // Example: interface mut_Interface {...} -> properties remain without readonly\n if (options.ignoredPrefixes.some((p) => node.getName().startsWith(p))) {\n return;\n }\n\n transformInterfaceDeclarationNode(node, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.ClassDeclaration)) {\n // Skip readonly conversion for class declarations with ignored prefixes\n // Example: class mut_Class {...} -> properties remain without readonly\n if (\n options.ignoredPrefixes.some(\n (p) => node.getName()?.startsWith(p) === true,\n )\n ) {\n return;\n }\n\n transformClassDeclarationNode(node, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.IntersectionType)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to IntersectionTypeNode',\n );\n }\n\n transformIntersectionTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.UnionType)) {\n if (readonlyContext.type === 'readonly') {\n throw new Error(\n 'Invalid readonlyContext \"readonly\" passed to UnionTypeNode',\n );\n }\n\n transformUnionTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n if (node.isKind(tsm.SyntaxKind.ParenthesizedType)) {\n // NOTE: readonlyContext を不変のままバケツリレーさせるためにこのケースも必要\n transformParenthesizedTypeNode(node, readonlyContext, options);\n\n return;\n }\n\n for (const child of node.getChildren()) {\n transformNode(child, initialReadonlyContext, options);\n }\n};\n\n//\n// Transformer implementation for each node type\n//\n\n/**\n * - `tr(ReadonlyArray<E>) |-> readonly tr(E)[]`\n * - `tr(Readonly<Readonly<E>>) |-> Readonly<tr(E)>`\n * - `tr(DeepReadonly<Readonly<E>>) |-> DeepReadonly<tr(E)>`\n * - `tr(Readonly<number>) |-> number`\n * - `tr(Readonly<E[]>) |-> readonly tr(E)[]`\n * - `tr(Readonly<[E1, E2, E3]>) |-> readonly [tr(E1), tr(E2), tr(E3)]`\n * - `tr(Readonly<readonly E[]>) |-> readonly tr(E)[]`\n * - `tr(Readonly<readonly [E1, E2, E3]>) |-> readonly [tr(E1), tr(E2), tr(E3)]`\n * - `tr(Readonly<A | readonly E[]>) |-> Readonly<tr(A)> | readonly tr(E)[]>`\n */\nconst transformTypeReferenceNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TypeReferenceNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n const typeNameStr = node.getTypeName().getText();\n\n const typeArguments = node.getTypeArguments();\n\n // Array<T> / ReadonlyArray<T> to readonly T[]\n if (typeNameStr === 'Array' || typeNameStr === 'ReadonlyArray') {\n if (!Arr.isFixedLengthArray(1, typeArguments)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for ${typeNameStr}.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n {\n type: 'none',\n indexedAccessDepth: readonlyContext.indexedAccessDepth,\n },\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = node.getTypeArguments()[0]!;\n\n options.replaceNode(\n node,\n readonlyContext.type === 'DeepReadonly'\n ? wrapWithParentheses(`${wrapWithParentheses(T.getFullText())}[]`)\n : wrapWithParentheses(\n `readonly ${wrapWithParentheses(T.getFullText())}[]`,\n ),\n );\n\n return;\n }\n\n // Set<T> to ReadonlySet<T>\n if (typeNameStr === 'Set') {\n if (!Arr.isFixedLengthArray(1, typeArguments)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Set.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n {\n type: 'none',\n indexedAccessDepth: readonlyContext.indexedAccessDepth,\n },\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = node.getTypeArguments()[0]!;\n\n options.replaceNode(node, `ReadonlySet<${T.getFullText()}>`);\n\n return;\n }\n\n // Map<T> to ReadonlyMap<T>\n if (typeNameStr === 'Map') {\n if (!Arr.isFixedLengthArray(2, typeArguments)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Map.`,\n );\n }\n\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'keep',\n });\n\n // Recursive processing\n for (const t of typeArguments) {\n transformNode(t, nextReadonlyContextValue, options);\n }\n\n const [K, V] = node.getTypeArguments();\n\n options.replaceNode(\n node,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n `ReadonlyMap<${K!.getFullText()}, ${V!.getFullText()}>`,\n );\n\n return;\n }\n\n // remove unnecessary `Readonly` wrapper or convert to readonly operator\n if (typeNameStr === 'Readonly') {\n if (!Arr.isFixedLengthArray(1, typeArguments)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Readonly.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'Readonly',\n indexedAccessDepthChange: 'keep',\n }),\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = removeParentheses(node.getTypeArguments()[0]!);\n\n // DeepReadonly<Readonly<T>> -> DeepReadonly<T>\n if (readonlyContext.type === 'DeepReadonly') {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<{ ... }>[I] -> { ... }[I]\n if (readonlyContext.indexedAccessDepth > 0) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<Readonly<T>> -> Readonly<T>\n if (isReadonlyTypeReferenceNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<number> -> number\n if (isAtomicTypeNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // T = E[]\n // Readonly<E[]> -> readonly E[]\n //\n // T = [E1, E2, E3]\n // Readonly<[E1, E2, E3]> -> readonly [E1, E2, E3]\n if (\n T.isKind(tsm.SyntaxKind.ArrayType) ||\n T.isKind(tsm.SyntaxKind.TupleType)\n ) {\n const readonlyText = `readonly ${T.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n\n return;\n }\n\n // T = readonly E[] or readonly [E1, E2, E3]\n // Readonly<readonly E[]> -> readonly E[]\n // Readonly<readonly [E1, E2, E3]> -> readonly [E1, E2, E3]\n if (isReadonlyTupleOrArrayTypeNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // T = A | B | C\n // T = A & B & C\n if (\n T.isKind(tsm.SyntaxKind.UnionType) ||\n T.isKind(tsm.SyntaxKind.IntersectionType)\n ) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n return;\n }\n\n // DeepReadonly\n if (typeNameStr === options.DeepReadonly.typeName) {\n if (!Arr.isFixedLengthArray(1, typeArguments)) {\n throw new Error(\n `Unexpected number of type arguments \"${typeArguments.length}\" for Readonly.`,\n );\n }\n\n // Recursive processing\n transformNode(\n typeArguments[0],\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'DeepReadonly',\n }),\n options,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const T = node.getTypeArguments()[0]!;\n\n // DeepReadonly<DeepReadonly<T>> -> DeepReadonly<T>\n if (readonlyContext.type === 'DeepReadonly') {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // Readonly<number> -> number\n if (isAtomicTypeNode(T)) {\n options.replaceNode(node, T.getFullText());\n\n return;\n }\n\n // T = P[]\n // DeepReadonly<P[]> -> readonly P[] (for primitive type arrays, convert to readonly P[] form)\n // DeepReadonly<O[]> -> DeepReadonly<O[]> (for object type arrays, keep as is to recursively apply Readonly)\n // DeepReadonly<P[][]> -> DeepReadonly<P[][]>\n if (\n T.isKind(tsm.SyntaxKind.ArrayType) &&\n isAtomicTypeNode(T.getElementTypeNode())\n ) {\n const readonlyText = `readonly ${T.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n\n return;\n }\n\n // T = [P1, P2, P3]\n // DeepReadonly<[P1, P2, P3]> -> readonly [P1, P2, P3]\n if (\n T.isKind(tsm.SyntaxKind.TupleType) &&\n T.getElements().every(isAtomicTypeNode)\n ) {\n const readonlyText = `readonly ${T.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n\n return;\n }\n\n return;\n }\n\n {\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'keep',\n });\n\n // Recursive processing\n for (const t of node.getTypeArguments()) {\n transformNode(t, nextReadonlyContextValue, options);\n }\n }\n};\n\n/** `tr(E[]) |-> tr(E)[]` */\nconst transformArrayTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.ArrayTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getElementTypeNode(),\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n switch (readonlyContext.type) {\n case 'DeepReadonly':\n case 'readonly':\n return; // remain tr(E)[] as is\n\n // Unnecessary `Readonly` wrapper will be remove in transformTypeReferenceNode\n case 'Readonly':\n case 'none':\n // Skip the `A[] extends B[] ? ...` union-distribution-guard idiom: adding\n // `readonly` there does not improve immutability and breaks the idiom.\n if (\n readonlyContext.indexedAccessDepth === 0 &&\n !isConditionalTypeDistributionGuard(node)\n ) {\n const readonlyText = `readonly ${node.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n }\n }\n};\n\n/** `tr([E1, E2, E3])` |-> `[tr(E1), tr(E2), tr(E3)]` */\nconst transformTupleTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TupleTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n {\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n });\n\n for (const el of node.getElements()) {\n if (el.isKind(tsm.SyntaxKind.NamedTupleMember)) {\n if (options.ignoredPrefixes.every((p) => !el.getName().startsWith(p))) {\n transformNode(el.getTypeNode(), nextReadonlyContextValue, options);\n }\n } else {\n transformNode(el, nextReadonlyContextValue, options);\n }\n }\n }\n\n switch (readonlyContext.type) {\n case 'DeepReadonly':\n case 'readonly':\n return; // remain tr(E)[] as is\n\n // Unnecessary `Readonly` wrapper will be remove in transformTypeReferenceNode\n case 'Readonly':\n case 'none':\n // Skip the `[A] extends [B] ? ...` union-distribution-guard idiom: adding\n // `readonly` there does not improve immutability and breaks the idiom.\n if (\n readonlyContext.indexedAccessDepth === 0 &&\n !isConditionalTypeDistributionGuard(node)\n ) {\n const readonlyText = `readonly ${node.getFullText()}` as const;\n\n options.replaceNode(\n node,\n shouldAvoidParenthesesForReadonly(node)\n ? readonlyText\n : wrapWithParentheses(readonlyText),\n );\n }\n }\n};\n\n/** `tr(\"...T\")` |-> `...tr(T)` */\nconst transformRestTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.RestTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getTypeNode() /* = T */,\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n const R = removeParentheses(node.getTypeNode());\n\n // `tr(\"...readonly E[]\") |-> ...tr(E)[]`\n // `tr(\"...readonly [E1, E2]\") |-> ...[tr(E1), tr(E2)]`\n if (isReadonlyArrayTypeNode(R) || isReadonlyTupleTypeNode(R)) {\n options.replaceNode(\n node,\n `...${R.getTypeNode().getFullText()}` /* = tr(E)[] or [tr(E1), tr(E2)] */,\n );\n }\n};\n\n/**\n * - `readonly T[][] |-> readonly (readonly T[])[]`\n * - `keyof { a: number[] } |-> keyof Readonly<{ a: readonly number[] }>`\n */\nconst transformTypeOperatorNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TypeOperatorTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getTypeNode(),\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType:\n node.getOperator() === tsm.SyntaxKind.ReadonlyKeyword\n ? 'readonly'\n : 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n switch (readonlyContext.type) {\n // DeepReadonly<readonly E[]> -> DeepReadonly<E[]>\n case 'DeepReadonly':\n options.replaceNode(node, node.getTypeNode().getFullText());\n\n return;\n\n case 'Readonly':\n case 'none':\n if (readonlyContext.indexedAccessDepth > 0) {\n options.replaceNode(node, node.getTypeNode().getFullText());\n }\n }\n};\n\n// `{ readonly member: V } |-> Readonly<{ member: V }>`\nconst transformTypeLiteralNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.TypeLiteralNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (options.ignoreEmptyObjectTypes && Arr.isEmpty(node.getMembers())) {\n return;\n }\n\n // Recursive processing\n transformMembers(\n node.getMembers(),\n 'remove',\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n\n switch (readonlyContext.type) {\n case 'DeepReadonly':\n case 'Readonly':\n // Don't wrap with Readonly if already readonly\n return;\n\n case 'none': {\n if (readonlyContext.indexedAccessDepth === 0) {\n // `{ readonly x: X, readonly y: Y } |-> Readonly<{ x: X, y: Y }>`\n options.replaceNode(node, `Readonly<${node.getFullText()}>`);\n }\n }\n }\n};\n\n/** `tr([A, B, C][I])` |-> `[tr(A), tr(B), tr(C)][I]` */\nconst transformIndexedAccessTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IndexedAccessTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n // Recursive processing\n transformNode(\n node.getObjectTypeNode(),\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'incr',\n }),\n options,\n );\n\n transformNode(\n node.getIndexTypeNode() /* = I */,\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'Readonly',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n};\n\n/**\n * - `{ [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n * - `{ -readonly [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n * - `{ readonly [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n * - `{ +readonly [key in Obj]: V }` -> `Readonly<{ [key in Obj]: V }>`\n */\nconst transformMappedTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.MappedTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n const typeNode = node.getTypeNode();\n\n if (typeNode !== undefined) {\n transformNode(\n typeNode,\n nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'decr',\n }),\n options,\n );\n }\n\n const questionTokenText =\n pipe(node.getQuestionToken()?.getText()).mapNullable((t) =>\n t === '?' ? '?' : t === '-' ? '-?' : t === '+' ? '+?' : undefined,\n ).value ?? '';\n\n const result: string = pipe(\n // remove readonlyToken\n `{ [${node.getTypeParameter().getFullText()}]${questionTokenText}: ${node.getTypeNode()?.getFullText()} }`,\n ).map((mpt) =>\n match(readonlyContext.type, {\n // Don't wrap with Readonly if already readonly or unnecessary\n DeepReadonly: mpt,\n Readonly: mpt,\n none: readonlyContext.indexedAccessDepth > 0 ? mpt : `Readonly<${mpt}>`,\n }),\n ).value;\n\n options.replaceNode(node, result);\n};\n\n// Making interface members readonly\nconst transformInterfaceDeclarationNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.InterfaceDeclaration,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n for (const param of node.getTypeParameters()) {\n transformNode(param, initialReadonlyContext, options);\n }\n\n for (const n of node.getHeritageClauses()) {\n transformNode(n, initialReadonlyContext, options);\n }\n\n transformMembers(node.getMembers(), 'add', initialReadonlyContext, options);\n};\n\nconst transformClassDeclarationNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.ClassDeclaration,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n for (const n of node.getTypeParameters()) {\n transformNode(n, initialReadonlyContext, options);\n }\n\n for (const n of node.getHeritageClauses()) {\n transformNode(n, initialReadonlyContext, options);\n }\n\n for (const mb of node.getMembers()) {\n if (hasDisableNextLineComment(mb)) {\n options.debugPrint('skipped member by disable-next-line comment');\n\n continue;\n }\n\n if (mb.isKind(tsm.SyntaxKind.PropertyDeclaration)) {\n if (!checkIfPropertyNameShouldBeIgnored(mb.getNameNode(), options)) {\n mb.setIsReadonly(true);\n\n const type = mb.getTypeNode();\n\n if (type !== undefined) {\n transformNode(type, initialReadonlyContext, options);\n }\n\n const initializer = mb.getInitializer();\n\n if (initializer !== undefined) {\n transformNode(initializer, initialReadonlyContext, options);\n }\n }\n\n continue;\n }\n\n // MethodDeclaration, GetAccessorDeclaration, SetAccessorDeclaration\n // Check if method name has ignored prefix (e.g., mut_)\n if (\n (mb.isKind(tsm.SyntaxKind.MethodDeclaration) ||\n mb.isKind(tsm.SyntaxKind.GetAccessor) ||\n mb.isKind(tsm.SyntaxKind.SetAccessor)) &&\n checkIfPropertyNameShouldBeIgnored(mb.getNameNode(), options)\n ) {\n options.debugPrint('skipped method by ignored prefix');\n\n continue;\n }\n\n transformNode(mb, initialReadonlyContext, options);\n }\n\n for (const mb of node.getChildrenOfKind(tsm.SyntaxKind.IndexSignature)) {\n transformIndexSignatureDeclaration(\n mb,\n 'add',\n initialReadonlyContext,\n options,\n );\n }\n\n for (const ctor of node.getConstructors()) {\n for (const param of ctor.getParameters()) {\n transformConstructorParameter(param, options);\n }\n\n const body = ctor.getBody();\n\n if (body !== undefined) {\n transformNode(body, initialReadonlyContext, options);\n }\n }\n};\n\nconst transformConstructorParameter = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n param: tsm.ParameterDeclaration,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (hasDisableNextLineComment(param)) {\n options.debugPrint(\n 'skipped class constructor parameter by disable-next-line comment',\n );\n\n return;\n }\n\n const name = param.getName();\n\n if (options.ignoredPrefixes.some((p) => name.startsWith(p))) {\n return;\n }\n\n // Check if parameter is a property declaration (public/protected/private)\n const scope = param.getScope();\n\n // public -> public readonly\n // protected -> protected readonly\n // private -> private readonly\n if (\n scope === tsm.Scope.Public ||\n scope === tsm.Scope.Protected ||\n scope === tsm.Scope.Private\n ) {\n param.setIsReadonly(true);\n }\n\n const type = param.getTypeNode();\n\n if (type !== undefined) {\n transformNode(type, initialReadonlyContext, options);\n }\n};\n\n/**\n * - `tr(A & B) -> tr(A) & tr(B)`\n * - `tr(Readonly<A> & Readonly<B>) -> Readonly<tr(A) & tr(B)>`\n */\nconst transformIntersectionTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IntersectionTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n transformUnionOrIntersectionTypeNodeImpl(node, readonlyContext, options, '&');\n};\n\n/**\n * - `tr(A | B) |-> tr(A) | tr(B)`\n * - `tr(Readonly<A> | Readonly<B>) |-> Readonly<tr(A) | tr(B)>`\n */\nconst transformUnionTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.UnionTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n transformUnionOrIntersectionTypeNodeImpl(node, readonlyContext, options, '|');\n};\n\nconst transformUnionOrIntersectionTypeNodeImpl = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IntersectionTypeNode | tsm.UnionTypeNode,\n readonlyContext: Exclude<\n ReadonlyContext,\n Readonly<{ type: 'readonly'; indexedAccessDepth: SafeUintWithSmallInt }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n operator: '&' | '|',\n): void => {\n const nextReadonlyContextValue = nextReadonlyContext({\n currentReadonlyContext: readonlyContext,\n nextReadonlyContextType: 'none',\n indexedAccessDepthChange: 'keep',\n });\n\n // Recursive processing\n for (const n of node.getTypeNodes() /* = [A, B] */) {\n transformNode(n, nextReadonlyContextValue, options);\n }\n\n const newTypes = node.getTypeNodes();\n\n const { primitives, arraysAndTuples, typeLiterals, others } =\n groupUnionIntersectionTypes(newTypes);\n\n options.debugPrint({ primitives, arraysAndTuples, typeLiterals, others });\n\n // Separate empty type literals from non-empty ones when ignoreEmptyObjectTypes is true\n const isEmptyTypeLiteral = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n n: tsm.TypeLiteralNode | ReadonlyTypeReferenceNode,\n ): boolean =>\n n.isKind(tsm.SyntaxKind.TypeLiteral) && Arr.isEmpty(n.getMembers());\n\n const nonEmptyTypeLiterals =\n typeLiterals === undefined\n ? undefined\n : options.ignoreEmptyObjectTypes\n ? typeLiterals.nodes.filter((n) => !isEmptyTypeLiteral(n))\n : typeLiterals.nodes;\n\n const emptyTypeLiterals =\n typeLiterals === undefined || !options.ignoreEmptyObjectTypes\n ? undefined\n : typeLiterals.nodes.filter(isEmptyTypeLiteral);\n\n const typeLiteralsWrappedWithReadonly: readonly [] | readonly [string] =\n nonEmptyTypeLiterals === undefined || Arr.isEmpty(nonEmptyTypeLiterals)\n ? ([] as const)\n : ([\n unionToString({\n types: nonEmptyTypeLiterals.map((n) =>\n isReadonlyTypeReferenceNode(n)\n ? // NOTE: Readonly<A & B> -> (A & B)\n unwrapReadonlyTypeArgText(n)\n : (n satisfies tsm.TypeLiteralNode).getFullText(),\n ),\n op: operator,\n wrapWithReadonly:\n nextReadonlyContextValue.type !== 'DeepReadonly' &&\n nextReadonlyContextValue.indexedAccessDepth === 0,\n }),\n ] as const);\n\n // Sort by first occurrence (preserving the original union order as much as possible)\n const sorted: readonly string[] = [\n mapNullable(\n primitives,\n (a) => [a.nodes.map((n) => n.getFullText()), a.firstPosition] as const,\n ),\n mapNullable(\n arraysAndTuples,\n (a) => [a.nodes.map((n) => n.getFullText()), a.firstPosition] as const,\n ),\n nonEmptyTypeLiterals !== undefined && Arr.isNonEmpty(nonEmptyTypeLiterals)\n ? mapNullable(\n typeLiterals,\n (a) => [typeLiteralsWrappedWithReadonly, a.firstPosition] as const,\n )\n : undefined,\n emptyTypeLiterals !== undefined && Arr.isNonEmpty(emptyTypeLiterals)\n ? mapNullable(\n typeLiterals,\n (a) =>\n [\n emptyTypeLiterals.map((n) => n.getFullText()),\n // Use a position after non-empty type literals if they exist\n a.firstPosition +\n (nonEmptyTypeLiterals !== undefined &&\n Arr.isNonEmpty(nonEmptyTypeLiterals)\n ? 0.5\n : 0),\n ] as const,\n )\n : undefined,\n mapNullable(\n others,\n (a) =>\n [\n a.nodes.map((n) => wrapWithParentheses(n.getFullText())),\n a.firstPosition,\n ] as const,\n ),\n ]\n .filter((x) => x !== undefined)\n .toSorted((a, b) => a[1] - b[1])\n .flatMap((a) => a[0]);\n\n // Readonly<number & { x: X } & { y: Y } & readonly E[]>\n // -> number & readonly E[] & Readonly<{ x: X } & { y: Y }>\n\n // Readonly<number | { x: X } | { y: Y } | readonly E[]>\n // -> number | readonly E[] | Readonly<{ x: X } | { y: Y }>\n // Readonly<number & { x: X } & { y: Y } & readonly E[]>\n // -> number & readonly E[] & Readonly<{ x: X } & { y: Y }>\n\n // Readonly<number | { x: X } | { y: Y } | readonly E[]>\n // -> number | readonly E[] | Readonly<{ x: X } | { y: Y }>\n //\n // NOTE: The result is wrapped in parentheses (via `unionToString`). This is\n // intentional and required for precedence safety: without it, a member such\n // as a function type (`() => T`), or a mix of `&` and `|`, or a `readonly`\n // operator would produce invalid syntax when this node is spliced back in.\n // Idempotency is guaranteed by `transformParenthesizedTypeNode`, which\n // collapses the redundant nesting (`((X))` -> `(X)`) this wrapping can create\n // — see the note there. That prevents the parentheses from growing without\n // bound when a union/intersection sits inside a `ParenthesizedType`.\n options.replaceNode(\n node,\n unionToString({ types: sorted, op: operator, wrapWithReadonly: false }),\n );\n};\n\nconst unionToString = ({\n types,\n op,\n wrapWithReadonly,\n}: Readonly<{\n types: readonly string[];\n op: '&' | '|';\n wrapWithReadonly: boolean | string;\n}>): string =>\n Arr.isEmpty(types)\n ? 'never'\n : Arr.isFixedLengthArray(1, types)\n ? wrapWithReadonly === false\n ? wrapWithParentheses(types[0])\n : (`${isString(wrapWithReadonly) ? wrapWithReadonly : 'Readonly'}<${types[0]}>` as const)\n : wrapWithReadonly === false\n ? wrapWithParentheses(types.join(` ${op} `))\n : (`${isString(wrapWithReadonly) ? wrapWithReadonly : 'Readonly'}<${types.join(` ${op} `)}>` as const);\n\n/** Convert ((T)) -> (T) recursively */\nconst transformParenthesizedTypeNode = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.ParenthesizedTypeNode,\n readonlyContext: ReadonlyContext,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n const typeNode = node.getTypeNode();\n\n if (typeNode.isKind(tsm.SyntaxKind.ParenthesizedType)) {\n // Recursive processing\n transformParenthesizedTypeNode(typeNode, readonlyContext, options);\n }\n\n transformNode(node.getTypeNode(), readonlyContext, options);\n\n const T = node.getTypeNode();\n\n if (\n // remove () if T is TypeReferenceNode\n // e.g. `(Readonly<A>) |-> Readonly<A>`\n T.isKind(tsm.SyntaxKind.TypeReference) ||\n // remove () if T is ArrayTypeNode\n // e.g. `(A[]) |-> A[]`\n T.isKind(tsm.SyntaxKind.ArrayType) ||\n // remove () if T is TupleTypeNode\n // e.g. `([A]) |-> [A]`\n T.isKind(tsm.SyntaxKind.TupleType) ||\n // remove () if T is PrimitiveTypeNode\n // e.g. `(number) |-> number`\n isAtomicTypeNode(T) ||\n // remove () if T is TypeLiteralNode\n // e.g. `({ member: V }) |-> { member: V }`\n T.isKind(tsm.SyntaxKind.TypeLiteral) ||\n // collapse redundant nested parentheses if T is itself a ParenthesizedType\n // e.g. `((X)) |-> (X)`\n //\n // This is what makes the transform terminate on nested parentheses. The\n // union/intersection handler defensively wraps its result in parentheses\n // for precedence safety, which turns `(A | B)` into `((A | B))` when the\n // union already sits inside a `ParenthesizedType`. Collapsing the redundant\n // outer layer here means each pass removes exactly the layer the wrapping\n // added, so the parentheses no longer grow without bound (which previously\n // overflowed the parser stack on inputs like `type T = (('a' | 'b'))`).\n T.isKind(tsm.SyntaxKind.ParenthesizedType)\n ) {\n options.replaceNode(node, T.getFullText());\n }\n};\n\n/**\n * `tr([\"member1: V1\", \"member2: V2\", \"member3: V3\"])`\n *\n * -> `[\"member1: tr(V1)\", \"member2: tr(V2)\", \"member3: tr(V3)\"]`\n */\nconst transformMembers = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n members: readonly tsm.TypeElementTypes[],\n readonlyModifier: 'add' | 'remove',\n readonlyContext: Extract<\n ReadonlyContext,\n Readonly<{\n type: 'DeepReadonly' | 'none';\n indexedAccessDepth: SafeUintWithSmallInt;\n }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n for (const mb of members) {\n if (hasDisableNextLineComment(mb)) {\n options.debugPrint('skipped by member disable-next-line comment');\n\n continue;\n }\n\n if (mb.isKind(tsm.SyntaxKind.PropertySignature)) {\n if (!checkIfPropertyNameShouldBeIgnored(mb.getNameNode(), options)) {\n transformPropertySignature(\n mb,\n readonlyModifier,\n readonlyContext,\n options,\n );\n }\n\n continue;\n }\n\n if (mb.isKind(tsm.SyntaxKind.IndexSignature)) {\n transformIndexSignatureDeclaration(\n mb,\n readonlyModifier,\n readonlyContext,\n options,\n );\n\n continue;\n }\n\n transformNode(mb, readonlyContext, options);\n\n continue;\n }\n};\n\nconst transformPropertySignature = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.PropertySignature,\n readonlyModifier: 'add' | 'remove',\n readonlyContext: Extract<\n ReadonlyContext,\n Readonly<{\n type: 'DeepReadonly' | 'none';\n indexedAccessDepth: SafeUintWithSmallInt;\n }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (\n readonlyContext.type === 'DeepReadonly' ||\n readonlyModifier === 'remove'\n ) {\n node.setIsReadonly(false);\n } else {\n node.setIsReadonly(true);\n }\n\n {\n const type = node.getTypeNode();\n\n if (type !== undefined) {\n transformNode(type, readonlyContext, options);\n }\n }\n};\n\nconst transformIndexSignatureDeclaration = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n node: tsm.IndexSignatureDeclaration,\n readonlyModifier: 'add' | 'remove',\n readonlyContext: Extract<\n ReadonlyContext,\n Readonly<{\n type: 'DeepReadonly' | 'none';\n indexedAccessDepth: SafeUintWithSmallInt;\n }>\n >,\n options: ReadonlyTransformerOptionsInternal,\n): void => {\n if (hasDisableNextLineComment(node, TRANSFORMER_NAME)) {\n options.debugPrint('skipped index signature by disable-next-line comment');\n\n return;\n }\n\n if (\n readonlyContext.type === 'DeepReadonly' ||\n readonlyModifier === 'remove'\n ) {\n // node.setIsReadonly(false);\n node.toggleModifier('readonly', false);\n } else {\n node.toggleModifier('readonly', true);\n // node.setIsReadonly(true);\n }\n\n {\n const key = node.getKeyTypeNode();\n\n transformNode(key, readonlyContext, options);\n }\n\n {\n const ret = node.getReturnTypeNode();\n\n if (ret !== undefined) {\n transformNode(ret, readonlyContext, options);\n }\n }\n};\n\nconst checkIfPropertyNameShouldBeIgnored = (\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n nameNode: tsm.PropertyName,\n options: ReadonlyTransformerOptionsInternal,\n): boolean => {\n expectType<typeof nameNode, tsm.PropertyName>('=');\n\n expectType<\n tsm.PropertyName,\n | tsm.NumericLiteral\n | tsm.BigIntLiteral\n | tsm.NoSubstitutionTemplateLiteral\n | tsm.Identifier\n | tsm.StringLiteral\n | tsm.PrivateIdentifier\n | tsm.ComputedPropertyName // [`mut_x`]: number[]\n >('=');\n\n return (\n // mut_x: number[]\n (nameNode.isKind(tsm.SyntaxKind.Identifier) &&\n pipe(nameNode.getText()).map((nm) =>\n options.ignoredPrefixes.some((p) => nm.startsWith(p)),\n ).value) ||\n // \"mut_x\": number[]\n (nameNode.isKind(tsm.SyntaxKind.StringLiteral) &&\n pipe(nameNode.getLiteralValue()).map((nm) =>\n options.ignoredPrefixes.some((p) => nm.startsWith(p)),\n ).value) ||\n // #memberName: number[] (class only)\n (nameNode.isKind(tsm.SyntaxKind.PrivateIdentifier) &&\n pipe(nameNode.getText()).map((nm) =>\n options.ignoredPrefixes.some((p) => nm.startsWith(`#${p}`)),\n ).value) ||\n // [`mut_x`]: number[]\n (nameNode.isKind(tsm.SyntaxKind.ComputedPropertyName) &&\n pipe(nameNode.getExpression()).map((exp) => {\n if (exp.isKind(tsm.SyntaxKind.StringLiteral)) {\n const nm = exp.getLiteralValue();\n\n return options.ignoredPrefixes.some((p) => nm.startsWith(p));\n }\n\n return false;\n }).value)\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAkCA,MAAM,gBAAA,GAAmB,qBAAA;AAElB,MAAM,4BAAA,GAA+B,CAC1C,OAAA,KACuB;AACvB,EAAA,IACE,OAAA,EAAS,cAAc,QAAA,KAAa,MAAA,IACpC,4BAA4B,GAAA,CAAI,OAAA,CAAQ,YAAA,CAAa,QAAQ,CAAA,EAC7D;AACA,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,OAAA,CAAQ,YAAA,CAAa,QAAQ,CAAA,iCAAA;AAAA,KACjE;AAAA,EAAA;AAGF,EAAA,MAAM,oBAAA,GACJ,OAAA,EAAS,YAAA,EAAc,QAAA,IAAY,cAAA;AAErC,EAAA,MAAM,iBAAiB,IAAA,CAAK,MAAA;AAAA,IAC1B,SAAS,cAAA,IAAkB,CAAC,MAAA,EAAQ,OAAA,EAAS,SAAS,OAAO;AAAA,GAC/D;AAEA,EAAA,MAAM,eAAA,GAAsD;AAAA,IAC1D,YAAA,EAAc;AAAA,MACZ,QAAA,EAAU,oBAAA;AAAA,MACV,UAAA,EAAY;AAAA,KACd;AAAA,IACA,sBAAA,EAAwB,SAAS,sBAAA,IAA0B,IAAA;AAAA,IAC3D,eAAA,EAAiB,cAAA;AAAA,IACjB,YAAY,OAAA,EAAS,KAAA,KAAU,IAAA,GAAO,OAAA,CAA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":["../../../src/functions/ast-transformers/replace-record-with-unknown-record.mts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQtD;;;;;;;GAOG;AACH,eAAO,MAAM,yCAAyC,QAChD,kBAeS,CAAC"}
1
+ {"version":3,"file":"replace-record-with-unknown-record.d.mts","sourceRoot":"","sources":["../../../src/functions/ast-transformers/replace-record-with-unknown-record.mts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQtD;;;;;;;GAOG;AACH,eAAO,MAAM,yCAAyC,QAChD,kBAaS,CAAC"}
@@ -10,7 +10,7 @@ const replaceRecordWithUnknownRecordTransformer = () => ({
10
10
  name: TRANSFORMER_NAME,
11
11
  transform: (sourceAst) => {
12
12
  const containerModifications = Arr.toUnshifted(
13
- sourceAst.getModules().map((namespace) => processDeclarations(namespace)),
13
+ sourceAst.getModules().map(processDeclarations),
14
14
  processDeclarations(sourceAst)
15
15
  );
16
16
  if (containerModifications.includes(true)) {
@@ -27,7 +27,7 @@ const processDeclarations = (container) => {
27
27
  if (typeNode === void 0) return false;
28
28
  return visitTypeNode(typeNode);
29
29
  });
30
- const interfaceModifications = container.getInterfaces().map((interfaceDecl) => processInterfaceDeclaration(interfaceDecl));
30
+ const interfaceModifications = container.getInterfaces().map(processInterfaceDeclaration);
31
31
  return [...typeAliasModifications, ...interfaceModifications].includes(true);
32
32
  };
33
33
  const processInterfaceDeclaration = (interfaceDecl) => {
@@ -40,7 +40,7 @@ const processInterfaceDeclaration = (interfaceDecl) => {
40
40
  const returnType = sig.getReturnType();
41
41
  return keyType.getText() === "string" && returnType.getText() === "unknown";
42
42
  });
43
- if (hasStringUnknownSignature && Arr.isArrayOfLength(interfaceDecl.getProperties(), 0) && Arr.isArrayOfLength(indexSignatures, 1) && Arr.isArrayOfLength(interfaceDecl.getTypeParameters(), 0) && Arr.isArrayOfLength(interfaceDecl.getExtends(), 0) && !interfaceDecl.hasDeclareKeyword() && !interfaceDecl.hasDefaultKeyword()) {
43
+ if (hasStringUnknownSignature && Arr.isEmpty(interfaceDecl.getProperties()) && Arr.isFixedLengthArray(1, indexSignatures) && Arr.isEmpty(interfaceDecl.getTypeParameters()) && Arr.isEmpty(interfaceDecl.getExtends()) && !interfaceDecl.hasDeclareKeyword() && !interfaceDecl.hasDefaultKeyword()) {
44
44
  const exportPrefix = interfaceDecl.hasExportKeyword() ? "export " : "";
45
45
  const interfaceName = interfaceDecl.getName();
46
46
  interfaceDecl.replaceWithText(
@@ -58,14 +58,14 @@ const visitTypeNode = (node) => {
58
58
  if (tsm.Node.isTypeReference(node)) {
59
59
  if (node.getTypeName().getText() === "Readonly") {
60
60
  const typeArgs = node.getTypeArguments();
61
- if (Arr.isArrayOfLength(typeArgs, 1)) {
61
+ if (Arr.isFixedLengthArray(1, typeArgs)) {
62
62
  const typeArg = typeArgs[0];
63
63
  if (tsm.Node.isTypeLiteral(typeArg)) {
64
64
  const members = typeArg.getMembers();
65
65
  const indexSigs = members.filter(
66
66
  (m) => tsm.Node.isIndexSignatureDeclaration(m)
67
67
  );
68
- if (Arr.isArrayOfLength(members, 1) && Arr.isArrayOfLength(indexSigs, 1) && isStringUnknownIndexSignature(indexSigs[0])) {
68
+ if (Arr.isFixedLengthArray(1, members) && Arr.isFixedLengthArray(1, indexSigs) && isStringUnknownIndexSignature(indexSigs[0])) {
69
69
  node.replaceWithText("UnknownRecord");
70
70
  return true;
71
71
  }
@@ -80,7 +80,7 @@ const visitTypeNode = (node) => {
80
80
  const indexSigs = members.filter(
81
81
  (m) => tsm.Node.isIndexSignatureDeclaration(m)
82
82
  );
83
- if (Arr.isArrayOfLength(members, 1) && Arr.isArrayOfLength(indexSigs, 1) && isStringUnknownIndexSignature(indexSigs[0])) {
83
+ if (Arr.isFixedLengthArray(1, members) && Arr.isFixedLengthArray(1, indexSigs) && isStringUnknownIndexSignature(indexSigs[0])) {
84
84
  node.replaceWithText("UnknownRecord");
85
85
  return true;
86
86
  }
@@ -97,13 +97,13 @@ const visitTypeNode = (node) => {
97
97
  }).includes(true);
98
98
  }
99
99
  if (tsm.Node.isUnionTypeNode(node) || tsm.Node.isIntersectionTypeNode(node)) {
100
- return node.getTypeNodes().map((typeNode) => visitTypeNode(typeNode)).includes(true);
100
+ return node.getTypeNodes().map(visitTypeNode).includes(true);
101
101
  }
102
102
  if (tsm.Node.isArrayTypeNode(node)) {
103
103
  return visitTypeNode(node.getElementTypeNode());
104
104
  }
105
105
  if (tsm.Node.isTupleTypeNode(node)) {
106
- return node.getElements().map((element) => visitTypeNode(element)).includes(true);
106
+ return node.getElements().map(visitTypeNode).includes(true);
107
107
  }
108
108
  if (tsm.Node.isParenthesizedTypeNode(node)) {
109
109
  return visitTypeNode(node.getTypeNode());
@@ -129,21 +129,21 @@ const replaceIfRecordUnknown = (node) => {
129
129
  switch (typeName) {
130
130
  case "Record": {
131
131
  const typeArgs = node.getTypeArguments();
132
- if (Arr.isArrayOfLength(typeArgs, 2) && typeArgs[0].getText() === "string" && typeArgs[1].getText() === "unknown") {
132
+ if (Arr.isFixedLengthArray(2, typeArgs) && typeArgs[0].getText() === "string" && typeArgs[1].getText() === "unknown") {
133
133
  node.replaceWithText("UnknownRecord");
134
134
  return true;
135
135
  }
136
- return typeArgs.map((typeArg) => visitTypeNode(typeArg)).includes(true);
136
+ return typeArgs.map(visitTypeNode).includes(true);
137
137
  }
138
138
  case "Readonly": {
139
139
  const typeArgs = node.getTypeArguments();
140
- if (Arr.isArrayOfLength(typeArgs, 1)) {
140
+ if (Arr.isFixedLengthArray(1, typeArgs)) {
141
141
  const innerType = typeArgs[0];
142
142
  if (tsm.Node.isTypeReference(innerType)) {
143
143
  const innerTypeName = innerType.getTypeName().getText();
144
144
  if (innerTypeName === "Record") {
145
145
  const innerTypeArgs = innerType.getTypeArguments();
146
- if (Arr.isArrayOfLength(innerTypeArgs, 2) && innerTypeArgs[0].getText() === "string" && innerTypeArgs[1].getText() === "unknown") {
146
+ if (Arr.isFixedLengthArray(2, innerTypeArgs) && innerTypeArgs[0].getText() === "string" && innerTypeArgs[1].getText() === "unknown") {
147
147
  node.replaceWithText("UnknownRecord");
148
148
  return true;
149
149
  }
@@ -154,7 +154,7 @@ const replaceIfRecordUnknown = (node) => {
154
154
  return false;
155
155
  }
156
156
  default: {
157
- return node.getTypeArguments().map((typeArg) => visitTypeNode(typeArg)).includes(true);
157
+ return node.getTypeArguments().map(visitTypeNode).includes(true);
158
158
  }
159
159
  }
160
160
  };
@@ -1 +1 @@
1
- {"version":3,"file":"replace-record-with-unknown-record.mjs","sources":["../../../src/functions/ast-transformers/replace-record-with-unknown-record.mts"],"sourcesContent":["/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- ts-morph uses mutable types */\nimport { Arr } from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { hasDisableNextLineComment } from '../functions/index.mjs';\nimport { type TsMorphTransformer } from './types.mjs';\n\nconst TRANSFORMER_NAME = 'replace-record-with-unknown-record';\n\nconst UNKNOWN_RECORD_MODULE = 'ts-type-forge';\n\nconst UNKNOWN_RECORD_NAME = 'UnknownRecord';\n\n/**\n * Replaces `Readonly<Record<string, unknown>>`, `Record<string, unknown>`,\n * and index signatures `[k: string]: unknown` with `UnknownRecord`.\n *\n * When a replacement occurs, also inserts\n * `import { type UnknownRecord } from 'ts-type-forge';` at the top of the\n * source file (or merges into an existing import from `'ts-type-forge'`).\n */\nexport const replaceRecordWithUnknownRecordTransformer =\n (): TsMorphTransformer =>\n ({\n name: TRANSFORMER_NAME,\n transform: (sourceAst) => {\n const containerModifications = Arr.toUnshifted(\n sourceAst\n .getModules()\n .map((namespace) => processDeclarations(namespace)),\n processDeclarations(sourceAst),\n );\n\n if (containerModifications.includes(true)) {\n ensureUnknownRecordImport(sourceAst);\n }\n },\n }) as const;\n\nconst processDeclarations = (\n container: tsm.SourceFile | tsm.ModuleDeclaration,\n): boolean => {\n const typeAliasModifications = container.getTypeAliases().map((typeAlias) => {\n if (hasDisableNextLineComment(typeAlias, TRANSFORMER_NAME)) {\n return false;\n }\n\n const typeNode = typeAlias.getTypeNode();\n\n if (typeNode === undefined) return false;\n\n return visitTypeNode(typeNode);\n });\n\n const interfaceModifications = container\n .getInterfaces()\n .map((interfaceDecl) => processInterfaceDeclaration(interfaceDecl));\n\n return [...typeAliasModifications, ...interfaceModifications].includes(true);\n};\n\nconst processInterfaceDeclaration = (\n interfaceDecl: tsm.InterfaceDeclaration,\n): boolean => {\n if (hasDisableNextLineComment(interfaceDecl, TRANSFORMER_NAME)) {\n return false;\n }\n\n // Check if interface has index signature [k: string]: unknown\n const indexSignatures = interfaceDecl.getIndexSignatures();\n\n const hasStringUnknownSignature = indexSignatures.some((sig) => {\n const keyType = sig.getKeyType();\n\n const returnType = sig.getReturnType();\n\n return keyType.getText() === 'string' && returnType.getText() === 'unknown';\n });\n\n // If it has the signature and no other members, replace entire interface with type alias.\n // Skip when the interface carries semantics that a plain type alias would lose\n // (type parameters, extends clauses, declare modifier, default export).\n if (\n hasStringUnknownSignature &&\n Arr.isArrayOfLength(interfaceDecl.getProperties(), 0) &&\n Arr.isArrayOfLength(indexSignatures, 1) &&\n Arr.isArrayOfLength(interfaceDecl.getTypeParameters(), 0) &&\n Arr.isArrayOfLength(interfaceDecl.getExtends(), 0) &&\n !interfaceDecl.hasDeclareKeyword() &&\n !interfaceDecl.hasDefaultKeyword()\n ) {\n const exportPrefix = interfaceDecl.hasExportKeyword() ? 'export ' : '';\n\n const interfaceName = interfaceDecl.getName();\n\n interfaceDecl.replaceWithText(\n `${exportPrefix}type ${interfaceName} = UnknownRecord;`,\n );\n\n return true;\n }\n\n // Otherwise, check properties for Record types\n return interfaceDecl\n .getProperties()\n .map((property) => {\n const typeNode = property.getTypeNode();\n\n if (typeNode === undefined) return false;\n\n return visitTypeNode(typeNode);\n })\n .includes(true);\n};\n\nconst visitTypeNode = (node: tsm.TypeNode): boolean => {\n if (tsm.Node.isTypeReference(node)) {\n // Check if it's Readonly<{ [k: string]: unknown }>\n if (node.getTypeName().getText() === 'Readonly') {\n const typeArgs = node.getTypeArguments();\n\n if (Arr.isArrayOfLength(typeArgs, 1)) {\n const typeArg = typeArgs[0];\n\n if (tsm.Node.isTypeLiteral(typeArg)) {\n const members = typeArg.getMembers();\n\n const indexSigs = members.filter((m) =>\n tsm.Node.isIndexSignatureDeclaration(m),\n );\n\n // Check if it has only one index signature [k: string]: unknown\n if (\n Arr.isArrayOfLength(members, 1) &&\n Arr.isArrayOfLength(indexSigs, 1) &&\n isStringUnknownIndexSignature(indexSigs[0])\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n\n // Otherwise, recurse into the type literal to visit its properties\n return visitTypeNode(typeArg);\n }\n }\n }\n\n return replaceIfRecordUnknown(node);\n }\n\n // Check for type literal { [k: string]: unknown }\n if (tsm.Node.isTypeLiteral(node)) {\n const members = node.getMembers();\n\n const indexSigs = members.filter((m) =>\n tsm.Node.isIndexSignatureDeclaration(m),\n );\n\n // Check if it has only one index signature [k: string]: unknown\n if (\n Arr.isArrayOfLength(members, 1) &&\n Arr.isArrayOfLength(indexSigs, 1) &&\n isStringUnknownIndexSignature(indexSigs[0])\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n\n return members\n .map((member) => {\n if (tsm.Node.isPropertySignature(member)) {\n const typeNode = member.getTypeNode();\n\n return typeNode === undefined ? false : visitTypeNode(typeNode);\n }\n\n if (tsm.Node.isIndexSignatureDeclaration(member)) {\n const typeNode = member.getReturnTypeNode();\n\n return typeNode === undefined ? false : visitTypeNode(typeNode);\n }\n\n return false;\n })\n .includes(true);\n }\n\n // Recursively visit child type nodes\n if (tsm.Node.isUnionTypeNode(node) || tsm.Node.isIntersectionTypeNode(node)) {\n return node\n .getTypeNodes()\n .map((typeNode) => visitTypeNode(typeNode))\n .includes(true);\n }\n\n if (tsm.Node.isArrayTypeNode(node)) {\n return visitTypeNode(node.getElementTypeNode());\n }\n\n if (tsm.Node.isTupleTypeNode(node)) {\n return node\n .getElements()\n .map((element) => visitTypeNode(element))\n .includes(true);\n }\n\n if (tsm.Node.isParenthesizedTypeNode(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n // Handles `readonly T[]`, `readonly [...]`, `keyof T`\n if (tsm.Node.isTypeOperatorTypeNode(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n if (tsm.Node.isRestTypeNode(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n if (tsm.Node.isNamedTupleMember(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n return false;\n};\n\nconst isStringUnknownIndexSignature = (\n sig: tsm.IndexSignatureDeclaration,\n): boolean => {\n const keyType = sig.getKeyTypeNode();\n\n const returnType = sig.getReturnTypeNode();\n\n return keyType.getText() === 'string' && returnType?.getText() === 'unknown';\n};\n\nconst replaceIfRecordUnknown = (node: tsm.TypeReferenceNode): boolean => {\n const typeName = node.getTypeName().getText();\n\n switch (typeName) {\n case 'Record': {\n // Check if it's Record<string, unknown>\n const typeArgs = node.getTypeArguments();\n\n if (\n Arr.isArrayOfLength(typeArgs, 2) &&\n typeArgs[0].getText() === 'string' &&\n typeArgs[1].getText() === 'unknown'\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n\n // Recurse into type arguments (e.g. Record<string, Record<string, unknown>>)\n return typeArgs.map((typeArg) => visitTypeNode(typeArg)).includes(true);\n }\n case 'Readonly': {\n // Check if it's Readonly<Record<string, unknown>>\n const typeArgs = node.getTypeArguments();\n\n if (Arr.isArrayOfLength(typeArgs, 1)) {\n const innerType = typeArgs[0];\n\n if (tsm.Node.isTypeReference(innerType)) {\n const innerTypeName = innerType.getTypeName().getText();\n\n if (innerTypeName === 'Record') {\n const innerTypeArgs = innerType.getTypeArguments();\n\n if (\n Arr.isArrayOfLength(innerTypeArgs, 2) &&\n innerTypeArgs[0].getText() === 'string' &&\n innerTypeArgs[1].getText() === 'unknown'\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n }\n }\n\n // Otherwise, recurse into the type argument\n return visitTypeNode(innerType);\n }\n\n return false;\n }\n\n default: {\n // Recurse into type arguments for any other generic type\n return node\n .getTypeArguments()\n .map((typeArg) => visitTypeNode(typeArg))\n .includes(true);\n }\n }\n};\n\nconst ensureUnknownRecordImport = (sourceFile: tsm.SourceFile): void => {\n const existingImport = sourceFile\n .getImportDeclarations()\n .find((decl) => decl.getModuleSpecifierValue() === UNKNOWN_RECORD_MODULE);\n\n if (existingImport === undefined) {\n sourceFile.insertImportDeclaration(0, {\n moduleSpecifier: UNKNOWN_RECORD_MODULE,\n namedImports: [{ name: UNKNOWN_RECORD_NAME, isTypeOnly: true }],\n });\n\n return;\n }\n\n const alreadyImported = existingImport\n .getNamedImports()\n .some((ni) => ni.getName() === UNKNOWN_RECORD_NAME);\n\n if (alreadyImported) return;\n\n existingImport.addNamedImport({\n name: UNKNOWN_RECORD_NAME,\n isTypeOnly: true,\n });\n};\n"],"names":[],"mappings":";;;;;AAMA,MAAM,gBAAA,GAAmB,oCAAA;AAEzB,MAAM,qBAAA,GAAwB,eAAA;AAE9B,MAAM,mBAAA,GAAsB,eAAA;AAUrB,MAAM,4CACX,OACG;AAAA,EACC,IAAA,EAAM,gBAAA;AAAA,EACN,SAAA,EAAW,CAAC,SAAA,KAAc;AACxB,IAAA,MAAM,yBAAyB,GAAA,CAAI,WAAA;AAAA,MACjC,SAAA,CACG,YAAW,CACX,GAAA,CAAI,CAAC,SAAA,KAAc,mBAAA,CAAoB,SAAS,CAAC,CAAA;AAAA,MACpD,oBAAoB,SAAS;AAAA,KAC/B;AAEA,IAAA,IAAI,sBAAA,CAAuB,QAAA,CAAS,IAAI,CAAA,EAAG;AACzC,MAAA,yBAAA,CAA0B,SAAS,CAAA;AAAA,IACrC;AAAA,EACF;AACF,CAAA;AAEJ,MAAM,mBAAA,GAAsB,CAC1B,SAAA,KACY;AACZ,EAAA,MAAM,yBAAyB,SAAA,CAAU,cAAA,EAAe,CAAE,G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AAC,EAAE,MAAM,mBAAA,EAAqB,UAAA,EAAY,MAAM;AAAA,KAC/D,CAAA;AAED,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,eAAA,GAAkB,cAAA,CACrB,eAAA,EAAgB,CAChB,IAAA,CAAK,CAAC,EAAA,KAAO,EAAA,CAAG,OAAA,EAAQ,KAAM,mBAAmB,CAAA;AAEpD,EAAA,IAAI,eAAA,EAAiB;AAErB,EAAA,cAAA,CAAe,cAAA,CAAe;AAAA,IAC5B,IAAA,EAAM,mBAAA;AAAA,IACN,UAAA,EAAY;AAAA,GACb,CAAA;AACH,CAAA;;;;"}
1
+ {"version":3,"file":"replace-record-with-unknown-record.mjs","sources":["../../../src/functions/ast-transformers/replace-record-with-unknown-record.mts"],"sourcesContent":["/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- ts-morph uses mutable types */\nimport { Arr } from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { hasDisableNextLineComment } from '../functions/index.mjs';\nimport { type TsMorphTransformer } from './types.mjs';\n\nconst TRANSFORMER_NAME = 'replace-record-with-unknown-record';\n\nconst UNKNOWN_RECORD_MODULE = 'ts-type-forge';\n\nconst UNKNOWN_RECORD_NAME = 'UnknownRecord';\n\n/**\n * Replaces `Readonly<Record<string, unknown>>`, `Record<string, unknown>`,\n * and index signatures `[k: string]: unknown` with `UnknownRecord`.\n *\n * When a replacement occurs, also inserts\n * `import { type UnknownRecord } from 'ts-type-forge';` at the top of the\n * source file (or merges into an existing import from `'ts-type-forge'`).\n */\nexport const replaceRecordWithUnknownRecordTransformer =\n (): TsMorphTransformer =>\n ({\n name: TRANSFORMER_NAME,\n transform: (sourceAst) => {\n const containerModifications = Arr.toUnshifted(\n sourceAst.getModules().map(processDeclarations),\n processDeclarations(sourceAst),\n );\n\n if (containerModifications.includes(true)) {\n ensureUnknownRecordImport(sourceAst);\n }\n },\n }) as const;\n\nconst processDeclarations = (\n container: tsm.SourceFile | tsm.ModuleDeclaration,\n): boolean => {\n const typeAliasModifications = container.getTypeAliases().map((typeAlias) => {\n if (hasDisableNextLineComment(typeAlias, TRANSFORMER_NAME)) {\n return false;\n }\n\n const typeNode = typeAlias.getTypeNode();\n\n if (typeNode === undefined) return false;\n\n return visitTypeNode(typeNode);\n });\n\n const interfaceModifications = container\n .getInterfaces()\n .map(processInterfaceDeclaration);\n\n return [...typeAliasModifications, ...interfaceModifications].includes(true);\n};\n\nconst processInterfaceDeclaration = (\n interfaceDecl: tsm.InterfaceDeclaration,\n): boolean => {\n if (hasDisableNextLineComment(interfaceDecl, TRANSFORMER_NAME)) {\n return false;\n }\n\n // Check if interface has index signature [k: string]: unknown\n const indexSignatures = interfaceDecl.getIndexSignatures();\n\n const hasStringUnknownSignature = indexSignatures.some((sig) => {\n const keyType = sig.getKeyType();\n\n const returnType = sig.getReturnType();\n\n return keyType.getText() === 'string' && returnType.getText() === 'unknown';\n });\n\n // If it has the signature and no other members, replace entire interface with type alias.\n // Skip when the interface carries semantics that a plain type alias would lose\n // (type parameters, extends clauses, declare modifier, default export).\n if (\n hasStringUnknownSignature &&\n Arr.isEmpty(interfaceDecl.getProperties()) &&\n Arr.isFixedLengthArray(1, indexSignatures) &&\n Arr.isEmpty(interfaceDecl.getTypeParameters()) &&\n Arr.isEmpty(interfaceDecl.getExtends()) &&\n !interfaceDecl.hasDeclareKeyword() &&\n !interfaceDecl.hasDefaultKeyword()\n ) {\n const exportPrefix = interfaceDecl.hasExportKeyword() ? 'export ' : '';\n\n const interfaceName = interfaceDecl.getName();\n\n interfaceDecl.replaceWithText(\n `${exportPrefix}type ${interfaceName} = UnknownRecord;`,\n );\n\n return true;\n }\n\n // Otherwise, check properties for Record types\n return interfaceDecl\n .getProperties()\n .map((property) => {\n const typeNode = property.getTypeNode();\n\n if (typeNode === undefined) return false;\n\n return visitTypeNode(typeNode);\n })\n .includes(true);\n};\n\nconst visitTypeNode = (node: tsm.TypeNode): boolean => {\n if (tsm.Node.isTypeReference(node)) {\n // Check if it's Readonly<{ [k: string]: unknown }>\n if (node.getTypeName().getText() === 'Readonly') {\n const typeArgs = node.getTypeArguments();\n\n if (Arr.isFixedLengthArray(1, typeArgs)) {\n const typeArg = typeArgs[0];\n\n if (tsm.Node.isTypeLiteral(typeArg)) {\n const members = typeArg.getMembers();\n\n const indexSigs = members.filter((m) =>\n tsm.Node.isIndexSignatureDeclaration(m),\n );\n\n // Check if it has only one index signature [k: string]: unknown\n if (\n Arr.isFixedLengthArray(1, members) &&\n Arr.isFixedLengthArray(1, indexSigs) &&\n isStringUnknownIndexSignature(indexSigs[0])\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n\n // Otherwise, recurse into the type literal to visit its properties\n return visitTypeNode(typeArg);\n }\n }\n }\n\n return replaceIfRecordUnknown(node);\n }\n\n // Check for type literal { [k: string]: unknown }\n if (tsm.Node.isTypeLiteral(node)) {\n const members = node.getMembers();\n\n const indexSigs = members.filter((m) =>\n tsm.Node.isIndexSignatureDeclaration(m),\n );\n\n // Check if it has only one index signature [k: string]: unknown\n if (\n Arr.isFixedLengthArray(1, members) &&\n Arr.isFixedLengthArray(1, indexSigs) &&\n isStringUnknownIndexSignature(indexSigs[0])\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n\n return members\n .map((member) => {\n if (tsm.Node.isPropertySignature(member)) {\n const typeNode = member.getTypeNode();\n\n return typeNode === undefined ? false : visitTypeNode(typeNode);\n }\n\n if (tsm.Node.isIndexSignatureDeclaration(member)) {\n const typeNode = member.getReturnTypeNode();\n\n return typeNode === undefined ? false : visitTypeNode(typeNode);\n }\n\n return false;\n })\n .includes(true);\n }\n\n // Recursively visit child type nodes\n if (tsm.Node.isUnionTypeNode(node) || tsm.Node.isIntersectionTypeNode(node)) {\n return node.getTypeNodes().map(visitTypeNode).includes(true);\n }\n\n if (tsm.Node.isArrayTypeNode(node)) {\n return visitTypeNode(node.getElementTypeNode());\n }\n\n if (tsm.Node.isTupleTypeNode(node)) {\n return node.getElements().map(visitTypeNode).includes(true);\n }\n\n if (tsm.Node.isParenthesizedTypeNode(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n // Handles `readonly T[]`, `readonly [...]`, `keyof T`\n if (tsm.Node.isTypeOperatorTypeNode(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n if (tsm.Node.isRestTypeNode(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n if (tsm.Node.isNamedTupleMember(node)) {\n return visitTypeNode(node.getTypeNode());\n }\n\n return false;\n};\n\nconst isStringUnknownIndexSignature = (\n sig: tsm.IndexSignatureDeclaration,\n): boolean => {\n const keyType = sig.getKeyTypeNode();\n\n const returnType = sig.getReturnTypeNode();\n\n return keyType.getText() === 'string' && returnType?.getText() === 'unknown';\n};\n\nconst replaceIfRecordUnknown = (node: tsm.TypeReferenceNode): boolean => {\n const typeName = node.getTypeName().getText();\n\n switch (typeName) {\n case 'Record': {\n // Check if it's Record<string, unknown>\n const typeArgs = node.getTypeArguments();\n\n if (\n Arr.isFixedLengthArray(2, typeArgs) &&\n typeArgs[0].getText() === 'string' &&\n typeArgs[1].getText() === 'unknown'\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n\n // Recurse into type arguments (e.g. Record<string, Record<string, unknown>>)\n return typeArgs.map(visitTypeNode).includes(true);\n }\n case 'Readonly': {\n // Check if it's Readonly<Record<string, unknown>>\n const typeArgs = node.getTypeArguments();\n\n if (Arr.isFixedLengthArray(1, typeArgs)) {\n const innerType = typeArgs[0];\n\n if (tsm.Node.isTypeReference(innerType)) {\n const innerTypeName = innerType.getTypeName().getText();\n\n if (innerTypeName === 'Record') {\n const innerTypeArgs = innerType.getTypeArguments();\n\n if (\n Arr.isFixedLengthArray(2, innerTypeArgs) &&\n innerTypeArgs[0].getText() === 'string' &&\n innerTypeArgs[1].getText() === 'unknown'\n ) {\n node.replaceWithText('UnknownRecord');\n\n return true;\n }\n }\n }\n\n // Otherwise, recurse into the type argument\n return visitTypeNode(innerType);\n }\n\n return false;\n }\n\n default: {\n // Recurse into type arguments for any other generic type\n return node.getTypeArguments().map(visitTypeNode).includes(true);\n }\n }\n};\n\nconst ensureUnknownRecordImport = (sourceFile: tsm.SourceFile): void => {\n const existingImport = sourceFile\n .getImportDeclarations()\n .find((decl) => decl.getModuleSpecifierValue() === UNKNOWN_RECORD_MODULE);\n\n if (existingImport === undefined) {\n sourceFile.insertImportDeclaration(0, {\n moduleSpecifier: UNKNOWN_RECORD_MODULE,\n namedImports: [{ name: UNKNOWN_RECORD_NAME, isTypeOnly: true }],\n });\n\n return;\n }\n\n const alreadyImported = existingImport\n .getNamedImports()\n .some((ni) => ni.getName() === UNKNOWN_RECORD_NAME);\n\n if (alreadyImported) return;\n\n existingImport.addNamedImport({\n name: UNKNOWN_RECORD_NAME,\n isTypeOnly: true,\n });\n};\n"],"names":[],"mappings":";;;;;AAMA,MAAM,gBAAA,GAAmB,oCAAA;AAEzB,MAAM,qBAAA,GAAwB,eAAA;AAE9B,MAAM,mBAAA,GAAsB,eAAA;AAUrB,MAAM,4CACX,OACG;AAAA,EACC,IAAA,EAAM,gBAAA;AAAA,EACN,SAAA,EAAW,CAAC,SAAA,KAAc;AACxB,IAAA,MAAM,yBAAyB,GAAA,CAAI,WAAA;AAAA,MACjC,SAAA,CAAU,UAAA,EAAW,CAAE,GAAA,CAAI,mBAAmB,CAAA;AAAA,MAC9C,oBAAoB,SAAS;AAAA,KAC/B;AAEA,IAAA,IAAI,sBAAA,CAAuB,QAAA,CAAS,IAAI,CAAA,EAAG;AACzC,MAAA,yBAAA,CAA0B,SAAS,CAAA;AAAA,IACrC;AAAA,EACF;AACF,CAAA;AAEJ,MAAM,mBAAA,GAAsB,CAC1B,SAAA,KACY;AACZ,EAAA,MAAM,yBAAyB,SAAA,CAAU,cAAA,EAAe,CAAE,GAAA,CAAI,CAAC,SAAA,KAAc;AAC3E,IAAA,IAAI,yBAAA,CAA0B,SAAA,EAAW,gBAAgB,CAAA,EAAG;AAC1D,MAAA,OAAO,K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AAY;AAAA,GACb,CAAA;AACH,CAAA;;;;"}
@@ -41,10 +41,10 @@ const shouldSkipFile = (code, transformerName) => {
41
41
  /\/\*\s*transform-ignore\s*.*?\s*\*\//u
42
42
  ];
43
43
  const hasFileIgnoreComment = patterns.some((regex) => regex.test(code));
44
- if (Arr.isArrayOfLength(ignoredTransformers, 0) && !hasFileIgnoreComment) {
44
+ if (Arr.isEmpty(ignoredTransformers) && !hasFileIgnoreComment) {
45
45
  return false;
46
46
  }
47
- if (Arr.isArrayOfLength(ignoredTransformers, 0)) {
47
+ if (Arr.isEmpty(ignoredTransformers)) {
48
48
  return true;
49
49
  }
50
50
  if (transformerName === void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"transform-source-code.mjs","sources":["../../../src/functions/ast-transformers/transform-source-code.mts"],"sourcesContent":["import { Arr } from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { type TsMorphTransformer } from './types.mjs';\n\nconst extractFileIgnoreTransformers = (code: string): readonly string[] => {\n // Try to find any of the supported file-level ignore comment prefixes\n const patterns = [\n {\n prefix: 'transformer-ignore',\n regex: /\\/\\*\\s*transformer-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n {\n prefix: 'ts-codemod-ignore',\n regex: /\\/\\*\\s*ts-codemod-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n {\n prefix: 'codemod-ignore',\n regex: /\\/\\*\\s*codemod-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n {\n prefix: 'transform-ignore',\n regex: /\\/\\*\\s*transform-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n ] as const;\n\n for (const { regex } of patterns) {\n const match = regex.exec(code);\n\n if (match !== null) {\n const targetTransformers = match[1]?.trim() ?? '';\n\n // Empty means ignore all transformers\n if (targetTransformers === '') {\n return [];\n }\n\n // Parse comma-separated transformer names\n return targetTransformers.split(',').map((name) => name.trim());\n }\n }\n\n return [];\n};\n\nconst shouldSkipFile = (\n code: string,\n transformerName: string | undefined,\n): boolean => {\n const ignoredTransformers = extractFileIgnoreTransformers(code);\n\n // If no file-level ignore comment found, don't skip\n const patterns = [\n /\\/\\*\\s*transformer-ignore\\s*.*?\\s*\\*\\//u,\n /\\/\\*\\s*ts-codemod-ignore\\s*.*?\\s*\\*\\//u,\n /\\/\\*\\s*codemod-ignore\\s*.*?\\s*\\*\\//u,\n /\\/\\*\\s*transform-ignore\\s*.*?\\s*\\*\\//u,\n ] as const;\n\n const hasFileIgnoreComment = patterns.some((regex) => regex.test(code));\n\n if (Arr.isArrayOfLength(ignoredTransformers, 0) && !hasFileIgnoreComment) {\n return false;\n }\n\n // Empty array means ignore all transformers (file-level ignore without specific transformers)\n if (Arr.isArrayOfLength(ignoredTransformers, 0)) {\n return true;\n }\n\n // If transformer name is not specified, don't skip\n if (transformerName === undefined) {\n return false;\n }\n\n // Check if the transformer is in the ignore list\n return ignoredTransformers.includes(transformerName);\n};\n\nexport const transformSourceCode = (\n code: string,\n isTsx: boolean,\n transformers: readonly TsMorphTransformer[],\n debug: boolean = false,\n): string => {\n const project = new tsm.Project({\n useInMemoryFileSystem: true,\n compilerOptions: {\n jsx: isTsx ? tsm.ts.JsxEmit.React : undefined,\n target: tsm.ts.ScriptTarget.ESNext,\n module: tsm.ts.ModuleKind.ESNext,\n },\n });\n\n const sourceAst = project.createSourceFile(\n `source.${isTsx ? 'tsx' : 'ts'}`,\n code,\n );\n\n for (const transformer of transformers) {\n const transformerName = transformer.name;\n\n if (shouldSkipFile(code, transformerName)) {\n if (debug) {\n console.debug(\n `skipped by ignore-file comment for transformer: ${transformerName}`,\n );\n }\n\n continue;\n }\n\n transformer.transform(sourceAst);\n }\n\n return sourceAst.getFullText();\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,6BAAA,GAAgC,CAAC,IAAA,KAAoC;AAEzE,EAAA,MAAM,QAAA,GAAW;AAAA,IACf;AAAA,MACE,MAAA,EAAQ,oBAAA;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA;AAAA,MACE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A,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,oBAAoB,MAAA,EAAW;AACjC,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,OAAO,mBAAA,CAAoB,SAAS,eAAe,CAAA;AACrD,CAAA;AAEO,MAAM,sBAAsB,CACjC,IAAA,EACA,KAAA,EACA,YAAA,EACA,QAAiB,KAAA,KACN;AACX,EAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,OAAA,CAAQ;AAAA,IAC9B,qBAAA,EAAuB,IAAA;AAAA,IACvB,eAAA,EAAiB;AAAA,MACf,GAAA,EAAK,KAAA,GAAQ,GAAA,CAAI,EAAA,CAAG,QAAQ,KAAA,GAAQ,MAAA;AAAA,MACpC,MAAA,EAAQ,GAAA,CAAI,EAAA,CAAG,YAAA,CAAa,MAAA;AAAA,MAC5B,MAAA,EAAQ,GAAA,CAAI,EAAA,CAAG,UAAA,CAAW;AAAA;AAC5B,GACD,CAAA;AAED,EAAA,MAAM,YAAY,OAAA,CAAQ,gBAAA;AAAA,IACxB,CAAA,OAAA,EAAU,KAAA,GAAQ,KAAA,GAAQ,IAAI,CAAA,CAAA;AAAA,IAC9B;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,eAAe,YAAA,EAAc;AACtC,IAAA,MAAM,kBAAkB,WAAA,CAAY,IAAA;AAEpC,IAAA,IAAI,cAAA,CAAe,IAAA,EAAM,eAAe,CAAA,EAAG;AACzC,MAAA,IAAI,KAAA,EAAO;AACT,QAAA,OAAA,CAAQ,KAAA;AAAA,UACN,mDAAmD,eAAe,CAAA;AAAA,SACpE;AAAA,MACF;AAEA,MAAA;AAAA,IACF;AAEA,IAAA,WAAA,CAAY,UAAU,SAAS,CAAA;AAAA,EACjC;AAEA,EAAA,OAAO,UAAU,WAAA,EAAY;AAC/B;;;;"}
1
+ {"version":3,"file":"transform-source-code.mjs","sources":["../../../src/functions/ast-transformers/transform-source-code.mts"],"sourcesContent":["import { Arr } from 'ts-data-forge';\nimport * as tsm from 'ts-morph';\nimport { type TsMorphTransformer } from './types.mjs';\n\nconst extractFileIgnoreTransformers = (code: string): readonly string[] => {\n // Try to find any of the supported file-level ignore comment prefixes\n const patterns = [\n {\n prefix: 'transformer-ignore',\n regex: /\\/\\*\\s*transformer-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n {\n prefix: 'ts-codemod-ignore',\n regex: /\\/\\*\\s*ts-codemod-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n {\n prefix: 'codemod-ignore',\n regex: /\\/\\*\\s*codemod-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n {\n prefix: 'transform-ignore',\n regex: /\\/\\*\\s*transform-ignore\\s*(.*?)\\s*\\*\\//u,\n },\n ] as const;\n\n for (const { regex } of patterns) {\n const match = regex.exec(code);\n\n if (match !== null) {\n const targetTransformers = match[1]?.trim() ?? '';\n\n // Empty means ignore all transformers\n if (targetTransformers === '') {\n return [];\n }\n\n // Parse comma-separated transformer names\n return targetTransformers.split(',').map((name) => name.trim());\n }\n }\n\n return [];\n};\n\nconst shouldSkipFile = (\n code: string,\n transformerName: string | undefined,\n): boolean => {\n const ignoredTransformers = extractFileIgnoreTransformers(code);\n\n // If no file-level ignore comment found, don't skip\n const patterns = [\n /\\/\\*\\s*transformer-ignore\\s*.*?\\s*\\*\\//u,\n /\\/\\*\\s*ts-codemod-ignore\\s*.*?\\s*\\*\\//u,\n /\\/\\*\\s*codemod-ignore\\s*.*?\\s*\\*\\//u,\n /\\/\\*\\s*transform-ignore\\s*.*?\\s*\\*\\//u,\n ] as const;\n\n const hasFileIgnoreComment = patterns.some((regex) => regex.test(code));\n\n if (Arr.isEmpty(ignoredTransformers) && !hasFileIgnoreComment) {\n return false;\n }\n\n // Empty array means ignore all transformers (file-level ignore without specific transformers)\n if (Arr.isEmpty(ignoredTransformers)) {\n return true;\n }\n\n // If transformer name is not specified, don't skip\n if (transformerName === undefined) {\n return false;\n }\n\n // Check if the transformer is in the ignore list\n return ignoredTransformers.includes(transformerName);\n};\n\nexport const transformSourceCode = (\n code: string,\n isTsx: boolean,\n transformers: readonly TsMorphTransformer[],\n debug: boolean = false,\n): string => {\n const project = new tsm.Project({\n useInMemoryFileSystem: true,\n compilerOptions: {\n jsx: isTsx ? tsm.ts.JsxEmit.React : undefined,\n target: tsm.ts.ScriptTarget.ESNext,\n module: tsm.ts.ModuleKind.ESNext,\n },\n });\n\n const sourceAst = project.createSourceFile(\n `source.${isTsx ? 'tsx' : 'ts'}`,\n code,\n );\n\n for (const transformer of transformers) {\n const transformerName = transformer.name;\n\n if (shouldSkipFile(code, transformerName)) {\n if (debug) {\n console.debug(\n `skipped by ignore-file comment for transformer: ${transformerName}`,\n );\n }\n\n continue;\n }\n\n transformer.transform(sourceAst);\n }\n\n return sourceAst.getFullText();\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,6BAAA,GAAgC,CAAC,IAAA,KAAoC;AAEzE,EAAA,MAAM,QAAA,GAAW;AAAA,IACf;AAAA,MACE,MAAA,EAAQ,oBAAA;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA;AAAA,MACE,MAAA,EAAQ,mBAAA;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA;AAAA,MACE,MAAA,EAAQ,gBAAA;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA;AAAA,MACE,MAAA,EAAQ,kBAAA;AAAA,MACR,KAAA,EAAO;AAAA;AACT,GACF;AAEA,EAAA,KAAA,MAAW,EAAE,KAAA,EAAM,IAAK,QAAA,EAAU;AAChC,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAE7B,IAAA,IAAI,UAAU,IAAA,EAAM;AAClB,MAAA,MAAM,kBAAA,GAAqB,KAAA,CAAM,CAAC,CAAA,EAAG,MAAK,IAAK,EAAA;AAG/C,MAAA,IAAI,uBAAuB,EAAA,EAAI;AAC7B,QAAA,OAAO,EAAC;AAAA,MACV;AAGA,MAAA,O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