@intlayer/chokidar 7.3.12 → 7.3.14

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.
@@ -1 +1 @@
1
- {"version":3,"file":"transformJSFile.cjs","names":["translationParts: string[]","updatedTranslationMap: Record<string, string>","enumerationParts: string[]","conditionParts: string[]","genderParts: string[]","NodeType","Node","translationMap: Record<string, string | string[]>","stringArray: string[]","keyValueMap: Record<string, string>","serializedArrayElements: string[]","existingArrayElements: import('ts-morph').Node[] | undefined","existingArrayTypeArguments: string | undefined","existingPropertyTypeArguments: string | undefined","property","translationMap: Record<string, string>","SyntaxKind","translationMap: Record<string, unknown>","translationInitializerText","translationParts","enumerationMap: EnumerationContent[NodeType.Enumeration]","conditionMap: ConditionContent[NodeType.Condition]","existingTranslationMap: Record<string, string | string[]>","genderMap: GenderContent[NodeType.Gender]","insertionContent: InsertionContent[NodeType.Insertion]","markdownContent: MarkdownContent[NodeType.Markdown]","markdownNodeType","filePath: FileContent[NodeType.File]","nestedContent: NestedContent[NodeType.Nested]","childObject: ObjectLiteralExpression | undefined","map: Record<string, string>","path: string | undefined","spreads: ObjectLiteralExpression[]","serialized: string[]","map: any","translations: TranslationContent[NodeType.Translation]","map: EnumerationContent[NodeType.Enumeration]","map: ConditionContent[NodeType.Condition]","map: GenderContent[NodeType.Gender]","content: InsertionContent[NodeType.Insertion]","content: MarkdownContent[NodeType.Markdown]","path: FileContent[NodeType.File]","content: NestedContent[NodeType.Nested]","lines: string[]","Project","ts","IndentationText","QuoteKind","NewLineKind","contentObject: ObjectLiteralExpression | undefined","effectiveFallbackLocale: string","dictContent: Record<string, unknown>"],"sources":["../../../src/writeContentDeclaration/transformJSFile.ts"],"sourcesContent":["import type {\n ConditionContent,\n EnumerationContent,\n GenderContent,\n InsertionContent,\n MarkdownContent,\n NestedContent,\n TranslationContent,\n} from '@intlayer/core';\nimport { getNodeType } from '@intlayer/core';\nimport type { FileContent } from '@intlayer/core/file';\nimport {\n type ContentNode,\n type Dictionary,\n type Locale,\n NodeType,\n type StrictModeLocaleMap,\n} from '@intlayer/types';\nimport {\n type CallExpression,\n IndentationText,\n NewLineKind,\n Node,\n type ObjectLiteralExpression,\n Project,\n QuoteKind,\n type SourceFile,\n SyntaxKind,\n ts,\n} from 'ts-morph';\n\n/**\n * Builds a translation initializer string for the 't' function call.\n * Creates a properly formatted translation object with locale keys and values.\n *\n * @param translationMap - Map of locale codes to translation values\n * @param typeArgumentsText - Optional generic type arguments for the translation function\n * @returns Formatted string for the translation function call\n */\nconst buildTranslationInitializer = (\n translationMap: TranslationContent[NodeType.Translation],\n typeArgumentsText?: string\n): string => {\n // Convert map to entries and sort for consistent output\n // Identifiers first (a-z), then others alphabetically\n const translationEntries = Object.entries(translationMap).sort(\n ([firstKey], [secondKey]) => firstKey.localeCompare(secondKey)\n );\n\n const translationParts: string[] = [];\n\n for (const [localeCode, translationValue] of translationEntries) {\n // Check if locale code is a valid JavaScript identifier\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n localeCode\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? localeCode\n : JSON.stringify(localeCode);\n\n if (typeof translationValue === 'string') {\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n } else if (Array.isArray(translationValue)) {\n const serializedArrayElements = (translationValue as string[])\n .map((arrayElement) => JSON.stringify(arrayElement))\n .join(', ');\n\n translationParts.push(\n `${formattedLocaleKey}: [ ${serializedArrayElements} ]`\n );\n } else {\n // Fallback to JSON serialization for non-string values to avoid breaking\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n }\n }\n\n return `t${typeArgumentsText ?? ''}({ ${translationParts.join(', ')} })`;\n};\n\n/**\n * Synchronizes numeric suffixes across locales to maintain consistency.\n * When updating a fallback locale's numeric suffix, this function updates\n * the corresponding numeric suffixes in other locales to match.\n *\n * This is useful for maintaining numbered lists across translations,\n * e.g., \"Hello 1\" / \"Bonjour 1\" when updating to \"Hello 3\".\n *\n * @param existingTranslationMap - Current translation map with locale values\n * @param fallbackLocaleCode - The locale being updated (fallback)\n * @param newFallbackValue - The new value for the fallback locale\n * @returns Updated translation map with synchronized numeric suffixes\n */\nconst syncNumericSuffixAcrossLocales = (\n existingTranslationMap: Record<string, string>,\n fallbackLocaleCode: string,\n newFallbackValue: string\n): Record<string, string> => {\n const updatedTranslationMap: Record<string, string> = {\n ...existingTranslationMap,\n [fallbackLocaleCode]: newFallbackValue,\n };\n\n // Extract the trailing number from the new fallback value\n const trailingNumberMatch = newFallbackValue.match(/\\d+(?!.*\\d)/);\n\n if (!trailingNumberMatch) return updatedTranslationMap;\n const newTrailingNumber = trailingNumberMatch[0];\n\n // Update numeric suffixes in other locales to match the new fallback number\n for (const [localeCode, currentValue] of Object.entries(\n existingTranslationMap\n )) {\n if (localeCode === fallbackLocaleCode) continue;\n\n const currentTrailingNumberMatch = currentValue.match(/\\d+(?!.*\\d)/);\n\n if (!currentTrailingNumberMatch) continue;\n\n // Replace the trailing number in this locale with the new number\n updatedTranslationMap[localeCode] = currentValue.replace(\n /(\\d+)(?!.*\\d)/,\n newTrailingNumber\n );\n }\n\n return updatedTranslationMap;\n};\n\n/**\n * Safely formats a key for use in object literals.\n * Handles special cases like reserved keywords and non-identifier keys.\n *\n * @param objectKey - The key to format\n * @returns Properly formatted key string\n */\nconst stringifyKey = (objectKey: string): string => {\n const isKeyValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(objectKey);\n\n if (!isKeyValidIdentifier) return JSON.stringify(objectKey);\n\n // Handle reserved keywords that need to be quoted\n if (objectKey === 'true' || objectKey === 'false')\n return JSON.stringify(objectKey);\n\n return objectKey;\n};\n\n/**\n * Builds an enumeration initializer string for the 'enu' function call.\n * Creates a properly formatted enumeration object with key-value pairs.\n *\n * @param enumerationMap - Map of enumeration keys to string values\n * @returns Formatted string for the enumeration function call, or empty string if invalid\n */\nconst buildEnumerationInitializer = (\n enumerationMap: EnumerationContent[NodeType.Enumeration]\n): string => {\n const enumerationParts: string[] = [];\n\n for (const [enumerationKey, enumerationValue] of Object.entries(\n enumerationMap\n )) {\n if (typeof enumerationValue !== 'string') return '';\n // Non-string values are not supported for enumerations\n enumerationParts.push(\n `${stringifyKey(enumerationKey)}: ${JSON.stringify(enumerationValue)}`\n );\n }\n\n return `enu({ ${enumerationParts.join(', ')} })`;\n};\n\n/**\n * Builds a condition initializer string for the 'cond' function call.\n * Creates a properly formatted condition object with key-value pairs.\n *\n * @param conditionMap - Map of condition keys to string values\n * @returns Formatted string for the condition function call, or empty string if invalid\n */\nconst buildConditionInitializer = (\n conditionMap: ConditionContent[NodeType.Condition]\n): string => {\n const conditionParts: string[] = [];\n\n for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {\n if (typeof conditionValue !== 'string') return '';\n\n conditionParts.push(\n `${stringifyKey(conditionKey)}: ${JSON.stringify(conditionValue)}`\n );\n }\n\n return `cond({ ${conditionParts.join(', ')} })`;\n};\n\n/**\n * Builds a gender initializer string for the 'gender' function call.\n * Creates a properly formatted gender object with key-value pairs.\n *\n * @param genderMap - Map of gender keys to string values\n * @returns Formatted string for the gender function call, or empty string if invalid\n */\nconst buildGenderInitializer = (\n genderMap: GenderContent[NodeType.Gender]\n): string => {\n const genderParts: string[] = [];\n\n for (const [genderKey, genderValue] of Object.entries(genderMap)) {\n if (typeof genderValue !== 'string') return '';\n\n genderParts.push(\n `${stringifyKey(genderKey)}: ${JSON.stringify(genderValue)}`\n );\n }\n\n return `gender({ ${genderParts.join(', ')} })`;\n};\n\n/**\n * Builds an insertion initializer string for the 'insert' function call.\n * Handles both string content and translation content for insertions.\n *\n * @param insertionContent - The content to be inserted (string or translation)\n * @returns Formatted string for the insertion function call, or undefined if invalid\n */\nconst buildInsertionInitializer = (\n insertionContent: InsertionContent[NodeType.Insertion]\n): string | undefined => {\n if (typeof insertionContent === 'string')\n return `insert(${JSON.stringify(insertionContent)})`;\n\n if (getNodeType(insertionContent as ContentNode) === NodeType.Translation) {\n const translationContent = insertionContent as TranslationContent;\n const translationMap = translationContent[NodeType.Translation] ?? {};\n\n const areAllValuesStrings = Object.values(translationMap).every(\n (translationValue) => typeof translationValue === 'string'\n );\n\n if (!areAllValuesStrings) return undefined;\n\n return `insert(${buildTranslationInitializer(translationMap)})`;\n }\n\n return;\n};\n\n/**\n * Builds a file initializer string for the 'file' function call.\n * Creates a properly formatted file path reference.\n *\n * @param filePath - The file path to reference\n * @returns Formatted string for the file function call, or undefined if invalid\n */\nconst buildFileInitializer = (filePath: unknown): string | undefined => {\n if (typeof filePath === 'string') return `file(${JSON.stringify(filePath)})`;\n\n return;\n};\n\n/**\n * Builds a markdown initializer string for the 'md' function call.\n * Handles string content, translation content, and file references for markdown.\n *\n * @param markdownContent - The markdown content (string, translation, or file reference)\n * @returns Formatted string for the markdown function call, or undefined if invalid\n */\nconst buildMarkdownInitializer = (\n markdownContent: MarkdownContent[NodeType.Markdown]\n): string | undefined => {\n if (typeof markdownContent === 'string')\n return `md(${JSON.stringify(markdownContent)})`;\n\n // Support markdown translations: md(t({ en: '...', fr: '...' }))\n if (getNodeType(markdownContent as ContentNode) === NodeType.Translation) {\n const translationContent = markdownContent as TranslationContent;\n const translationMap = translationContent[NodeType.Translation] ?? {};\n const areAllValuesStrings = Object.values(translationMap).every(\n (translationValue) => typeof translationValue === 'string'\n );\n\n if (!areAllValuesStrings) return undefined;\n\n return `md(${buildTranslationInitializer(translationMap)})`;\n }\n\n if (getNodeType(markdownContent as ContentNode) === NodeType.File) {\n const filePath = (markdownContent as FileContent)[NodeType.File];\n\n const fileInitializer = buildFileInitializer(filePath);\n\n if (!fileInitializer) return undefined;\n\n return `md(${fileInitializer})`;\n }\n\n return;\n};\n\n/**\n * Builds a nested initializer string for the 'nest' function call.\n * Creates a properly formatted nested dictionary reference.\n *\n * @param nestedContent - The nested content with dictionary key and optional path\n * @returns Formatted string for the nested function call, or undefined if invalid\n */\nconst buildNestedInitializer = (\n nestedContent: NestedContent[NodeType.Nested]\n): string | undefined => {\n // nestedContent is already the unwrapped { dictionaryKey, path } object\n\n if (!nestedContent || typeof nestedContent.dictionaryKey !== 'string')\n return undefined;\n\n if (nestedContent.path && typeof nestedContent.path === 'string') {\n return `nest(${JSON.stringify(nestedContent.dictionaryKey)}, ${JSON.stringify(nestedContent.path)})`;\n }\n\n return `nest(${JSON.stringify(nestedContent.dictionaryKey)})`;\n};\n\n/**\n * Reads an existing translation map from a property in a content object.\n * Parses the 't' function call and extracts the translation key-value pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyName - The name of the property to read\n * @returns Translation map with locale keys and values, or undefined if not found\n */\nconst readExistingTranslationMap = (\n contentObject: ObjectLiteralExpression,\n propertyName: string\n): Record<string, string | string[]> | undefined => {\n const property = contentObject.getProperty(propertyName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const propertyInitializer = property.getInitializer();\n\n if (!propertyInitializer) return undefined;\n\n if (!Node.isCallExpression(propertyInitializer)) return undefined;\n\n const callExpression = propertyInitializer.getExpression();\n\n if (!Node.isIdentifier(callExpression) || callExpression.getText() !== 't')\n return undefined;\n\n const translationArgument = propertyInitializer.getArguments()[0];\n\n if (\n !translationArgument ||\n !Node.isObjectLiteralExpression(translationArgument)\n )\n return undefined;\n\n const translationMap: Record<string, string | string[]> = {};\n\n for (const propertyAssignment of translationArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n translationMap[cleanPropertyName] = valueInitializer.getLiteralValue();\n } else if (\n valueInitializer &&\n Node.isArrayLiteralExpression(valueInitializer)\n ) {\n const stringArray: string[] = [];\n\n for (const arrayElement of valueInitializer.getElements()) {\n if (!Node.isStringLiteral(arrayElement)) return undefined;\n stringArray.push(arrayElement.getLiteralValue());\n }\n translationMap[cleanPropertyName] = stringArray;\n } else {\n return undefined;\n }\n }\n\n return translationMap;\n};\n\n/**\n * Reads an existing map from a function call (enu, cond, or gender).\n * Parses the function call and extracts the key-value pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyName - The name of the property to read\n * @param functionName - The name of the function to look for ('enu', 'cond', or 'gender')\n * @returns Map with keys and string values, or undefined if not found\n */\nconst readExistingMapFromCall = (\n contentObject: ObjectLiteralExpression,\n propertyName: string,\n functionName: 'enu' | 'cond' | 'gender'\n): Record<string, string> | undefined => {\n const property = contentObject.getProperty(propertyName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const propertyInitializer = property.getInitializer();\n\n if (!propertyInitializer || !Node.isCallExpression(propertyInitializer))\n return undefined;\n\n const callExpression = propertyInitializer.getExpression();\n\n if (\n !Node.isIdentifier(callExpression) ||\n callExpression.getText() !== functionName\n )\n return undefined;\n\n const functionArgument = propertyInitializer.getArguments()[0];\n\n if (!functionArgument || !Node.isObjectLiteralExpression(functionArgument))\n return undefined;\n\n const keyValueMap: Record<string, string> = {};\n\n for (const propertyAssignment of functionArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n keyValueMap[cleanPropertyName] = valueInitializer.getLiteralValue();\n }\n }\n\n return keyValueMap;\n};\n\n/**\n * Extracts generic type arguments text from a call expression.\n * Returns the type arguments as a string (e.g., \"<string[]>\").\n *\n * @param callExpression - The call expression to extract type arguments from\n * @returns Type arguments as a string, or undefined if none found\n */\nconst getCallExpressionTypeArgsText = (\n callExpression: CallExpression\n): string | undefined => {\n try {\n const typeArguments = callExpression.getTypeArguments();\n if (!typeArguments || typeArguments.length === 0) return undefined;\n const typeArgumentsText = `<${typeArguments.map((typeArgument) => typeArgument.getText()).join(', ')}>`;\n return typeArgumentsText;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Reads existing type arguments used in a specific property call.\n * Supports both direct calls and nested calls (e.g., md(t<...>(...))).\n *\n * @param contentObject - The object containing the property\n * @param propertyName - The name of the property to read\n * @param functionName - The name of the function to look for\n * @returns Type arguments as a string, or undefined if not found\n */\nconst readExistingTypeArgsForCall = (\n contentObject: ObjectLiteralExpression,\n propertyName: string,\n functionName:\n | 't'\n | 'md'\n | 'insert'\n | 'enu'\n | 'cond'\n | 'gender'\n | 'nest'\n | 'file'\n): string | undefined => {\n const property = contentObject.getProperty(propertyName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n const propertyInitializer = property.getInitializer();\n\n if (!propertyInitializer || !Node.isCallExpression(propertyInitializer))\n return undefined;\n const callExpression = propertyInitializer.getExpression();\n\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === functionName\n ) {\n return getCallExpressionTypeArgsText(propertyInitializer);\n }\n\n // Support nested md(t<...>(...)) when asking for 't'\n if (\n functionName === 't' &&\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 'md'\n ) {\n const markdownArgument = propertyInitializer.getArguments()[0];\n if (markdownArgument && Node.isCallExpression(markdownArgument)) {\n const innerExpression = markdownArgument.getExpression();\n if (\n Node.isIdentifier(innerExpression) &&\n innerExpression.getText() === 't'\n ) {\n return getCallExpressionTypeArgsText(markdownArgument);\n }\n }\n }\n return undefined;\n};\n\n/**\n * Compares two string maps for equality.\n * Filters out non-string values from the first map before comparison.\n *\n * @param firstMap - First map to compare (may contain non-string values)\n * @param secondMap - Second map to compare (should contain only strings)\n * @returns True if the string values in both maps are equal\n */\nconst areStringMapsEqual = (\n firstMap: Record<string, unknown>,\n secondMap: Record<string, string> | undefined\n): boolean => {\n if (!secondMap) return false;\n\n // Filter to only string values from the first map\n const firstMapStringEntries = Object.entries(firstMap).filter(\n ([, value]) => typeof value === 'string'\n ) as [string, string][];\n\n // Check if all values in first map are strings\n if (firstMapStringEntries.length !== Object.keys(firstMap).length)\n return false;\n\n // Check if both maps have the same number of entries\n if (firstMapStringEntries.length !== Object.keys(secondMap).length)\n return false;\n\n // Compare each key-value pair\n for (const [key, value] of firstMapStringEntries) {\n if (!(key in secondMap)) return false;\n\n if (secondMap[key] !== value) return false;\n }\n\n return true;\n};\n\n/**\n * Compares translation maps for equality.\n * Handles both string and array values in translations.\n *\n * @param desiredTranslationMap - The desired translation map\n * @param existingTranslationMap - The existing translation map to compare against\n * @returns True if both translation maps are equal\n */\nconst areTranslationsEqual = (\n desiredTranslationMap: Record<string, unknown>,\n existingTranslationMap: Record<string, string | string[]> | undefined\n): boolean => {\n if (!existingTranslationMap) return false;\n\n for (const [localeCode, desiredValue] of Object.entries(\n desiredTranslationMap\n )) {\n if (!(localeCode in existingTranslationMap)) return false;\n const existingValue = existingTranslationMap[localeCode];\n\n if (typeof desiredValue === 'string') {\n if (typeof existingValue !== 'string') return false;\n\n if (existingValue !== desiredValue) return false;\n } else if (Array.isArray(desiredValue)) {\n if (!Array.isArray(existingValue)) return false;\n\n if (existingValue.length !== desiredValue.length) return false;\n\n for (let arrayIndex = 0; arrayIndex < desiredValue.length; arrayIndex++)\n if (existingValue[arrayIndex] !== desiredValue[arrayIndex])\n return false;\n } else {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Gets existing property names from the content object.\n * Handles both regular property assignments and shorthand properties.\n *\n * @param contentObject - The object literal expression to extract property names from\n * @returns Set of existing property names\n */\nconst getExistingPropertyNames = (\n contentObject: ObjectLiteralExpression\n): Set<string> => {\n const existingPropertyNames = new Set<string>();\n\n for (const property of contentObject.getProperties()) {\n if (Node.isPropertyAssignment(property)) {\n const propertyName = property.getName();\n\n if (propertyName)\n existingPropertyNames.add(propertyName.replace(/^['\"]|['\"]$/g, ''));\n continue;\n }\n // Also consider shorthand properties like { pricing }\n if (Node.isShorthandPropertyAssignment(property)) {\n const shorthandPropertyName = property.getNameNode().getText();\n if (shorthandPropertyName)\n existingPropertyNames.add(shorthandPropertyName);\n }\n }\n return existingPropertyNames;\n};\n\n/**\n * Processes array content entries.\n * Handles arrays of various content types including strings, objects, and complex content nodes.\n * Supports nested objects within arrays and maintains existing translation structures.\n *\n * @param contentObject - The object containing the array property\n * @param propertyKey - The key of the array property\n * @param arrayValue - The array of values to process\n * @param existingPropertyKeys - Set of existing property names in the content object\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processArrayContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n arrayValue: unknown[],\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n // If property key is absent locally but present in a spread source, defer to that object\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processArrayContent(\n spreadTargetObject,\n propertyKey,\n arrayValue,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n }\n const serializedArrayElements: string[] = [];\n let hasUnsupportedContent = false;\n let existingArrayElements: import('ts-morph').Node[] | undefined;\n let existingArrayHasTranslation = false;\n let existingArrayTypeArguments: string | undefined;\n let arrayWasChanged = false;\n\n const existingProperty = contentObject.getProperty(propertyKey);\n\n if (existingProperty && Node.isPropertyAssignment(existingProperty)) {\n const propertyInitializer = existingProperty.getInitializer();\n let existingPropertyTypeArguments: string | undefined;\n const areAllDesiredValuesStrings = arrayValue.every(\n (arrayElement) => typeof arrayElement === 'string'\n );\n\n if (\n propertyInitializer &&\n Node.isCallExpression(propertyInitializer) &&\n Node.isIdentifier(propertyInitializer.getExpression()) &&\n propertyInitializer.getExpression().getText() === 't' &&\n areAllDesiredValuesStrings\n ) {\n existingPropertyTypeArguments =\n getCallExpressionTypeArgsText(propertyInitializer);\n const existingTranslationMap = readExistingTranslationMap(\n contentObject,\n propertyKey\n );\n\n if (existingTranslationMap) {\n const updatedTranslationMap = {\n ...existingTranslationMap,\n [effectiveFallbackLocale]: arrayValue as string[],\n } as Record<string, string | string[]>;\n const translationInitializerText = buildTranslationInitializer(\n updatedTranslationMap as any,\n existingPropertyTypeArguments\n );\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n const currentInitializerText = property.getInitializer()?.getText();\n\n if (currentInitializerText !== translationInitializerText) {\n property.setInitializer(translationInitializerText);\n return true;\n }\n }\n return false;\n }\n }\n\n if (\n propertyInitializer &&\n Node.isArrayLiteralExpression(propertyInitializer)\n ) {\n existingArrayElements = propertyInitializer.getElements();\n existingArrayHasTranslation = propertyInitializer\n .getElements()\n .some((arrayElement) => {\n if (!Node.isCallExpression(arrayElement)) return false;\n const callExpression = arrayElement.getExpression();\n return (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 't'\n );\n });\n if (existingArrayHasTranslation) {\n for (const arrayElement of existingArrayElements) {\n if (Node.isCallExpression(arrayElement)) {\n const callExpression = arrayElement.getExpression();\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 't'\n ) {\n existingArrayTypeArguments =\n getCallExpressionTypeArgsText(arrayElement);\n if (existingArrayTypeArguments) break;\n }\n }\n }\n }\n }\n }\n\n for (let elementIndex = 0; elementIndex < arrayValue.length; elementIndex++) {\n const currentElement = arrayValue[elementIndex];\n\n if (\n currentElement === null ||\n currentElement === undefined ||\n typeof currentElement === 'string' ||\n typeof currentElement === 'number' ||\n typeof currentElement === 'boolean'\n ) {\n let serializedElementValue = serializeValue(\n currentElement as ContentNode\n );\n\n if (\n typeof currentElement === 'string' &&\n existingArrayElements &&\n elementIndex < existingArrayElements.length\n ) {\n const existingArrayElement = existingArrayElements[elementIndex];\n\n if (Node.isCallExpression(existingArrayElement)) {\n const callExpression = existingArrayElement.getExpression();\n\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 't'\n ) {\n const translationArgument = existingArrayElement.getArguments()[0];\n\n if (\n translationArgument &&\n Node.isObjectLiteralExpression(translationArgument)\n ) {\n const translationMap: Record<string, string> = {};\n\n for (const propertyAssignment of translationArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(\n /^['\"]|['\"]$/g,\n ''\n );\n const propertyValue = propertyAssignment.getInitializer();\n\n if (propertyValue && Node.isStringLiteral(propertyValue)) {\n translationMap[cleanPropertyName] =\n propertyValue.getLiteralValue();\n }\n }\n\n const updatedTranslationMap = syncNumericSuffixAcrossLocales(\n translationMap,\n effectiveFallbackLocale,\n currentElement\n ) as StrictModeLocaleMap;\n\n const translationTypeArguments =\n getCallExpressionTypeArgsText(existingArrayElement);\n serializedElementValue = buildTranslationInitializer(\n updatedTranslationMap,\n translationTypeArguments\n );\n requiredImports.add('t');\n }\n }\n }\n }\n\n if (\n typeof currentElement === 'string' &&\n existingArrayHasTranslation &&\n serializedElementValue &&\n serializedElementValue.startsWith('\"')\n ) {\n serializedElementValue = buildTranslationInitializer(\n {\n [effectiveFallbackLocale]: currentElement,\n } as StrictModeLocaleMap,\n existingArrayTypeArguments\n );\n\n requiredImports.add('t');\n }\n\n if (serializedElementValue === undefined) {\n hasUnsupportedContent = true;\n break;\n }\n\n serializedArrayElements.push(serializedElementValue);\n } else if (typeof currentElement === 'object' && currentElement !== null) {\n // Handle nested objects within arrays\n\n if (\n existingArrayElements &&\n elementIndex < existingArrayElements.length\n ) {\n const existingArrayElement = existingArrayElements[elementIndex];\n\n if (Node.isObjectLiteralExpression(existingArrayElement)) {\n // Process nested object within array element\n const elementWasChanged = processContentEntries(\n existingArrayElement,\n currentElement as Record<string, unknown>,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (elementWasChanged) arrayWasChanged = true;\n\n serializedArrayElements.push(existingArrayElement.getText());\n } else {\n // Element exists but is not an object - serialize normally\n const serializedElementValue = serializeValue(\n currentElement as ContentNode\n );\n\n if (serializedElementValue === undefined) {\n hasUnsupportedContent = true;\n break;\n }\n\n serializedArrayElements.push(serializedElementValue);\n }\n } else {\n // New element - serialize it\n const serializedElementValue = serializeValue(\n currentElement as ContentNode\n );\n\n if (serializedElementValue === undefined) {\n hasUnsupportedContent = true;\n break;\n }\n\n serializedArrayElements.push(serializedElementValue);\n }\n\n const elementNodeType = getNodeType(currentElement as ContentNode);\n\n if (elementNodeType === NodeType.Translation) requiredImports.add('t');\n else if (elementNodeType === NodeType.Enumeration)\n requiredImports.add('enu');\n else if (elementNodeType === NodeType.Condition)\n requiredImports.add('cond');\n else if (elementNodeType === NodeType.Gender)\n requiredImports.add('gender');\n else if (elementNodeType === NodeType.Insertion) {\n requiredImports.add('insert');\n const insertionContent = (currentElement as InsertionContent)[\n NodeType.Insertion\n ];\n\n if (\n typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation\n ) {\n requiredImports.add('t');\n }\n } else if (elementNodeType === NodeType.Markdown) {\n requiredImports.add('md');\n const markdownContent = (currentElement as MarkdownContent)[\n NodeType.Markdown\n ];\n\n if (\n typeof markdownContent === 'object' &&\n markdownContent !== null &&\n getNodeType(markdownContent as ContentNode) === NodeType.File\n ) {\n requiredImports.add('file');\n }\n } else if (elementNodeType === NodeType.File) requiredImports.add('file');\n else if (elementNodeType === NodeType.Nested) requiredImports.add('nest');\n } else {\n hasUnsupportedContent = true;\n break;\n }\n }\n\n if (hasUnsupportedContent) {\n return false;\n }\n\n // If we modified nested objects in place, return the changed status\n if (arrayWasChanged) {\n return true;\n }\n\n const arrayInitializerText = `[ ${serializedArrayElements.join(', ')} ]`;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: arrayInitializerText,\n });\n return true;\n }\n\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n const existingSerializedArray = readExistingArraySerialized(\n contentObject,\n propertyKey\n );\n\n const areArraysEqual =\n existingSerializedArray !== undefined &&\n existingSerializedArray.length === serializedArrayElements.length &&\n existingSerializedArray.every(\n (existingElement, elementIndex) =>\n existingElement === serializedArrayElements[elementIndex]\n );\n\n if (!areArraysEqual) {\n property.setInitializer(arrayInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes primitive content entries (string, number, boolean, null).\n * Handles simple value types and updates existing translation maps when appropriate.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param primitiveValue - The primitive value to process\n * @param existingPropertyKeys - Set of existing property names\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processPrimitiveContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n primitiveValue: string | number | boolean | null,\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n if (\n typeof primitiveValue === 'string' &&\n existingPropertyKeys.has(propertyKey)\n ) {\n const property = contentObject.getProperty(propertyKey);\n\n // Check if existing value is a non-string-literal (e.g., variable reference)\n\n if (property && Node.isPropertyAssignment(property)) {\n const propertyInitializer = property.getInitializer();\n\n // If the existing value is not a string literal or a call expression (like t()),\n // skip updating it to preserve variable references\n\n if (\n propertyInitializer &&\n !Node.isStringLiteral(propertyInitializer) &&\n !Node.isCallExpression(propertyInitializer)\n ) {\n console.log(\n `Skipping update for key \"${propertyKey}\" because existing value is not a string literal`\n );\n return false;\n }\n }\n\n const existingTranslationMap = readExistingTranslationMap(\n contentObject,\n propertyKey\n );\n\n if (existingTranslationMap) {\n const updatedTranslationMap = {\n ...existingTranslationMap,\n [effectiveFallbackLocale]: primitiveValue,\n } as StrictModeLocaleMap;\n\n const translationTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n const translationInitializerText = buildTranslationInitializer(\n updatedTranslationMap,\n translationTypeArguments\n );\n\n requiredImports.add('t');\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(translationInitializerText);\n return true;\n }\n\n return false;\n }\n }\n\n if (!existingPropertyKeys.has(propertyKey)) {\n // If the key is not locally present, but exists in a spread source, update that spread source instead\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n // Recurse into the spread target object\n const nestedObjectWasChanged = processPrimitiveContent(\n spreadTargetObject,\n propertyKey,\n primitiveValue,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n return nestedObjectWasChanged;\n }\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer:\n typeof primitiveValue === 'string'\n ? JSON.stringify(primitiveValue)\n : String(primitiveValue),\n });\n\n return true;\n }\n\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n const propertyInitializer = property.getInitializer();\n\n // Check if existing value is a non-primitive-literal (e.g., variable reference)\n const isPrimitiveLiteral =\n propertyInitializer &&\n (Node.isStringLiteral(propertyInitializer) ||\n Node.isNumericLiteral(propertyInitializer) ||\n propertyInitializer.getKind() === SyntaxKind.TrueKeyword ||\n propertyInitializer.getKind() === SyntaxKind.FalseKeyword ||\n Node.isNullLiteral(propertyInitializer) ||\n Node.isCallExpression(propertyInitializer));\n\n if (propertyInitializer && !isPrimitiveLiteral) {\n console.log(\n `Skipping update for key \"${propertyKey}\" because existing value is not a primitive literal`\n );\n return false;\n }\n\n const currentInitializerText = propertyInitializer?.getText();\n const desiredInitializerText =\n typeof primitiveValue === 'string'\n ? JSON.stringify(primitiveValue)\n : String(primitiveValue);\n\n if (currentInitializerText !== desiredInitializerText) {\n property.setInitializer(desiredInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes complex content entries (translation, enumeration, condition, etc.).\n * Routes content to the appropriate specialized processor based on node type.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The complex content node to process\n * @param existingPropertyKeys - Set of existing property names\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processComplexContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const nodeType = getNodeType(contentNode);\n\n switch (nodeType) {\n case NodeType.Translation:\n return processTranslationContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Enumeration:\n return processEnumerationContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Condition:\n return processConditionContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Gender:\n return processGenderContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Insertion:\n return processInsertionContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Markdown:\n return processMarkdownContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n case NodeType.File:\n return processFileContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Nested:\n return processNestedContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n default:\n return false;\n }\n};\n\n/**\n * Processes translation content.\n * Handles translation objects with locale keys and string/array values.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The translation content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processTranslationContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const translationMap: Record<string, unknown> =\n (contentNode as TranslationContent)[NodeType.Translation] ?? {};\n\n // Check if all values are simple types (strings or arrays)\n const areAllValuesStringsOrArrays = Object.values(translationMap).every(\n (translationValue) =>\n typeof translationValue === 'string' || Array.isArray(translationValue)\n );\n\n // Check if any values are complex content nodes\n const hasComplexContentNodes = Object.values(translationMap).some(\n (translationValue) =>\n typeof translationValue === 'object' &&\n translationValue !== null &&\n !Array.isArray(translationValue) &&\n getNodeType(translationValue as ContentNode) !== NodeType.Text\n );\n\n // If we have complex content nodes, handle them separately\n if (hasComplexContentNodes && !areAllValuesStringsOrArrays) {\n // If property key is absent locally, try to delegate into a spread source that contains the key\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processTranslationContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n }\n\n const translationParts: string[] = [];\n let hasUnsupportedValue = false;\n\n for (const [localeCode, translationValue] of Object.entries(\n translationMap\n )) {\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n localeCode\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? localeCode\n : JSON.stringify(localeCode);\n\n // Handle complex content nodes\n if (\n typeof translationValue === 'object' &&\n translationValue !== null &&\n !Array.isArray(translationValue)\n ) {\n const serializedValue = serializeValue(translationValue as ContentNode);\n if (serializedValue === undefined) {\n hasUnsupportedValue = true;\n break;\n }\n translationParts.push(`${formattedLocaleKey}: ${serializedValue}`);\n\n // Track required imports for nested content\n const nodeType = getNodeType(translationValue as ContentNode);\n if (nodeType === NodeType.Markdown) {\n requiredImports.add('md');\n const markdownContent = (translationValue as MarkdownContent)[\n NodeType.Markdown\n ];\n if (\n typeof markdownContent === 'object' &&\n markdownContent !== null &&\n getNodeType(markdownContent as ContentNode) === NodeType.File\n ) {\n requiredImports.add('file');\n }\n } else if (nodeType === NodeType.File) {\n requiredImports.add('file');\n } else if (nodeType === NodeType.Insertion) {\n requiredImports.add('insert');\n } else if (nodeType === NodeType.Enumeration) {\n requiredImports.add('enu');\n } else if (nodeType === NodeType.Condition) {\n requiredImports.add('cond');\n } else if (nodeType === NodeType.Gender) {\n requiredImports.add('gender');\n } else if (nodeType === NodeType.Nested) {\n requiredImports.add('nest');\n }\n } else if (typeof translationValue === 'string') {\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n } else if (Array.isArray(translationValue)) {\n const serializedArrayElements = translationValue\n .map((arrayElement) => JSON.stringify(arrayElement))\n .join(', ');\n translationParts.push(\n `${formattedLocaleKey}: [ ${serializedArrayElements} ]`\n );\n }\n }\n\n if (hasUnsupportedValue) return false;\n\n const existingTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n const translationInitializerText = `t${existingTypeArguments ?? ''}({ ${translationParts.join(', ')} })`;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n requiredImports.add('t');\n\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: translationInitializerText,\n });\n return true;\n }\n\n const property = contentObject.getProperty(propertyKey);\n if (property && Node.isPropertyAssignment(property)) {\n const currentInitializer = property.getInitializer()?.getText();\n if (currentInitializer !== translationInitializerText) {\n requiredImports.add('t');\n property.setInitializer(translationInitializerText);\n return true;\n }\n }\n\n return false;\n }\n\n // Original logic for simple string/array translations\n if (!areAllValuesStringsOrArrays) return false;\n\n // If property key is absent locally, try to delegate into a spread source that contains the key\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processTranslationContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n }\n\n const translationParts: string[] = [];\n\n for (const [localeCode, translationValue] of Object.entries(translationMap)) {\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n localeCode\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? localeCode\n : JSON.stringify(localeCode);\n\n if (typeof translationValue === 'string') {\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n } else if (Array.isArray(translationValue)) {\n const serializedArrayElements = translationValue\n .map((arrayElement) => JSON.stringify(arrayElement))\n .join(', ');\n translationParts.push(\n `${formattedLocaleKey}: [ ${serializedArrayElements} ]`\n );\n }\n }\n const existingTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n const translationInitializerText = `t${existingTypeArguments ?? ''}({ ${translationParts.join(', ')} })`;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n requiredImports.add('t');\n\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: translationInitializerText,\n });\n return true;\n }\n\n const existingTranslationMap = readExistingTranslationMap(\n contentObject,\n propertyKey\n );\n\n if (!areTranslationsEqual(translationMap, existingTranslationMap)) {\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(translationInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes enumeration content.\n * Handles enumeration objects with key-value string pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The enumeration content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processEnumerationContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const enumerationMap: EnumerationContent[NodeType.Enumeration] = (\n contentNode as EnumerationContent\n )[NodeType.Enumeration];\n\n if (\n !Object.values(enumerationMap).every(\n (enumerationValue) => typeof enumerationValue === 'string'\n )\n )\n return false;\n const enumerationInitializerText =\n buildEnumerationInitializer(enumerationMap);\n\n if (!enumerationInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n // Delegate into spread source if available\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processEnumerationContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('enu');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: enumerationInitializerText,\n });\n return true;\n }\n const existingEnumerationMap = readExistingMapFromCall(\n contentObject,\n propertyKey,\n 'enu'\n );\n\n if (!areStringMapsEqual(enumerationMap, existingEnumerationMap)) {\n requiredImports.add('enu');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(enumerationInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes condition content.\n * Handles condition objects with key-value string pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The condition content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processConditionContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const conditionMap: ConditionContent[NodeType.Condition] = (\n contentNode as ConditionContent\n )[NodeType.Condition];\n\n // Check if condition values are simple strings (old format)\n const hasSimpleStringValues = Object.values(conditionMap).every(\n (conditionValue) => typeof conditionValue === 'string'\n );\n\n if (hasSimpleStringValues) {\n // Handle simple string conditions (old behavior)\n const conditionInitializerText = buildConditionInitializer(conditionMap);\n\n if (!conditionInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processConditionContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('cond');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: conditionInitializerText,\n });\n return true;\n }\n const existingConditionMap = readExistingMapFromCall(\n contentObject,\n propertyKey,\n 'cond'\n );\n\n if (!areStringMapsEqual(conditionMap, existingConditionMap)) {\n requiredImports.add('cond');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(conditionInitializerText);\n return true;\n }\n }\n\n return false;\n }\n\n // Handle nested content nodes within conditions (new behavior)\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processConditionContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n // Property doesn't exist, we can't process nested content\n return false;\n }\n\n // Get the existing cond() call\n const property = contentObject.getProperty(propertyKey);\n if (!property || !Node.isPropertyAssignment(property)) return false;\n\n const propertyInitializer = property.getInitializer();\n if (!propertyInitializer || !Node.isCallExpression(propertyInitializer))\n return false;\n\n const callExpression = propertyInitializer.getExpression();\n if (!Node.isIdentifier(callExpression) || callExpression.getText() !== 'cond')\n return false;\n\n const condArgument = propertyInitializer.getArguments()[0];\n if (!condArgument || !Node.isObjectLiteralExpression(condArgument))\n return false;\n\n requiredImports.add('cond');\n\n // Process each condition branch (true, false, etc.)\n let hasModifications = false;\n for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {\n const nodeType = getNodeType(conditionValue as ContentNode);\n\n if (!nodeType) continue;\n\n // Find the property for this condition key in the cond() argument\n // Handle both regular identifiers and keywords like 'true'/'false'\n let condProperty = condArgument.getProperty(conditionKey);\n // If not found directly, try with stringifyKey which handles special cases\n if (!condProperty) {\n condProperty = condArgument.getProperty(stringifyKey(conditionKey));\n }\n if (!condProperty || !Node.isPropertyAssignment(condProperty)) continue;\n\n const condValueInitializer = condProperty.getInitializer();\n if (!condValueInitializer) continue;\n\n // Handle different content node types within the condition\n if (nodeType === NodeType.Translation) {\n if (!Node.isCallExpression(condValueInitializer)) continue;\n\n const tCallExpression = condValueInitializer.getExpression();\n if (\n !Node.isIdentifier(tCallExpression) ||\n tCallExpression.getText() !== 't'\n )\n continue;\n\n const tArgument = condValueInitializer.getArguments()[0];\n if (!tArgument || !Node.isObjectLiteralExpression(tArgument)) continue;\n\n // Process the translation object\n const translationContent = conditionValue as TranslationContent;\n const translationMap = translationContent[NodeType.Translation];\n\n // Skip if translation map is invalid\n if (!translationMap || typeof translationMap !== 'object') continue;\n\n // Read existing translations from the t() argument\n const existingTranslationMap: Record<string, string | string[]> = {};\n for (const propertyAssignment of tArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n existingTranslationMap[cleanPropertyName] =\n valueInitializer.getLiteralValue();\n } else if (\n valueInitializer &&\n Node.isArrayLiteralExpression(valueInitializer)\n ) {\n const stringArray: string[] = [];\n for (const arrayElement of valueInitializer.getElements()) {\n if (Node.isStringLiteral(arrayElement)) {\n stringArray.push(arrayElement.getLiteralValue());\n }\n }\n existingTranslationMap[cleanPropertyName] = stringArray;\n }\n }\n\n const areEqual = areTranslationsEqual(\n translationMap,\n existingTranslationMap\n );\n\n if (!areEqual) {\n requiredImports.add('t');\n\n // Update the translation object\n for (const [locale, localeValue] of Object.entries(translationMap)) {\n // Format locale key properly for property lookup\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n locale\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? locale\n : JSON.stringify(locale);\n\n // Try to find the property with both the raw locale and formatted key\n let existingProperty = tArgument.getProperty(locale);\n if (!existingProperty && !isLocaleCodeValidIdentifier) {\n // Try with quotes if locale has special characters\n existingProperty = tArgument.getProperty(JSON.stringify(locale));\n }\n\n if (existingProperty && Node.isPropertyAssignment(existingProperty)) {\n const currentValue = existingProperty.getInitializer();\n const newValue = Array.isArray(localeValue)\n ? `[${localeValue.map((v) => JSON.stringify(v)).join(', ')}]`\n : JSON.stringify(localeValue);\n\n if (currentValue?.getText() !== newValue) {\n existingProperty.setInitializer(newValue);\n hasModifications = true;\n }\n } else if (!existingProperty) {\n // Add new locale\n const newValue = Array.isArray(localeValue)\n ? `[${localeValue.map((v) => JSON.stringify(v)).join(', ')}]`\n : JSON.stringify(localeValue);\n\n tArgument.addPropertyAssignment({\n name: formattedLocaleKey,\n initializer: newValue,\n });\n hasModifications = true;\n }\n }\n }\n }\n // Add more handlers for other node types if needed\n }\n\n return hasModifications;\n};\n\n/**\n * Processes gender content.\n * Handles gender objects with key-value string pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The gender content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processGenderContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const genderMap: GenderContent[NodeType.Gender] = (\n contentNode as GenderContent\n )[NodeType.Gender];\n\n if (\n !Object.values(genderMap).every(\n (genderValue) => typeof genderValue === 'string'\n )\n )\n return false;\n const genderInitializerText = buildGenderInitializer(genderMap);\n\n if (!genderInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processGenderContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('gender');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: genderInitializerText,\n });\n return true;\n }\n const existingGenderMap = readExistingMapFromCall(\n contentObject,\n propertyKey,\n 'gender'\n );\n\n if (!areStringMapsEqual(genderMap, existingGenderMap)) {\n requiredImports.add('gender');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(genderInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes insertion content.\n * Handles insertion objects with string or translation content.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The insertion content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processInsertionContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const insertionContent: InsertionContent[NodeType.Insertion] = (\n contentNode as InsertionContent\n )[NodeType.Insertion];\n const insertionInitializerText = buildInsertionInitializer(insertionContent);\n\n if (!insertionInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processInsertionContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('insert');\n\n if (\n typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation\n ) {\n requiredImports.add('t');\n }\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: insertionInitializerText,\n });\n return true;\n }\n const existingInsertion = readExistingInsertion(contentObject, propertyKey);\n const isInsertionSame =\n (typeof insertionContent === 'string' &&\n existingInsertion?.kind === 'string' &&\n existingInsertion.value === insertionContent) ||\n (typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation &&\n existingInsertion?.kind === 'translation' &&\n areStringMapsEqual(\n (insertionContent as TranslationContent)[NodeType.Translation] ?? {},\n existingInsertion.map\n ));\n\n if (!isInsertionSame) {\n requiredImports.add('insert');\n\n if (\n typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation\n ) {\n requiredImports.add('t');\n }\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(insertionInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes markdown content.\n * Handles markdown objects with string, translation, or file content.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The markdown content node\n * @param existingPropertyKeys - Set of existing property names\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processMarkdownContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const markdownContent: MarkdownContent[NodeType.Markdown] = (\n contentNode as MarkdownContent\n )[NodeType.Markdown];\n const markdownInitializerText = buildMarkdownInitializer(markdownContent);\n\n if (!markdownInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processMarkdownContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('md');\n const markdownNodeType = getNodeType(markdownContent as ContentNode);\n\n if (markdownNodeType === NodeType.File) {\n requiredImports.add('file');\n } else if (markdownNodeType === NodeType.Translation) {\n requiredImports.add('t');\n }\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: markdownInitializerText,\n });\n return true;\n }\n const markdownNodeType = getNodeType(markdownContent as ContentNode);\n const existingSimpleMarkdown = readExistingMarkdown(\n contentObject,\n propertyKey\n );\n const existingMarkdownTranslationMap = readExistingMarkdownTranslationMap(\n contentObject,\n propertyKey\n );\n const existingTranslationTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n\n if (\n typeof markdownContent === 'string' &&\n existingMarkdownTranslationMap &&\n effectiveFallbackLocale\n ) {\n const updatedTranslationMap = {\n ...existingMarkdownTranslationMap,\n [effectiveFallbackLocale]: markdownContent,\n } as StrictModeLocaleMap;\n requiredImports.add('md');\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(\n `md(${buildTranslationInitializer(updatedTranslationMap, existingTranslationTypeArguments)})`\n );\n return true;\n }\n return false;\n }\n\n if (markdownNodeType === NodeType.Translation) {\n const markdownTranslationMap = (markdownContent as TranslationContent)[\n NodeType.Translation\n ] as StrictModeLocaleMap;\n const areAllValuesStrings = Object.values(markdownTranslationMap).every(\n (translationValue) => typeof translationValue === 'string'\n );\n\n if (!areAllValuesStrings) return false;\n const areTranslationMapsEqual = areStringMapsEqual(\n markdownTranslationMap,\n existingMarkdownTranslationMap\n );\n\n if (!areTranslationMapsEqual) {\n requiredImports.add('md');\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(\n `md(${buildTranslationInitializer(markdownTranslationMap, existingTranslationTypeArguments)})`\n );\n return true;\n }\n }\n return false;\n }\n\n const isSimpleMarkdownSame =\n (typeof markdownContent === 'string' &&\n existingSimpleMarkdown?.kind === 'string' &&\n existingSimpleMarkdown.value === markdownContent) ||\n (markdownNodeType === NodeType.File &&\n existingSimpleMarkdown?.kind === 'file' &&\n existingSimpleMarkdown.path ===\n (markdownContent as FileContent)[NodeType.File]);\n\n if (!isSimpleMarkdownSame) {\n requiredImports.add('md');\n\n if (markdownNodeType === NodeType.File) {\n requiredImports.add('file');\n }\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(markdownInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes file content.\n * Handles file objects with file path references.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The file content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processFileContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const filePath: FileContent[NodeType.File] = (contentNode as FileContent)[\n NodeType.File\n ];\n const fileInitializerText = buildFileInitializer(filePath);\n\n if (!fileInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processFileContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('file');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: fileInitializerText,\n });\n return true;\n }\n const existingFilePath = readExistingFilePath(contentObject, propertyKey);\n\n if (existingFilePath !== filePath) {\n requiredImports.add('file');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(fileInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes nested content.\n * Handles nested objects with dictionary key and optional path references.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The nested content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processNestedContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const nestedContent: NestedContent[NodeType.Nested] = (\n contentNode as NestedContent\n )[NodeType.Nested];\n const nestedInitializerText = buildNestedInitializer(nestedContent);\n\n if (!nestedInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processNestedContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('nest');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: nestedInitializerText,\n });\n return true;\n }\n const existingNestedContent = readExistingNest(contentObject, propertyKey);\n const isNestedContentSame =\n !!nestedContent &&\n existingNestedContent?.dictionaryKey === nestedContent.dictionaryKey &&\n existingNestedContent?.path === nestedContent.path;\n\n if (!isNestedContentSame) {\n requiredImports.add('nest');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(nestedInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes nested object content.\n * Handles nested objects within content structures.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param nestedObjectValue - The nested object value to process\n * @param _existingPropertyKeys - Set of existing property names (unused)\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processNestedObjectContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n nestedObjectValue: Record<string, unknown>,\n _existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n let childObject: ObjectLiteralExpression | undefined;\n const existingProperty = contentObject.getProperty(propertyKey);\n\n if (existingProperty && Node.isPropertyAssignment(existingProperty)) {\n childObject = existingProperty.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n }\n\n // If property is shorthand or an identifier referencing another object, resolve it\n if (!childObject) {\n const shorthandProperty = contentObject.getProperty(propertyKey);\n if (\n shorthandProperty &&\n Node.isShorthandPropertyAssignment(shorthandProperty)\n ) {\n childObject = resolveNameToObjectLiteral(\n contentObject.getSourceFile(),\n propertyKey\n );\n } else if (\n existingProperty &&\n Node.isPropertyAssignment(existingProperty)\n ) {\n const propertyInitializer = existingProperty.getInitializer();\n if (propertyInitializer) {\n if (Node.isIdentifier(propertyInitializer)) {\n childObject = resolveNameToObjectLiteral(\n sourceFile,\n propertyInitializer.getText()\n );\n } else if (Node.isPropertyAccessExpression(propertyInitializer)) {\n childObject = resolveExpressionToObjectLiteral(\n sourceFile,\n propertyInitializer\n );\n }\n }\n }\n }\n\n if (!childObject) {\n // If property key not local, try route into a spread that already defines it (including nested object/property access like planDetails.free)\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processNestedObjectContent(\n spreadTargetObject,\n propertyKey,\n nestedObjectValue,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: '{ }',\n });\n const newProperty = contentObject.getProperty(propertyKey);\n\n if (newProperty && Node.isPropertyAssignment(newProperty)) {\n childObject = newProperty.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n }\n }\n\n if (childObject) {\n return processContentEntries(\n childObject,\n nestedObjectValue,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n\n return false;\n};\n\n/**\n * Processes content entries in a dictionary object.\n * Routes different content types to appropriate processors.\n *\n * @param contentObject - The object containing the content\n * @param dictionaryContent - The dictionary content to process\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if any content was modified\n */\nconst processContentEntries = (\n contentObject: ObjectLiteralExpression,\n dictionaryContent: Record<string, unknown>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n let contentWasChanged = false;\n\n const existingPropertyKeys = getExistingPropertyNames(contentObject);\n\n for (const [propertyKey, propertyValue] of Object.entries(\n dictionaryContent\n )) {\n if (Array.isArray(propertyValue)) {\n const arrayWasChanged = processArrayContent(\n contentObject,\n propertyKey,\n propertyValue,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (arrayWasChanged) contentWasChanged = true;\n continue;\n }\n\n if (\n typeof propertyValue === 'string' ||\n typeof propertyValue === 'number' ||\n typeof propertyValue === 'boolean' ||\n propertyValue === null\n ) {\n const primitiveWasChanged = processPrimitiveContent(\n contentObject,\n propertyKey,\n propertyValue as string | number | boolean | null,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (primitiveWasChanged) contentWasChanged = true;\n continue;\n }\n\n // Check if it's a complex content node\n const nodeType = getNodeType(propertyValue as ContentNode);\n\n if (\n nodeType !== NodeType.Text &&\n nodeType !== NodeType.Number &&\n nodeType !== NodeType.Boolean &&\n nodeType !== NodeType.Null\n ) {\n const complexContentWasChanged = processComplexContent(\n contentObject,\n propertyKey,\n propertyValue as ContentNode,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (complexContentWasChanged) {\n contentWasChanged = true;\n continue; // Only skip nested handling if we actually processed a complex node\n }\n // Fall through to nested object handling when not a recognized complex node\n }\n\n // Handle nested objects\n\n if (\n propertyValue &&\n typeof propertyValue === 'object' &&\n !Array.isArray(propertyValue) &&\n !(propertyValue as any).nodeType\n ) {\n const nestedObjectWasChanged = processNestedObjectContent(\n contentObject,\n propertyKey,\n propertyValue as Record<string, unknown>,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (nestedObjectWasChanged) contentWasChanged = true;\n }\n }\n\n return contentWasChanged;\n};\n\ntype ExistingInsertionContent =\n | { kind: 'string'; value: string }\n | { kind: 'translation'; map: Record<string, string> };\n\nconst readExistingInsertion = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): ExistingInsertionContent | undefined => {\n const prop = contentObject.getProperty(propName);\n\n if (!prop || !Node.isPropertyAssignment(prop)) return undefined;\n\n const init = prop.getInitializer();\n\n if (!init || !Node.isCallExpression(init)) return undefined;\n\n const exp = init.getExpression();\n\n if (!Node.isIdentifier(exp) || exp.getText() !== 'insert') return undefined;\n\n const argument = init.getArguments()[0];\n\n if (!argument) return undefined;\n\n if (Node.isStringLiteral(argument)) {\n return { kind: 'string', value: argument.getLiteralValue() };\n }\n\n if (Node.isCallExpression(argument)) {\n const argumentExpression = argument.getExpression();\n\n if (\n Node.isIdentifier(argumentExpression) &&\n argumentExpression.getText() === 't'\n ) {\n const translationArgument = argument.getArguments()[0];\n\n if (\n translationArgument &&\n Node.isObjectLiteralExpression(translationArgument)\n ) {\n const map: Record<string, string> = {};\n\n for (const propertyAssignment of translationArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const nameNode = propertyAssignment.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n map[name] = valueInitializer.getLiteralValue();\n }\n }\n\n return { kind: 'translation', map };\n }\n }\n }\n\n return;\n};\n\ntype ExistingMarkdownContent =\n | { kind: 'string'; value: string }\n | { kind: 'file'; path: string };\n\nconst readExistingMarkdown = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): ExistingMarkdownContent | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer) return undefined;\n\n // Pattern 1: md(\"...\") or md(file(\"...\")) or md(t({...}))\n\n if (Node.isCallExpression(initializer)) {\n const expression = initializer.getExpression();\n\n if (!Node.isIdentifier(expression)) return undefined;\n\n if (expression.getText() === 'md') {\n const argument = initializer.getArguments()[0];\n\n if (!argument) return undefined;\n\n if (Node.isStringLiteral(argument)) {\n return { kind: 'string', value: argument.getLiteralValue() };\n }\n\n if (Node.isCallExpression(argument)) {\n const argumentExpression = argument.getExpression();\n\n if (\n Node.isIdentifier(argumentExpression) &&\n argumentExpression.getText() === 'file'\n ) {\n const fileArgument = argument.getArguments()[0];\n\n if (fileArgument && Node.isStringLiteral(fileArgument)) {\n return { kind: 'file', path: fileArgument.getLiteralValue() };\n }\n }\n }\n }\n }\n\n return;\n};\n\nconst readExistingFilePath = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): string | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer || !Node.isCallExpression(initializer)) return undefined;\n\n const expression = initializer.getExpression();\n\n if (!Node.isIdentifier(expression) || expression.getText() !== 'file')\n return undefined;\n\n const argument = initializer.getArguments()[0];\n\n if (argument && Node.isStringLiteral(argument))\n return argument.getLiteralValue();\n\n return;\n};\n\n// Read an existing translation map stored either as md(t({...})) or t({ en: md(\"...\"), fr: md(\"...\") })\nconst readExistingMarkdownTranslationMap = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): Record<string, string> | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer) return undefined;\n\n // Case A: md(t({...}))\n\n if (Node.isCallExpression(initializer)) {\n const exp = initializer.getExpression();\n\n if (Node.isIdentifier(exp) && exp.getText() === 'md') {\n const arg = initializer.getArguments()[0];\n\n if (arg && Node.isCallExpression(arg)) {\n const tExp = arg.getExpression();\n\n if (Node.isIdentifier(tExp) && tExp.getText() === 't') {\n const tArg = arg.getArguments()[0];\n\n if (tArg && Node.isObjectLiteralExpression(tArg)) {\n const map: Record<string, string> = {};\n\n for (const prop of tArg.getProperties()) {\n if (!Node.isPropertyAssignment(prop)) continue;\n const nameNode = prop.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInit = prop.getInitializer();\n\n if (valueInit && Node.isStringLiteral(valueInit)) {\n map[name] = valueInit.getLiteralValue();\n } else {\n return undefined;\n }\n }\n return map;\n }\n }\n }\n }\n }\n\n // Case B: t({ en: md(\"...\"), fr: md(\"...\") })\n\n if (Node.isCallExpression(initializer)) {\n const exp = initializer.getExpression();\n\n if (Node.isIdentifier(exp) && exp.getText() === 't') {\n const tArg = initializer.getArguments()[0];\n\n if (tArg && Node.isObjectLiteralExpression(tArg)) {\n const map: Record<string, string> = {};\n\n for (const prop of tArg.getProperties()) {\n if (!Node.isPropertyAssignment(prop)) continue;\n const nameNode = prop.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInit = prop.getInitializer();\n\n if (\n valueInit &&\n Node.isCallExpression(valueInit) &&\n Node.isIdentifier(valueInit.getExpression()) &&\n valueInit.getExpression().getText() === 'md'\n ) {\n const mdArg = valueInit.getArguments()[0];\n\n if (mdArg && Node.isStringLiteral(mdArg)) {\n map[name] = mdArg.getLiteralValue();\n } else {\n return undefined;\n }\n } else {\n return undefined;\n }\n }\n return map;\n }\n }\n }\n\n return;\n};\n\nconst readExistingNest = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): { dictionaryKey: string; path?: string } | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n let initializer = property.getInitializer();\n\n if (!initializer) return undefined;\n\n // Unwrap type assertions and parentheses\n // Keep drilling until we reach a CallExpression or cannot unwrap further\n let safetyCounter = 0;\n while (safetyCounter++ < 5) {\n if (Node.isCallExpression(initializer)) break;\n // AsExpression, TypeAssertion, ParenthesizedExpression expose getExpression\n const anyInitializer = initializer as unknown as {\n getExpression?: () => unknown;\n };\n const nextExpression = anyInitializer.getExpression?.();\n\n if (\n nextExpression &&\n typeof nextExpression === 'object' &&\n nextExpression !== initializer\n ) {\n initializer = nextExpression as any;\n continue;\n }\n break;\n }\n\n if (!Node.isCallExpression(initializer)) return undefined;\n\n const expression = initializer.getExpression();\n\n if (!Node.isIdentifier(expression) || expression.getText() !== 'nest')\n return undefined;\n\n const [firstArgument, secondArgument] = initializer.getArguments();\n\n if (!firstArgument || !Node.isStringLiteral(firstArgument)) return undefined;\n\n const dictionaryKey = firstArgument.getLiteralValue();\n let path: string | undefined;\n\n if (secondArgument && Node.isStringLiteral(secondArgument))\n path = secondArgument.getLiteralValue();\n\n return { dictionaryKey, path };\n};\n\n// Safely unwrap common wrapper nodes (satisfies/as/parenthesized) to reach the underlying ObjectLiteralExpression\nconst unwrapToObjectLiteral = (\n node: unknown\n): ObjectLiteralExpression | undefined => {\n if (!node || typeof node !== 'object') return undefined;\n\n let current = node as any;\n let safetyCounter = 0;\n while (safetyCounter++ < 8) {\n if (Node.isObjectLiteralExpression(current)) return current;\n\n const next = current?.getExpression?.();\n\n if (next && typeof next === 'object' && next !== current) {\n current = next;\n continue;\n }\n break;\n }\n\n return;\n};\n\n// Resolve an identifier/shorthand property name to the object literal of its variable initializer\nconst resolveNameToObjectLiteral = (\n sourceFile: SourceFile,\n name: string\n): ObjectLiteralExpression | undefined => {\n // Try to find a variable declaration in the same file\n const varDecl = sourceFile.getVariableDeclaration(name);\n if (varDecl) {\n const init = varDecl.getInitializer();\n const obj = unwrapToObjectLiteral(init);\n if (obj) return obj;\n }\n\n // Fallback via symbol resolution\n const identifier = sourceFile.getDescendants().find((n) => {\n return Node.isIdentifier(n) && n.getText() === name;\n });\n const decl = identifier?.getSymbol()?.getDeclarations()?.[0];\n if (decl && Node.isVariableDeclaration(decl)) {\n const obj = unwrapToObjectLiteral(decl.getInitializer());\n if (obj) return obj;\n }\n return undefined;\n};\n\n// Resolve an arbitrary expression to an object literal if it refers to one (identifier or property access)\nconst resolveExpressionToObjectLiteral = (\n sourceFile: SourceFile,\n expr: import('ts-morph').Expression\n): ObjectLiteralExpression | undefined => {\n if (Node.isIdentifier(expr)) {\n return resolveNameToObjectLiteral(sourceFile, expr.getText());\n }\n\n if (Node.isPropertyAccessExpression(expr)) {\n // Resolve the left side first (could be identifier or nested property access)\n const leftResolved = resolveExpressionToObjectLiteral(\n sourceFile,\n expr.getExpression()\n );\n if (!leftResolved) return undefined;\n const propName = expr.getName();\n const prop = leftResolved.getProperty(propName);\n if (prop && Node.isPropertyAssignment(prop)) {\n const init = prop.getInitializer();\n const obj = unwrapToObjectLiteral(init);\n if (obj) return obj;\n // Support aliasing to another identifier: const x = planDetails.free; then use x\n if (init && Node.isIdentifier(init)) {\n return resolveNameToObjectLiteral(sourceFile, init.getText());\n }\n }\n }\n return undefined;\n};\n\n// Find spread source objects for a given object literal, in declaration order\nconst getSpreadSourceObjects = (\n contentObject: ObjectLiteralExpression,\n sourceFile: SourceFile\n): ObjectLiteralExpression[] => {\n const spreads: ObjectLiteralExpression[] = [];\n for (const prop of contentObject.getProperties()) {\n if (Node.isSpreadAssignment(prop)) {\n const expr = prop.getExpression();\n const resolved = resolveExpressionToObjectLiteral(sourceFile, expr);\n if (resolved) spreads.push(resolved);\n }\n }\n return spreads;\n};\n\n// Find the spread source object (prefer the last one) that contains a given key\nconst findSpreadTargetObjectForKey = (\n contentObject: ObjectLiteralExpression,\n key: string,\n sourceFile: SourceFile\n): ObjectLiteralExpression | undefined => {\n const spreads = getSpreadSourceObjects(contentObject, sourceFile);\n for (let i = spreads.length - 1; i >= 0; i--) {\n const spreadObj = spreads[i];\n const prop = spreadObj.getProperty(key);\n if (prop && Node.isPropertyAssignment(prop)) {\n return spreadObj;\n }\n }\n return undefined;\n};\n\nconst readExistingArraySerialized = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): string[] | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer || !Node.isArrayLiteralExpression(initializer))\n return undefined;\n\n const serialized: string[] = [];\n\n for (const element of initializer.getElements()) {\n if (Node.isStringLiteral(element)) {\n serialized.push(JSON.stringify(element.getLiteralValue()));\n continue;\n }\n\n if (Node.isNumericLiteral(element)) {\n serialized.push(element.getText());\n continue;\n }\n\n if (\n element.getKind() === SyntaxKind.TrueKeyword ||\n element.getKind() === SyntaxKind.FalseKeyword\n ) {\n serialized.push(element.getText());\n continue;\n }\n\n if (Node.isNullLiteral(element)) {\n serialized.push('null');\n continue;\n }\n\n if (Node.isCallExpression(element)) {\n const expression = element.getExpression();\n\n if (Node.isIdentifier(expression) && expression.getText() === 't') {\n const argument = element.getArguments()[0];\n\n if (argument && Node.isObjectLiteralExpression(argument)) {\n const map: any = {};\n\n for (const propertyAssignment of argument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment))\n return undefined;\n\n const nameNode = propertyAssignment.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n map[name] = valueInitializer.getLiteralValue();\n } else {\n return undefined;\n }\n }\n serialized.push(buildTranslationInitializer(map));\n continue;\n }\n }\n }\n\n return undefined;\n }\n\n return serialized;\n};\n\nconst serializeValue = (value: ContentNode): string | undefined => {\n const nodeType = getNodeType(value);\n\n if (nodeType === NodeType.Text) return JSON.stringify(value);\n\n if (nodeType === NodeType.Number || nodeType === NodeType.Boolean)\n return String(value);\n\n if (nodeType === NodeType.Null) return 'null';\n\n if (nodeType === NodeType.Translation) {\n const translations: TranslationContent[NodeType.Translation] =\n (value as TranslationContent)[NodeType.Translation] ?? {};\n const allStrings = Object.values(translations).every(\n (v) => typeof v === 'string'\n );\n\n if (!allStrings) return undefined;\n\n return buildTranslationInitializer(translations);\n }\n\n if (nodeType === NodeType.Enumeration) {\n const map: EnumerationContent[NodeType.Enumeration] = (\n value as EnumerationContent\n )[NodeType.Enumeration];\n\n const initializer = buildEnumerationInitializer(map);\n\n return initializer;\n }\n\n if (nodeType === NodeType.Condition) {\n const map: ConditionContent[NodeType.Condition] = (\n value as ConditionContent\n )[NodeType.Condition];\n\n const initializer = buildConditionInitializer(map);\n\n return initializer;\n }\n\n if (nodeType === NodeType.Gender) {\n const map: GenderContent[NodeType.Gender] = (value as GenderContent)[\n NodeType.Gender\n ];\n\n const initializer = buildGenderInitializer(map);\n\n return initializer;\n }\n\n if (nodeType === NodeType.Insertion) {\n const content: InsertionContent[NodeType.Insertion] = (\n value as InsertionContent\n )[NodeType.Insertion];\n\n return buildInsertionInitializer(content);\n }\n\n if (nodeType === NodeType.Markdown) {\n const content: MarkdownContent[NodeType.Markdown] = (\n value as MarkdownContent\n )[NodeType.Markdown];\n\n return buildMarkdownInitializer(content);\n }\n\n if (nodeType === NodeType.File) {\n const path: FileContent[NodeType.File] = (value as FileContent)[\n NodeType.File\n ];\n\n return buildFileInitializer(path);\n }\n\n if (nodeType === NodeType.Nested) {\n const content: NestedContent[NodeType.Nested] = (value as NestedContent)[\n NodeType.Nested\n ];\n\n return buildNestedInitializer(content);\n }\n\n return;\n};\n\n/**\n * Gets the existing imports from @intlayer/core in the source file\n */\nconst getExistingIntlayerImports = (sourceFile: SourceFile): Set<string> => {\n const imported = new Set<string>();\n\n for (const importDecl of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = importDecl.getModuleSpecifierValue();\n\n if (moduleSpecifier === 'intlayer') {\n const namedImports = importDecl.getNamedImports();\n\n for (const namedImport of namedImports) {\n imported.add(namedImport.getName());\n }\n }\n\n if (moduleSpecifier === 'intlayer/file') {\n const namedImports = importDecl.getNamedImports();\n\n for (const namedImport of namedImports) {\n const alias = namedImport.getAliasNode();\n imported.add(alias ? alias.getText() : namedImport.getName());\n }\n }\n }\n\n return imported;\n};\n\n/**\n * Adds missing imports to the source file\n */\nconst addMissingImports = (\n sourceFile: SourceFile,\n requiredImports: Set<string>\n): boolean => {\n if (requiredImports.size === 0) return false;\n\n const existingImports = getExistingIntlayerImports(sourceFile);\n const missingImports = [...requiredImports].filter(\n (imp) => !existingImports.has(imp)\n );\n\n if (missingImports.length === 0) return false;\n\n // Separate 'file' from other imports\n const hasMissingFile = missingImports.includes('file');\n const otherMissingImports = missingImports.filter((imp) => imp !== 'file');\n\n // Find or create @intlayer/core import\n\n if (otherMissingImports.length > 0) {\n const coreImport = sourceFile\n .getImportDeclarations()\n .find((imp) => imp.getModuleSpecifierValue() === 'intlayer');\n\n if (coreImport) {\n // Add to existing import\n const existingNamedImports = coreImport\n .getNamedImports()\n .map((ni) => ni.getName());\n const allImports = [\n ...new Set([...existingNamedImports, ...otherMissingImports]),\n ].sort();\n\n coreImport.removeNamedImports();\n coreImport.addNamedImports(allImports.map((name) => ({ name })));\n } else {\n // Create new import at the top\n sourceFile.insertImportDeclaration(0, {\n moduleSpecifier: 'intlayer',\n namedImports: otherMissingImports.sort().map((name) => ({ name })),\n });\n }\n }\n\n // Handle file import separately with alias\n\n if (hasMissingFile) {\n const fileImport = sourceFile\n .getImportDeclarations()\n .find((imp) => imp.getModuleSpecifierValue() === 'intlayer/file');\n\n if (!fileImport) {\n // Find the position to insert (after @intlayer/core import if it exists)\n const coreImportIndex = sourceFile\n .getImportDeclarations()\n .findIndex((imp) => imp.getModuleSpecifierValue() === 'intlayer');\n\n const insertIndex = coreImportIndex >= 0 ? coreImportIndex + 1 : 0;\n\n sourceFile.insertImportDeclaration(insertIndex, {\n moduleSpecifier: 'intlayer/file',\n namedImports: [{ name: 'file' }],\n });\n }\n }\n\n return true;\n};\n\n/**\n * Detect whether the current source file is written in CommonJS style.\n * Prefers ESM when import/export syntax is present; otherwise detects CJS via require/module.exports.\n */\nconst isCommonJS = (sourceFile: SourceFile): boolean => {\n // Prefer ESM if any ESM import/export is present\n if (sourceFile.getImportDeclarations().length > 0) return false;\n if (sourceFile.getExportDeclarations().length > 0) return false;\n if (sourceFile.getExportAssignments().length > 0) return false;\n\n // Detect classic CJS markers\n for (const statement of sourceFile.getStatements()) {\n if (!Node.isExpressionStatement(statement)) continue;\n const expression = statement.getExpression();\n\n if (!Node.isBinaryExpression(expression)) continue;\n const leftSide = expression.getLeft();\n\n if (!Node.isPropertyAccessExpression(leftSide)) continue;\n const leftExpression = leftSide.getExpression();\n const leftName = leftSide.getName();\n const isModuleExports =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'module' &&\n leftName === 'exports';\n const isExportsDefault =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'exports';\n\n if (isModuleExports || isExportsDefault) return true;\n }\n\n const hasRequire = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .some((call) => {\n const exp = call.getExpression();\n return Node.isIdentifier(exp) && exp.getText() === 'require';\n });\n\n return hasRequire;\n};\n\n/**\n * Adds missing CommonJS requires for intlayer helpers.\n * - Core helpers (t, md, insert, enu, cond, gender, nest) come from require('intlayer') via destructuring\n * - file helper comes from require('intlayer/file') via destructuring\n * Existing destructured requires are respected to avoid duplicates.\n */\nconst addMissingRequires = (\n sourceFile: SourceFile,\n requiredImports: Set<string>\n): boolean => {\n if (requiredImports.size === 0) return false;\n\n const existingCoreNames = new Set<string>();\n let hasFileHelper = false;\n\n for (const varDecl of sourceFile.getVariableDeclarations()) {\n const init = varDecl.getInitializer();\n\n if (!init || !Node.isCallExpression(init)) continue;\n const callee = init.getExpression();\n\n if (!Node.isIdentifier(callee) || callee.getText() !== 'require') continue;\n const arg = init.getArguments()[0];\n\n if (!arg || !Node.isStringLiteral(arg)) continue;\n const spec = arg.getLiteralValue();\n const nameNode = varDecl.getNameNode();\n\n if (spec === 'intlayer') {\n if (Node.isObjectBindingPattern(nameNode)) {\n for (const el of nameNode.getElements()) {\n existingCoreNames.add(el.getNameNode().getText());\n }\n }\n }\n\n if (spec === 'intlayer/file') {\n if (Node.isObjectBindingPattern(nameNode)) {\n for (const el of nameNode.getElements()) {\n if (el.getNameNode().getText() === 'file') hasFileHelper = true;\n }\n } else if (Node.isIdentifier(nameNode) && nameNode.getText() === 'file') {\n hasFileHelper = true;\n }\n }\n }\n\n const requiredList = Array.from(requiredImports);\n const missingCore = requiredList\n .filter((n) => n !== 'file')\n .filter((n) => !existingCoreNames.has(n));\n const needsFile = requiredImports.has('file') && !hasFileHelper;\n\n if (missingCore.length === 0 && !needsFile) return false;\n\n // Insert after directive prologue (e.g., 'use strict') if present\n let insertIndex = 0;\n const statements = sourceFile.getStatements();\n for (const st of statements) {\n if (Node.isExpressionStatement(st)) {\n const expr = st.getExpression();\n\n if (Node.isStringLiteral(expr)) {\n insertIndex += 1;\n continue;\n }\n }\n break;\n }\n\n const lines: string[] = [];\n if (missingCore.length > 0) {\n const sorted = Array.from(new Set(missingCore)).sort();\n lines.push(`const { ${sorted.join(', ')} } = require('intlayer');`);\n }\n if (needsFile) {\n lines.push(\"const { file } = require('intlayer/file');\");\n }\n\n if (lines.length > 0) {\n sourceFile.insertStatements(insertIndex, lines.join('\\n'));\n return true;\n }\n\n return false;\n};\n\n/**\n * Serializes a metadata value to its string representation for code generation\n * Handles: boolean, number, string, and array of strings\n */\nconst serializeMetadataValue = (value: unknown): string => {\n if (Array.isArray(value)) {\n return `[${value.map((item) => JSON.stringify(item)).join(', ')}]`;\n }\n if (typeof value === 'boolean' || typeof value === 'number') {\n return String(value);\n }\n return JSON.stringify(value);\n};\n\n/**\n * Updates a single property in the root object if the value has changed\n */\nconst updateMetadataProperty = (\n rootObject: ObjectLiteralExpression,\n propertyName: string,\n value: unknown\n): boolean => {\n const property =\n rootObject.getProperty(propertyName) ||\n rootObject.getProperty(`'${propertyName}'`) ||\n rootObject.getProperty(`\"${propertyName}\"`);\n const serializedValue = serializeMetadataValue(value);\n\n if (property && Node.isPropertyAssignment(property)) {\n const currentValue = property.getInitializer()?.getText();\n\n if (currentValue !== serializedValue) {\n property.setInitializer(serializedValue);\n return true;\n }\n } else if (!property) {\n rootObject.addPropertyAssignment({\n name: propertyName,\n initializer: serializedValue,\n });\n return true;\n }\n\n return false;\n};\n\n/**\n * Updates dictionary metadata properties in the root object\n * Supports: id, locale, filled, fill, title, description, tags, version, priority, live\n * and any future fields that may be added\n */\nconst updateDictionaryMetadata = (\n rootObject: ObjectLiteralExpression,\n dictionary: Dictionary\n): boolean => {\n let changed = false;\n\n // List of metadata properties to update (excluding 'key' and 'content')\n const metadataProperties: (keyof Dictionary)[] = [\n 'id',\n 'locale',\n 'filled',\n 'fill',\n 'title',\n 'description',\n 'tags',\n 'version',\n 'priority',\n 'live',\n ];\n\n for (const prop of metadataProperties) {\n const value = dictionary[prop];\n\n if (value !== undefined) {\n if (updateMetadataProperty(rootObject, prop as string, value)) {\n changed = true;\n }\n }\n }\n\n return changed;\n};\n\n/**\n * Locates the root dictionary object in the source file\n */\nconst findRootDictionaryObject = (\n sourceFile: SourceFile\n): ObjectLiteralExpression | undefined => {\n // Try to find via export assignment\n const exportAssignment = sourceFile.getExportAssignment((_) => true);\n\n if (exportAssignment) {\n const expression = exportAssignment.getExpression();\n\n if (Node.isIdentifier(expression)) {\n const declarationFromSymbol = expression\n .getSymbol()\n ?.getDeclarations()?.[0];\n const declarationByName =\n declarationFromSymbol ??\n sourceFile.getVariableDeclaration(expression.getText());\n\n if (declarationByName && Node.isVariableDeclaration(declarationByName)) {\n const initializerAny = declarationByName.getInitializer();\n const objectLiteral = unwrapToObjectLiteral(initializerAny);\n\n if (objectLiteral) return objectLiteral;\n }\n } else {\n // Support wrapped default exports like: export default ({ ... } as const)\n // or: export default ({ ... } satisfies Dictionary)\n const objectLiteral = unwrapToObjectLiteral(expression);\n\n if (objectLiteral) return objectLiteral;\n }\n }\n\n // Fallback: find a variable of type Dictionary\n const variableDeclaration = sourceFile.getVariableDeclaration((variable) => {\n try {\n const typeText = variable.getType().getText();\n return (\n typeText.includes('Dictionary') ||\n variable.getName() === 'content' ||\n variable.getName().toLowerCase().includes('dictionary')\n );\n } catch {\n return variable.getName() === 'content';\n }\n });\n\n if (variableDeclaration) {\n const objectLiteral = unwrapToObjectLiteral(\n variableDeclaration.getInitializer()\n );\n\n if (objectLiteral) return objectLiteral;\n }\n\n // Fallback: handle CommonJS patterns\n\n for (const statement of sourceFile.getStatements()) {\n if (!Node.isExpressionStatement(statement)) continue;\n\n const expression = statement.getExpression();\n\n if (!Node.isBinaryExpression(expression)) continue;\n\n const operator = expression.getOperatorToken();\n\n if (operator.getText() !== '=') continue;\n\n const leftSide = expression.getLeft();\n\n if (!Node.isPropertyAccessExpression(leftSide)) continue;\n\n const leftExpression = leftSide.getExpression();\n const leftName = leftSide.getName();\n const isModuleExports =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'module' &&\n leftName === 'exports';\n const isExportsDefault =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'exports' &&\n leftName === 'default';\n\n if (!isModuleExports && !isExportsDefault) continue;\n\n const rightSide = expression.getRight();\n\n if (Node.isObjectLiteralExpression(rightSide)) {\n return rightSide;\n }\n\n if (Node.isIdentifier(rightSide)) {\n const declaration = rightSide.getSymbol()?.getDeclarations()?.[0];\n\n if (declaration && Node.isVariableDeclaration(declaration)) {\n const objectLiteral = unwrapToObjectLiteral(\n declaration.getInitializer()\n );\n\n if (objectLiteral) return objectLiteral;\n }\n }\n }\n\n return;\n};\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided dictionary.\n * It targets a specific dictionary object within the file and updates its\n * metadata (title, description, tags) and content entries.\n *\n * This function now supports inserting translation keys into nested objects\n * within arrays. For example, if you have:\n * ```\n * content: [\n * { question: t({ en: '...', fr: '...' }) }\n * ]\n * ```\n *\n * You can add a new locale (e.g., 'pl') by providing a dictionary with:\n * ```\n * {\n * content: [\n * { question: { [NodeType.Translation]: { en: '...', fr: '...', pl: '...' } } }\n * ]\n * }\n * ```\n *\n * The function will:\n * 1. Detect the existing array structure\n * 2. Navigate into each array element (if it's an object)\n * 3. Recursively process nested properties\n * 4. Update translation maps while preserving existing locales\n */\nexport const transformJSFile = async (\n fileContent: string,\n dictionary: Dictionary,\n fallbackLocale?: Locale\n): Promise<string> => {\n try {\n // If no dictionary provided, nothing to transform\n\n if (!dictionary || typeof dictionary !== 'object') {\n return fileContent;\n }\n\n const project = new Project({\n useInMemoryFileSystem: true,\n skipAddingFilesFromTsConfig: true,\n skipFileDependencyResolution: true,\n compilerOptions: {\n allowJs: true,\n jsx: ts.JsxEmit.Preserve,\n },\n manipulationSettings: {\n indentationText: IndentationText.TwoSpaces,\n quoteKind: QuoteKind.Double, // More safe for JSON.stringify compatibility\n newLineKind: NewLineKind.LineFeed,\n },\n });\n\n const sourceFile = project.createSourceFile('file.tsx', fileContent, {\n overwrite: true,\n });\n\n // Locate the root dictionary object\n const rootObject = findRootDictionaryObject(sourceFile);\n\n if (!rootObject) return fileContent;\n\n let changed = false;\n const requiredImports = new Set<string>();\n\n // Update dictionary metadata (title, description, tags)\n const metadataChanged = updateDictionaryMetadata(rootObject, dictionary);\n\n if (metadataChanged) changed = true;\n\n // Update content if provided\n\n if (dictionary.content) {\n const contentProperty = rootObject.getProperty('content');\n let contentObject: ObjectLiteralExpression | undefined;\n let isContentArrayInSource = false;\n\n if (contentProperty && Node.isPropertyAssignment(contentProperty)) {\n contentObject = contentProperty.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n // Detect if the source file defines content as an array\n isContentArrayInSource = !!contentProperty.getInitializerIfKind(\n SyntaxKind.ArrayLiteralExpression\n );\n }\n\n const effectiveFallbackLocale: string =\n (fallbackLocale as unknown as string) ?? 'en';\n\n if (contentObject && !Array.isArray(dictionary.content)) {\n // Existing behavior when content is an object\n const dictContent: Record<string, unknown> =\n (dictionary.content as unknown as Record<string, unknown>) ?? {};\n\n const contentChanged = processContentEntries(\n contentObject,\n dictContent,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (contentChanged) changed = true;\n } else if (Array.isArray(dictionary.content) && isContentArrayInSource) {\n // New behavior: content is an array in both the dictionary and the source file\n const dictArrayContent: unknown[] =\n (dictionary.content as unknown[]) ?? [];\n\n const contentChanged = processArrayContent(\n rootObject,\n 'content',\n dictArrayContent,\n getExistingPropertyNames(rootObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (contentChanged) changed = true;\n }\n }\n\n if (!changed) return fileContent;\n\n // Add any missing imports/requires before returning the transformed content\n const useCJS = isCommonJS(sourceFile);\n const importsAdded = useCJS\n ? addMissingRequires(sourceFile, requiredImports)\n : addMissingImports(sourceFile, requiredImports);\n\n if (importsAdded || changed) {\n return sourceFile.getFullText();\n }\n\n return fileContent;\n } catch {\n //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iBACA,WACD,CAEmB,WAAU;;;AAIlC,MAAI,CAAC,QAAS,QAAO;AAQrB,OALe,WAAW,WAAW,GAEjC,mBAAmB,YAAY,gBAAgB,GAC/C,kBAAkB,YAAY,gBAAgB,KAE9B,QAClB,QAAO,WAAW,aAAa;AAGjC,SAAO;SACD;AAEN,SAAO"}
1
+ {"version":3,"file":"transformJSFile.cjs","names":["translationParts: string[]","updatedTranslationMap: Record<string, string>","enumerationParts: string[]","conditionParts: string[]","genderParts: string[]","NodeType","Node","translationMap: Record<string, string | string[]>","stringArray: string[]","keyValueMap: Record<string, string>","serializedArrayElements: string[]","existingArrayElements: import('ts-morph').Node[] | undefined","existingArrayTypeArguments: string | undefined","existingPropertyTypeArguments: string | undefined","property","translationMap: Record<string, string>","SyntaxKind","translationMap: Record<string, unknown>","translationInitializerText","translationParts","enumerationMap: EnumerationContent[NodeType.Enumeration]","conditionMap: ConditionContent[NodeType.Condition]","existingTranslationMap: Record<string, string | string[]>","genderMap: GenderContent[NodeType.Gender]","insertionContent: InsertionContent[NodeType.Insertion]","markdownContent: MarkdownContent[NodeType.Markdown]","markdownNodeType","filePath: FileContent[NodeType.File]","nestedContent: NestedContent[NodeType.Nested]","childObject: ObjectLiteralExpression | undefined","map: Record<string, string>","path: string | undefined","spreads: ObjectLiteralExpression[]","serialized: string[]","map: any","translations: TranslationContent[NodeType.Translation]","map: EnumerationContent[NodeType.Enumeration]","map: ConditionContent[NodeType.Condition]","map: GenderContent[NodeType.Gender]","content: InsertionContent[NodeType.Insertion]","content: MarkdownContent[NodeType.Markdown]","path: FileContent[NodeType.File]","content: NestedContent[NodeType.Nested]","lines: string[]","Project","ts","IndentationText","QuoteKind","NewLineKind","contentObject: ObjectLiteralExpression | undefined","effectiveFallbackLocale: string","dictContent: Record<string, unknown>"],"sources":["../../../src/writeContentDeclaration/transformJSFile.ts"],"sourcesContent":["import type {\n ConditionContent,\n EnumerationContent,\n GenderContent,\n InsertionContent,\n MarkdownContent,\n NestedContent,\n TranslationContent,\n} from '@intlayer/core';\nimport { getNodeType } from '@intlayer/core';\nimport type { FileContent } from '@intlayer/core/file';\nimport {\n type ContentNode,\n type Dictionary,\n type Locale,\n NodeType,\n type StrictModeLocaleMap,\n} from '@intlayer/types';\nimport {\n type CallExpression,\n IndentationText,\n NewLineKind,\n Node,\n type ObjectLiteralExpression,\n Project,\n QuoteKind,\n type SourceFile,\n SyntaxKind,\n ts,\n} from 'ts-morph';\n\n/**\n * Builds a translation initializer string for the 't' function call.\n * Creates a properly formatted translation object with locale keys and values.\n *\n * @param translationMap - Map of locale codes to translation values\n * @param typeArgumentsText - Optional generic type arguments for the translation function\n * @returns Formatted string for the translation function call\n */\nconst buildTranslationInitializer = (\n translationMap: TranslationContent[NodeType.Translation],\n typeArgumentsText?: string\n): string => {\n // Convert map to entries and sort for consistent output\n // Identifiers first (a-z), then others alphabetically\n const translationEntries = Object.entries(translationMap).sort(\n ([firstKey], [secondKey]) => firstKey.localeCompare(secondKey)\n );\n\n const translationParts: string[] = [];\n\n for (const [localeCode, translationValue] of translationEntries) {\n // Check if locale code is a valid JavaScript identifier\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n localeCode\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? localeCode\n : JSON.stringify(localeCode);\n\n if (typeof translationValue === 'string') {\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n } else if (Array.isArray(translationValue)) {\n const serializedArrayElements = (translationValue as string[])\n .map((arrayElement) => JSON.stringify(arrayElement))\n .join(', ');\n\n translationParts.push(\n `${formattedLocaleKey}: [ ${serializedArrayElements} ]`\n );\n } else {\n // Fallback to JSON serialization for non-string values to avoid breaking\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n }\n }\n\n return `t${typeArgumentsText ?? ''}({ ${translationParts.join(', ')} })`;\n};\n\n/**\n * Synchronizes numeric suffixes across locales to maintain consistency.\n * When updating a fallback locale's numeric suffix, this function updates\n * the corresponding numeric suffixes in other locales to match.\n *\n * This is useful for maintaining numbered lists across translations,\n * e.g., \"Hello 1\" / \"Bonjour 1\" when updating to \"Hello 3\".\n *\n * @param existingTranslationMap - Current translation map with locale values\n * @param fallbackLocaleCode - The locale being updated (fallback)\n * @param newFallbackValue - The new value for the fallback locale\n * @returns Updated translation map with synchronized numeric suffixes\n */\nconst syncNumericSuffixAcrossLocales = (\n existingTranslationMap: Record<string, string>,\n fallbackLocaleCode: string,\n newFallbackValue: string\n): Record<string, string> => {\n const updatedTranslationMap: Record<string, string> = {\n ...existingTranslationMap,\n [fallbackLocaleCode]: newFallbackValue,\n };\n\n // Extract the trailing number from the new fallback value\n const trailingNumberMatch = newFallbackValue.match(/\\d+(?!.*\\d)/);\n\n if (!trailingNumberMatch) return updatedTranslationMap;\n const newTrailingNumber = trailingNumberMatch[0];\n\n // Update numeric suffixes in other locales to match the new fallback number\n for (const [localeCode, currentValue] of Object.entries(\n existingTranslationMap\n )) {\n if (localeCode === fallbackLocaleCode) continue;\n\n const currentTrailingNumberMatch = currentValue.match(/\\d+(?!.*\\d)/);\n\n if (!currentTrailingNumberMatch) continue;\n\n // Replace the trailing number in this locale with the new number\n updatedTranslationMap[localeCode] = currentValue.replace(\n /(\\d+)(?!.*\\d)/,\n newTrailingNumber\n );\n }\n\n return updatedTranslationMap;\n};\n\n/**\n * Safely formats a key for use in object literals.\n * Handles special cases like reserved keywords and non-identifier keys.\n *\n * @param objectKey - The key to format\n * @returns Properly formatted key string\n */\nconst stringifyKey = (objectKey: string): string => {\n const isKeyValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(objectKey);\n\n if (!isKeyValidIdentifier) return JSON.stringify(objectKey);\n\n // Handle reserved keywords that need to be quoted\n if (objectKey === 'true' || objectKey === 'false')\n return JSON.stringify(objectKey);\n\n return objectKey;\n};\n\n/**\n * Builds an enumeration initializer string for the 'enu' function call.\n * Creates a properly formatted enumeration object with key-value pairs.\n *\n * @param enumerationMap - Map of enumeration keys to string values\n * @returns Formatted string for the enumeration function call, or empty string if invalid\n */\nconst buildEnumerationInitializer = (\n enumerationMap: EnumerationContent[NodeType.Enumeration]\n): string => {\n const enumerationParts: string[] = [];\n\n for (const [enumerationKey, enumerationValue] of Object.entries(\n enumerationMap\n )) {\n if (typeof enumerationValue !== 'string') return '';\n // Non-string values are not supported for enumerations\n enumerationParts.push(\n `${stringifyKey(enumerationKey)}: ${JSON.stringify(enumerationValue)}`\n );\n }\n\n return `enu({ ${enumerationParts.join(', ')} })`;\n};\n\n/**\n * Builds a condition initializer string for the 'cond' function call.\n * Creates a properly formatted condition object with key-value pairs.\n *\n * @param conditionMap - Map of condition keys to string values\n * @returns Formatted string for the condition function call, or empty string if invalid\n */\nconst buildConditionInitializer = (\n conditionMap: ConditionContent[NodeType.Condition]\n): string => {\n const conditionParts: string[] = [];\n\n for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {\n if (typeof conditionValue !== 'string') return '';\n\n conditionParts.push(\n `${stringifyKey(conditionKey)}: ${JSON.stringify(conditionValue)}`\n );\n }\n\n return `cond({ ${conditionParts.join(', ')} })`;\n};\n\n/**\n * Builds a gender initializer string for the 'gender' function call.\n * Creates a properly formatted gender object with key-value pairs.\n *\n * @param genderMap - Map of gender keys to string values\n * @returns Formatted string for the gender function call, or empty string if invalid\n */\nconst buildGenderInitializer = (\n genderMap: GenderContent[NodeType.Gender]\n): string => {\n const genderParts: string[] = [];\n\n for (const [genderKey, genderValue] of Object.entries(genderMap)) {\n if (typeof genderValue !== 'string') return '';\n\n genderParts.push(\n `${stringifyKey(genderKey)}: ${JSON.stringify(genderValue)}`\n );\n }\n\n return `gender({ ${genderParts.join(', ')} })`;\n};\n\n/**\n * Builds an insertion initializer string for the 'insert' function call.\n * Handles both string content and translation content for insertions.\n *\n * @param insertionContent - The content to be inserted (string or translation)\n * @returns Formatted string for the insertion function call, or undefined if invalid\n */\nconst buildInsertionInitializer = (\n insertionContent: InsertionContent[NodeType.Insertion]\n): string | undefined => {\n if (typeof insertionContent === 'string')\n return `insert(${JSON.stringify(insertionContent)})`;\n\n if (getNodeType(insertionContent as ContentNode) === NodeType.Translation) {\n const translationContent = insertionContent as TranslationContent;\n const translationMap = translationContent[NodeType.Translation] ?? {};\n\n const areAllValuesStrings = Object.values(translationMap).every(\n (translationValue) => typeof translationValue === 'string'\n );\n\n if (!areAllValuesStrings) return undefined;\n\n return `insert(${buildTranslationInitializer(translationMap)})`;\n }\n\n return;\n};\n\n/**\n * Builds a file initializer string for the 'file' function call.\n * Creates a properly formatted file path reference.\n *\n * @param filePath - The file path to reference\n * @returns Formatted string for the file function call, or undefined if invalid\n */\nconst buildFileInitializer = (filePath: unknown): string | undefined => {\n if (typeof filePath === 'string') return `file(${JSON.stringify(filePath)})`;\n\n return;\n};\n\n/**\n * Builds a markdown initializer string for the 'md' function call.\n * Handles string content, translation content, and file references for markdown.\n *\n * @param markdownContent - The markdown content (string, translation, or file reference)\n * @returns Formatted string for the markdown function call, or undefined if invalid\n */\nconst buildMarkdownInitializer = (\n markdownContent: MarkdownContent[NodeType.Markdown]\n): string | undefined => {\n if (typeof markdownContent === 'string')\n return `md(${JSON.stringify(markdownContent)})`;\n\n // Support markdown translations: md(t({ en: '...', fr: '...' }))\n if (getNodeType(markdownContent as ContentNode) === NodeType.Translation) {\n const translationContent = markdownContent as TranslationContent;\n const translationMap = translationContent[NodeType.Translation] ?? {};\n const areAllValuesStrings = Object.values(translationMap).every(\n (translationValue) => typeof translationValue === 'string'\n );\n\n if (!areAllValuesStrings) return undefined;\n\n return `md(${buildTranslationInitializer(translationMap)})`;\n }\n\n if (getNodeType(markdownContent as ContentNode) === NodeType.File) {\n const filePath = (markdownContent as FileContent)[NodeType.File];\n\n const fileInitializer = buildFileInitializer(filePath);\n\n if (!fileInitializer) return undefined;\n\n return `md(${fileInitializer})`;\n }\n\n return;\n};\n\n/**\n * Builds a nested initializer string for the 'nest' function call.\n * Creates a properly formatted nested dictionary reference.\n *\n * @param nestedContent - The nested content with dictionary key and optional path\n * @returns Formatted string for the nested function call, or undefined if invalid\n */\nconst buildNestedInitializer = (\n nestedContent: NestedContent[NodeType.Nested]\n): string | undefined => {\n // nestedContent is already the unwrapped { dictionaryKey, path } object\n\n if (!nestedContent || typeof nestedContent.dictionaryKey !== 'string')\n return undefined;\n\n if (nestedContent.path && typeof nestedContent.path === 'string') {\n return `nest(${JSON.stringify(nestedContent.dictionaryKey)}, ${JSON.stringify(nestedContent.path)})`;\n }\n\n return `nest(${JSON.stringify(nestedContent.dictionaryKey)})`;\n};\n\n/**\n * Reads an existing translation map from a property in a content object.\n * Parses the 't' function call and extracts the translation key-value pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyName - The name of the property to read\n * @returns Translation map with locale keys and values, or undefined if not found\n */\nconst readExistingTranslationMap = (\n contentObject: ObjectLiteralExpression,\n propertyName: string\n): Record<string, string | string[]> | undefined => {\n const property = contentObject.getProperty(propertyName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const propertyInitializer = property.getInitializer();\n\n if (!propertyInitializer) return undefined;\n\n if (!Node.isCallExpression(propertyInitializer)) return undefined;\n\n const callExpression = propertyInitializer.getExpression();\n\n if (!Node.isIdentifier(callExpression) || callExpression.getText() !== 't')\n return undefined;\n\n const translationArgument = propertyInitializer.getArguments()[0];\n\n if (\n !translationArgument ||\n !Node.isObjectLiteralExpression(translationArgument)\n )\n return undefined;\n\n const translationMap: Record<string, string | string[]> = {};\n\n for (const propertyAssignment of translationArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n translationMap[cleanPropertyName] = valueInitializer.getLiteralValue();\n } else if (\n valueInitializer &&\n Node.isArrayLiteralExpression(valueInitializer)\n ) {\n const stringArray: string[] = [];\n\n for (const arrayElement of valueInitializer.getElements()) {\n if (!Node.isStringLiteral(arrayElement)) return undefined;\n stringArray.push(arrayElement.getLiteralValue());\n }\n translationMap[cleanPropertyName] = stringArray;\n } else {\n return undefined;\n }\n }\n\n return translationMap;\n};\n\n/**\n * Reads an existing map from a function call (enu, cond, or gender).\n * Parses the function call and extracts the key-value pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyName - The name of the property to read\n * @param functionName - The name of the function to look for ('enu', 'cond', or 'gender')\n * @returns Map with keys and string values, or undefined if not found\n */\nconst readExistingMapFromCall = (\n contentObject: ObjectLiteralExpression,\n propertyName: string,\n functionName: 'enu' | 'cond' | 'gender'\n): Record<string, string> | undefined => {\n const property = contentObject.getProperty(propertyName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const propertyInitializer = property.getInitializer();\n\n if (!propertyInitializer || !Node.isCallExpression(propertyInitializer))\n return undefined;\n\n const callExpression = propertyInitializer.getExpression();\n\n if (\n !Node.isIdentifier(callExpression) ||\n callExpression.getText() !== functionName\n )\n return undefined;\n\n const functionArgument = propertyInitializer.getArguments()[0];\n\n if (!functionArgument || !Node.isObjectLiteralExpression(functionArgument))\n return undefined;\n\n const keyValueMap: Record<string, string> = {};\n\n for (const propertyAssignment of functionArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n keyValueMap[cleanPropertyName] = valueInitializer.getLiteralValue();\n }\n }\n\n return keyValueMap;\n};\n\n/**\n * Extracts generic type arguments text from a call expression.\n * Returns the type arguments as a string (e.g., \"<string[]>\").\n *\n * @param callExpression - The call expression to extract type arguments from\n * @returns Type arguments as a string, or undefined if none found\n */\nconst getCallExpressionTypeArgsText = (\n callExpression: CallExpression\n): string | undefined => {\n try {\n const typeArguments = callExpression.getTypeArguments();\n if (!typeArguments || typeArguments.length === 0) return undefined;\n const typeArgumentsText = `<${typeArguments.map((typeArgument) => typeArgument.getText()).join(', ')}>`;\n return typeArgumentsText;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Reads existing type arguments used in a specific property call.\n * Supports both direct calls and nested calls (e.g., md(t<...>(...))).\n *\n * @param contentObject - The object containing the property\n * @param propertyName - The name of the property to read\n * @param functionName - The name of the function to look for\n * @returns Type arguments as a string, or undefined if not found\n */\nconst readExistingTypeArgsForCall = (\n contentObject: ObjectLiteralExpression,\n propertyName: string,\n functionName:\n | 't'\n | 'md'\n | 'insert'\n | 'enu'\n | 'cond'\n | 'gender'\n | 'nest'\n | 'file'\n): string | undefined => {\n const property = contentObject.getProperty(propertyName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n const propertyInitializer = property.getInitializer();\n\n if (!propertyInitializer || !Node.isCallExpression(propertyInitializer))\n return undefined;\n const callExpression = propertyInitializer.getExpression();\n\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === functionName\n ) {\n return getCallExpressionTypeArgsText(propertyInitializer);\n }\n\n // Support nested md(t<...>(...)) when asking for 't'\n if (\n functionName === 't' &&\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 'md'\n ) {\n const markdownArgument = propertyInitializer.getArguments()[0];\n if (markdownArgument && Node.isCallExpression(markdownArgument)) {\n const innerExpression = markdownArgument.getExpression();\n if (\n Node.isIdentifier(innerExpression) &&\n innerExpression.getText() === 't'\n ) {\n return getCallExpressionTypeArgsText(markdownArgument);\n }\n }\n }\n return undefined;\n};\n\n/**\n * Compares two string maps for equality.\n * Filters out non-string values from the first map before comparison.\n *\n * @param firstMap - First map to compare (may contain non-string values)\n * @param secondMap - Second map to compare (should contain only strings)\n * @returns True if the string values in both maps are equal\n */\nconst areStringMapsEqual = (\n firstMap: Record<string, unknown>,\n secondMap: Record<string, string> | undefined\n): boolean => {\n if (!secondMap) return false;\n\n // Filter to only string values from the first map\n const firstMapStringEntries = Object.entries(firstMap).filter(\n ([, value]) => typeof value === 'string'\n ) as [string, string][];\n\n // Check if all values in first map are strings\n if (firstMapStringEntries.length !== Object.keys(firstMap).length)\n return false;\n\n // Check if both maps have the same number of entries\n if (firstMapStringEntries.length !== Object.keys(secondMap).length)\n return false;\n\n // Compare each key-value pair\n for (const [key, value] of firstMapStringEntries) {\n if (!(key in secondMap)) return false;\n\n if (secondMap[key] !== value) return false;\n }\n\n return true;\n};\n\n/**\n * Compares translation maps for equality.\n * Handles both string and array values in translations.\n *\n * @param desiredTranslationMap - The desired translation map\n * @param existingTranslationMap - The existing translation map to compare against\n * @returns True if both translation maps are equal\n */\nconst areTranslationsEqual = (\n desiredTranslationMap: Record<string, unknown>,\n existingTranslationMap: Record<string, string | string[]> | undefined\n): boolean => {\n if (!existingTranslationMap) return false;\n\n for (const [localeCode, desiredValue] of Object.entries(\n desiredTranslationMap\n )) {\n if (!(localeCode in existingTranslationMap)) return false;\n const existingValue = existingTranslationMap[localeCode];\n\n if (typeof desiredValue === 'string') {\n if (typeof existingValue !== 'string') return false;\n\n if (existingValue !== desiredValue) return false;\n } else if (Array.isArray(desiredValue)) {\n if (!Array.isArray(existingValue)) return false;\n\n if (existingValue.length !== desiredValue.length) return false;\n\n for (let arrayIndex = 0; arrayIndex < desiredValue.length; arrayIndex++)\n if (existingValue[arrayIndex] !== desiredValue[arrayIndex])\n return false;\n } else {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Gets existing property names from the content object.\n * Handles both regular property assignments and shorthand properties.\n *\n * @param contentObject - The object literal expression to extract property names from\n * @returns Set of existing property names\n */\nconst getExistingPropertyNames = (\n contentObject: ObjectLiteralExpression\n): Set<string> => {\n const existingPropertyNames = new Set<string>();\n\n for (const property of contentObject.getProperties()) {\n if (Node.isPropertyAssignment(property)) {\n const propertyName = property.getName();\n\n if (propertyName)\n existingPropertyNames.add(propertyName.replace(/^['\"]|['\"]$/g, ''));\n continue;\n }\n // Also consider shorthand properties like { pricing }\n if (Node.isShorthandPropertyAssignment(property)) {\n const shorthandPropertyName = property.getNameNode().getText();\n if (shorthandPropertyName)\n existingPropertyNames.add(shorthandPropertyName);\n }\n }\n return existingPropertyNames;\n};\n\n/**\n * Processes array content entries.\n * Handles arrays of various content types including strings, objects, and complex content nodes.\n * Supports nested objects within arrays and maintains existing translation structures.\n *\n * @param contentObject - The object containing the array property\n * @param propertyKey - The key of the array property\n * @param arrayValue - The array of values to process\n * @param existingPropertyKeys - Set of existing property names in the content object\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processArrayContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n arrayValue: unknown[],\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n // If property key is absent locally but present in a spread source, defer to that object\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processArrayContent(\n spreadTargetObject,\n propertyKey,\n arrayValue,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n }\n const serializedArrayElements: string[] = [];\n let hasUnsupportedContent = false;\n let existingArrayElements: import('ts-morph').Node[] | undefined;\n let existingArrayHasTranslation = false;\n let existingArrayTypeArguments: string | undefined;\n let arrayWasChanged = false;\n\n const existingProperty = contentObject.getProperty(propertyKey);\n\n if (existingProperty && Node.isPropertyAssignment(existingProperty)) {\n const propertyInitializer = existingProperty.getInitializer();\n let existingPropertyTypeArguments: string | undefined;\n const areAllDesiredValuesStrings = arrayValue.every(\n (arrayElement) => typeof arrayElement === 'string'\n );\n\n if (\n propertyInitializer &&\n Node.isCallExpression(propertyInitializer) &&\n Node.isIdentifier(propertyInitializer.getExpression()) &&\n propertyInitializer.getExpression().getText() === 't' &&\n areAllDesiredValuesStrings\n ) {\n existingPropertyTypeArguments =\n getCallExpressionTypeArgsText(propertyInitializer);\n const existingTranslationMap = readExistingTranslationMap(\n contentObject,\n propertyKey\n );\n\n if (existingTranslationMap) {\n const updatedTranslationMap = {\n ...existingTranslationMap,\n [effectiveFallbackLocale]: arrayValue as string[],\n } as Record<string, string | string[]>;\n const translationInitializerText = buildTranslationInitializer(\n updatedTranslationMap as any,\n existingPropertyTypeArguments\n );\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n const currentInitializerText = property.getInitializer()?.getText();\n\n if (currentInitializerText !== translationInitializerText) {\n property.setInitializer(translationInitializerText);\n return true;\n }\n }\n return false;\n }\n }\n\n if (\n propertyInitializer &&\n Node.isArrayLiteralExpression(propertyInitializer)\n ) {\n existingArrayElements = propertyInitializer.getElements();\n existingArrayHasTranslation = propertyInitializer\n .getElements()\n .some((arrayElement) => {\n if (!Node.isCallExpression(arrayElement)) return false;\n const callExpression = arrayElement.getExpression();\n return (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 't'\n );\n });\n if (existingArrayHasTranslation) {\n for (const arrayElement of existingArrayElements) {\n if (Node.isCallExpression(arrayElement)) {\n const callExpression = arrayElement.getExpression();\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 't'\n ) {\n existingArrayTypeArguments =\n getCallExpressionTypeArgsText(arrayElement);\n if (existingArrayTypeArguments) break;\n }\n }\n }\n }\n }\n }\n\n for (let elementIndex = 0; elementIndex < arrayValue.length; elementIndex++) {\n const currentElement = arrayValue[elementIndex];\n\n if (\n currentElement === null ||\n currentElement === undefined ||\n typeof currentElement === 'string' ||\n typeof currentElement === 'number' ||\n typeof currentElement === 'boolean'\n ) {\n let serializedElementValue = serializeValue(\n currentElement as ContentNode\n );\n\n if (\n typeof currentElement === 'string' &&\n existingArrayElements &&\n elementIndex < existingArrayElements.length\n ) {\n const existingArrayElement = existingArrayElements[elementIndex];\n\n if (Node.isCallExpression(existingArrayElement)) {\n const callExpression = existingArrayElement.getExpression();\n\n if (\n Node.isIdentifier(callExpression) &&\n callExpression.getText() === 't'\n ) {\n const translationArgument = existingArrayElement.getArguments()[0];\n\n if (\n translationArgument &&\n Node.isObjectLiteralExpression(translationArgument)\n ) {\n const translationMap: Record<string, string> = {};\n\n for (const propertyAssignment of translationArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(\n /^['\"]|['\"]$/g,\n ''\n );\n const propertyValue = propertyAssignment.getInitializer();\n\n if (propertyValue && Node.isStringLiteral(propertyValue)) {\n translationMap[cleanPropertyName] =\n propertyValue.getLiteralValue();\n }\n }\n\n const updatedTranslationMap = syncNumericSuffixAcrossLocales(\n translationMap,\n effectiveFallbackLocale,\n currentElement\n ) as StrictModeLocaleMap;\n\n const translationTypeArguments =\n getCallExpressionTypeArgsText(existingArrayElement);\n serializedElementValue = buildTranslationInitializer(\n updatedTranslationMap,\n translationTypeArguments\n );\n requiredImports.add('t');\n }\n }\n }\n }\n\n if (\n typeof currentElement === 'string' &&\n existingArrayHasTranslation &&\n serializedElementValue &&\n serializedElementValue.startsWith('\"')\n ) {\n serializedElementValue = buildTranslationInitializer(\n {\n [effectiveFallbackLocale]: currentElement,\n } as StrictModeLocaleMap,\n existingArrayTypeArguments\n );\n\n requiredImports.add('t');\n }\n\n if (serializedElementValue === undefined) {\n hasUnsupportedContent = true;\n break;\n }\n\n serializedArrayElements.push(serializedElementValue);\n } else if (typeof currentElement === 'object' && currentElement !== null) {\n // Handle nested objects within arrays\n\n if (\n existingArrayElements &&\n elementIndex < existingArrayElements.length\n ) {\n const existingArrayElement = existingArrayElements[elementIndex];\n\n if (Node.isObjectLiteralExpression(existingArrayElement)) {\n // Process nested object within array element\n const elementWasChanged = processContentEntries(\n existingArrayElement,\n currentElement as Record<string, unknown>,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (elementWasChanged) arrayWasChanged = true;\n\n serializedArrayElements.push(existingArrayElement.getText());\n } else {\n // Element exists but is not an object - serialize normally\n const serializedElementValue = serializeValue(\n currentElement as ContentNode\n );\n\n if (serializedElementValue === undefined) {\n hasUnsupportedContent = true;\n break;\n }\n\n serializedArrayElements.push(serializedElementValue);\n }\n } else {\n // New element - serialize it\n const serializedElementValue = serializeValue(\n currentElement as ContentNode\n );\n\n if (serializedElementValue === undefined) {\n hasUnsupportedContent = true;\n break;\n }\n\n serializedArrayElements.push(serializedElementValue);\n }\n\n const elementNodeType = getNodeType(currentElement as ContentNode);\n\n if (elementNodeType === NodeType.Translation) requiredImports.add('t');\n else if (elementNodeType === NodeType.Enumeration)\n requiredImports.add('enu');\n else if (elementNodeType === NodeType.Condition)\n requiredImports.add('cond');\n else if (elementNodeType === NodeType.Gender)\n requiredImports.add('gender');\n else if (elementNodeType === NodeType.Insertion) {\n requiredImports.add('insert');\n const insertionContent = (currentElement as InsertionContent)[\n NodeType.Insertion\n ];\n\n if (\n typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation\n ) {\n requiredImports.add('t');\n }\n } else if (elementNodeType === NodeType.Markdown) {\n requiredImports.add('md');\n const markdownContent = (currentElement as MarkdownContent)[\n NodeType.Markdown\n ];\n\n if (\n typeof markdownContent === 'object' &&\n markdownContent !== null &&\n getNodeType(markdownContent as ContentNode) === NodeType.File\n ) {\n requiredImports.add('file');\n }\n } else if (elementNodeType === NodeType.File) requiredImports.add('file');\n else if (elementNodeType === NodeType.Nested) requiredImports.add('nest');\n } else {\n hasUnsupportedContent = true;\n break;\n }\n }\n\n if (hasUnsupportedContent) {\n return false;\n }\n\n // If we modified nested objects in place, return the changed status\n if (arrayWasChanged) {\n return true;\n }\n\n const arrayInitializerText = `[ ${serializedArrayElements.join(', ')} ]`;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: arrayInitializerText,\n });\n return true;\n }\n\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n const existingSerializedArray = readExistingArraySerialized(\n contentObject,\n propertyKey\n );\n\n const areArraysEqual =\n existingSerializedArray !== undefined &&\n existingSerializedArray.length === serializedArrayElements.length &&\n existingSerializedArray.every(\n (existingElement, elementIndex) =>\n existingElement === serializedArrayElements[elementIndex]\n );\n\n if (!areArraysEqual) {\n property.setInitializer(arrayInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes primitive content entries (string, number, boolean, null).\n * Handles simple value types and updates existing translation maps when appropriate.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param primitiveValue - The primitive value to process\n * @param existingPropertyKeys - Set of existing property names\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processPrimitiveContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n primitiveValue: string | number | boolean | null,\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n if (\n typeof primitiveValue === 'string' &&\n existingPropertyKeys.has(propertyKey)\n ) {\n const property = contentObject.getProperty(propertyKey);\n\n // Check if existing value is a non-string-literal (e.g., variable reference)\n\n if (property && Node.isPropertyAssignment(property)) {\n const propertyInitializer = property.getInitializer();\n\n // If the existing value is not a string literal or a call expression (like t()),\n // skip updating it to preserve variable references\n\n if (\n propertyInitializer &&\n !Node.isStringLiteral(propertyInitializer) &&\n !Node.isCallExpression(propertyInitializer)\n ) {\n console.log(\n `Skipping update for key \"${propertyKey}\" because existing value is not a string literal`\n );\n return false;\n }\n }\n\n const existingTranslationMap = readExistingTranslationMap(\n contentObject,\n propertyKey\n );\n\n if (existingTranslationMap) {\n const updatedTranslationMap = {\n ...existingTranslationMap,\n [effectiveFallbackLocale]: primitiveValue,\n } as StrictModeLocaleMap;\n\n const translationTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n const translationInitializerText = buildTranslationInitializer(\n updatedTranslationMap,\n translationTypeArguments\n );\n\n requiredImports.add('t');\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(translationInitializerText);\n return true;\n }\n\n return false;\n }\n }\n\n if (!existingPropertyKeys.has(propertyKey)) {\n // If the key is not locally present, but exists in a spread source, update that spread source instead\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n // Recurse into the spread target object\n const nestedObjectWasChanged = processPrimitiveContent(\n spreadTargetObject,\n propertyKey,\n primitiveValue,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n return nestedObjectWasChanged;\n }\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer:\n typeof primitiveValue === 'string'\n ? JSON.stringify(primitiveValue)\n : String(primitiveValue),\n });\n\n return true;\n }\n\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n const propertyInitializer = property.getInitializer();\n\n // Check if existing value is a non-primitive-literal (e.g., variable reference)\n const isPrimitiveLiteral =\n propertyInitializer &&\n (Node.isStringLiteral(propertyInitializer) ||\n Node.isNumericLiteral(propertyInitializer) ||\n propertyInitializer.getKind() === SyntaxKind.TrueKeyword ||\n propertyInitializer.getKind() === SyntaxKind.FalseKeyword ||\n Node.isNullLiteral(propertyInitializer) ||\n Node.isCallExpression(propertyInitializer));\n\n if (propertyInitializer && !isPrimitiveLiteral) {\n console.log(\n `Skipping update for key \"${propertyKey}\" because existing value is not a primitive literal`\n );\n return false;\n }\n\n const currentInitializerText = propertyInitializer?.getText();\n const desiredInitializerText =\n typeof primitiveValue === 'string'\n ? JSON.stringify(primitiveValue)\n : String(primitiveValue);\n\n if (currentInitializerText !== desiredInitializerText) {\n property.setInitializer(desiredInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes complex content entries (translation, enumeration, condition, etc.).\n * Routes content to the appropriate specialized processor based on node type.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The complex content node to process\n * @param existingPropertyKeys - Set of existing property names\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processComplexContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const nodeType = getNodeType(contentNode);\n\n switch (nodeType) {\n case NodeType.Translation:\n return processTranslationContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Enumeration:\n return processEnumerationContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Condition:\n return processConditionContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Gender:\n return processGenderContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Insertion:\n return processInsertionContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Markdown:\n return processMarkdownContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n case NodeType.File:\n return processFileContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n case NodeType.Nested:\n return processNestedContent(\n contentObject,\n propertyKey,\n contentNode,\n existingPropertyKeys,\n requiredImports,\n sourceFile\n );\n default:\n return false;\n }\n};\n\n/**\n * Processes translation content.\n * Handles translation objects with locale keys and string/array values.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The translation content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processTranslationContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const translationMap: Record<string, unknown> =\n (contentNode as TranslationContent)[NodeType.Translation] ?? {};\n\n // Check if all values are simple types (strings or arrays)\n const areAllValuesStringsOrArrays = Object.values(translationMap).every(\n (translationValue) =>\n typeof translationValue === 'string' || Array.isArray(translationValue)\n );\n\n // Check if any values are complex content nodes\n const hasComplexContentNodes = Object.values(translationMap).some(\n (translationValue) =>\n typeof translationValue === 'object' &&\n translationValue !== null &&\n !Array.isArray(translationValue) &&\n getNodeType(translationValue as ContentNode) !== NodeType.Text\n );\n\n // If we have complex content nodes, handle them separately\n if (hasComplexContentNodes && !areAllValuesStringsOrArrays) {\n // If property key is absent locally, try to delegate into a spread source that contains the key\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processTranslationContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n }\n\n const translationParts: string[] = [];\n let hasUnsupportedValue = false;\n\n for (const [localeCode, translationValue] of Object.entries(\n translationMap\n )) {\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n localeCode\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? localeCode\n : JSON.stringify(localeCode);\n\n // Handle complex content nodes\n if (\n typeof translationValue === 'object' &&\n translationValue !== null &&\n !Array.isArray(translationValue)\n ) {\n const serializedValue = serializeValue(translationValue as ContentNode);\n if (serializedValue === undefined) {\n hasUnsupportedValue = true;\n break;\n }\n translationParts.push(`${formattedLocaleKey}: ${serializedValue}`);\n\n // Track required imports for nested content\n const nodeType = getNodeType(translationValue as ContentNode);\n if (nodeType === NodeType.Markdown) {\n requiredImports.add('md');\n const markdownContent = (translationValue as MarkdownContent)[\n NodeType.Markdown\n ];\n if (\n typeof markdownContent === 'object' &&\n markdownContent !== null &&\n getNodeType(markdownContent as ContentNode) === NodeType.File\n ) {\n requiredImports.add('file');\n }\n } else if (nodeType === NodeType.File) {\n requiredImports.add('file');\n } else if (nodeType === NodeType.Insertion) {\n requiredImports.add('insert');\n } else if (nodeType === NodeType.Enumeration) {\n requiredImports.add('enu');\n } else if (nodeType === NodeType.Condition) {\n requiredImports.add('cond');\n } else if (nodeType === NodeType.Gender) {\n requiredImports.add('gender');\n } else if (nodeType === NodeType.Nested) {\n requiredImports.add('nest');\n }\n } else if (typeof translationValue === 'string') {\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n } else if (Array.isArray(translationValue)) {\n const serializedArrayElements = translationValue\n .map((arrayElement) => JSON.stringify(arrayElement))\n .join(', ');\n translationParts.push(\n `${formattedLocaleKey}: [ ${serializedArrayElements} ]`\n );\n }\n }\n\n if (hasUnsupportedValue) return false;\n\n const existingTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n const translationInitializerText = `t${existingTypeArguments ?? ''}({ ${translationParts.join(', ')} })`;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n requiredImports.add('t');\n\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: translationInitializerText,\n });\n return true;\n }\n\n const property = contentObject.getProperty(propertyKey);\n if (property && Node.isPropertyAssignment(property)) {\n const currentInitializer = property.getInitializer()?.getText();\n if (currentInitializer !== translationInitializerText) {\n requiredImports.add('t');\n property.setInitializer(translationInitializerText);\n return true;\n }\n }\n\n return false;\n }\n\n // Original logic for simple string/array translations\n if (!areAllValuesStringsOrArrays) return false;\n\n // If property key is absent locally, try to delegate into a spread source that contains the key\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processTranslationContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n }\n\n const translationParts: string[] = [];\n\n for (const [localeCode, translationValue] of Object.entries(translationMap)) {\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n localeCode\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? localeCode\n : JSON.stringify(localeCode);\n\n if (typeof translationValue === 'string') {\n translationParts.push(\n `${formattedLocaleKey}: ${JSON.stringify(translationValue)}`\n );\n } else if (Array.isArray(translationValue)) {\n const serializedArrayElements = translationValue\n .map((arrayElement) => JSON.stringify(arrayElement))\n .join(', ');\n translationParts.push(\n `${formattedLocaleKey}: [ ${serializedArrayElements} ]`\n );\n }\n }\n const existingTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n const translationInitializerText = `t${existingTypeArguments ?? ''}({ ${translationParts.join(', ')} })`;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n requiredImports.add('t');\n\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: translationInitializerText,\n });\n return true;\n }\n\n const existingTranslationMap = readExistingTranslationMap(\n contentObject,\n propertyKey\n );\n\n if (!areTranslationsEqual(translationMap, existingTranslationMap)) {\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(translationInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes enumeration content.\n * Handles enumeration objects with key-value string pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The enumeration content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processEnumerationContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const enumerationMap: EnumerationContent[NodeType.Enumeration] = (\n contentNode as EnumerationContent\n )[NodeType.Enumeration];\n\n if (\n !Object.values(enumerationMap).every(\n (enumerationValue) => typeof enumerationValue === 'string'\n )\n )\n return false;\n const enumerationInitializerText =\n buildEnumerationInitializer(enumerationMap);\n\n if (!enumerationInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n // Delegate into spread source if available\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processEnumerationContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('enu');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: enumerationInitializerText,\n });\n return true;\n }\n const existingEnumerationMap = readExistingMapFromCall(\n contentObject,\n propertyKey,\n 'enu'\n );\n\n if (!areStringMapsEqual(enumerationMap, existingEnumerationMap)) {\n requiredImports.add('enu');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(enumerationInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes condition content.\n * Handles condition objects with key-value string pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The condition content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processConditionContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const conditionMap: ConditionContent[NodeType.Condition] = (\n contentNode as ConditionContent\n )[NodeType.Condition];\n\n // Check if condition values are simple strings (old format)\n const hasSimpleStringValues = Object.values(conditionMap).every(\n (conditionValue) => typeof conditionValue === 'string'\n );\n\n if (hasSimpleStringValues) {\n // Handle simple string conditions (old behavior)\n const conditionInitializerText = buildConditionInitializer(conditionMap);\n\n if (!conditionInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processConditionContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('cond');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: conditionInitializerText,\n });\n return true;\n }\n const existingConditionMap = readExistingMapFromCall(\n contentObject,\n propertyKey,\n 'cond'\n );\n\n if (!areStringMapsEqual(conditionMap, existingConditionMap)) {\n requiredImports.add('cond');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(conditionInitializerText);\n return true;\n }\n }\n\n return false;\n }\n\n // Handle nested content nodes within conditions (new behavior)\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processConditionContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n // Property doesn't exist, we can't process nested content\n return false;\n }\n\n // Get the existing cond() call\n const property = contentObject.getProperty(propertyKey);\n if (!property || !Node.isPropertyAssignment(property)) return false;\n\n const propertyInitializer = property.getInitializer();\n if (!propertyInitializer || !Node.isCallExpression(propertyInitializer))\n return false;\n\n const callExpression = propertyInitializer.getExpression();\n if (!Node.isIdentifier(callExpression) || callExpression.getText() !== 'cond')\n return false;\n\n const condArgument = propertyInitializer.getArguments()[0];\n if (!condArgument || !Node.isObjectLiteralExpression(condArgument))\n return false;\n\n requiredImports.add('cond');\n\n // Process each condition branch (true, false, etc.)\n let hasModifications = false;\n for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {\n const nodeType = getNodeType(conditionValue as ContentNode);\n\n if (!nodeType) continue;\n\n // Find the property for this condition key in the cond() argument\n // Handle both regular identifiers and keywords like 'true'/'false'\n let condProperty = condArgument.getProperty(conditionKey);\n // If not found directly, try with stringifyKey which handles special cases\n if (!condProperty) {\n condProperty = condArgument.getProperty(stringifyKey(conditionKey));\n }\n if (!condProperty || !Node.isPropertyAssignment(condProperty)) continue;\n\n const condValueInitializer = condProperty.getInitializer();\n if (!condValueInitializer) continue;\n\n // Handle different content node types within the condition\n if (nodeType === NodeType.Translation) {\n if (!Node.isCallExpression(condValueInitializer)) continue;\n\n const tCallExpression = condValueInitializer.getExpression();\n if (\n !Node.isIdentifier(tCallExpression) ||\n tCallExpression.getText() !== 't'\n )\n continue;\n\n const tArgument = condValueInitializer.getArguments()[0];\n if (!tArgument || !Node.isObjectLiteralExpression(tArgument)) continue;\n\n // Process the translation object\n const translationContent = conditionValue as TranslationContent;\n const translationMap = translationContent[NodeType.Translation];\n\n // Skip if translation map is invalid\n if (!translationMap || typeof translationMap !== 'object') continue;\n\n // Read existing translations from the t() argument\n const existingTranslationMap: Record<string, string | string[]> = {};\n for (const propertyAssignment of tArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const propertyNameNode = propertyAssignment.getNameNode();\n const rawPropertyName = propertyNameNode.getText();\n const cleanPropertyName = rawPropertyName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n existingTranslationMap[cleanPropertyName] =\n valueInitializer.getLiteralValue();\n } else if (\n valueInitializer &&\n Node.isArrayLiteralExpression(valueInitializer)\n ) {\n const stringArray: string[] = [];\n for (const arrayElement of valueInitializer.getElements()) {\n if (Node.isStringLiteral(arrayElement)) {\n stringArray.push(arrayElement.getLiteralValue());\n }\n }\n existingTranslationMap[cleanPropertyName] = stringArray;\n }\n }\n\n const areEqual = areTranslationsEqual(\n translationMap,\n existingTranslationMap\n );\n\n if (!areEqual) {\n requiredImports.add('t');\n\n // Update the translation object\n for (const [locale, localeValue] of Object.entries(translationMap)) {\n // Format locale key properly for property lookup\n const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(\n locale\n );\n const formattedLocaleKey = isLocaleCodeValidIdentifier\n ? locale\n : JSON.stringify(locale);\n\n // Try to find the property with both the raw locale and formatted key\n let existingProperty = tArgument.getProperty(locale);\n if (!existingProperty && !isLocaleCodeValidIdentifier) {\n // Try with quotes if locale has special characters\n existingProperty = tArgument.getProperty(JSON.stringify(locale));\n }\n\n if (existingProperty && Node.isPropertyAssignment(existingProperty)) {\n const currentValue = existingProperty.getInitializer();\n const newValue = Array.isArray(localeValue)\n ? `[${localeValue.map((v) => JSON.stringify(v)).join(', ')}]`\n : JSON.stringify(localeValue);\n\n if (currentValue?.getText() !== newValue) {\n existingProperty.setInitializer(newValue);\n hasModifications = true;\n }\n } else if (!existingProperty) {\n // Add new locale\n const newValue = Array.isArray(localeValue)\n ? `[${localeValue.map((v) => JSON.stringify(v)).join(', ')}]`\n : JSON.stringify(localeValue);\n\n tArgument.addPropertyAssignment({\n name: formattedLocaleKey,\n initializer: newValue,\n });\n hasModifications = true;\n }\n }\n }\n }\n // Add more handlers for other node types if needed\n }\n\n return hasModifications;\n};\n\n/**\n * Processes gender content.\n * Handles gender objects with key-value string pairs.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The gender content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processGenderContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const genderMap: GenderContent[NodeType.Gender] = (\n contentNode as GenderContent\n )[NodeType.Gender];\n\n if (\n !Object.values(genderMap).every(\n (genderValue) => typeof genderValue === 'string'\n )\n )\n return false;\n const genderInitializerText = buildGenderInitializer(genderMap);\n\n if (!genderInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processGenderContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('gender');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: genderInitializerText,\n });\n return true;\n }\n const existingGenderMap = readExistingMapFromCall(\n contentObject,\n propertyKey,\n 'gender'\n );\n\n if (!areStringMapsEqual(genderMap, existingGenderMap)) {\n requiredImports.add('gender');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(genderInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes insertion content.\n * Handles insertion objects with string or translation content.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The insertion content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processInsertionContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const insertionContent: InsertionContent[NodeType.Insertion] = (\n contentNode as InsertionContent\n )[NodeType.Insertion];\n const insertionInitializerText = buildInsertionInitializer(insertionContent);\n\n if (!insertionInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processInsertionContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('insert');\n\n if (\n typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation\n ) {\n requiredImports.add('t');\n }\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: insertionInitializerText,\n });\n return true;\n }\n const existingInsertion = readExistingInsertion(contentObject, propertyKey);\n const isInsertionSame =\n (typeof insertionContent === 'string' &&\n existingInsertion?.kind === 'string' &&\n existingInsertion.value === insertionContent) ||\n (typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation &&\n existingInsertion?.kind === 'translation' &&\n areStringMapsEqual(\n (insertionContent as TranslationContent)[NodeType.Translation] ?? {},\n existingInsertion.map\n ));\n\n if (!isInsertionSame) {\n requiredImports.add('insert');\n\n if (\n typeof insertionContent === 'object' &&\n insertionContent !== null &&\n getNodeType(insertionContent as ContentNode) === NodeType.Translation\n ) {\n requiredImports.add('t');\n }\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(insertionInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes markdown content.\n * Handles markdown objects with string, translation, or file content.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The markdown content node\n * @param existingPropertyKeys - Set of existing property names\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processMarkdownContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const markdownContent: MarkdownContent[NodeType.Markdown] = (\n contentNode as MarkdownContent\n )[NodeType.Markdown];\n const markdownInitializerText = buildMarkdownInitializer(markdownContent);\n\n if (!markdownInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processMarkdownContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('md');\n const markdownNodeType = getNodeType(markdownContent as ContentNode);\n\n if (markdownNodeType === NodeType.File) {\n requiredImports.add('file');\n } else if (markdownNodeType === NodeType.Translation) {\n requiredImports.add('t');\n }\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: markdownInitializerText,\n });\n return true;\n }\n const markdownNodeType = getNodeType(markdownContent as ContentNode);\n const existingSimpleMarkdown = readExistingMarkdown(\n contentObject,\n propertyKey\n );\n const existingMarkdownTranslationMap = readExistingMarkdownTranslationMap(\n contentObject,\n propertyKey\n );\n const existingTranslationTypeArguments = readExistingTypeArgsForCall(\n contentObject,\n propertyKey,\n 't'\n );\n\n if (\n typeof markdownContent === 'string' &&\n existingMarkdownTranslationMap &&\n effectiveFallbackLocale\n ) {\n const updatedTranslationMap = {\n ...existingMarkdownTranslationMap,\n [effectiveFallbackLocale]: markdownContent,\n } as StrictModeLocaleMap;\n requiredImports.add('md');\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(\n `md(${buildTranslationInitializer(updatedTranslationMap, existingTranslationTypeArguments)})`\n );\n return true;\n }\n return false;\n }\n\n if (markdownNodeType === NodeType.Translation) {\n const markdownTranslationMap = (markdownContent as TranslationContent)[\n NodeType.Translation\n ] as StrictModeLocaleMap;\n const areAllValuesStrings = Object.values(markdownTranslationMap).every(\n (translationValue) => typeof translationValue === 'string'\n );\n\n if (!areAllValuesStrings) return false;\n const areTranslationMapsEqual = areStringMapsEqual(\n markdownTranslationMap,\n existingMarkdownTranslationMap\n );\n\n if (!areTranslationMapsEqual) {\n requiredImports.add('md');\n requiredImports.add('t');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(\n `md(${buildTranslationInitializer(markdownTranslationMap, existingTranslationTypeArguments)})`\n );\n return true;\n }\n }\n return false;\n }\n\n const isSimpleMarkdownSame =\n (typeof markdownContent === 'string' &&\n existingSimpleMarkdown?.kind === 'string' &&\n existingSimpleMarkdown.value === markdownContent) ||\n (markdownNodeType === NodeType.File &&\n existingSimpleMarkdown?.kind === 'file' &&\n existingSimpleMarkdown.path ===\n (markdownContent as FileContent)[NodeType.File]);\n\n if (!isSimpleMarkdownSame) {\n requiredImports.add('md');\n\n if (markdownNodeType === NodeType.File) {\n requiredImports.add('file');\n }\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(markdownInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes file content.\n * Handles file objects with file path references.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The file content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processFileContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const filePath: FileContent[NodeType.File] = (contentNode as FileContent)[\n NodeType.File\n ];\n const fileInitializerText = buildFileInitializer(filePath);\n\n if (!fileInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processFileContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('file');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: fileInitializerText,\n });\n return true;\n }\n const existingFilePath = readExistingFilePath(contentObject, propertyKey);\n\n if (existingFilePath !== filePath) {\n requiredImports.add('file');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(fileInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes nested content.\n * Handles nested objects with dictionary key and optional path references.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param contentNode - The nested content node\n * @param existingPropertyKeys - Set of existing property names\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processNestedContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n contentNode: ContentNode,\n existingPropertyKeys: Set<string>,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n const nestedContent: NestedContent[NodeType.Nested] = (\n contentNode as NestedContent\n )[NodeType.Nested];\n const nestedInitializerText = buildNestedInitializer(nestedContent);\n\n if (!nestedInitializerText) return false;\n\n if (!existingPropertyKeys.has(propertyKey)) {\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processNestedContent(\n spreadTargetObject,\n propertyKey,\n contentNode,\n getExistingPropertyNames(spreadTargetObject),\n requiredImports,\n sourceFile\n );\n }\n requiredImports.add('nest');\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: nestedInitializerText,\n });\n return true;\n }\n const existingNestedContent = readExistingNest(contentObject, propertyKey);\n const isNestedContentSame =\n !!nestedContent &&\n existingNestedContent?.dictionaryKey === nestedContent.dictionaryKey &&\n existingNestedContent?.path === nestedContent.path;\n\n if (!isNestedContentSame) {\n requiredImports.add('nest');\n const property = contentObject.getProperty(propertyKey);\n\n if (property && Node.isPropertyAssignment(property)) {\n property.setInitializer(nestedInitializerText);\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Processes nested object content.\n * Handles nested objects within content structures.\n *\n * @param contentObject - The object containing the property\n * @param propertyKey - The key of the property to process\n * @param nestedObjectValue - The nested object value to process\n * @param _existingPropertyKeys - Set of existing property names (unused)\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if the content was modified\n */\nconst processNestedObjectContent = (\n contentObject: ObjectLiteralExpression,\n propertyKey: string,\n nestedObjectValue: Record<string, unknown>,\n _existingPropertyKeys: Set<string>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n let childObject: ObjectLiteralExpression | undefined;\n const existingProperty = contentObject.getProperty(propertyKey);\n\n if (existingProperty && Node.isPropertyAssignment(existingProperty)) {\n childObject = existingProperty.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n }\n\n // If property is shorthand or an identifier referencing another object, resolve it\n if (!childObject) {\n const shorthandProperty = contentObject.getProperty(propertyKey);\n if (\n shorthandProperty &&\n Node.isShorthandPropertyAssignment(shorthandProperty)\n ) {\n childObject = resolveNameToObjectLiteral(\n contentObject.getSourceFile(),\n propertyKey\n );\n } else if (\n existingProperty &&\n Node.isPropertyAssignment(existingProperty)\n ) {\n const propertyInitializer = existingProperty.getInitializer();\n if (propertyInitializer) {\n if (Node.isIdentifier(propertyInitializer)) {\n childObject = resolveNameToObjectLiteral(\n sourceFile,\n propertyInitializer.getText()\n );\n } else if (Node.isPropertyAccessExpression(propertyInitializer)) {\n childObject = resolveExpressionToObjectLiteral(\n sourceFile,\n propertyInitializer\n );\n }\n }\n }\n }\n\n if (!childObject) {\n // If property key not local, try route into a spread that already defines it (including nested object/property access like planDetails.free)\n const spreadTargetObject = findSpreadTargetObjectForKey(\n contentObject,\n propertyKey,\n sourceFile\n );\n if (spreadTargetObject) {\n return processNestedObjectContent(\n spreadTargetObject,\n propertyKey,\n nestedObjectValue,\n getExistingPropertyNames(spreadTargetObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n\n contentObject.addPropertyAssignment({\n name: propertyKey,\n initializer: '{ }',\n });\n const newProperty = contentObject.getProperty(propertyKey);\n\n if (newProperty && Node.isPropertyAssignment(newProperty)) {\n childObject = newProperty.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n }\n }\n\n if (childObject) {\n return processContentEntries(\n childObject,\n nestedObjectValue,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n }\n\n return false;\n};\n\n/**\n * Processes content entries in a dictionary object.\n * Routes different content types to appropriate processors.\n *\n * @param contentObject - The object containing the content\n * @param dictionaryContent - The dictionary content to process\n * @param effectiveFallbackLocale - The fallback locale for translations\n * @param requiredImports - Set to track required imports\n * @param sourceFile - The source file being processed\n * @returns True if any content was modified\n */\nconst processContentEntries = (\n contentObject: ObjectLiteralExpression,\n dictionaryContent: Record<string, unknown>,\n effectiveFallbackLocale: string,\n requiredImports: Set<string>,\n sourceFile: SourceFile\n): boolean => {\n let contentWasChanged = false;\n\n const existingPropertyKeys = getExistingPropertyNames(contentObject);\n\n for (const [propertyKey, propertyValue] of Object.entries(\n dictionaryContent\n )) {\n if (Array.isArray(propertyValue)) {\n const arrayWasChanged = processArrayContent(\n contentObject,\n propertyKey,\n propertyValue,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (arrayWasChanged) contentWasChanged = true;\n continue;\n }\n\n if (\n typeof propertyValue === 'string' ||\n typeof propertyValue === 'number' ||\n typeof propertyValue === 'boolean' ||\n propertyValue === null\n ) {\n const primitiveWasChanged = processPrimitiveContent(\n contentObject,\n propertyKey,\n propertyValue as string | number | boolean | null,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (primitiveWasChanged) contentWasChanged = true;\n continue;\n }\n\n // Check if it's a complex content node\n const nodeType = getNodeType(propertyValue as ContentNode);\n\n if (\n nodeType !== NodeType.Text &&\n nodeType !== NodeType.Number &&\n nodeType !== NodeType.Boolean &&\n nodeType !== NodeType.Null\n ) {\n const complexContentWasChanged = processComplexContent(\n contentObject,\n propertyKey,\n propertyValue as ContentNode,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (complexContentWasChanged) {\n contentWasChanged = true;\n continue; // Only skip nested handling if we actually processed a complex node\n }\n // Fall through to nested object handling when not a recognized complex node\n }\n\n // Handle nested objects\n\n if (\n propertyValue &&\n typeof propertyValue === 'object' &&\n !Array.isArray(propertyValue) &&\n !(propertyValue as any).nodeType\n ) {\n const nestedObjectWasChanged = processNestedObjectContent(\n contentObject,\n propertyKey,\n propertyValue as Record<string, unknown>,\n existingPropertyKeys,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (nestedObjectWasChanged) contentWasChanged = true;\n }\n }\n\n return contentWasChanged;\n};\n\ntype ExistingInsertionContent =\n | { kind: 'string'; value: string }\n | { kind: 'translation'; map: Record<string, string> };\n\nconst readExistingInsertion = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): ExistingInsertionContent | undefined => {\n const prop = contentObject.getProperty(propName);\n\n if (!prop || !Node.isPropertyAssignment(prop)) return undefined;\n\n const init = prop.getInitializer();\n\n if (!init || !Node.isCallExpression(init)) return undefined;\n\n const exp = init.getExpression();\n\n if (!Node.isIdentifier(exp) || exp.getText() !== 'insert') return undefined;\n\n const argument = init.getArguments()[0];\n\n if (!argument) return undefined;\n\n if (Node.isStringLiteral(argument)) {\n return { kind: 'string', value: argument.getLiteralValue() };\n }\n\n if (Node.isCallExpression(argument)) {\n const argumentExpression = argument.getExpression();\n\n if (\n Node.isIdentifier(argumentExpression) &&\n argumentExpression.getText() === 't'\n ) {\n const translationArgument = argument.getArguments()[0];\n\n if (\n translationArgument &&\n Node.isObjectLiteralExpression(translationArgument)\n ) {\n const map: Record<string, string> = {};\n\n for (const propertyAssignment of translationArgument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment)) continue;\n\n const nameNode = propertyAssignment.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n map[name] = valueInitializer.getLiteralValue();\n }\n }\n\n return { kind: 'translation', map };\n }\n }\n }\n\n return;\n};\n\ntype ExistingMarkdownContent =\n | { kind: 'string'; value: string }\n | { kind: 'file'; path: string };\n\nconst readExistingMarkdown = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): ExistingMarkdownContent | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer) return undefined;\n\n // Pattern 1: md(\"...\") or md(file(\"...\")) or md(t({...}))\n\n if (Node.isCallExpression(initializer)) {\n const expression = initializer.getExpression();\n\n if (!Node.isIdentifier(expression)) return undefined;\n\n if (expression.getText() === 'md') {\n const argument = initializer.getArguments()[0];\n\n if (!argument) return undefined;\n\n if (Node.isStringLiteral(argument)) {\n return { kind: 'string', value: argument.getLiteralValue() };\n }\n\n if (Node.isCallExpression(argument)) {\n const argumentExpression = argument.getExpression();\n\n if (\n Node.isIdentifier(argumentExpression) &&\n argumentExpression.getText() === 'file'\n ) {\n const fileArgument = argument.getArguments()[0];\n\n if (fileArgument && Node.isStringLiteral(fileArgument)) {\n return { kind: 'file', path: fileArgument.getLiteralValue() };\n }\n }\n }\n }\n }\n\n return;\n};\n\nconst readExistingFilePath = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): string | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer || !Node.isCallExpression(initializer)) return undefined;\n\n const expression = initializer.getExpression();\n\n if (!Node.isIdentifier(expression) || expression.getText() !== 'file')\n return undefined;\n\n const argument = initializer.getArguments()[0];\n\n if (argument && Node.isStringLiteral(argument))\n return argument.getLiteralValue();\n\n return;\n};\n\n// Read an existing translation map stored either as md(t({...})) or t({ en: md(\"...\"), fr: md(\"...\") })\nconst readExistingMarkdownTranslationMap = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): Record<string, string> | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer) return undefined;\n\n // Case A: md(t({...}))\n\n if (Node.isCallExpression(initializer)) {\n const exp = initializer.getExpression();\n\n if (Node.isIdentifier(exp) && exp.getText() === 'md') {\n const arg = initializer.getArguments()[0];\n\n if (arg && Node.isCallExpression(arg)) {\n const tExp = arg.getExpression();\n\n if (Node.isIdentifier(tExp) && tExp.getText() === 't') {\n const tArg = arg.getArguments()[0];\n\n if (tArg && Node.isObjectLiteralExpression(tArg)) {\n const map: Record<string, string> = {};\n\n for (const prop of tArg.getProperties()) {\n if (!Node.isPropertyAssignment(prop)) continue;\n const nameNode = prop.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInit = prop.getInitializer();\n\n if (valueInit && Node.isStringLiteral(valueInit)) {\n map[name] = valueInit.getLiteralValue();\n } else {\n return undefined;\n }\n }\n return map;\n }\n }\n }\n }\n }\n\n // Case B: t({ en: md(\"...\"), fr: md(\"...\") })\n\n if (Node.isCallExpression(initializer)) {\n const exp = initializer.getExpression();\n\n if (Node.isIdentifier(exp) && exp.getText() === 't') {\n const tArg = initializer.getArguments()[0];\n\n if (tArg && Node.isObjectLiteralExpression(tArg)) {\n const map: Record<string, string> = {};\n\n for (const prop of tArg.getProperties()) {\n if (!Node.isPropertyAssignment(prop)) continue;\n const nameNode = prop.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInit = prop.getInitializer();\n\n if (\n valueInit &&\n Node.isCallExpression(valueInit) &&\n Node.isIdentifier(valueInit.getExpression()) &&\n valueInit.getExpression().getText() === 'md'\n ) {\n const mdArg = valueInit.getArguments()[0];\n\n if (mdArg && Node.isStringLiteral(mdArg)) {\n map[name] = mdArg.getLiteralValue();\n } else {\n return undefined;\n }\n } else {\n return undefined;\n }\n }\n return map;\n }\n }\n }\n\n return;\n};\n\nconst readExistingNest = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): { dictionaryKey: string; path?: string } | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n let initializer = property.getInitializer();\n\n if (!initializer) return undefined;\n\n // Unwrap type assertions and parentheses\n // Keep drilling until we reach a CallExpression or cannot unwrap further\n let safetyCounter = 0;\n while (safetyCounter++ < 5) {\n if (Node.isCallExpression(initializer)) break;\n // AsExpression, TypeAssertion, ParenthesizedExpression expose getExpression\n const anyInitializer = initializer as unknown as {\n getExpression?: () => unknown;\n };\n const nextExpression = anyInitializer.getExpression?.();\n\n if (\n nextExpression &&\n typeof nextExpression === 'object' &&\n nextExpression !== initializer\n ) {\n initializer = nextExpression as any;\n continue;\n }\n break;\n }\n\n if (!Node.isCallExpression(initializer)) return undefined;\n\n const expression = initializer.getExpression();\n\n if (!Node.isIdentifier(expression) || expression.getText() !== 'nest')\n return undefined;\n\n const [firstArgument, secondArgument] = initializer.getArguments();\n\n if (!firstArgument || !Node.isStringLiteral(firstArgument)) return undefined;\n\n const dictionaryKey = firstArgument.getLiteralValue();\n let path: string | undefined;\n\n if (secondArgument && Node.isStringLiteral(secondArgument))\n path = secondArgument.getLiteralValue();\n\n return { dictionaryKey, path };\n};\n\n// Safely unwrap common wrapper nodes (satisfies/as/parenthesized) to reach the underlying ObjectLiteralExpression\nconst unwrapToObjectLiteral = (\n node: unknown\n): ObjectLiteralExpression | undefined => {\n if (!node || typeof node !== 'object') return undefined;\n\n let current = node as any;\n let safetyCounter = 0;\n while (safetyCounter++ < 8) {\n if (Node.isObjectLiteralExpression(current)) return current;\n\n const next = current?.getExpression?.();\n\n if (next && typeof next === 'object' && next !== current) {\n current = next;\n continue;\n }\n break;\n }\n\n return;\n};\n\n// Resolve an identifier/shorthand property name to the object literal of its variable initializer\nconst resolveNameToObjectLiteral = (\n sourceFile: SourceFile,\n name: string\n): ObjectLiteralExpression | undefined => {\n // Try to find a variable declaration in the same file\n const varDecl = sourceFile.getVariableDeclaration(name);\n if (varDecl) {\n const init = varDecl.getInitializer();\n const obj = unwrapToObjectLiteral(init);\n if (obj) return obj;\n }\n\n // Fallback via symbol resolution\n const identifier = sourceFile.getDescendants().find((n) => {\n return Node.isIdentifier(n) && n.getText() === name;\n });\n const decl = identifier?.getSymbol()?.getDeclarations()?.[0];\n if (decl && Node.isVariableDeclaration(decl)) {\n const obj = unwrapToObjectLiteral(decl.getInitializer());\n if (obj) return obj;\n }\n return undefined;\n};\n\n// Resolve an arbitrary expression to an object literal if it refers to one (identifier or property access)\nconst resolveExpressionToObjectLiteral = (\n sourceFile: SourceFile,\n expr: import('ts-morph').Expression\n): ObjectLiteralExpression | undefined => {\n if (Node.isIdentifier(expr)) {\n return resolveNameToObjectLiteral(sourceFile, expr.getText());\n }\n\n if (Node.isPropertyAccessExpression(expr)) {\n // Resolve the left side first (could be identifier or nested property access)\n const leftResolved = resolveExpressionToObjectLiteral(\n sourceFile,\n expr.getExpression()\n );\n if (!leftResolved) return undefined;\n const propName = expr.getName();\n const prop = leftResolved.getProperty(propName);\n if (prop && Node.isPropertyAssignment(prop)) {\n const init = prop.getInitializer();\n const obj = unwrapToObjectLiteral(init);\n if (obj) return obj;\n // Support aliasing to another identifier: const x = planDetails.free; then use x\n if (init && Node.isIdentifier(init)) {\n return resolveNameToObjectLiteral(sourceFile, init.getText());\n }\n }\n }\n return undefined;\n};\n\n// Find spread source objects for a given object literal, in declaration order\nconst getSpreadSourceObjects = (\n contentObject: ObjectLiteralExpression,\n sourceFile: SourceFile\n): ObjectLiteralExpression[] => {\n const spreads: ObjectLiteralExpression[] = [];\n for (const prop of contentObject.getProperties()) {\n if (Node.isSpreadAssignment(prop)) {\n const expr = prop.getExpression();\n const resolved = resolveExpressionToObjectLiteral(sourceFile, expr);\n if (resolved) spreads.push(resolved);\n }\n }\n return spreads;\n};\n\n// Find the spread source object (prefer the last one) that contains a given key\nconst findSpreadTargetObjectForKey = (\n contentObject: ObjectLiteralExpression,\n key: string,\n sourceFile: SourceFile\n): ObjectLiteralExpression | undefined => {\n const spreads = getSpreadSourceObjects(contentObject, sourceFile);\n for (let i = spreads.length - 1; i >= 0; i--) {\n const spreadObj = spreads[i];\n const prop = spreadObj.getProperty(key);\n if (prop && Node.isPropertyAssignment(prop)) {\n return spreadObj;\n }\n }\n return undefined;\n};\n\nconst readExistingArraySerialized = (\n contentObject: ObjectLiteralExpression,\n propName: string\n): string[] | undefined => {\n const property = contentObject.getProperty(propName);\n\n if (!property || !Node.isPropertyAssignment(property)) return undefined;\n\n const initializer = property.getInitializer();\n\n if (!initializer || !Node.isArrayLiteralExpression(initializer))\n return undefined;\n\n const serialized: string[] = [];\n\n for (const element of initializer.getElements()) {\n if (Node.isStringLiteral(element)) {\n serialized.push(JSON.stringify(element.getLiteralValue()));\n continue;\n }\n\n if (Node.isNumericLiteral(element)) {\n serialized.push(element.getText());\n continue;\n }\n\n if (\n element.getKind() === SyntaxKind.TrueKeyword ||\n element.getKind() === SyntaxKind.FalseKeyword\n ) {\n serialized.push(element.getText());\n continue;\n }\n\n if (Node.isNullLiteral(element)) {\n serialized.push('null');\n continue;\n }\n\n if (Node.isCallExpression(element)) {\n const expression = element.getExpression();\n\n if (Node.isIdentifier(expression) && expression.getText() === 't') {\n const argument = element.getArguments()[0];\n\n if (argument && Node.isObjectLiteralExpression(argument)) {\n const map: any = {};\n\n for (const propertyAssignment of argument.getProperties()) {\n if (!Node.isPropertyAssignment(propertyAssignment))\n return undefined;\n\n const nameNode = propertyAssignment.getNameNode();\n const rawName = nameNode.getText();\n const name = rawName.replace(/^['\"]|['\"]$/g, '');\n const valueInitializer = propertyAssignment.getInitializer();\n\n if (valueInitializer && Node.isStringLiteral(valueInitializer)) {\n map[name] = valueInitializer.getLiteralValue();\n } else {\n return undefined;\n }\n }\n serialized.push(buildTranslationInitializer(map));\n continue;\n }\n }\n }\n\n return undefined;\n }\n\n return serialized;\n};\n\nconst serializeValue = (value: ContentNode): string | undefined => {\n const nodeType = getNodeType(value);\n\n if (nodeType === NodeType.Text) return JSON.stringify(value);\n\n if (nodeType === NodeType.Number || nodeType === NodeType.Boolean)\n return String(value);\n\n if (nodeType === NodeType.Null) return 'null';\n\n if (nodeType === NodeType.Translation) {\n const translations: TranslationContent[NodeType.Translation] =\n (value as TranslationContent)[NodeType.Translation] ?? {};\n const allStrings = Object.values(translations).every(\n (v) => typeof v === 'string'\n );\n\n if (!allStrings) return undefined;\n\n return buildTranslationInitializer(translations);\n }\n\n if (nodeType === NodeType.Enumeration) {\n const map: EnumerationContent[NodeType.Enumeration] = (\n value as EnumerationContent\n )[NodeType.Enumeration];\n\n const initializer = buildEnumerationInitializer(map);\n\n return initializer;\n }\n\n if (nodeType === NodeType.Condition) {\n const map: ConditionContent[NodeType.Condition] = (\n value as ConditionContent\n )[NodeType.Condition];\n\n const initializer = buildConditionInitializer(map);\n\n return initializer;\n }\n\n if (nodeType === NodeType.Gender) {\n const map: GenderContent[NodeType.Gender] = (value as GenderContent)[\n NodeType.Gender\n ];\n\n const initializer = buildGenderInitializer(map);\n\n return initializer;\n }\n\n if (nodeType === NodeType.Insertion) {\n const content: InsertionContent[NodeType.Insertion] = (\n value as InsertionContent\n )[NodeType.Insertion];\n\n return buildInsertionInitializer(content);\n }\n\n if (nodeType === NodeType.Markdown) {\n const content: MarkdownContent[NodeType.Markdown] = (\n value as MarkdownContent\n )[NodeType.Markdown];\n\n return buildMarkdownInitializer(content);\n }\n\n if (nodeType === NodeType.File) {\n const path: FileContent[NodeType.File] = (value as FileContent)[\n NodeType.File\n ];\n\n return buildFileInitializer(path);\n }\n\n if (nodeType === NodeType.Nested) {\n const content: NestedContent[NodeType.Nested] = (value as NestedContent)[\n NodeType.Nested\n ];\n\n return buildNestedInitializer(content);\n }\n\n return;\n};\n\n/**\n * Gets the existing imports from @intlayer/core in the source file\n */\nconst getExistingIntlayerImports = (sourceFile: SourceFile): Set<string> => {\n const imported = new Set<string>();\n\n for (const importDecl of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = importDecl.getModuleSpecifierValue();\n\n if (moduleSpecifier === 'intlayer') {\n const namedImports = importDecl.getNamedImports();\n\n for (const namedImport of namedImports) {\n imported.add(namedImport.getName());\n }\n }\n\n if (moduleSpecifier === 'intlayer/file') {\n const namedImports = importDecl.getNamedImports();\n\n for (const namedImport of namedImports) {\n const alias = namedImport.getAliasNode();\n imported.add(alias ? alias.getText() : namedImport.getName());\n }\n }\n }\n\n return imported;\n};\n\n/**\n * Adds missing imports to the source file\n */\nconst addMissingImports = (\n sourceFile: SourceFile,\n requiredImports: Set<string>\n): boolean => {\n if (requiredImports.size === 0) return false;\n\n const existingImports = getExistingIntlayerImports(sourceFile);\n const missingImports = [...requiredImports].filter(\n (imp) => !existingImports.has(imp)\n );\n\n if (missingImports.length === 0) return false;\n\n // Separate 'file' from other imports\n const hasMissingFile = missingImports.includes('file');\n const otherMissingImports = missingImports.filter((imp) => imp !== 'file');\n\n // Find or create @intlayer/core import\n\n if (otherMissingImports.length > 0) {\n const coreImport = sourceFile\n .getImportDeclarations()\n .find((imp) => imp.getModuleSpecifierValue() === 'intlayer');\n\n if (coreImport) {\n // Add to existing import\n const existingNamedImports = coreImport\n .getNamedImports()\n .map((ni) => ni.getName());\n const allImports = [\n ...new Set([...existingNamedImports, ...otherMissingImports]),\n ].sort();\n\n coreImport.removeNamedImports();\n coreImport.addNamedImports(allImports.map((name) => ({ name })));\n } else {\n // Create new import at the top\n sourceFile.insertImportDeclaration(0, {\n moduleSpecifier: 'intlayer',\n namedImports: otherMissingImports.sort().map((name) => ({ name })),\n });\n }\n }\n\n // Handle file import separately with alias\n\n if (hasMissingFile) {\n const fileImport = sourceFile\n .getImportDeclarations()\n .find((imp) => imp.getModuleSpecifierValue() === 'intlayer/file');\n\n if (!fileImport) {\n // Find the position to insert (after @intlayer/core import if it exists)\n const coreImportIndex = sourceFile\n .getImportDeclarations()\n .findIndex((imp) => imp.getModuleSpecifierValue() === 'intlayer');\n\n const insertIndex = coreImportIndex >= 0 ? coreImportIndex + 1 : 0;\n\n sourceFile.insertImportDeclaration(insertIndex, {\n moduleSpecifier: 'intlayer/file',\n namedImports: [{ name: 'file' }],\n });\n }\n }\n\n return true;\n};\n\n/**\n * Detect whether the current source file is written in CommonJS style.\n * Prefers ESM when import/export syntax is present; otherwise detects CJS via require/module.exports.\n */\nconst isCommonJS = (sourceFile: SourceFile): boolean => {\n // Prefer ESM if any ESM import/export is present\n if (sourceFile.getImportDeclarations().length > 0) return false;\n if (sourceFile.getExportDeclarations().length > 0) return false;\n if (sourceFile.getExportAssignments().length > 0) return false;\n\n // Detect classic CJS markers\n for (const statement of sourceFile.getStatements()) {\n if (!Node.isExpressionStatement(statement)) continue;\n const expression = statement.getExpression();\n\n if (!Node.isBinaryExpression(expression)) continue;\n const leftSide = expression.getLeft();\n\n if (!Node.isPropertyAccessExpression(leftSide)) continue;\n const leftExpression = leftSide.getExpression();\n const leftName = leftSide.getName();\n const isModuleExports =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'module' &&\n leftName === 'exports';\n const isExportsDefault =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'exports';\n\n if (isModuleExports || isExportsDefault) return true;\n }\n\n const hasRequire = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .some((call) => {\n const exp = call.getExpression();\n return Node.isIdentifier(exp) && exp.getText() === 'require';\n });\n\n return hasRequire;\n};\n\n/**\n * Adds missing CommonJS requires for intlayer helpers.\n * - Core helpers (t, md, insert, enu, cond, gender, nest) come from require('intlayer') via destructuring\n * - file helper comes from require('intlayer/file') via destructuring\n * Existing destructured requires are respected to avoid duplicates.\n */\nconst addMissingRequires = (\n sourceFile: SourceFile,\n requiredImports: Set<string>\n): boolean => {\n if (requiredImports.size === 0) return false;\n\n const existingCoreNames = new Set<string>();\n let hasFileHelper = false;\n\n for (const varDecl of sourceFile.getVariableDeclarations()) {\n const init = varDecl.getInitializer();\n\n if (!init || !Node.isCallExpression(init)) continue;\n const callee = init.getExpression();\n\n if (!Node.isIdentifier(callee) || callee.getText() !== 'require') continue;\n const arg = init.getArguments()[0];\n\n if (!arg || !Node.isStringLiteral(arg)) continue;\n const spec = arg.getLiteralValue();\n const nameNode = varDecl.getNameNode();\n\n if (spec === 'intlayer') {\n if (Node.isObjectBindingPattern(nameNode)) {\n for (const el of nameNode.getElements()) {\n existingCoreNames.add(el.getNameNode().getText());\n }\n }\n }\n\n if (spec === 'intlayer/file') {\n if (Node.isObjectBindingPattern(nameNode)) {\n for (const el of nameNode.getElements()) {\n if (el.getNameNode().getText() === 'file') hasFileHelper = true;\n }\n } else if (Node.isIdentifier(nameNode) && nameNode.getText() === 'file') {\n hasFileHelper = true;\n }\n }\n }\n\n const requiredList = Array.from(requiredImports);\n const missingCore = requiredList\n .filter((n) => n !== 'file')\n .filter((n) => !existingCoreNames.has(n));\n const needsFile = requiredImports.has('file') && !hasFileHelper;\n\n if (missingCore.length === 0 && !needsFile) return false;\n\n // Insert after directive prologue (e.g., 'use strict') if present\n let insertIndex = 0;\n const statements = sourceFile.getStatements();\n for (const st of statements) {\n if (Node.isExpressionStatement(st)) {\n const expr = st.getExpression();\n\n if (Node.isStringLiteral(expr)) {\n insertIndex += 1;\n continue;\n }\n }\n break;\n }\n\n const lines: string[] = [];\n if (missingCore.length > 0) {\n const sorted = Array.from(new Set(missingCore)).sort();\n lines.push(`const { ${sorted.join(', ')} } = require('intlayer');`);\n }\n if (needsFile) {\n lines.push(\"const { file } = require('intlayer/file');\");\n }\n\n if (lines.length > 0) {\n sourceFile.insertStatements(insertIndex, lines.join('\\n'));\n return true;\n }\n\n return false;\n};\n\n/**\n * Serializes a metadata value to its string representation for code generation\n * Handles: boolean, number, string, and array of strings\n */\nconst serializeMetadataValue = (value: unknown): string => {\n if (Array.isArray(value)) {\n return `[${value.map((item) => JSON.stringify(item)).join(', ')}]`;\n }\n if (typeof value === 'boolean' || typeof value === 'number') {\n return String(value);\n }\n return JSON.stringify(value);\n};\n\n/**\n * Updates a single property in the root object if the value has changed\n */\nconst updateMetadataProperty = (\n rootObject: ObjectLiteralExpression,\n propertyName: string,\n value: unknown\n): boolean => {\n const property =\n rootObject.getProperty(propertyName) ||\n rootObject.getProperty(`'${propertyName}'`) ||\n rootObject.getProperty(`\"${propertyName}\"`);\n const serializedValue = serializeMetadataValue(value);\n\n if (property && Node.isPropertyAssignment(property)) {\n const currentValue = property.getInitializer()?.getText();\n\n if (currentValue !== serializedValue) {\n property.setInitializer(serializedValue);\n return true;\n }\n } else if (!property) {\n rootObject.addPropertyAssignment({\n name: propertyName,\n initializer: serializedValue,\n });\n return true;\n }\n\n return false;\n};\n\n/**\n * Updates dictionary metadata properties in the root object\n * Supports: id, locale, filled, fill, title, description, tags, version, priority, live\n * and any future fields that may be added\n */\nconst updateDictionaryMetadata = (\n rootObject: ObjectLiteralExpression,\n dictionary: Dictionary\n): boolean => {\n let changed = false;\n\n // List of metadata properties to update (excluding 'key' and 'content')\n const metadataProperties: (keyof Dictionary)[] = [\n 'id',\n 'locale',\n 'filled',\n 'fill',\n 'title',\n 'description',\n 'tags',\n 'version',\n 'priority',\n 'live',\n ];\n\n for (const prop of metadataProperties) {\n const value = dictionary[prop];\n\n if (value !== undefined) {\n if (updateMetadataProperty(rootObject, prop as string, value)) {\n changed = true;\n }\n }\n }\n\n return changed;\n};\n\n/**\n * Locates the root dictionary object in the source file\n */\nconst findRootDictionaryObject = (\n sourceFile: SourceFile\n): ObjectLiteralExpression | undefined => {\n // Try to find via export assignment\n const exportAssignment = sourceFile.getExportAssignment((_) => true);\n\n if (exportAssignment) {\n const expression = exportAssignment.getExpression();\n\n if (Node.isIdentifier(expression)) {\n const declarationFromSymbol = expression\n .getSymbol()\n ?.getDeclarations()?.[0];\n const declarationByName =\n declarationFromSymbol ??\n sourceFile.getVariableDeclaration(expression.getText());\n\n if (declarationByName && Node.isVariableDeclaration(declarationByName)) {\n const initializerAny = declarationByName.getInitializer();\n const objectLiteral = unwrapToObjectLiteral(initializerAny);\n\n if (objectLiteral) return objectLiteral;\n }\n } else {\n // Support wrapped default exports like: export default ({ ... } as const)\n // or: export default ({ ... } satisfies Dictionary)\n const objectLiteral = unwrapToObjectLiteral(expression);\n\n if (objectLiteral) return objectLiteral;\n }\n }\n\n // Fallback: find a variable of type Dictionary\n const variableDeclaration = sourceFile.getVariableDeclaration((variable) => {\n try {\n const typeText = variable.getType().getText();\n return (\n typeText.includes('Dictionary') ||\n variable.getName() === 'content' ||\n variable.getName().toLowerCase().includes('dictionary')\n );\n } catch {\n return variable.getName() === 'content';\n }\n });\n\n if (variableDeclaration) {\n const objectLiteral = unwrapToObjectLiteral(\n variableDeclaration.getInitializer()\n );\n\n if (objectLiteral) return objectLiteral;\n }\n\n // Fallback: handle CommonJS patterns\n\n for (const statement of sourceFile.getStatements()) {\n if (!Node.isExpressionStatement(statement)) continue;\n\n const expression = statement.getExpression();\n\n if (!Node.isBinaryExpression(expression)) continue;\n\n const operator = expression.getOperatorToken();\n\n if (operator.getText() !== '=') continue;\n\n const leftSide = expression.getLeft();\n\n if (!Node.isPropertyAccessExpression(leftSide)) continue;\n\n const leftExpression = leftSide.getExpression();\n const leftName = leftSide.getName();\n const isModuleExports =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'module' &&\n leftName === 'exports';\n const isExportsDefault =\n Node.isIdentifier(leftExpression) &&\n leftExpression.getText() === 'exports' &&\n leftName === 'default';\n\n if (!isModuleExports && !isExportsDefault) continue;\n\n const rightSide = expression.getRight();\n\n if (Node.isObjectLiteralExpression(rightSide)) {\n return rightSide;\n }\n\n if (Node.isIdentifier(rightSide)) {\n const declaration = rightSide.getSymbol()?.getDeclarations()?.[0];\n\n if (declaration && Node.isVariableDeclaration(declaration)) {\n const objectLiteral = unwrapToObjectLiteral(\n declaration.getInitializer()\n );\n\n if (objectLiteral) return objectLiteral;\n }\n }\n }\n\n return;\n};\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided dictionary.\n * It targets a specific dictionary object within the file and updates its\n * metadata (title, description, tags) and content entries.\n *\n * This function now supports inserting translation keys into nested objects\n * within arrays. For example, if you have:\n * ```\n * content: [\n * { question: t({ en: '...', fr: '...' }) }\n * ]\n * ```\n *\n * You can add a new locale (e.g., 'pl') by providing a dictionary with:\n * ```\n * {\n * content: [\n * { question: { [NodeType.Translation]: { en: '...', fr: '...', pl: '...' } } }\n * ]\n * }\n * ```\n *\n * The function will:\n * 1. Detect the existing array structure\n * 2. Navigate into each array element (if it's an object)\n * 3. Recursively process nested properties\n * 4. Update translation maps while preserving existing locales\n */\nexport const transformJSFile = async (\n fileContent: string,\n dictionary: Dictionary,\n fallbackLocale?: Locale\n): Promise<string> => {\n try {\n // If no dictionary provided, nothing to transform\n\n if (!dictionary || typeof dictionary !== 'object') {\n return fileContent;\n }\n\n const project = new Project({\n useInMemoryFileSystem: true,\n skipAddingFilesFromTsConfig: true,\n skipFileDependencyResolution: true,\n compilerOptions: {\n allowJs: true,\n jsx: ts.JsxEmit.Preserve,\n },\n manipulationSettings: {\n indentationText: IndentationText.TwoSpaces,\n quoteKind: QuoteKind.Double, // More safe for JSON.stringify compatibility\n newLineKind: NewLineKind.LineFeed,\n },\n });\n\n const sourceFile = project.createSourceFile('file.tsx', fileContent, {\n overwrite: true,\n });\n\n // Locate the root dictionary object\n const rootObject = findRootDictionaryObject(sourceFile);\n\n if (!rootObject) return fileContent;\n\n let changed = false;\n const requiredImports = new Set<string>();\n\n // Update dictionary metadata (title, description, tags)\n const metadataChanged = updateDictionaryMetadata(rootObject, dictionary);\n\n if (metadataChanged) changed = true;\n\n // Update content if provided\n\n if (dictionary.content) {\n const contentProperty = rootObject.getProperty('content');\n let contentObject: ObjectLiteralExpression | undefined;\n let isContentArrayInSource = false;\n let isContentCallExpression = false;\n\n if (contentProperty && Node.isPropertyAssignment(contentProperty)) {\n contentObject = contentProperty.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n // Detect if the source file defines content as an array\n isContentArrayInSource = !!contentProperty.getInitializerIfKind(\n SyntaxKind.ArrayLiteralExpression\n );\n // Detect if the source file defines content as a function call (e.g. t(...))\n const initializer = contentProperty.getInitializer();\n isContentCallExpression =\n !!initializer && Node.isCallExpression(initializer);\n }\n\n const effectiveFallbackLocale: string =\n (fallbackLocale as unknown as string) ?? 'en';\n\n if (contentObject && !Array.isArray(dictionary.content)) {\n // Existing behavior when content is an object\n const dictContent: Record<string, unknown> =\n (dictionary.content as unknown as Record<string, unknown>) ?? {};\n\n const contentChanged = processContentEntries(\n contentObject,\n dictContent,\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (contentChanged) changed = true;\n } else if (Array.isArray(dictionary.content) && isContentArrayInSource) {\n // New behavior: content is an array in both the dictionary and the source file\n const dictArrayContent: unknown[] =\n (dictionary.content as unknown[]) ?? [];\n\n const contentChanged = processArrayContent(\n rootObject,\n 'content',\n dictArrayContent,\n getExistingPropertyNames(rootObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (contentChanged) changed = true;\n } else if (isContentCallExpression) {\n // New behavior: content is a function call (e.g. t(...)) in source\n // We treat the dictionary.content as the complex content node\n const nodeType = getNodeType(dictionary.content as ContentNode);\n\n if (nodeType) {\n const contentChanged = processComplexContent(\n rootObject,\n 'content',\n dictionary.content as ContentNode,\n getExistingPropertyNames(rootObject),\n effectiveFallbackLocale,\n requiredImports,\n sourceFile\n );\n\n if (contentChanged) changed = true;\n }\n }\n }\n\n if (!changed) return fileContent;\n\n // Add any missing imports/requires before returning the transformed content\n const useCJS = isCommonJS(sourceFile);\n const importsAdded = useCJS\n ? addMissingRequires(sourceFile, requiredImports)\n : addMissingImports(sourceFile, requiredImports);\n\n if (importsAdded || changed) {\n return sourceFile.getFullText();\n }\n\n return fileContent;\n } catch {\n // Fail-safe: return original content on any unexpected parsing issue\n return fileContent;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAuCA,MAAM,+BACJ,gBACA,sBACW;CAGX,MAAM,qBAAqB,OAAO,QAAQ,eAAe,CAAC,MACvD,CAAC,WAAW,CAAC,eAAe,SAAS,cAAc,UAAU,CAC/D;CAED,MAAMA,mBAA6B,EAAE;AAErC,MAAK,MAAM,CAAC,YAAY,qBAAqB,oBAAoB;EAK/D,MAAM,qBAH8B,6BAA6B,KAC/D,WACD,GAEG,aACA,KAAK,UAAU,WAAW;AAE9B,MAAI,OAAO,qBAAqB,SAC9B,kBAAiB,KACf,GAAG,mBAAmB,IAAI,KAAK,UAAU,iBAAiB,GAC3D;WACQ,MAAM,QAAQ,iBAAiB,EAAE;GAC1C,MAAM,0BAA2B,iBAC9B,KAAK,iBAAiB,KAAK,UAAU,aAAa,CAAC,CACnD,KAAK,KAAK;AAEb,oBAAiB,KACf,GAAG,mBAAmB,MAAM,wBAAwB,IACrD;QAGD,kBAAiB,KACf,GAAG,mBAAmB,IAAI,KAAK,UAAU,iBAAiB,GAC3D;;AAIL,QAAO,IAAI,qBAAqB,GAAG,KAAK,iBAAiB,KAAK,KAAK,CAAC;;;;;;;;;;;;;;;AAgBtE,MAAM,kC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