{"version":3,"file":"transformJSFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/transformJSFile.ts"],"sourcesContent":["import { getNodeType } from '@intlayer/core/dictionaryManipulator';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport * as recast from 'recast';\nimport { babelTsParser } from '../utils/babelParser';\n\nconst b = recast.types.builders;\nconst n = recast.types.namedTypes;\n\n/**\n * Name of an `intlayer` helper function a node type is printed as.\n *\n * Mirrors the transpiler helpers re-exported by the `intlayer` package\n * (`@intlayer/core/transpiler`).\n */\ntype HelperName =\n  | 't'\n  | 'enu'\n  | 'plural'\n  | 'cond'\n  | 'gender'\n  | 'select'\n  | 'insert'\n  | 'md'\n  | 'html'\n  | 'file'\n  | 'nest';\n\n/**\n * How a {@link NodeType} is materialized back into source code.\n *\n * - `helperRecord` — printed as `helper({ … })`. The node data is a record of\n *   variants (locales, plural categories, conditions, cases…) whose values are\n *   rebuilt recursively and merged into the existing object literal.\n * - `helperValue` — printed as `helper(value)`. The node data is a single\n *   content, itself possibly another node (e.g. `md(t({ … }))`).\n * - `nesting` — printed as `nest(dictionaryKey, path?)`.\n * - `unwrap` — not a source-level helper: the wrapped value replaces the node,\n *   so `{ nodeType: 'text', text: 'Hello' }` is printed as `\"Hello\"`.\n * - `preserve` — framework elements have no data representation, so the\n *   existing source expression is kept untouched and nothing is written when\n *   there is none.\n * - `structural` — plain objects, arrays and unrecognized nodes, rebuilt by the\n *   generic object/array branches.\n */\ntype NodeTypeStrategy =\n  | {\n      kind: 'helperRecord';\n      helper: HelperName;\n      /**\n       * Extra arguments appended after the record argument, rebuilt from the\n       * node attributes (e.g. the variable name carried by a `select` node).\n       */\n      getExtraArguments?: (\n        node: Record<string, unknown>\n      ) => recast.types.namedTypes.Literal[];\n    }\n  | { kind: 'helperValue'; helper: HelperName }\n  | { kind: 'nesting'; helper: HelperName }\n  | { kind: 'unwrap' }\n  | { kind: 'preserve' }\n  | { kind: 'structural' };\n\n/**\n * Every {@link NodeType} and how it is written back to a JS/TS declaration file.\n *\n * Typed as `Record<NodeType, NodeTypeStrategy>` so that adding a node type to\n * `@intlayer/types` without registering it here becomes a compile-time error —\n * the same guarantee `getNodeType` gives on the read side.\n */\nconst nodeTypeStrategies: Record<NodeType, NodeTypeStrategy> = {\n  [NodeTypes.TRANSLATION]: { kind: 'helperRecord', helper: 't' },\n  [NodeTypes.ENUMERATION]: { kind: 'helperRecord', helper: 'enu' },\n  [NodeTypes.PLURAL]: { kind: 'helperRecord', helper: 'plural' },\n  [NodeTypes.CONDITION]: { kind: 'helperRecord', helper: 'cond' },\n  [NodeTypes.GENDER]: { kind: 'helperRecord', helper: 'gender' },\n  [NodeTypes.SELECT]: {\n    kind: 'helperRecord',\n    helper: 'select',\n    getExtraArguments: (node) =>\n      typeof node.variable === 'string' && node.variable.length > 0\n        ? [b.literal(node.variable)]\n        : [],\n  },\n  [NodeTypes.INSERTION]: { kind: 'helperValue', helper: 'insert' },\n  [NodeTypes.MARKDOWN]: { kind: 'helperValue', helper: 'md' },\n  [NodeTypes.HTML]: { kind: 'helperValue', helper: 'html' },\n  [NodeTypes.FILE]: { kind: 'helperValue', helper: 'file' },\n  [NodeTypes.NESTED]: { kind: 'nesting', helper: 'nest' },\n  [NodeTypes.TEXT]: { kind: 'unwrap' },\n  [NodeTypes.NUMBER]: { kind: 'unwrap' },\n  [NodeTypes.BOOLEAN]: { kind: 'unwrap' },\n  [NodeTypes.NULL]: { kind: 'unwrap' },\n  [NodeTypes.REACT_NODE]: { kind: 'preserve' },\n  [NodeTypes.PREACT_NODE]: { kind: 'preserve' },\n  [NodeTypes.SOLID_NODE]: { kind: 'preserve' },\n  [NodeTypes.OBJECT]: { kind: 'structural' },\n  [NodeTypes.ARRAY]: { kind: 'structural' },\n  [NodeTypes.UNKNOWN]: { kind: 'structural' },\n};\n\n/** Every `intlayer` helper the transform is allowed to rewrite. */\nconst helperNames = new Set<string>(\n  Object.values(nodeTypeStrategies).flatMap((strategy) =>\n    'helper' in strategy ? [strategy.helper] : []\n  )\n);\n\n/** Helpers wrapping a single content, e.g. `md(t({ … }))`. */\nconst wrapperHelperNames = new Set<string>(\n  Object.values(nodeTypeStrategies).flatMap((strategy) =>\n    strategy.kind === 'helperValue' ? [strategy.helper] : []\n  )\n);\n\n/**\n * Returned by {@link buildNodeForValue} when a value must not be written to the\n * source file — framework elements and functions have no data representation,\n * so the original expression (when there is one) is left untouched and no new\n * property is created otherwise.\n */\nconst SKIP_WRITE = Symbol('intlayer.skipWrite');\n\n/**\n * Unwraps TypeScript/Babel expression wrappers (satisfies, as, !, <Type>).\n * Uses string fallbacks to bypass outdated ast-types definitions.\n */\nconst unwrap = (node: any) => {\n  while (\n    node &&\n    (n.TSSatisfiesExpression?.check(node) ||\n      n.TSAsExpression?.check(node) ||\n      n.TSTypeAssertion?.check(node) ||\n      n.TSNonNullExpression?.check(node) ||\n      [\n        'TSSatisfiesExpression',\n        'TSAsExpression',\n        'TSTypeAssertion',\n        'TSNonNullExpression',\n      ].includes(node.type))\n  ) {\n    node = node.expression;\n  }\n  return node;\n};\n\n/**\n * Robustly finds a property in a recast ObjectExpression.\n * Handles quoted (\"key\") or unquoted (key) properties.\n */\nconst getMatchingProperty = (node: any, key: string) => {\n  return node.properties.find((prop: any) => {\n    if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n      if (n.Identifier.check(prop.key) && prop.key.name === key) return true;\n\n      if (n.StringLiteral.check(prop.key) && prop.key.value === key)\n        return true;\n\n      if (n.Literal.check(prop.key) && prop.key.value === key) return true;\n    }\n\n    return false;\n  });\n};\n\n/**\n * Synchronizes numeric suffixes across locales.\n * E.g. \"Hello 1\" -> \"Hello 3\" updates \"Bonjour 1\" to \"Bonjour 3\".\n */\nconst syncNumericSuffixAcrossLocales = (\n  existingNode: any,\n  fallbackLocaleCode: string,\n  newFallbackValue: string\n) => {\n  const trailingNumberMatch = newFallbackValue.match(/\\d+(?!.*\\d)/);\n  if (!trailingNumberMatch) return;\n  const newTrailingNumber = trailingNumberMatch[0];\n\n  if (n.ObjectExpression.check(existingNode)) {\n    for (const prop of existingNode.properties) {\n      if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n        let propName = '';\n\n        if (n.Identifier.check(prop.key)) propName = prop.key.name;\n        else if (\n          n.Literal.check(prop.key) &&\n          typeof prop.key.value === 'string'\n        )\n          propName = prop.key.value;\n        else if (n.StringLiteral.check(prop.key)) propName = prop.key.value;\n\n        if (propName && propName !== fallbackLocaleCode) {\n          if (\n            n.Literal.check(prop.value) &&\n            typeof prop.value.value === 'string'\n          ) {\n            const currentValue = prop.value.value;\n            const currentTrailingNumberMatch =\n              currentValue.match(/\\d+(?!.*\\d)/);\n\n            if (currentTrailingNumberMatch) {\n              prop.value = b.literal(\n                currentValue.replace(/(\\d+)(?!.*\\d)/, newTrailingNumber)\n              );\n            }\n          } else if (n.StringLiteral.check(prop.value)) {\n            const currentValue = prop.value.value;\n            const currentTrailingNumberMatch =\n              currentValue.match(/\\d+(?!.*\\d)/);\n\n            if (currentTrailingNumberMatch) {\n              prop.value = b.stringLiteral(\n                currentValue.replace(/(\\d+)(?!.*\\d)/, newTrailingNumber)\n              );\n            }\n          }\n        }\n      }\n    }\n  }\n};\n\n/**\n * Checks if a value represents a multilingual Intlayer node.\n *\n * A node is multilingual if it is a Translation node, if it wraps one\n * (Markdown, HTML, Insertion…), or if any of its variants contains one\n * (Enumeration, Plural, Condition, Gender, Select…).\n */\nconst isMultilingualNode = (val: any): boolean => {\n  if (typeof val !== 'object' || val === null || Array.isArray(val)) {\n    return false;\n  }\n\n  const nodeType = getNodeType(val as ContentNode);\n\n  if (nodeType === NodeTypes.TRANSLATION) {\n    return true;\n  }\n\n  const strategy = nodeTypeStrategies[nodeType];\n  const nodeData = (val as any)[nodeType];\n\n  if (strategy.kind === 'helperValue' || strategy.kind === 'unwrap') {\n    return isMultilingualNode(nodeData);\n  }\n\n  if (\n    strategy.kind === 'helperRecord' &&\n    nodeData &&\n    typeof nodeData === 'object'\n  ) {\n    return Object.values(nodeData).some((variant) =>\n      isMultilingualNode(variant)\n    );\n  }\n\n  return false;\n};\n\n/**\n * Checks whether two AST nodes are literals holding the same value.\n */\nconst isEquivalentLiteral = (left: any, right: any): boolean => {\n  const isLiteral = (node: any) =>\n    n.Literal.check(node) ||\n    n.StringLiteral.check(node) ||\n    n.NumericLiteral.check(node) ||\n    n.BooleanLiteral.check(node);\n\n  return isLiteral(left) && isLiteral(right) && left.value === right.value;\n};\n\n/**\n * Aligns the arguments of an existing call expression with the desired ones.\n *\n * Mutates the call only when the arguments actually differ, so Recast keeps the\n * original formatting (and quote style) of calls that did not change.\n */\nconst syncCallArguments = (callNode: any, desiredArguments: any[]) => {\n  const isUnchanged =\n    callNode.arguments.length === desiredArguments.length &&\n    desiredArguments.every((desired, index) => {\n      const current = callNode.arguments[index];\n\n      return current === desired || isEquivalentLiteral(current, desired);\n    });\n\n  if (!isUnchanged) {\n    callNode.arguments = desiredArguments;\n  }\n};\n\n/**\n * Recursively builds or updates an AST node for a given dictionary value.\n *\n * Returns {@link SKIP_WRITE} when the value cannot be represented in source and\n * no existing expression can be kept.\n */\nconst buildNodeForValue = (\n  val: any,\n  existingNode: any,\n  fallbackLocale: string | undefined, // In per-locale mode, this is the locale of the file\n  requiredImports: Set<string>\n): any => {\n  // Values with no source representation must never overwrite existing code.\n  if (val === undefined || typeof val === 'function') {\n    return existingNode ?? SKIP_WRITE;\n  }\n\n  const unwrappedExisting = unwrap(existingNode);\n\n  // --- CRITICAL GUARD: STRICT AST PRESERVATION ---\n  // If the existing node is code (JSX, Variables, standard functions), leave it alone.\n  // Only allow updates to literals, plain objects, arrays, and Intlayer helpers.\n  if (unwrappedExisting) {\n    const isUpdatableNode =\n      n.Literal.check(unwrappedExisting) ||\n      n.StringLiteral.check(unwrappedExisting) ||\n      n.NumericLiteral.check(unwrappedExisting) ||\n      n.BooleanLiteral.check(unwrappedExisting) ||\n      n.TemplateLiteral.check(unwrappedExisting) ||\n      n.ObjectExpression.check(unwrappedExisting) ||\n      n.ArrayExpression.check(unwrappedExisting) ||\n      (n.CallExpression.check(unwrappedExisting) &&\n        n.Identifier.check(unwrappedExisting.callee) &&\n        helperNames.has(unwrappedExisting.callee.name));\n\n    if (!isUpdatableNode) {\n      return existingNode;\n    }\n  }\n\n  // If we are in per-locale mode (fallbackLocale is set)\n  // and the value is not already a complex translation node,\n  // we want to store it as a simple literal, NOT wrapped in t().\n  if (fallbackLocale && !existingNode && !isMultilingualNode(val)) {\n    if (val === null) return b.literal(null);\n    if (\n      typeof val === 'string' ||\n      typeof val === 'number' ||\n      typeof val === 'boolean'\n    ) {\n      if (typeof val === 'string' && val.includes('\\n')) {\n        return b.templateLiteral(\n          [b.templateElement({ raw: val, cooked: val }, true)],\n          []\n        );\n      }\n      return b.literal(val);\n    }\n  }\n\n  if (fallbackLocale && existingNode && !isMultilingualNode(val)) {\n    if (\n      n.CallExpression.check(existingNode) &&\n      n.Identifier.check(existingNode.callee) &&\n      existingNode.callee.name === 't'\n    ) {\n      const arg = unwrap(existingNode.arguments[0]);\n\n      if (n.ObjectExpression.check(arg)) {\n        if (typeof val === 'string') {\n          syncNumericSuffixAcrossLocales(arg, fallbackLocale, val);\n        }\n        updateObjectLiteral(\n          arg,\n          { [fallbackLocale]: val },\n          fallbackLocale,\n          requiredImports\n        );\n\n        if (!fallbackLocale) {\n          requiredImports.add('t');\n        }\n\n        return existingNode;\n      }\n    }\n\n    // Wrapped translations — `md(t({ … }))`, `html(t({ … }))`, `insert(t({ … }))`:\n    // update the inner translation in place instead of replacing the wrapper.\n    if (\n      (!val || typeof val !== 'object') &&\n      n.CallExpression.check(existingNode) &&\n      n.Identifier.check(existingNode.callee) &&\n      wrapperHelperNames.has(existingNode.callee.name)\n    ) {\n      const wrapperName = existingNode.callee.name;\n      const innerArg = existingNode.arguments[0];\n\n      if (\n        n.CallExpression.check(innerArg) &&\n        n.Identifier.check(innerArg.callee) &&\n        innerArg.callee.name === 't'\n      ) {\n        const tArg = unwrap(innerArg.arguments[0]);\n\n        if (n.ObjectExpression.check(tArg)) {\n          if (typeof val === 'string') {\n            syncNumericSuffixAcrossLocales(tArg, fallbackLocale, val);\n          }\n          updateObjectLiteral(\n            tArg,\n            { [fallbackLocale]: val },\n            fallbackLocale,\n            requiredImports\n          );\n          requiredImports.add(wrapperName);\n          requiredImports.add('t');\n\n          return existingNode;\n        }\n      }\n    }\n  }\n\n  // 1. Primitives\n  if (val === null) return b.literal(null);\n  if (\n    typeof val === 'string' ||\n    typeof val === 'number' ||\n    typeof val === 'boolean'\n  ) {\n    if (unwrappedExisting) {\n      // Preserve existing template literals (backticks)\n      if (\n        n.TemplateLiteral.check(unwrappedExisting) &&\n        unwrappedExisting.quasis[0] &&\n        unwrappedExisting.expressions.length === 0\n      ) {\n        unwrappedExisting.quasis[0].value.raw = String(val);\n        unwrappedExisting.quasis[0].value.cooked = String(val);\n        return existingNode;\n      }\n      // Preserve existing standard literals (keeps quote styling)\n      if (\n        n.Literal.check(unwrappedExisting) ||\n        n.StringLiteral.check(unwrappedExisting)\n      ) {\n        unwrappedExisting.value = val;\n        return existingNode;\n      }\n    }\n\n    // Force multiline strings to use Template Literals\n    if (typeof val === 'string' && val.includes('\\n')) {\n      return b.templateLiteral(\n        [b.templateElement({ raw: val, cooked: val }, true)],\n        []\n      );\n    }\n    return b.literal(val);\n  }\n\n  // 2. Arrays\n  if (Array.isArray(val)) {\n    if (unwrappedExisting && n.ArrayExpression.check(unwrappedExisting)) {\n      const elements = [...unwrappedExisting.elements];\n      val.forEach((item, i) => {\n        const elementNode = buildNodeForValue(\n          item,\n          elements[i],\n          fallbackLocale,\n          requiredImports\n        );\n\n        elements[i] =\n          elementNode === SKIP_WRITE\n            ? (elements[i] ?? b.literal(null))\n            : elementNode;\n      });\n\n      if (elements.length > val.length) elements.length = val.length;\n      unwrappedExisting.elements = elements as any;\n\n      return existingNode;\n    } else {\n      return b.arrayExpression(\n        val.map((item) => {\n          const elementNode = buildNodeForValue(\n            item,\n            null,\n            fallbackLocale,\n            requiredImports\n          );\n\n          return elementNode === SKIP_WRITE ? b.literal(null) : elementNode;\n        })\n      );\n    }\n  }\n\n  // 3. Intlayer Specialized Nodes — dispatched through the exhaustive registry\n  const nodeType =\n    val && typeof val === 'object' && !Array.isArray(val)\n      ? getNodeType(val as ContentNode)\n      : null;\n\n  if (nodeType) {\n    const strategy = nodeTypeStrategies[nodeType];\n\n    // Framework elements (React/Preact/Solid) cannot be serialized back to\n    // source: keep whatever the file already declares.\n    if (strategy.kind === 'preserve') {\n      return existingNode ?? SKIP_WRITE;\n    }\n\n    const hasNodeData = Object.hasOwn(val as object, nodeType);\n    const nodeData = (val as any)[nodeType];\n\n    // A typed node missing its payload is malformed — fall back to the generic\n    // object branch rather than printing a broken helper call.\n    if (strategy.kind !== 'structural' && hasNodeData) {\n      if (strategy.kind === 'unwrap') {\n        return buildNodeForValue(\n          nodeData,\n          existingNode,\n          fallbackLocale,\n          requiredImports\n        );\n      }\n\n      const { helper } = strategy;\n\n      requiredImports.add(helper);\n\n      const isMatchingCall =\n        existingNode &&\n        n.CallExpression.check(existingNode) &&\n        n.Identifier.check(existingNode.callee) &&\n        existingNode.callee.name === helper;\n\n      if (strategy.kind === 'helperRecord') {\n        const recordArgument =\n          isMatchingCall &&\n          existingNode.arguments.length > 0 &&\n          n.ObjectExpression.check(existingNode.arguments[0])\n            ? existingNode.arguments[0]\n            : b.objectExpression([]);\n\n        updateObjectLiteral(\n          recordArgument,\n          nodeData ?? {},\n          fallbackLocale,\n          requiredImports\n        );\n\n        const callArguments = [\n          recordArgument,\n          ...(strategy.getExtraArguments?.(val as Record<string, unknown>) ??\n            []),\n        ];\n\n        if (isMatchingCall) {\n          syncCallArguments(existingNode, callArguments);\n\n          return existingNode;\n        }\n\n        return b.callExpression(b.identifier(helper), callArguments);\n      }\n\n      if (strategy.kind === 'helperValue') {\n        const contentArgument = buildNodeForValue(\n          nodeData,\n          isMatchingCall && existingNode.arguments.length > 0\n            ? existingNode.arguments[0]\n            : null,\n          fallbackLocale,\n          requiredImports\n        );\n\n        if (contentArgument === SKIP_WRITE) {\n          return existingNode ?? SKIP_WRITE;\n        }\n\n        if (isMatchingCall) {\n          // Keep any extra argument the source declares (custom components\n          // passed to `md()` / `html()`), which the node does not carry back.\n          syncCallArguments(existingNode, [\n            contentArgument,\n            ...existingNode.arguments.slice(1),\n          ]);\n\n          return existingNode;\n        }\n\n        return b.callExpression(b.identifier(helper), [contentArgument]);\n      }\n\n      // strategy.kind === 'nesting'\n      const callArguments = [b.literal(nodeData?.dictionaryKey ?? '')];\n\n      if (nodeData?.path) callArguments.push(b.literal(nodeData.path));\n\n      if (isMatchingCall) {\n        syncCallArguments(existingNode, callArguments);\n\n        return existingNode;\n      }\n\n      return b.callExpression(b.identifier(helper), callArguments);\n    }\n  }\n\n  // 4. Plain Object\n  const objNode =\n    unwrappedExisting && n.ObjectExpression.check(unwrappedExisting)\n      ? unwrappedExisting\n      : b.objectExpression([]);\n\n  updateObjectLiteral(objNode, val, fallbackLocale, requiredImports);\n\n  return existingNode && unwrappedExisting === existingNode\n    ? objNode\n    : existingNode || objNode;\n};\n\n/**\n * Recursively updates the AST object literal properties.\n */\nconst updateObjectLiteral = (\n  node: recast.types.namedTypes.ObjectExpression,\n  data: Record<string, any>,\n  fallbackLocale: string | undefined,\n  requiredImports: Set<string>\n) => {\n  for (const [key, val] of Object.entries(data)) {\n    if (val === undefined) continue;\n\n    const existingProp = getMatchingProperty(node, key);\n\n    if (existingProp) {\n      const valueNode = buildNodeForValue(\n        val,\n        existingProp.value,\n        fallbackLocale,\n        requiredImports\n      );\n\n      if (valueNode !== SKIP_WRITE) {\n        existingProp.value = valueNode;\n      }\n    } else {\n      const isValidId = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);\n      const keyNode = isValidId ? b.identifier(key) : b.literal(key);\n      const valueNode = buildNodeForValue(\n        val,\n        null,\n        fallbackLocale,\n        requiredImports\n      );\n\n      if (valueNode === SKIP_WRITE) continue;\n\n      node.properties.push(b.property('init', keyNode, valueNode));\n    }\n  }\n};\n\n/**\n * Modifies the AST's top-level imports to inject dynamically needed helper utilities seamlessly.\n */\nconst addImports = (ast: any, requiredImports: Set<string>, isESM: boolean) => {\n  if (requiredImports.size === 0) return;\n\n  const existingCoreImports = new Set<string>();\n  let coreImportPath: any = null;\n\n  recast.visit(ast, {\n    visitImportDeclaration(path) {\n      const source = path.node.source.value;\n\n      if (source === 'intlayer') {\n        coreImportPath = path;\n        path.node.specifiers?.forEach((spec) => {\n          if (\n            n.ImportSpecifier.check(spec) &&\n            typeof spec.imported.name === 'string'\n          ) {\n            existingCoreImports.add(spec.imported.name);\n          }\n        });\n      }\n\n      return false;\n    },\n    visitVariableDeclaration(path) {\n      path.node.declarations.forEach((decl) => {\n        if (\n          n.VariableDeclarator.check(decl) &&\n          n.CallExpression.check(decl.init) &&\n          n.Identifier.check(decl.init.callee) &&\n          decl.init.callee.name === 'require'\n        ) {\n          const arg = decl.init.arguments[0];\n\n          if (n.Literal.check(arg)) {\n            if (arg.value === 'intlayer') {\n              if (n.ObjectPattern.check(decl.id)) {\n                decl.id.properties.forEach((prop) => {\n                  if (\n                    n.Property.check(prop) &&\n                    (n.Identifier.check(prop.key) ||\n                      n.Identifier.check(prop.value))\n                  ) {\n                    const name = n.Identifier.check(prop.key)\n                      ? prop.key.name\n                      : (prop.value as any).name;\n                    existingCoreImports.add(name);\n                  }\n                });\n              } else if (n.Identifier.check(decl.id)) {\n                // Handle const intlayer = require('intlayer')\n                existingCoreImports.add(decl.id.name);\n              }\n            }\n          }\n        }\n      });\n\n      return false;\n    },\n  });\n\n  const missingCore = Array.from(requiredImports).filter(\n    (imp) => !existingCoreImports.has(imp)\n  );\n\n  if (missingCore.length === 0) return;\n\n  if (isESM) {\n    if (coreImportPath) {\n      missingCore.forEach((imp) => {\n        coreImportPath.node.specifiers.push(\n          b.importSpecifier(b.identifier(imp))\n        );\n      });\n      coreImportPath.node.specifiers.sort((a: any, b: any) =>\n        a.imported.name.localeCompare(b.imported.name)\n      );\n    } else {\n      const specifiers = missingCore\n        .sort()\n        .map((imp) => b.importSpecifier(b.identifier(imp)));\n      const newImport = b.importDeclaration(specifiers, b.literal('intlayer'));\n      ast.program.body.unshift(newImport);\n    }\n  } else {\n    let insertIndex = 0;\n\n    if (\n      ast.program.body.length > 0 &&\n      n.ExpressionStatement.check(ast.program.body[0]) &&\n      n.Literal.check(ast.program.body[0].expression)\n    ) {\n      insertIndex = 1; // Insert after 'use strict'\n    }\n    const cjsLines: any[] = [];\n\n    const properties = missingCore.sort().map((imp) => {\n      const prop = b.property('init', b.identifier(imp), b.identifier(imp));\n      prop.shorthand = true;\n\n      return prop;\n    });\n    cjsLines.push(\n      b.variableDeclaration('const', [\n        b.variableDeclarator(\n          b.objectPattern(properties),\n          b.callExpression(b.identifier('require'), [b.literal('intlayer')])\n        ),\n      ])\n    );\n\n    ast.program.body.splice(insertIndex, 0, ...cjsLines);\n  }\n};\n\n/**\n * Updates a JS/TS file seamlessly to map new localization keys, arrays, complex nodes and nested dictionaries gracefully using AST updates via Recast parser.\n */\nexport const transformJSFile = async (\n  fileContent: string,\n  dictionary: Dictionary,\n  fallbackLocale?: Locale,\n  noMetadata?: boolean\n): Promise<string> => {\n  if (!dictionary || typeof dictionary !== 'object') return fileContent;\n\n  let ast: any;\n  try {\n    ast = recast.parse(fileContent, {\n      parser: babelTsParser,\n    });\n  } catch (error) {\n    console.error({ error });\n    return fileContent;\n  }\n\n  let rootObject: any = null;\n  let isESM = false;\n\n  recast.visit(ast, {\n    visitExportDefaultDeclaration() {\n      isESM = true;\n\n      return false;\n    },\n    visitImportDeclaration() {\n      isESM = true;\n\n      return false;\n    },\n  });\n\n  recast.visit(ast, {\n    visitExportDefaultDeclaration(path) {\n      const decl = path.node.declaration;\n      const unwrappedDecl = unwrap(decl);\n\n      if (n.ObjectExpression.check(unwrappedDecl)) {\n        rootObject = unwrappedDecl;\n      } else if (n.Identifier.check(unwrappedDecl)) {\n        const varName = unwrappedDecl.name;\n        recast.visit(ast, {\n          visitVariableDeclarator(vp) {\n            const unwrappedInit = unwrap(vp.node.init);\n\n            if (\n              n.Identifier.check(vp.node.id) &&\n              vp.node.id.name === varName &&\n              n.ObjectExpression.check(unwrappedInit)\n            ) {\n              rootObject = unwrappedInit;\n            }\n\n            return false;\n          },\n        });\n      }\n\n      return false;\n    },\n    visitAssignmentExpression(path) {\n      const left = path.node.left;\n\n      if (n.MemberExpression.check(left)) {\n        if (\n          n.Identifier.check(left.object) &&\n          left.object.name === 'module' &&\n          n.Identifier.check(left.property) &&\n          left.property.name === 'exports'\n        ) {\n          const unwrappedRight = unwrap(path.node.right);\n\n          if (n.ObjectExpression.check(unwrappedRight)) {\n            rootObject = unwrappedRight;\n          }\n        }\n\n        if (\n          n.Identifier.check(left.object) &&\n          left.object.name === 'exports' &&\n          n.Identifier.check(left.property) &&\n          left.property.name === 'default'\n        ) {\n          const unwrappedRight = unwrap(path.node.right);\n\n          if (n.ObjectExpression.check(unwrappedRight)) {\n            rootObject = unwrappedRight;\n          }\n        }\n      }\n      this.traverse(path);\n    },\n  });\n\n  if (!rootObject) {\n    recast.visit(ast, {\n      visitVariableDeclarator(path) {\n        const unwrappedInit = unwrap(path.node.init);\n\n        if (!rootObject && n.ObjectExpression.check(unwrappedInit)) {\n          rootObject = unwrappedInit;\n        }\n\n        return false;\n      },\n    });\n  }\n\n  if (!rootObject) return fileContent;\n\n  const requiredImports = new Set<string>();\n  const effectiveFallbackLocale = (fallbackLocale as string) ?? 'en';\n\n  const metadataProperties = [\n    'id',\n    'locale',\n    'filled',\n    'fill',\n    'title',\n    'description',\n    'tags',\n    'version',\n    'priority',\n    'contentAutoTransformation',\n  ];\n\n  if (noMetadata) {\n    // Remove key, content and metadata properties if they exist\n    rootObject.properties = rootObject.properties.filter((prop: any) => {\n      if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n        let propName = '';\n        if (n.Identifier.check(prop.key)) propName = prop.key.name;\n        else if (n.StringLiteral.check(prop.key)) propName = prop.key.value;\n        else if (n.Literal.check(prop.key)) propName = String(prop.key.value);\n\n        return !['key', 'content', ...metadataProperties].includes(propName);\n      }\n      return true;\n    });\n\n    // Update satisfies type if exists\n    recast.visit(ast, {\n      visitNode(path) {\n        const node = path.node;\n        if (\n          (n.TSSatisfiesExpression?.check(node) ||\n            node.type === 'TSSatisfiesExpression') &&\n          (node as any).typeAnnotation &&\n          n.TSTypeReference.check((node as any).typeAnnotation) &&\n          n.Identifier.check((node as any).typeAnnotation.typeName) &&\n          (node as any).typeAnnotation.typeName.name === 'Dictionary'\n        ) {\n          (node as any).typeAnnotation = b.tsIndexedAccessType(\n            b.tsTypeReference(b.identifier('Dictionary')),\n            b.tsLiteralType(b.stringLiteral('content'))\n          );\n        }\n        this.traverse(path);\n      },\n    });\n  } else {\n    for (const prop of metadataProperties) {\n      if ((dictionary as any)[prop] !== undefined) {\n        updateObjectLiteral(\n          rootObject,\n          { [prop]: (dictionary as any)[prop] },\n          undefined,\n          requiredImports\n        );\n      }\n    }\n  }\n\n  if (dictionary.content !== undefined) {\n    updateObjectLiteral(\n      rootObject,\n      noMetadata\n        ? (dictionary.content as Record<string, any>)\n        : { content: dictionary.content },\n      effectiveFallbackLocale,\n      requiredImports\n    );\n  }\n\n  addImports(ast, requiredImports, isESM);\n\n  return recast.print(ast).code;\n};\n"],"mappings":";;;;;;AAQA,MAAM,IAAI,OAAO,MAAM;AACvB,MAAM,IAAI,OAAO,MAAM;;;;;;;;AA+DvB,MAAM,qBAAyD;EAC5D,UAAU,cAAc;EAAE,MAAM;EAAgB,QAAQ;CAAI;EAC5D,UAAU,cAAc;EAAE,MAAM;EAAgB,QAAQ;CAAM;EAC9D,UAAU,SAAS;EAAE,MAAM;EAAgB,QAAQ;CAAS;EAC5D,UAAU,YAAY;EAAE,MAAM;E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