@intlayer/babel 9.0.0-canary.2 → 9.0.0-canary.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/cjs/babel-plugin-intlayer-extract.cjs +3 -2
  2. package/dist/cjs/babel-plugin-intlayer-extract.cjs.map +1 -1
  3. package/dist/cjs/babel-plugin-intlayer-field-rename.cjs +160 -99
  4. package/dist/cjs/babel-plugin-intlayer-field-rename.cjs.map +1 -1
  5. package/dist/cjs/babel-plugin-intlayer-minify.cjs +11 -28
  6. package/dist/cjs/babel-plugin-intlayer-minify.cjs.map +1 -1
  7. package/dist/cjs/babel-plugin-intlayer-optimize.cjs +143 -13
  8. package/dist/cjs/babel-plugin-intlayer-optimize.cjs.map +1 -1
  9. package/dist/cjs/babel-plugin-intlayer-purge.cjs +38 -96
  10. package/dist/cjs/babel-plugin-intlayer-purge.cjs.map +1 -1
  11. package/dist/cjs/babel-plugin-intlayer-usage-analyzer.cjs +151 -52
  12. package/dist/cjs/babel-plugin-intlayer-usage-analyzer.cjs.map +1 -1
  13. package/dist/cjs/babelParser.cjs +62 -0
  14. package/dist/cjs/babelParser.cjs.map +1 -0
  15. package/dist/cjs/extractContent/babelProcessor.cjs +144 -71
  16. package/dist/cjs/extractContent/babelProcessor.cjs.map +1 -1
  17. package/dist/cjs/extractContent/contentWriter.cjs +10 -14
  18. package/dist/cjs/extractContent/contentWriter.cjs.map +1 -1
  19. package/dist/cjs/extractContent/extractContent.cjs +3 -3
  20. package/dist/cjs/extractContent/extractContent.cjs.map +1 -1
  21. package/dist/cjs/extractContent/processTsxFile.cjs +4 -7
  22. package/dist/cjs/extractContent/processTsxFile.cjs.map +1 -1
  23. package/dist/cjs/extractContent/utils/constants.cjs +2 -2
  24. package/dist/cjs/extractContent/utils/constants.cjs.map +1 -1
  25. package/dist/cjs/extractContent/utils/detectPackageName.cjs +0 -1
  26. package/dist/cjs/extractContent/utils/detectPackageName.cjs.map +1 -1
  27. package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs +4 -4
  28. package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs.map +1 -1
  29. package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs +2 -3
  30. package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs.map +1 -1
  31. package/dist/cjs/extractContent/utils/generateKey.cjs.map +1 -1
  32. package/dist/cjs/extractContent/utils/getComponentName.cjs.map +1 -1
  33. package/dist/cjs/extractContent/utils/getExistingIntlayerInfo.cjs.map +1 -1
  34. package/dist/cjs/extractContent/utils/getOrGenerateKey.cjs.map +1 -1
  35. package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs +0 -1
  36. package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs.map +1 -1
  37. package/dist/cjs/extractContent/utils/shouldExtract.cjs +2 -0
  38. package/dist/cjs/extractContent/utils/shouldExtract.cjs.map +1 -1
  39. package/dist/cjs/extractScriptBlocks.cjs +0 -1
  40. package/dist/cjs/extractScriptBlocks.cjs.map +1 -1
  41. package/dist/cjs/getExtractPluginOptions.cjs +2 -2
  42. package/dist/cjs/getExtractPluginOptions.cjs.map +1 -1
  43. package/dist/cjs/getOptimizePluginOptions.cjs +2 -3
  44. package/dist/cjs/getOptimizePluginOptions.cjs.map +1 -1
  45. package/dist/cjs/getPurgePluginOptions.cjs +2 -3
  46. package/dist/cjs/getPurgePluginOptions.cjs.map +1 -1
  47. package/dist/cjs/index.cjs +3 -0
  48. package/dist/cjs/normalizedFilesList.cjs +30 -0
  49. package/dist/cjs/normalizedFilesList.cjs.map +1 -0
  50. package/dist/cjs/transformers.cjs +20 -2
  51. package/dist/cjs/transformers.cjs.map +1 -1
  52. package/dist/esm/babel-plugin-intlayer-extract.mjs +3 -2
  53. package/dist/esm/babel-plugin-intlayer-extract.mjs.map +1 -1
  54. package/dist/esm/babel-plugin-intlayer-field-rename.mjs +159 -100
  55. package/dist/esm/babel-plugin-intlayer-field-rename.mjs.map +1 -1
  56. package/dist/esm/babel-plugin-intlayer-minify.mjs +12 -29
  57. package/dist/esm/babel-plugin-intlayer-minify.mjs.map +1 -1
  58. package/dist/esm/babel-plugin-intlayer-optimize.mjs +140 -9
  59. package/dist/esm/babel-plugin-intlayer-optimize.mjs.map +1 -1
  60. package/dist/esm/babel-plugin-intlayer-purge.mjs +40 -97
  61. package/dist/esm/babel-plugin-intlayer-purge.mjs.map +1 -1
  62. package/dist/esm/babel-plugin-intlayer-usage-analyzer.mjs +151 -52
  63. package/dist/esm/babel-plugin-intlayer-usage-analyzer.mjs.map +1 -1
  64. package/dist/esm/babelParser.mjs +60 -0
  65. package/dist/esm/babelParser.mjs.map +1 -0
  66. package/dist/esm/extractContent/babelProcessor.mjs +144 -71
  67. package/dist/esm/extractContent/babelProcessor.mjs.map +1 -1
  68. package/dist/esm/extractContent/contentWriter.mjs +6 -10
  69. package/dist/esm/extractContent/contentWriter.mjs.map +1 -1
  70. package/dist/esm/extractContent/extractContent.mjs +1 -1
  71. package/dist/esm/extractContent/extractContent.mjs.map +1 -1
  72. package/dist/esm/extractContent/processTsxFile.mjs +3 -6
  73. package/dist/esm/extractContent/processTsxFile.mjs.map +1 -1
  74. package/dist/esm/extractContent/utils/constants.mjs +2 -2
  75. package/dist/esm/extractContent/utils/constants.mjs.map +1 -1
  76. package/dist/esm/extractContent/utils/detectPackageName.mjs.map +1 -1
  77. package/dist/esm/extractContent/utils/extractDictionaryInfo.mjs +1 -1
  78. package/dist/esm/extractContent/utils/extractDictionaryInfo.mjs.map +1 -1
  79. package/dist/esm/extractContent/utils/extractDictionaryKey.mjs +1 -1
  80. package/dist/esm/extractContent/utils/extractDictionaryKey.mjs.map +1 -1
  81. package/dist/esm/extractContent/utils/generateKey.mjs.map +1 -1
  82. package/dist/esm/extractContent/utils/getComponentName.mjs.map +1 -1
  83. package/dist/esm/extractContent/utils/getExistingIntlayerInfo.mjs.map +1 -1
  84. package/dist/esm/extractContent/utils/getOrGenerateKey.mjs.map +1 -1
  85. package/dist/esm/extractContent/utils/resolveDictionaryKey.mjs.map +1 -1
  86. package/dist/esm/extractContent/utils/shouldExtract.mjs +2 -0
  87. package/dist/esm/extractContent/utils/shouldExtract.mjs.map +1 -1
  88. package/dist/esm/extractScriptBlocks.mjs.map +1 -1
  89. package/dist/esm/getExtractPluginOptions.mjs +1 -1
  90. package/dist/esm/getExtractPluginOptions.mjs.map +1 -1
  91. package/dist/esm/getOptimizePluginOptions.mjs +1 -1
  92. package/dist/esm/getOptimizePluginOptions.mjs.map +1 -1
  93. package/dist/esm/getPurgePluginOptions.mjs +1 -1
  94. package/dist/esm/getPurgePluginOptions.mjs.map +1 -1
  95. package/dist/esm/index.mjs +3 -3
  96. package/dist/esm/normalizedFilesList.mjs +29 -0
  97. package/dist/esm/normalizedFilesList.mjs.map +1 -0
  98. package/dist/esm/transformers.mjs +20 -2
  99. package/dist/esm/transformers.mjs.map +1 -1
  100. package/dist/types/babel-plugin-intlayer-extract.d.ts +2 -3
  101. package/dist/types/babel-plugin-intlayer-extract.d.ts.map +1 -1
  102. package/dist/types/babel-plugin-intlayer-field-rename.d.ts +29 -11
  103. package/dist/types/babel-plugin-intlayer-field-rename.d.ts.map +1 -1
  104. package/dist/types/babel-plugin-intlayer-minify.d.ts +2 -3
  105. package/dist/types/babel-plugin-intlayer-minify.d.ts.map +1 -1
  106. package/dist/types/babel-plugin-intlayer-optimize.d.ts +34 -11
  107. package/dist/types/babel-plugin-intlayer-optimize.d.ts.map +1 -1
  108. package/dist/types/babel-plugin-intlayer-purge.d.ts +2 -3
  109. package/dist/types/babel-plugin-intlayer-purge.d.ts.map +1 -1
  110. package/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts +35 -113
  111. package/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts.map +1 -1
  112. package/dist/types/babelParser.d.ts +12 -0
  113. package/dist/types/babelParser.d.ts.map +1 -0
  114. package/dist/types/extractContent/babelProcessor.d.ts +5 -2
  115. package/dist/types/extractContent/babelProcessor.d.ts.map +1 -1
  116. package/dist/types/extractContent/contentWriter.d.ts +0 -1
  117. package/dist/types/extractContent/contentWriter.d.ts.map +1 -1
  118. package/dist/types/extractContent/extractContent.d.ts +1 -1
  119. package/dist/types/extractContent/extractContent.d.ts.map +1 -1
  120. package/dist/types/extractContent/index.d.ts +1 -1
  121. package/dist/types/extractContent/processTsxFile.d.ts +1 -1
  122. package/dist/types/extractContent/processTsxFile.d.ts.map +1 -1
  123. package/dist/types/extractContent/utils/constants.d.ts +3 -3
  124. package/dist/types/extractContent/utils/constants.d.ts.map +1 -1
  125. package/dist/types/extractContent/utils/detectPackageName.d.ts +0 -1
  126. package/dist/types/extractContent/utils/detectPackageName.d.ts.map +1 -1
  127. package/dist/types/extractContent/utils/extractDictionaryInfo.d.ts +0 -1
  128. package/dist/types/extractContent/utils/extractDictionaryInfo.d.ts.map +1 -1
  129. package/dist/types/extractContent/utils/extractDictionaryKey.d.ts.map +1 -1
  130. package/dist/types/extractContent/utils/generateKey.d.ts.map +1 -1
  131. package/dist/types/extractContent/utils/getComponentName.d.ts +0 -1
  132. package/dist/types/extractContent/utils/getComponentName.d.ts.map +1 -1
  133. package/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts +8 -5
  134. package/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts.map +1 -1
  135. package/dist/types/extractContent/utils/getOrGenerateKey.d.ts.map +1 -1
  136. package/dist/types/extractContent/utils/resolveDictionaryKey.d.ts +0 -1
  137. package/dist/types/extractContent/utils/resolveDictionaryKey.d.ts.map +1 -1
  138. package/dist/types/extractContent/utils/shouldExtract.d.ts +1 -0
  139. package/dist/types/extractContent/utils/shouldExtract.d.ts.map +1 -1
  140. package/dist/types/extractScriptBlocks.d.ts.map +1 -1
  141. package/dist/types/getExtractPluginOptions.d.ts +0 -1
  142. package/dist/types/getExtractPluginOptions.d.ts.map +1 -1
  143. package/dist/types/getOptimizePluginOptions.d.ts +0 -1
  144. package/dist/types/getOptimizePluginOptions.d.ts.map +1 -1
  145. package/dist/types/getPurgePluginOptions.d.ts +0 -1
  146. package/dist/types/getPurgePluginOptions.d.ts.map +1 -1
  147. package/dist/types/index.d.ts +6 -5
  148. package/dist/types/normalizedFilesList.d.ts +12 -0
  149. package/dist/types/normalizedFilesList.d.ts.map +1 -0
  150. package/dist/types/transformers.d.ts +7 -2
  151. package/dist/types/transformers.d.ts.map +1 -1
  152. package/package.json +31 -23
@@ -0,0 +1,29 @@
1
+ import { normalizePath } from "@intlayer/config/utils";
2
+
3
+ //#region src/normalizedFilesList.ts
4
+ /**
5
+ * Cache of normalized files-list sets, keyed by the files-list array
6
+ * reference. Babel reuses the same plugin options object for every file of a
7
+ * build, so the (potentially large) list is normalized once per build instead
8
+ * of once per transformed file.
9
+ */
10
+ const normalizedFilesListCache = /* @__PURE__ */ new WeakMap();
11
+ /**
12
+ * Returns a set of POSIX-normalized paths for the given files list, computed
13
+ * once per unique array reference.
14
+ *
15
+ * @param filesList - The plugin's `filesList` option (absolute file paths).
16
+ * @returns A set of the same paths normalized via `normalizePath`.
17
+ */
18
+ const getNormalizedFilesListSet = (filesList) => {
19
+ let normalizedSet = normalizedFilesListCache.get(filesList);
20
+ if (!normalizedSet) {
21
+ normalizedSet = new Set(filesList.map(normalizePath));
22
+ normalizedFilesListCache.set(filesList, normalizedSet);
23
+ }
24
+ return normalizedSet;
25
+ };
26
+
27
+ //#endregion
28
+ export { getNormalizedFilesListSet };
29
+ //# sourceMappingURL=normalizedFilesList.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizedFilesList.mjs","names":[],"sources":["../../src/normalizedFilesList.ts"],"sourcesContent":["import { normalizePath } from '@intlayer/config/utils';\n\n/**\n * Cache of normalized files-list sets, keyed by the files-list array\n * reference. Babel reuses the same plugin options object for every file of a\n * build, so the (potentially large) list is normalized once per build instead\n * of once per transformed file.\n */\nconst normalizedFilesListCache = new WeakMap<readonly string[], Set<string>>();\n\n/**\n * Returns a set of POSIX-normalized paths for the given files list, computed\n * once per unique array reference.\n *\n * @param filesList - The plugin's `filesList` option (absolute file paths).\n * @returns A set of the same paths normalized via `normalizePath`.\n */\nexport const getNormalizedFilesListSet = (\n filesList: readonly string[]\n): Set<string> => {\n let normalizedSet = normalizedFilesListCache.get(filesList);\n\n if (!normalizedSet) {\n normalizedSet = new Set(filesList.map(normalizePath));\n normalizedFilesListCache.set(filesList, normalizedSet);\n }\n\n return normalizedSet;\n};\n"],"mappings":";;;;;;;;;AAQA,MAAM,2CAA2B,IAAI,QAAwC;;;;;;;;AAS7E,MAAa,6BACX,cACgB;CAChB,IAAI,gBAAgB,yBAAyB,IAAI,SAAS;CAE1D,IAAI,CAAC,eAAe;EAClB,gBAAgB,IAAI,IAAI,UAAU,IAAI,aAAa,CAAC;EACpD,yBAAyB,IAAI,WAAW,aAAa;CACvD;CAEA,OAAO;AACT"}
@@ -56,6 +56,24 @@ const buildUsageCheckRegex = (extraCallerNames) => {
56
56
  const uniqueNames = [...new Set(callerNames)];
57
57
  return new RegExp(`\\b(${uniqueNames.join("|")})\\b`);
58
58
  };
59
+ /** Usage-check regex covering only the native callers (no compat callers). */
60
+ const NATIVE_USAGE_CHECK_REGEX = buildUsageCheckRegex();
61
+ /** Cache of usage-check regexes, keyed by the compat-caller array reference. */
62
+ const usageCheckRegexCache = /* @__PURE__ */ new WeakMap();
63
+ /**
64
+ * Returns the usage-check regex for the given compat callers, memoised by the
65
+ * array reference. Plugins pass the same options array for every analysed
66
+ * file, so the regex is built once per build instead of once per file.
67
+ */
68
+ const getUsageCheckRegex = (compatCallers) => {
69
+ if (!compatCallers || compatCallers.length === 0) return NATIVE_USAGE_CHECK_REGEX;
70
+ let usageCheckRegex = usageCheckRegexCache.get(compatCallers);
71
+ if (!usageCheckRegex) {
72
+ usageCheckRegex = buildUsageCheckRegex(compatCallers.map((caller) => caller.callerName));
73
+ usageCheckRegexCache.set(compatCallers, usageCheckRegex);
74
+ }
75
+ return usageCheckRegex;
76
+ };
59
77
  /**
60
78
  * Matches source files that are valid targets for usage analysis and Babel
61
79
  * transformation. Excludes sourcemap files, declaration files, and other
@@ -90,7 +108,7 @@ const analyzeScriptContent = async (scriptContent, sourceFilePath, pruneContext,
90
108
  * `pruneContext.hasUnparsableSourceFiles`).
91
109
  */
92
110
  const analyzeFieldUsageInFile = async (sourceFilePath, code, pruneContext, compatCallers) => {
93
- const usageCheckRegex = buildUsageCheckRegex((compatCallers ?? []).map((caller) => caller.callerName));
111
+ const usageCheckRegex = getUsageCheckRegex(compatCallers);
94
112
  const scriptBlocks = extractScriptBlocks(sourceFilePath, code);
95
113
  for (const block of scriptBlocks) {
96
114
  if (!usageCheckRegex.test(block.content)) continue;
@@ -163,5 +181,5 @@ const optimizeSourceFile = async (code, sourceFilePath, options) => {
163
181
  };
164
182
 
165
183
  //#endregion
166
- export { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, buildUsageCheckRegex, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile };
184
+ export { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, buildUsageCheckRegex, getUsageCheckRegex, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile };
167
185
  //# sourceMappingURL=transformers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/transformers.ts"],"sourcesContent":["import { type TransformOptions, transformAsync } from '@babel/core';\nimport { makeFieldRenameBabelPlugin } from './babel-plugin-intlayer-field-rename';\nimport {\n intlayerOptimizeBabelPlugin,\n type OptimizePluginOptions,\n} from './babel-plugin-intlayer-optimize';\nimport {\n type CompatCallerConfig,\n makeUsageAnalyzerBabelPlugin,\n type PruneContext,\n} from './babel-plugin-intlayer-usage-analyzer';\nimport { extractScriptBlocks, injectScriptBlocks } from './extractScriptBlocks';\n\n// ── Shared Babel parser configuration ─────────────────────────────────────────\n\n/**\n * Babel parser options covering the superset of syntaxes used across all\n * supported frameworks (React / Vue / Svelte / Angular / …).\n */\nexport const BABEL_PARSER_OPTIONS: NonNullable<TransformOptions['parserOpts']> =\n {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n };\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer`). Used by the optimize/transform pass, which\n * only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = /\\b(use|get)Intlayer\\b/;\n\n/**\n * Builds a fast pre-check regex that matches files potentially containing\n * native intlayer calls and/or the given compat namespace caller names.\n *\n * The result is used to skip files that definitely contain none of the\n * relevant function names, avoiding unnecessary Babel parsing.\n *\n * Compat caller names are NOT hardcoded here — they are provided at runtime by\n * the compat adapter packages that configure the usage-analysis pipeline.\n *\n * @param extraCallerNames - Additional caller function names to match\n * (e.g. `['useTranslation', 'getFixedT']` from `@intlayer/react-i18next`).\n * @returns A `RegExp` matching any of the native or provided caller names.\n */\nexport const buildUsageCheckRegex = (extraCallerNames?: string[]): RegExp => {\n const callerNames = [\n 'useIntlayer',\n 'getIntlayer',\n ...(extraCallerNames ?? []),\n ];\n const uniqueNames = [...new Set(callerNames)];\n return new RegExp(`\\\\b(${uniqueNames.join('|')})\\\\b`);\n};\n\n/**\n * Matches source files that are valid targets for usage analysis and Babel\n * transformation. Excludes sourcemap files, declaration files, and other\n * non-source extensions.\n */\nexport const SOURCE_FILE_REGEX = /\\.(tsx?|[mc]?jsx?|vue|svelte|astro)$/;\n\n// ── High-level transformer functions ──────────────────────────────────────────\n\n/**\n * Runs the usage-analysis Babel plugin on a single JS/TS code string.\n *\n * This is analysis-only: the transformed code output is discarded.\n * Throws if Babel cannot parse the content.\n */\nconst analyzeScriptContent = async (\n scriptContent: string,\n sourceFilePath: string,\n pruneContext: PruneContext,\n compatCallers?: CompatCallerConfig[]\n): Promise<void> => {\n await transformAsync(scriptContent, {\n filename: sourceFilePath,\n plugins: [makeUsageAnalyzerBabelPlugin(pruneContext, { compatCallers })],\n parserOpts: BABEL_PARSER_OPTIONS,\n ast: false,\n code: false, // analysis only – no output needed\n });\n};\n\n/**\n * Runs the usage-analysis Babel plugin on a source file, accumulating\n * field-usage data into `pruneContext`.\n *\n * For Vue / Svelte SFC files, script blocks are extracted before analysis so\n * Babel does not attempt to parse the full SFC syntax (templates, styles, …).\n * For plain JS/TS files, the whole file content is analysed directly.\n *\n * This is analysis-only: the transformed code output is discarded.\n * Throws if Babel cannot parse the file (caller should handle and flag\n * `pruneContext.hasUnparsableSourceFiles`).\n */\nexport const analyzeFieldUsageInFile = async (\n sourceFilePath: string,\n code: string,\n pruneContext: PruneContext,\n compatCallers?: CompatCallerConfig[]\n): Promise<void> => {\n const extraCallerNames = (compatCallers ?? []).map(\n (caller) => caller.callerName\n );\n const usageCheckRegex = buildUsageCheckRegex(extraCallerNames);\n const scriptBlocks = extractScriptBlocks(sourceFilePath, code);\n\n // For SFC files (Vue / Svelte): scriptBlocks[0].contentStartOffset > 0\n // means we extracted actual <script> tags from the file.\n // For plain JS/TS: extractScriptBlocks returns the whole file as a single\n // block with offset 0, so we fall through to the same path.\n for (const block of scriptBlocks) {\n if (!usageCheckRegex.test(block.content)) continue;\n await analyzeScriptContent(\n block.content,\n sourceFilePath,\n pruneContext,\n compatCallers\n );\n }\n};\n\n/**\n * Applies field-renaming to a single JS/TS code string (not an SFC).\n *\n * Returns the renamed code string, or `null` if nothing changed or if\n * Babel failed to parse the input (caller should fall back to original code).\n */\nexport const renameFieldsInCode = async (\n code: string,\n sourceFilePath: string,\n pruneContext: PruneContext\n): Promise<string | null> => {\n try {\n const result = await transformAsync(code, {\n filename: sourceFilePath,\n plugins: [makeFieldRenameBabelPlugin(pruneContext)],\n parserOpts: BABEL_PARSER_OPTIONS,\n ast: false,\n });\n return result?.code ?? null;\n } catch {\n return null; // parse failure – caller falls back to original code\n }\n};\n\n/**\n * Applies field-renaming to a source file, correctly handling both plain\n * JS/TS files and SFC files (Vue / Svelte) by operating on each script block\n * individually and injecting the results back into the original source.\n *\n * Returns the renamed code string, or `null` if nothing changed.\n */\nexport const renameFieldsInSourceFile = async (\n sourceFilePath: string,\n code: string,\n pruneContext: PruneContext\n): Promise<string | null> => {\n if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return null;\n if (!INTLAYER_USAGE_REGEX.test(code)) return null;\n\n const scriptBlocks = extractScriptBlocks(sourceFilePath, code);\n\n const isSFC =\n scriptBlocks.length > 0 &&\n ((scriptBlocks[0]?.contentStartOffset ?? 0) > 0 || scriptBlocks.length > 1);\n\n if (isSFC) {\n // Raw SFC: rename each script block individually and inject back.\n const modifications: Array<{\n block: (typeof scriptBlocks)[number];\n modifiedContent: string;\n }> = [];\n\n for (const block of scriptBlocks) {\n if (!INTLAYER_USAGE_REGEX.test(block.content)) continue;\n\n const renamedCode = await renameFieldsInCode(\n block.content,\n sourceFilePath,\n pruneContext\n );\n if (renamedCode && renamedCode !== block.content) {\n modifications.push({ block, modifiedContent: renamedCode });\n }\n }\n\n if (modifications.length === 0) return null;\n return injectScriptBlocks(code, modifications);\n }\n\n // Plain JS/TS or compiled SFC (no block delimiters) – rename the whole file.\n return renameFieldsInCode(code, sourceFilePath, pruneContext);\n};\n\n/**\n * Runs the intlayer optimize Babel plugin on a source file, transforming\n * `useIntlayer('key')` / `getIntlayer('key')` calls into `useDictionary(_hash)`\n * / `getDictionary(_hash)` and injecting the corresponding dictionary imports.\n *\n * Returns `{ code, map }` on success, or `null` if the transformation produced\n * no output.\n */\nexport const optimizeSourceFile = async (\n code: string,\n sourceFilePath: string,\n options: OptimizePluginOptions\n): Promise<{\n code: string;\n map: string | object | null | undefined;\n} | null> => {\n const result = await transformAsync(code, {\n filename: sourceFilePath,\n plugins: [[intlayerOptimizeBabelPlugin, options]],\n parserOpts: BABEL_PARSER_OPTIONS,\n });\n\n if (!result?.code) return null;\n\n return { code: result.code, map: result.map };\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,uBACX;CACE,YAAY;CACZ,6BAA6B;CAC7B,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;CACF;;;;;;AAOH,MAAa,uBAAuB;;;;;;;;;;;;;;;AAgBpC,MAAa,wBAAwB,qBAAwC;CAC3E,MAAM,cAAc;EAClB;EACA;EACA,GAAI,oBAAoB,EAAE;EAC3B;CACD,MAAM,cAAc,CAAC,GAAG,IAAI,IAAI,YAAY,CAAC;AAC7C,QAAO,IAAI,OAAO,OAAO,YAAY,KAAK,IAAI,CAAC,MAAM;;;;;;;AAQvD,MAAa,oBAAoB;;;;;;;AAUjC,MAAM,uBAAuB,OAC3B,eACA,gBACA,cACA,kBACkB;AAClB,OAAM,eAAe,eAAe;EAClC,UAAU;EACV,SAAS,CAAC,6BAA6B,cAAc,EAAE,eAAe,CAAC,CAAC;EACxE,YAAY;EACZ,KAAK;EACL,MAAM;EACP,CAAC;;;;;;;;;;;;;;AAeJ,MAAa,0BAA0B,OACrC,gBACA,MACA,cACA,kBACkB;CAIlB,MAAM,kBAAkB,sBAHE,iBAAiB,EAAE,EAAE,KAC5C,WAAW,OAAO,WAEwC,CAAC;CAC9D,MAAM,eAAe,oBAAoB,gBAAgB,KAAK;AAM9D,MAAK,MAAM,SAAS,cAAc;AAChC,MAAI,CAAC,gBAAgB,KAAK,MAAM,QAAQ,CAAE;AAC1C,QAAM,qBACJ,MAAM,SACN,gBACA,cACA,cACD;;;;;;;;;AAUL,MAAa,qBAAqB,OAChC,MACA,gBACA,iBAC2B;AAC3B,KAAI;AAOF,UAAO,MANc,eAAe,MAAM;GACxC,UAAU;GACV,SAAS,CAAC,2BAA2B,aAAa,CAAC;GACnD,YAAY;GACZ,KAAK;GACN,CAAC,GACa,QAAQ;SACjB;AACN,SAAO;;;;;;;;;;AAWX,MAAa,2BAA2B,OACtC,gBACA,MACA,iBAC2B;AAC3B,KAAI,aAAa,8BAA8B,SAAS,EAAG,QAAO;AAClE,KAAI,CAAC,qBAAqB,KAAK,KAAK,CAAE,QAAO;CAE7C,MAAM,eAAe,oBAAoB,gBAAgB,KAAK;AAM9D,KAHE,aAAa,SAAS,OACpB,aAAa,IAAI,sBAAsB,KAAK,KAAK,aAAa,SAAS,IAEhE;EAET,MAAM,gBAGD,EAAE;AAEP,OAAK,MAAM,SAAS,cAAc;AAChC,OAAI,CAAC,qBAAqB,KAAK,MAAM,QAAQ,CAAE;GAE/C,MAAM,cAAc,MAAM,mBACxB,MAAM,SACN,gBACA,aACD;AACD,OAAI,eAAe,gBAAgB,MAAM,QACvC,eAAc,KAAK;IAAE;IAAO,iBAAiB;IAAa,CAAC;;AAI/D,MAAI,cAAc,WAAW,EAAG,QAAO;AACvC,SAAO,mBAAmB,MAAM,cAAc;;AAIhD,QAAO,mBAAmB,MAAM,gBAAgB,aAAa;;;;;;;;;;AAW/D,MAAa,qBAAqB,OAChC,MACA,gBACA,YAIW;CACX,MAAM,SAAS,MAAM,eAAe,MAAM;EACxC,UAAU;EACV,SAAS,CAAC,CAAC,6BAA6B,QAAQ,CAAC;EACjD,YAAY;EACb,CAAC;AAEF,KAAI,CAAC,QAAQ,KAAM,QAAO;AAE1B,QAAO;EAAE,MAAM,OAAO;EAAM,KAAK,OAAO;EAAK"}
1
+ {"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/transformers.ts"],"sourcesContent":["import { type TransformOptions, transformAsync } from '@babel/core';\nimport { makeFieldRenameBabelPlugin } from './babel-plugin-intlayer-field-rename';\nimport {\n intlayerOptimizeBabelPlugin,\n type OptimizePluginOptions,\n} from './babel-plugin-intlayer-optimize';\nimport {\n type CompatCallerConfig,\n makeUsageAnalyzerBabelPlugin,\n type PruneContext,\n} from './babel-plugin-intlayer-usage-analyzer';\nimport { extractScriptBlocks, injectScriptBlocks } from './extractScriptBlocks';\n\n// ── Shared Babel parser configuration ─────────────────────────────────────────\n\n/**\n * Babel parser options covering the superset of syntaxes used across all\n * supported frameworks (React / Vue / Svelte / Angular / …).\n */\nexport const BABEL_PARSER_OPTIONS: NonNullable<TransformOptions['parserOpts']> =\n {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n };\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer`). Used by the optimize/transform pass, which\n * only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = /\\b(use|get)Intlayer\\b/;\n\n/**\n * Builds a fast pre-check regex that matches files potentially containing\n * native intlayer calls and/or the given compat namespace caller names.\n *\n * The result is used to skip files that definitely contain none of the\n * relevant function names, avoiding unnecessary Babel parsing.\n *\n * Compat caller names are NOT hardcoded here — they are provided at runtime by\n * the compat adapter packages that configure the usage-analysis pipeline.\n *\n * @param extraCallerNames - Additional caller function names to match\n * (e.g. `['useTranslation', 'getFixedT']` from `@intlayer/react-i18next`).\n * @returns A `RegExp` matching any of the native or provided caller names.\n */\nexport const buildUsageCheckRegex = (extraCallerNames?: string[]): RegExp => {\n const callerNames = [\n 'useIntlayer',\n 'getIntlayer',\n ...(extraCallerNames ?? []),\n ];\n const uniqueNames = [...new Set(callerNames)];\n return new RegExp(`\\\\b(${uniqueNames.join('|')})\\\\b`);\n};\n\n/** Usage-check regex covering only the native callers (no compat callers). */\nconst NATIVE_USAGE_CHECK_REGEX = buildUsageCheckRegex();\n\n/** Cache of usage-check regexes, keyed by the compat-caller array reference. */\nconst usageCheckRegexCache = new WeakMap<\n readonly CompatCallerConfig[],\n RegExp\n>();\n\n/**\n * Returns the usage-check regex for the given compat callers, memoised by the\n * array reference. Plugins pass the same options array for every analysed\n * file, so the regex is built once per build instead of once per file.\n */\nexport const getUsageCheckRegex = (\n compatCallers?: readonly CompatCallerConfig[]\n): RegExp => {\n if (!compatCallers || compatCallers.length === 0) {\n return NATIVE_USAGE_CHECK_REGEX;\n }\n\n let usageCheckRegex = usageCheckRegexCache.get(compatCallers);\n if (!usageCheckRegex) {\n usageCheckRegex = buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n );\n usageCheckRegexCache.set(compatCallers, usageCheckRegex);\n }\n return usageCheckRegex;\n};\n\n/**\n * Matches source files that are valid targets for usage analysis and Babel\n * transformation. Excludes sourcemap files, declaration files, and other\n * non-source extensions.\n */\nexport const SOURCE_FILE_REGEX = /\\.(tsx?|[mc]?jsx?|vue|svelte|astro)$/;\n\n// ── High-level transformer functions ──────────────────────────────────────────\n\n/**\n * Runs the usage-analysis Babel plugin on a single JS/TS code string.\n *\n * This is analysis-only: the transformed code output is discarded.\n * Throws if Babel cannot parse the content.\n */\nconst analyzeScriptContent = async (\n scriptContent: string,\n sourceFilePath: string,\n pruneContext: PruneContext,\n compatCallers?: CompatCallerConfig[]\n): Promise<void> => {\n await transformAsync(scriptContent, {\n filename: sourceFilePath,\n plugins: [makeUsageAnalyzerBabelPlugin(pruneContext, { compatCallers })],\n parserOpts: BABEL_PARSER_OPTIONS,\n ast: false,\n code: false, // analysis only – no output needed\n });\n};\n\n/**\n * Runs the usage-analysis Babel plugin on a source file, accumulating\n * field-usage data into `pruneContext`.\n *\n * For Vue / Svelte SFC files, script blocks are extracted before analysis so\n * Babel does not attempt to parse the full SFC syntax (templates, styles, …).\n * For plain JS/TS files, the whole file content is analysed directly.\n *\n * This is analysis-only: the transformed code output is discarded.\n * Throws if Babel cannot parse the file (caller should handle and flag\n * `pruneContext.hasUnparsableSourceFiles`).\n */\nexport const analyzeFieldUsageInFile = async (\n sourceFilePath: string,\n code: string,\n pruneContext: PruneContext,\n compatCallers?: CompatCallerConfig[]\n): Promise<void> => {\n const usageCheckRegex = getUsageCheckRegex(compatCallers);\n const scriptBlocks = extractScriptBlocks(sourceFilePath, code);\n\n // For SFC files (Vue / Svelte): scriptBlocks[0].contentStartOffset > 0\n // means we extracted actual <script> tags from the file.\n // For plain JS/TS: extractScriptBlocks returns the whole file as a single\n // block with offset 0, so we fall through to the same path.\n for (const block of scriptBlocks) {\n if (!usageCheckRegex.test(block.content)) continue;\n await analyzeScriptContent(\n block.content,\n sourceFilePath,\n pruneContext,\n compatCallers\n );\n }\n};\n\n/**\n * Applies field-renaming to a single JS/TS code string (not an SFC).\n *\n * Returns the renamed code string, or `null` if nothing changed or if\n * Babel failed to parse the input (caller should fall back to original code).\n */\nexport const renameFieldsInCode = async (\n code: string,\n sourceFilePath: string,\n pruneContext: PruneContext\n): Promise<string | null> => {\n try {\n const result = await transformAsync(code, {\n filename: sourceFilePath,\n plugins: [makeFieldRenameBabelPlugin(pruneContext)],\n parserOpts: BABEL_PARSER_OPTIONS,\n ast: false,\n });\n return result?.code ?? null;\n } catch {\n return null; // parse failure – caller falls back to original code\n }\n};\n\n/**\n * Applies field-renaming to a source file, correctly handling both plain\n * JS/TS files and SFC files (Vue / Svelte) by operating on each script block\n * individually and injecting the results back into the original source.\n *\n * Returns the renamed code string, or `null` if nothing changed.\n */\nexport const renameFieldsInSourceFile = async (\n sourceFilePath: string,\n code: string,\n pruneContext: PruneContext\n): Promise<string | null> => {\n if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return null;\n if (!INTLAYER_USAGE_REGEX.test(code)) return null;\n\n const scriptBlocks = extractScriptBlocks(sourceFilePath, code);\n\n const isSFC =\n scriptBlocks.length > 0 &&\n ((scriptBlocks[0]?.contentStartOffset ?? 0) > 0 || scriptBlocks.length > 1);\n\n if (isSFC) {\n // Raw SFC: rename each script block individually and inject back.\n const modifications: Array<{\n block: (typeof scriptBlocks)[number];\n modifiedContent: string;\n }> = [];\n\n for (const block of scriptBlocks) {\n if (!INTLAYER_USAGE_REGEX.test(block.content)) continue;\n\n const renamedCode = await renameFieldsInCode(\n block.content,\n sourceFilePath,\n pruneContext\n );\n if (renamedCode && renamedCode !== block.content) {\n modifications.push({ block, modifiedContent: renamedCode });\n }\n }\n\n if (modifications.length === 0) return null;\n return injectScriptBlocks(code, modifications);\n }\n\n // Plain JS/TS or compiled SFC (no block delimiters) – rename the whole file.\n return renameFieldsInCode(code, sourceFilePath, pruneContext);\n};\n\n/**\n * Runs the intlayer optimize Babel plugin on a source file, transforming\n * `useIntlayer('key')` / `getIntlayer('key')` calls into `useDictionary(_hash)`\n * / `getDictionary(_hash)` and injecting the corresponding dictionary imports.\n *\n * Returns `{ code, map }` on success, or `null` if the transformation produced\n * no output.\n */\nexport const optimizeSourceFile = async (\n code: string,\n sourceFilePath: string,\n options: OptimizePluginOptions\n): Promise<{\n code: string;\n map: string | object | null | undefined;\n} | null> => {\n const result = await transformAsync(code, {\n filename: sourceFilePath,\n plugins: [[intlayerOptimizeBabelPlugin, options]],\n parserOpts: BABEL_PARSER_OPTIONS,\n });\n\n if (!result?.code) return null;\n\n return { code: result.code, map: result.map };\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,uBACX;CACE,YAAY;CACZ,6BAA6B;CAC7B,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;AAOF,MAAa,uBAAuB;;;;;;;;;;;;;;;AAgBpC,MAAa,wBAAwB,qBAAwC;CAC3E,MAAM,cAAc;EAClB;EACA;EACA,GAAI,oBAAoB,CAAC;CAC3B;CACA,MAAM,cAAc,CAAC,GAAG,IAAI,IAAI,WAAW,CAAC;CAC5C,OAAO,IAAI,OAAO,OAAO,YAAY,KAAK,GAAG,EAAE,KAAK;AACtD;;AAGA,MAAM,2BAA2B,qBAAqB;;AAGtD,MAAM,uCAAuB,IAAI,QAG/B;;;;;;AAOF,MAAa,sBACX,kBACW;CACX,IAAI,CAAC,iBAAiB,cAAc,WAAW,GAC7C,OAAO;CAGT,IAAI,kBAAkB,qBAAqB,IAAI,aAAa;CAC5D,IAAI,CAAC,iBAAiB;EACpB,kBAAkB,qBAChB,cAAc,KAAK,WAAW,OAAO,UAAU,CACjD;EACA,qBAAqB,IAAI,eAAe,eAAe;CACzD;CACA,OAAO;AACT;;;;;;AAOA,MAAa,oBAAoB;;;;;;;AAUjC,MAAM,uBAAuB,OAC3B,eACA,gBACA,cACA,kBACkB;CAClB,MAAM,eAAe,eAAe;EAClC,UAAU;EACV,SAAS,CAAC,6BAA6B,cAAc,EAAE,cAAc,CAAC,CAAC;EACvE,YAAY;EACZ,KAAK;EACL,MAAM;CACR,CAAC;AACH;;;;;;;;;;;;;AAcA,MAAa,0BAA0B,OACrC,gBACA,MACA,cACA,kBACkB;CAClB,MAAM,kBAAkB,mBAAmB,aAAa;CACxD,MAAM,eAAe,oBAAoB,gBAAgB,IAAI;CAM7D,KAAK,MAAM,SAAS,cAAc;EAChC,IAAI,CAAC,gBAAgB,KAAK,MAAM,OAAO,GAAG;EAC1C,MAAM,qBACJ,MAAM,SACN,gBACA,cACA,aACF;CACF;AACF;;;;;;;AAQA,MAAa,qBAAqB,OAChC,MACA,gBACA,iBAC2B;CAC3B,IAAI;EAOF,QAAO,MANc,eAAe,MAAM;GACxC,UAAU;GACV,SAAS,CAAC,2BAA2B,YAAY,CAAC;GAClD,YAAY;GACZ,KAAK;EACP,CAAC,EACY,EAAE,QAAQ;CACzB,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;AASA,MAAa,2BAA2B,OACtC,gBACA,MACA,iBAC2B;CAC3B,IAAI,aAAa,8BAA8B,SAAS,GAAG,OAAO;CAClE,IAAI,CAAC,qBAAqB,KAAK,IAAI,GAAG,OAAO;CAE7C,MAAM,eAAe,oBAAoB,gBAAgB,IAAI;CAM7D,IAHE,aAAa,SAAS,OACpB,aAAa,EAAE,EAAE,sBAAsB,KAAK,KAAK,aAAa,SAAS,IAEhE;EAET,MAAM,gBAGD,CAAC;EAEN,KAAK,MAAM,SAAS,cAAc;GAChC,IAAI,CAAC,qBAAqB,KAAK,MAAM,OAAO,GAAG;GAE/C,MAAM,cAAc,MAAM,mBACxB,MAAM,SACN,gBACA,YACF;GACA,IAAI,eAAe,gBAAgB,MAAM,SACvC,cAAc,KAAK;IAAE;IAAO,iBAAiB;GAAY,CAAC;EAE9D;EAEA,IAAI,cAAc,WAAW,GAAG,OAAO;EACvC,OAAO,mBAAmB,MAAM,aAAa;CAC/C;CAGA,OAAO,mBAAmB,MAAM,gBAAgB,YAAY;AAC9D;;;;;;;;;AAUA,MAAa,qBAAqB,OAChC,MACA,gBACA,YAIW;CACX,MAAM,SAAS,MAAM,eAAe,MAAM;EACxC,UAAU;EACV,SAAS,CAAC,CAAC,6BAA6B,OAAO,CAAC;EAChD,YAAY;CACd,CAAC;CAED,IAAI,CAAC,QAAQ,MAAM,OAAO;CAE1B,OAAO;EAAE,MAAM,OAAO;EAAM,KAAK,OAAO;CAAI;AAC9C"}
@@ -1,10 +1,9 @@
1
1
  import { PackageName } from "./extractContent/utils/constants.js";
2
- import { PluginObj, PluginPass } from "@babel/core";
2
+ import { PluginObject, PluginPass } from "@babel/core";
3
3
  import * as BabelTypes from "@babel/types";
4
4
  import { Locale } from "@intlayer/types/allLocales";
5
5
  import { IntlayerConfig } from "@intlayer/types/config";
6
6
  import { FilePathPattern } from "@intlayer/types/filePathPattern";
7
-
8
7
  //#region src/babel-plugin-intlayer-extract.d.ts
9
8
  type ExtractResult = {
10
9
  dictionaryKey: string;
@@ -51,7 +50,7 @@ type State = PluginPass & {
51
50
  */
52
51
  declare const intlayerExtractBabelPlugin: (_babel: {
53
52
  types: typeof BabelTypes;
54
- }) => PluginObj<State>;
53
+ }) => PluginObject<State>;
55
54
  //#endregion
56
55
  export { ExtractPluginOptions, ExtractResult, intlayerExtractBabelPlugin };
57
56
  //# sourceMappingURL=babel-plugin-intlayer-extract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-extract.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-extract.ts"],"mappings":";;;;;;;;KAcY,aAAA;EACV,aAAA;EACA,QAAA;EACA,OAAA,EAAS,MAAA;EACT,MAAA,EAAQ,MAAA;AAAA;AAAA,KAGE,oBAAA;EACV,WAAA,GAAc,WAAA;EACd,SAAA;EACA,OAAA;EAEA,aAAA,IAAiB,IAAA;EACjB,aAAA,EAAe,cAAA;EATD;;AAGhB;;;EAYE,SAAA,IAAa,MAAA,EAAQ,aAAA,YAAyB,OAAA;EAN/B;;;EAUf,MAAA,GAAS,eAAA;AAAA;AAAA,KAGN,KAAA,GAAQ,UAAA;EAAe,IAAA,EAAM,oBAAA;AAAA;;;;;;;;;;;;;;;AAFhC;;;cAqBW,0BAAA,GAA8B,MAAA;EACzC,KAAA,SAAc,UAAA;AAAA,MACZ,SAAA,CAAU,KAAA"}
1
+ {"version":3,"file":"babel-plugin-intlayer-extract.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-extract.ts"],"mappings":";;;;;;;KAeY;EACV;EACA;EACA,SAAS;EACT,QAAQ;;KAGE;EACV,cAAc;EACd;EACA;EAEA,iBAAiB;EACjB,eAAe;;;;;;EAMf,aAAa,QAAQ,yBAAyB;;;;EAI9C,SAAS;;KAGN,QAAQ;EAAe,MAAM;;;;;;;;;;;;;;;;;;;cAmBrB,6BAA0B;EACrC,cAAc;MACZ,aAAa"}
@@ -1,7 +1,6 @@
1
- import { NestedRenameMap, PruneContext } from "./babel-plugin-intlayer-usage-analyzer.js";
2
- import { PluginObj } from "@babel/core";
1
+ import { NestedRenameEntry, NestedRenameMap, PruneContext } from "./babel-plugin-intlayer-usage-analyzer.js";
2
+ import { NodePath, PluginObject } from "@babel/core";
3
3
  import * as BabelTypes from "@babel/types";
4
-
5
4
  //#region src/babel-plugin-intlayer-field-rename.d.ts
6
5
  /**
7
6
  * Converts a zero-based index to a short alphabetic identifier.
@@ -37,9 +36,20 @@ declare const generateShortFieldName: (index: number) => string;
37
36
  */
38
37
  declare const buildNestedRenameMapFromContent: (contentValue: unknown) => NestedRenameMap;
39
38
  /**
40
- * Creates a Babel plugin that rewrites dictionary content field accesses in
41
- * source files to their short aliases defined in
42
- * `pruneContext.dictionaryKeyToFieldRenameMap`.
39
+ * Walks `fieldPath` through a {@link NestedRenameMap} and returns the entry at
40
+ * the final path segment, or `undefined` when any segment is missing (e.g. the
41
+ * path crosses an array or leaf value whose children are not mapped).
42
+ *
43
+ * Used to locate the rename entry of an opaquely-consumed content value so its
44
+ * children map can be cleared before the JSON rename is applied.
45
+ *
46
+ * @param renameMap - The root rename map to walk.
47
+ * @param fieldPath - Original (pre-rename) field names from the content root.
48
+ */
49
+ declare const getNestedRenameEntryAtPath: (renameMap: NestedRenameMap, fieldPath: readonly string[]) => NestedRenameEntry | undefined;
50
+ /**
51
+ * Rewrites dictionary content field accesses in the given program to the
52
+ * short aliases defined in `pruneContext.dictionaryKeyToFieldRenameMap`.
43
53
  *
44
54
  * Handled patterns (mirrors the usage analyser):
45
55
  *
@@ -57,15 +67,23 @@ declare const buildNestedRenameMapFromContent: (contentValue: unknown) => Nested
57
67
  * → const { shortA: fieldA } = useIntlayer('key');
58
68
  * const { shortN: nested } = fieldA;
59
69
  *
70
+ * Exposed as a standalone function so that both
71
+ * {@link makeFieldRenameBabelPlugin} and `intlayerMinifyBabelPlugin` can
72
+ * invoke it from their own `Program.exit` visitors.
73
+ */
74
+ declare const renameIntlayerFieldAccesses: (babelTypes: typeof BabelTypes, programPath: NodePath<BabelTypes.Program>, pruneContext: PruneContext) => void;
75
+ /**
76
+ * Creates a Babel plugin that rewrites dictionary content field accesses in
77
+ * source files to their short aliases via
78
+ * {@link renameIntlayerFieldAccesses}.
79
+ *
60
80
  * This plugin must run in a separate `transformAsync` pass **before**
61
81
  * `intlayerOptimizeBabelPlugin`, because the latter replaces `useIntlayer`
62
82
  * with `useDictionary`, erasing the dictionary-key information needed here.
63
83
  */
64
- declare const makeFieldRenameBabelPlugin: (pruneContext: PruneContext) => ({
65
- types: babelTypes
66
- }: {
84
+ declare const makeFieldRenameBabelPlugin: (pruneContext: PruneContext) => ({ types: babelTypes }: {
67
85
  types: typeof BabelTypes;
68
- }) => PluginObj;
86
+ }) => PluginObject;
69
87
  //#endregion
70
- export { buildNestedRenameMapFromContent, generateShortFieldName, makeFieldRenameBabelPlugin };
88
+ export { buildNestedRenameMapFromContent, generateShortFieldName, getNestedRenameEntryAtPath, makeFieldRenameBabelPlugin, renameIntlayerFieldAccesses };
71
89
  //# sourceMappingURL=babel-plugin-intlayer-field-rename.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-field-rename.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-field-rename.ts"],"mappings":";;;;;;;AAsBA;;cAAa,sBAAA,GAA0B,KAAA;;;AAqCvC;;;;;AA0QA;;;;;;;;;;;;;;;;;;;;cA1Qa,+BAAA,GACX,YAAA,cACC,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;cAwQU,0BAAA,GACV,YAAA,EAAc,YAAA;EACd,KAAA,EAAA;AAAA;EAAyB,KAAA,SAAc,UAAA;AAAA,MAAe,SAAA"}
1
+ {"version":3,"file":"babel-plugin-intlayer-field-rename.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-field-rename.ts"],"mappings":";;;;;;;;cA0Ba,yBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0CtB,kCAA+B,0BAEzC;;;;;;;;;;;;cA2EU,6BAA0B,WAC1B,iBAAe,iCAEzB;;;;;;;;;;;;;;;;;;;;;;;;;cAiSU,8BAA2B,mBACnB,YAAU,aAChB,SAAS,WAAW,UAAQ,cAC3B;;;;;;;;;;cA8IH,6BAA0B,cACtB,oBAAY,OAAA;EACD,cAAc;MAAe"}
@@ -1,6 +1,5 @@
1
- import { PluginObj } from "@babel/core";
1
+ import { PluginObject } from "@babel/core";
2
2
  import * as BabelTypes from "@babel/types";
3
-
4
3
  //#region src/babel-plugin-intlayer-minify.d.ts
5
4
  /**
6
5
  * Pre-resolved options accepted by {@link intlayerMinifyBabelPlugin}.
@@ -78,7 +77,7 @@ type MinifyPluginOptions = {
78
77
  */
79
78
  declare const intlayerMinifyBabelPlugin: (babel: {
80
79
  types: typeof BabelTypes;
81
- }) => PluginObj;
80
+ }) => PluginObject;
82
81
  //#endregion
83
82
  export { MinifyPluginOptions, intlayerMinifyBabelPlugin };
84
83
  //# sourceMappingURL=babel-plugin-intlayer-minify.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-minify.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-minify.ts"],"mappings":";;;;;;AAgBA;;;;;KAAY,mBAAA;EAkBV;;;;EAbA,OAAA;EA8ID;;;;;EAvIC,MAAA;EA+DE;;;;EAzDF,QAAA;;;;EAKA,aAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkDW,yBAAA,GAA6B,KAAA;EACxC,KAAA,SAAc,UAAA;AAAA,MACZ,SAAA"}
1
+ {"version":3,"file":"babel-plugin-intlayer-minify.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-minify.ts"],"mappings":";;;;;;;;;;KAgBY;;;;;EAKV;;;;;;EAOA;;;;;EAMA;;;;EAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkDW,4BAAyB;EACpC,cAAc;MACZ"}
@@ -1,8 +1,8 @@
1
- import { PluginObj, PluginPass } from "@babel/core";
1
+ import { PluginObject, PluginPass } from "@babel/core";
2
2
  import * as BabelTypes from "@babel/types";
3
-
3
+ import { CallerDescriptor } from "@intlayer/config/callers";
4
4
  //#region src/babel-plugin-intlayer-optimize.d.ts
5
- declare const CALLER_LIST: readonly ["useIntlayer", "getIntlayer"];
5
+ declare const CALLER_LIST: readonly ['useIntlayer', 'getIntlayer'];
6
6
  /**
7
7
  * Options for the optimization Babel plugin
8
8
  */
@@ -63,15 +63,38 @@ type OptimizePluginOptions = {
63
63
  * Whether the current transform is for an SSR bundle.
64
64
  */
65
65
  isServer?: boolean;
66
+ /**
67
+ * Compat-adapter caller descriptors injected by the compat packages'
68
+ * bundler plugins (e.g. `@intlayer/react-i18next/plugin`).
69
+ *
70
+ * Callers carrying `staticReplacement` / `dynamicReplacement` are rewritten
71
+ * the same way as native `useIntlayer` calls: the namespace string argument
72
+ * is replaced by a pre-imported dictionary object and the import specifier
73
+ * is re-pointed to the dictionary-accepting variant, e.g.
74
+ * `useTranslation('about')` → `useDictionary(_dictHash)`.
75
+ *
76
+ * No compat-specific name is hard-coded in this plugin — the whole rewrite
77
+ * is driven by these descriptors.
78
+ */
79
+ compatCallers?: CallerDescriptor[];
66
80
  };
67
81
  type State = PluginPass & {
68
- opts: OptimizePluginOptions; /** map key → generated ident (per-file) for static imports */
69
- _newStaticImports?: Map<string, BabelTypes.Identifier>; /** map key → generated ident (per-file) for dynamic imports */
70
- _newDynamicImports?: Map<string, BabelTypes.Identifier>; /** whether the current file imported *any* intlayer package */
71
- _hasValidImport?: boolean; /** map from local identifier name to the imported intlayer func name ('useIntlayer' | 'getIntlayer') */
72
- _callerMap?: Map<string, (typeof CALLER_LIST)[number]>; /** map from local identifier name to the intlayer package it was imported from */
73
- _callerPackageMap?: Map<string, string>; /** whether the current file *is* the dictionaries entry file */
74
- _isDictEntry?: boolean; /** whether the current file is included in the filesList */
82
+ opts: OptimizePluginOptions;
83
+ /** map key → generated ident (per-file) for static imports */
84
+ _newStaticImports?: Map<string, BabelTypes.Identifier>;
85
+ /** map key → generated ident (per-file) for dynamic imports */
86
+ _newDynamicImports?: Map<string, BabelTypes.Identifier>;
87
+ /** whether the current file imported *any* intlayer package */
88
+ _hasValidImport?: boolean;
89
+ /** map from local identifier name to the imported intlayer func name ('useIntlayer' | 'getIntlayer') */
90
+ _callerMap?: Map<string, (typeof CALLER_LIST)[number]>;
91
+ /** map from local identifier name to the intlayer package it was imported from */
92
+ _callerPackageMap?: Map<string, string>;
93
+ /** map from local identifier name to the compat caller descriptor it was imported as */
94
+ _compatCallerMap?: Map<string, CallerDescriptor>;
95
+ /** whether the current file *is* the dictionaries entry file */
96
+ _isDictEntry?: boolean;
97
+ /** whether the current file is included in the filesList */
75
98
  _isIncluded?: boolean;
76
99
  };
77
100
  /**
@@ -158,7 +181,7 @@ type State = PluginPass & {
158
181
  */
159
182
  declare const intlayerOptimizeBabelPlugin: (babel: {
160
183
  types: typeof BabelTypes;
161
- }) => PluginObj<State>;
184
+ }) => PluginObject<State>;
162
185
  //#endregion
163
186
  export { OptimizePluginOptions, intlayerOptimizeBabelPlugin };
164
187
  //# sourceMappingURL=babel-plugin-intlayer-optimize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-optimize.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-optimize.ts"],"mappings":";;;;cAwBM,WAAA;;AAtB0C;;KAqEpC,qBAAA;EA/C+C;;AA+C3D;EAIE,QAAA;;;;EAIA,eAAA;EAIA;;;EAAA,qBAAA;EAgBA;;;EAZA,6BAAA;EA4BA;;;EAxBA,uBAAA;EAuCA;;;EAnCA,sBAAA;EAsCQ;;;EAlCR,4BAAA;EAqCgC;;;EAjChC,oBAAA;EAuCiC;;;EAnCjC,0BAAA;EAqCuB;;;EAjCvB,sBAAA;EAyBA;;;EArBA,UAAA;EAuBA;;;EAnBA,iBAAA,GAAoB,MAAA;EAqBpB;;;EAdA,SAAA;EAkBA;;;EAdA,QAAA;AAAA;AAAA,KAGG,KAAA,GAAQ,UAAA;EACX,IAAA,EAAM,qBAAA,EA6mBP;EA3mBC,iBAAA,GAAoB,GAAA,SAAY,UAAA,CAAW,UAAA,GAgN7B;EA9Md,kBAAA,GAAqB,GAAA,SAAY,UAAA,CAAW,UAAA,GA+M1C;EA7MF,eAAA,YA6MW;EA3MX,UAAA,GAAa,GAAA,iBAAoB,WAAA,YA0MnB;EAxMd,iBAAA,GAAoB,GAAA,kBAyMlB;EAvMF,YAAA,YAuMiB;EArMjB,WAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmMW,2BAAA,GAA+B,KAAA;EAC1C,KAAA,SAAc,UAAA;AAAA,MACZ,SAAA,CAAU,KAAA"}
1
+ {"version":3,"file":"babel-plugin-intlayer-optimize.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-optimize.ts"],"mappings":";;;;cA6BM;;;;KAqDM;;;;EAIV;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA,oBAAoB;;;;EAOpB;;;;EAIA;;;;;;;;;;;;;;EAcA,gBAAgB;;KAGb,QAAQ;EACX,MAAM;;EAEN,oBAAoB,YAAY,WAAW;;EAE3C,qBAAqB,YAAY,WAAW;;EAE5C;;EAEA,aAAa,oBAAoB;;EAEjC,oBAAoB;;EAEpB,mBAAmB,YAAY;;EAE/B;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8RW,8BAA2B;EACtC,cAAc;MACZ,aAAa"}
@@ -1,7 +1,6 @@
1
1
  import { CompatCallerConfig, PruneContext } from "./babel-plugin-intlayer-usage-analyzer.js";
2
- import { PluginObj } from "@babel/core";
2
+ import { PluginObject } from "@babel/core";
3
3
  import * as BabelTypes from "@babel/types";
4
-
5
4
  //#region src/babel-plugin-intlayer-purge.d.ts
6
5
  /**
7
6
  * Pre-resolved options accepted by {@link intlayerPurgeBabelPlugin}.
@@ -133,7 +132,7 @@ declare const getSharedPruneContext: (baseDir: string) => PruneContext | null;
133
132
  */
134
133
  declare const intlayerPurgeBabelPlugin: (_babel: {
135
134
  types: typeof BabelTypes;
136
- }) => PluginObj;
135
+ }) => PluginObject;
137
136
  //#endregion
138
137
  export { PurgePluginOptions, getSharedPruneContext, intlayerPurgeBabelPlugin };
139
138
  //# sourceMappingURL=babel-plugin-intlayer-purge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-purge.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-purge.ts"],"mappings":";;;;;;;AA6BA;;;;;KAAY,kBAAA;EAmBV;;;;;EAbA,OAAA;EAoDA;;;;EA9CA,KAAA;EA8DkC;AAyBpC;;;;EAhFE,MAAA;EA0sBW;;;;;EAnsBX,QAAA;EAmsBuC;;;;EA7rBvC,aAAA;;;;;EAMA,eAAA;;;;;EAMA,sBAAA;;;;;;EAOA,kBAAA;;;;;;EAOA,4BAAA,EAA8B,MAAA;;;;;;;;;;;;EAgB9B,aAAA,GAAgB,kBAAA;AAAA;;;;;;;;;cAyBL,qBAAA,GAAyB,OAAA,aAAkB,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0nB3C,wBAAA,GAA4B,MAAA;EACvC,KAAA,SAAc,UAAA;AAAA,MACZ,SAAA"}
1
+ {"version":3,"file":"babel-plugin-intlayer-purge.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-purge.ts"],"mappings":";;;;;;;;;;;KAgCY;;;;;;EAMV;;;;;EAMA;;;;;;EAOA;;;;;;EAOA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;;EAOA;;;;;;EAOA,8BAA8B;;;;;;;;;;;;EAgB9B,gBAAgB;;;;;;;;;;cAqBL,wBAAqB,oBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwjB3C,2BAAwB;EACnC,cAAc;MACZ"}
@@ -1,6 +1,6 @@
1
- import { PluginObj } from "@babel/core";
1
+ import { PluginObject } from "@babel/core";
2
2
  import * as BabelTypes from "@babel/types";
3
-
3
+ import { CallerDescriptor, CallerDescriptor as CallerDescriptor$1, CallerResultShape, CallerValueSource } from "@intlayer/config/callers";
4
4
  //#region src/babel-plugin-intlayer-usage-analyzer.d.ts
5
5
  /**
6
6
  * Dictionary field usage result for a single dictionary key.
@@ -23,6 +23,22 @@ type NestedRenameEntry = {
23
23
  };
24
24
  /** A level of the field-rename tree, mapping original field names to entries. */
25
25
  type NestedRenameMap = Map<string, NestedRenameEntry>;
26
+ /**
27
+ * One opaque consumption of a dictionary content value: the value at
28
+ * `fieldPath` escapes static analysis (passed as-is to a child component or a
29
+ * function argument), so its children must keep their original key names in
30
+ * the compiled JSON.
31
+ */
32
+ type OpaqueFieldOccurrence = {
33
+ /**
34
+ * Original (pre-rename) user-defined field names from the content root to
35
+ * the escaping value, e.g. `['sections', 'hero']` for
36
+ * `<Card data={content.sections.hero} />`.
37
+ */
38
+ fieldPath: string[];
39
+ /** Source locations (`filePath:line`) where the value escapes. */
40
+ locations: string[];
41
+ };
26
42
  /**
27
43
  * Shared mutable state created once by the vite plugin and passed by reference
28
44
  * to the usage-analyzer (writer) and the prune/minify plugins (readers).
@@ -61,14 +77,17 @@ type PruneContext = {
61
77
  */
62
78
  dictionaryKeyToFieldRenameMap: Map<string, NestedRenameMap>;
63
79
  /**
64
- * Maps each dictionary key to a per-field list of source locations where
65
- * the field value is consumed "opaquely" (passed as-is to a child component
66
- * or function argument). When a field is opaque AND has nested user-defined
67
- * structure, its children must not be renamed.
80
+ * Maps each dictionary key to the content field paths whose values are
81
+ * consumed "opaquely" (passed as-is to a child component or function
82
+ * argument). When an opaque value has nested user-defined structure, its
83
+ * children must not be renamed.
68
84
  *
69
- * Structure: dictionaryKey → fieldName → ["filePath:line", …]
85
+ * The inner map is keyed by the dot-joined field path for de-duplication
86
+ * only; the authoritative path is {@link OpaqueFieldOccurrence.fieldPath}.
87
+ *
88
+ * Structure: dictionaryKey → joinedFieldPath → { fieldPath, locations }
70
89
  */
71
- dictionaryKeysWithOpaqueTopLevelFields: Map<string, Map<string, string[]>>;
90
+ dictionaryKeysWithOpaqueFields: Map<string, Map<string, OpaqueFieldOccurrence>>;
72
91
  /**
73
92
  * Dictionary keys for which field-key renaming must be skipped even if a
74
93
  * finite field-usage set was determined.
@@ -99,110 +118,15 @@ type PruneContext = {
99
118
  };
100
119
  declare const createPruneContext: () => PruneContext;
101
120
  /** Canonical intlayer caller names that trigger usage analysis. */
102
- declare const INTLAYER_CALLER_NAMES: readonly ["useIntlayer", "getIntlayer"];
121
+ declare const INTLAYER_CALLER_NAMES: readonly ['useIntlayer', 'getIntlayer'];
103
122
  type IntlayerCallerName = (typeof INTLAYER_CALLER_NAMES)[number];
104
- /**
105
- * Describes how a compat-adapter "namespace caller" exposes the dictionary key
106
- * (namespace) and the translation function `t`.
107
- *
108
- * Compat adapters (`@intlayer/react-i18next`, `@intlayer/next-intl`, …) expose
109
- * the original i18n library API while delegating to intlayer under the hood.
110
- * Their call sites look like:
111
- *
112
- * const { t } = useTranslation('about'); t('counter.label')
113
- * const t = useTranslations('about'); t('counter.label')
114
- * const t = await getTranslations('about');
115
- * const t = i18n.getFixedT(null, 'about', 'counter');
116
- * const { t } = useI18n({ namespace: 'about' });
117
- *
118
- * The dictionary key is the *namespace* argument and the consumed top-level
119
- * field is the **first segment** of every dot-path passed to `t()` (or the
120
- * first segment of `keyPrefix` when one is supplied).
121
- */
122
- type CompatNamespaceSource = /** Namespace is a positional argument (string literal or `{ namespace }`). */{
123
- from: 'argument';
124
- index: number;
125
- } /** Namespace is a property of an options object argument. */ | {
126
- from: 'option';
127
- argumentIndex: number;
128
- property: string;
129
- }
130
- /**
131
- * Namespace is a compile-time constant — the same dictionary key is used for
132
- * every call site. Used by single-catalog libraries such as lingui, where all
133
- * translations live in a `messages` dictionary regardless of call location.
134
- */
135
- | {
136
- from: 'fixed';
137
- value: string;
138
- }
139
- /**
140
- * Namespace is the first dot-segment of the `id` in the first call argument.
141
- *
142
- * Used for libraries like react-intl where the full dotted id encodes both the
143
- * dictionary key and the field path in a single string:
144
- * `formatMessage({ id: 'home.title' })` → dictionaryKey = `'home'`, field = `'title'`
145
- *
146
- * Works with both string form (`func('home.title')`) and descriptor form
147
- * (`func({ id: 'home.title', ... })`). The paired `translationFunction` should
148
- * be `'self'` so the field (second segment) is also extracted from the same call.
149
- */
150
- | {
151
- from: 'path-first-segment';
152
- };
153
123
  /**
154
124
  * Configuration entry for a single compat namespace caller.
125
+ *
126
+ * @deprecated Alias kept for backward compatibility — use the shared
127
+ * {@link CallerDescriptor} from `@intlayer/config/callers` instead.
155
128
  */
156
- type CompatCallerConfig = {
157
- /** The imported (or method) function name, e.g. `'useTranslation'`. */callerName: string;
158
- /**
159
- * Module specifiers from which `callerName` must be imported to be treated as
160
- * a compat caller. Includes both the original library names and their
161
- * `@intlayer/*` adapter equivalents, because the bundler aliases the former
162
- * to the latter but user source code may import either.
163
- *
164
- * Ignored when `matchAsMethod` is `true`.
165
- */
166
- importSources: string[];
167
- /**
168
- * When `true`, the caller is matched by method name on any object
169
- * (`x.getFixedT(...)`) without an import check. Used for `i18next` instance
170
- * methods that are never imported as named specifiers.
171
- */
172
- matchAsMethod?: boolean; /** How the dictionary key (namespace) is read from the call arguments. */
173
- namespace: CompatNamespaceSource;
174
- /**
175
- * Optional location of a `keyPrefix` that prefixes every `t()` path. When a
176
- * static prefix is present, the only consumed top-level field is the first
177
- * segment of the prefix.
178
- */
179
- keyPrefix?: CompatNamespaceSource;
180
- /**
181
- * How the translation function is obtained from the call result.
182
- *
183
- * - `'return-value'` — `const t = useTranslations('ns'); t('key')`
184
- * - `'destructured-t'` — `const { t } = useTranslation('ns'); t('key')`
185
- * - `'self'` — the caller IS the translation call;
186
- * the first argument is the message key.
187
- * Used for lingui's `i18n._('key')` / `i18n.t('key')`.
188
- * - `'all'` — mark the entire dictionary as used without tracking
189
- * individual fields. Use when static key analysis is
190
- * impossible (e.g. lingui hashed IDs, Angular templates).
191
- */
192
- translationFunction: 'return-value' | 'destructured-t' | 'self' | 'all';
193
- /**
194
- * When set, the caller is *also* matched as a JSX element whose local name is
195
- * `callerName` (gated by `importSources`). The named attribute is read as the
196
- * message id and analysed with the same `namespace` + `translationFunction`
197
- * (`'self'` / `'all'`) semantics as the call-expression form.
198
- *
199
- * Required for libraries with a JSX message component, e.g. react-intl's
200
- * `<FormattedMessage id="home.title" />`. Without it, JSX usages are invisible
201
- * to the analyser and field-level pruning of the same dictionary becomes
202
- * unsafe (it could prune a field only referenced from JSX).
203
- */
204
- jsxIdAttribute?: string;
205
- };
129
+ type CompatCallerConfig = CallerDescriptor$1;
206
130
  /**
207
131
  * Default registry of compat namespace callers.
208
132
  *
@@ -230,11 +154,9 @@ declare const DEFAULT_COMPAT_CALLERS: CompatCallerConfig[];
230
154
  */
231
155
  declare const makeUsageAnalyzerBabelPlugin: (pruneContext: PruneContext, options?: {
232
156
  compatCallers?: CompatCallerConfig[];
233
- }) => ({
234
- types: babelTypes
235
- }: {
157
+ }) => ({ types: babelTypes }: {
236
158
  types: typeof BabelTypes;
237
- }) => PluginObj;
159
+ }) => PluginObject;
238
160
  //#endregion
239
- export { CompatCallerConfig, CompatNamespaceSource, DEFAULT_COMPAT_CALLERS, DictionaryFieldUsage, INTLAYER_CALLER_NAMES, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, PruneContext, createPruneContext, makeUsageAnalyzerBabelPlugin };
161
+ export { type CallerDescriptor, type CallerResultShape, type CallerValueSource, CompatCallerConfig, DEFAULT_COMPAT_CALLERS, DictionaryFieldUsage, INTLAYER_CALLER_NAMES, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, OpaqueFieldOccurrence, PruneContext, createPruneContext, makeUsageAnalyzerBabelPlugin };
240
162
  //# sourceMappingURL=babel-plugin-intlayer-usage-analyzer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-usage-analyzer.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-usage-analyzer.ts"],"mappings":";;;;;;AAYA;;;;;KAAY,oBAAA,GAAuB,GAAA;;;;;;;;KASvB,iBAAA;EACV,SAAA;EACA,QAAA,EAAU,eAAA;AAAA;;KAIA,eAAA,GAAkB,GAAA,SAAY,iBAAA;AAS1C;;;;;;;AAAA,KAAY,YAAA;EAiCqB;;;;;EA3B/B,4BAAA,EAA8B,GAAA,SAAY,oBAAA;EA+Db;;;;EAzD7B,yBAAA,EAA2B,GAAA;EAAA;;;;;EAO3B,wBAAA;EAc2C;;;;;EAP3C,mCAAA,EAAqC,GAAA;EA2CrC;;;;;EApCA,6BAAA,EAA+B,GAAA,SAAY,eAAA;EA0ChC;;;;;AAiBb;;;EAjDE,sCAAA,EAAwC,GAAA,SAAY,GAAA;EAiDsB;AAC5E;;;;;AAsBA;;;;;;EA1DE,+BAAA,EAAiC,GAAA;EA8Db;;;;;;;AAuBtB;;;EAzEE,wBAAA,EAA0B,GAAA;IAEtB,YAAA;IAAsB,aAAA;EAAA;AAAA;AAAA,cAIf,kBAAA,QAAyB,YAAA;;cAiBzB,qBAAA;AAAA,KACD,kBAAA,WAA6B,qBAAA;;;;AAgHzC;;;;;AAw2BA;;;;;;;;;;KAl8BY,qBAAA;EAEN,IAAA;EAAkB,KAAA;AAAA;EAElB,IAAA;EAAgB,aAAA;EAAuB,QAAA;AAAA;;;;;;;EAMvC,IAAA;EAAe,KAAA;AAAA;;;;;;;;;;;;;EAYf,IAAA;AAAA;;;;KAKM,kBAAA;yEAEV,UAAA;;;;;;;;;EASA,aAAA;;;;;;EAMA,aAAA;EAEA,SAAA,EAAW,qBAAA;;;;;;EAMX,SAAA,GAAY,qBAAA;;;;;;;;;;;;;EAaZ,mBAAA;;;;;;;;;;;;EAYA,cAAA;AAAA;;;;;;;;;;;cAaW,sBAAA,EAAwB,kBAAA;;;;;;;;;;;;;;;cAw2BxB,4BAAA,GAET,YAAA,EAAc,YAAA,EACd,OAAA;EAAY,aAAA,GAAgB,kBAAA;AAAA;EAE7B,KAAA,EAAA;AAAA;EAAyB,KAAA,SAAc,UAAA;AAAA,MAAe,SAAA"}
1
+ {"version":3,"file":"babel-plugin-intlayer-usage-analyzer.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-usage-analyzer.ts"],"mappings":";;;;;;;;;;;KAgBY,uBAAuB;;;;;;;;KASvB;EACV;EACA,UAAU;;;KAIA,kBAAkB,YAAY;;;;;;;KAQ9B;;;;;;EAMV;;EAGA;;;;;;;;;KAUU;;;;;;EAMV,8BAA8B,YAAY;;;;;EAM1C,2BAA2B;;;;;;EAO3B;;;;;;EAOA,qCAAqC;;;;;;EAOrC,+BAA+B,YAAY;;;;;;;;;;;;EAa3C,gCAAgC,YAE9B,YAAY;;;;;;;;;;;;;EAed,iCAAiC;;;;;;;;;;;EAYjC,0BAA0B;IAEtB;IAAsB;;;cAIf,0BAAyB;;cAiBzB;KACD,6BAA6B;;;;;;;KAmB7B,qBAAqB;;;;;;;;;;;cAYpB,wBAAwB;;;;;;;;;;;;;;;cAmiCxB,+BAA4B,cAEvB,cAAY;EACd,gBAAgB;SAAsB,OAAA;EAE1B,cAAc;MAAe"}
@@ -0,0 +1,12 @@
1
+ //#region src/babelParser.d.ts
2
+ /** A parser object accepted by `recast.parse`'s `parser` option. */
3
+ type RecastParser = {
4
+ parse: (source: string) => unknown;
5
+ };
6
+ /** Drop-in replacement for `recast/parsers/typescript` (TS without JSX). */
7
+ declare const typescriptParser: RecastParser;
8
+ /** Drop-in replacement for `recast/parsers/babel-ts` (TS *and* JSX). */
9
+ declare const babelTsParser: RecastParser;
10
+ //#endregion
11
+ export { RecastParser, babelTsParser, typescriptParser };
12
+ //# sourceMappingURL=babelParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babelParser.d.ts","names":[],"sources":["../../src/babelParser.ts"],"mappings":";;KAuDY;EACV,QAAQ;;;cAIG,kBAAkB;;cAMlB,eAAe"}
@@ -1,7 +1,8 @@
1
+ import { ExistingIntlayerInfo } from "./utils/getExistingIntlayerInfo.js";
2
+ import "./utils/index.js";
1
3
  import * as t from "@babel/types";
2
4
  import { IntlayerConfig } from "@intlayer/types/config";
3
5
  import { NodePath } from "@babel/traverse";
4
-
5
6
  //#region src/extractContent/babelProcessor.d.ts
6
7
  type BabelReplacement = {
7
8
  path: NodePath;
@@ -26,7 +27,9 @@ declare const extractBabelContentForComponents: (ast: t.File, fileCode: string,
26
27
  componentsNeedingHooks: Set<NodePath>;
27
28
  componentKeyMap: Map<t.Node, string>;
28
29
  componentPaths: NodePath[];
29
- hookMap: Map<t.Node, "useIntlayer" | "getIntlayer">;
30
+ hookMap: Map<t.Node, 'useIntlayer' | 'getIntlayer'>;
31
+ /** Cached `getExistingIntlayerInfo` result per component node, so callers do not re-traverse. */
32
+ existingInfoByNode: Map<t.Node, ExistingIntlayerInfo | undefined>;
30
33
  isSolid: boolean;
31
34
  };
32
35
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"babelProcessor.d.ts","names":[],"sources":["../../../src/extractContent/babelProcessor.ts"],"mappings":";;;;;KAYY,gBAAA;EACV,IAAA,EAAM,QAAA;EACN,GAAA;EACA,IAAA;EAOA,YAAA;EACA,iBAAA,GAAoB,CAAA,CAAE,IAAA;EACtB,SAAA;AAAA;;;;;cAYW,uBAAA,GACX,IAAA,EAAM,QAAA,CAAS,CAAA,CAAE,UAAA,GAAa,CAAA,CAAE,WAAA,GAChC,QAAA,UACA,YAAA,EAAc,GAAA,UACd,sBAAA,GAAyB,IAAA,EAAM,QAAA,aAC/B,gBAAA,EAAkB,MAAA,SAAe,MAAA,mBACjC,YAAA,EAAc,gBAAA,IACd,YAAA,EAAc,GAAA,CAAI,CAAA,CAAE,IAAA;;;;;cAwIT,gCAAA,GACX,GAAA,EAAK,CAAA,CAAE,IAAA,EACP,QAAA,UACA,YAAA,EAAc,GAAA,UACd,UAAA,UACA,aAAA,EAAe,cAAA,EACf,QAAA,UACA,oBAAA,GAAsB,MAAA;EAEtB,gBAAA,EAAkB,MAAA,SAAe,MAAA;EACjC,YAAA,EAAc,gBAAA;EACd,sBAAA,EAAwB,GAAA,CAAI,QAAA;EAC5B,eAAA,EAAiB,GAAA,CAAI,CAAA,CAAE,IAAA;EACvB,cAAA,EAAgB,QAAA;EAChB,OAAA,EAAS,GAAA,CAAI,CAAA,CAAE,IAAA;EACf,OAAA;AAAA;;;;cAobW,gBAAA,GACX,GAAA,EAAK,CAAA,CAAE,IAAA,EACP,QAAA,UACA,YAAA,EAAc,GAAA,UACd,aAAA,EAAe,cAAA,EACf,QAAA,UACA,oBAAA,GAAsB,MAAA;EAEtB,gBAAA,EAAkB,MAAA;EAClB,YAAA,EAAc,gBAAA;AAAA"}
1
+ {"version":3,"file":"babelProcessor.d.ts","names":[],"sources":["../../../src/extractContent/babelProcessor.ts"],"mappings":";;;;;;KAaY;EACV,MAAM;EACN;EACA;EAOA;EACA,oBAAoB,EAAE;EACtB;;;;;;cA4IW,0BAAuB,MAC5B,SAAS,EAAE,aAAa,EAAE,cAAY,kBAC5B,cACF,aAAW,yBACA,MAAM,qBAAmB,kBAChC,eAAe,yBAAuB,cAC1C,oBAAkB,cAClB,IAAI,EAAE;;;;;cAwIT,mCAAgC,KACtC,EAAE,MAAI,kBACK,cACF,aAAW,oBACP,eACH,gBAAc,kBACb,uBACM;EAEtB,kBAAkB,eAAe;EACjC,cAAc;EACd,wBAAwB,IAAI;EAC5B,iBAAiB,IAAI,EAAE;EACvB,gBAAgB;EAChB,SAAS,IAAI,EAAE;;EAEf,oBAAoB,IAAI,EAAE,MAAM;EAChC;;;;;cA6ZW,mBAAgB,KACtB,EAAE,MAAI,kBACK,cACF,aAAW,eACV,gBAAc,kBACb,uBACM;EAEtB,kBAAkB;EAClB,cAAc"}
@@ -1,6 +1,5 @@
1
1
  import { IntlayerConfig } from "@intlayer/types/config";
2
2
  import { Dictionary, DictionaryKey } from "@intlayer/types/dictionary";
3
-
4
3
  //#region src/extractContent/contentWriter.d.ts
5
4
  /**
6
5
  * Translation node structure used in dictionaries
@@ -1 +1 @@
1
- {"version":3,"file":"contentWriter.d.ts","names":[],"sources":["../../../src/extractContent/contentWriter.ts"],"mappings":";;;;;;AAY4E;KA2BvE,eAAA;EACH,QAAA;EACA,WAAA,EAAa,MAAA;AAAA;;;;KAMV,oBAAA,GAAuB,MAAA,SAAe,eAAA;AANtB;;;;;AAmBrB;AAnBqB,cAmBR,uCAAA,GACX,gBAAA,EAAkB,MAAA,kBAClB,kBAAA,EAAoB,UAAA,SACpB,aAAA,aACC,oBAAA;;;;;;;cAkDU,oCAAA,GACX,gBAAA,EAAkB,MAAA,kBAClB,kBAAA,EAAoB,UAAA,YACnB,MAAA;;;;cA8CU,kBAAA,GACX,gBAAA,EAAkB,MAAA,kBAClB,aAAA,EAAe,aAAA,EACf,QAAA,UACA,aAAA,EAAe,cAAA,KACd,OAAA"}
1
+ {"version":3,"file":"contentWriter.d.ts","names":[],"sources":["../../../src/extractContent/contentWriter.ts"],"mappings":";;;;;;KAmCK;EACH;EACA,aAAa;;;;;KAMV,uBAAuB,eAAe;;;;;;;cAa9B,0CAAuC,kBAChC,wBAAsB,oBACpB,mBAAiB,0BAEpC;;;;;;;cAkDU,uCAAoC,kBAC7B,wBAAsB,oBACpB,sBACnB;;;;cA8CU,qBAAkB,kBACX,wBAAsB,eACzB,eAAa,kBACZ,eACD,mBACd"}
@@ -1,7 +1,7 @@
1
1
  import { PackageName } from "./utils/constants.js";
2
+ import "./utils/index.js";
2
3
  import { IntlayerConfig } from "@intlayer/types/config";
3
4
  import { GetConfigurationOptions } from "@intlayer/config/node";
4
-
5
5
  //#region src/extractContent/extractContent.d.ts
6
6
  type ExtractIntlayerOptions = {
7
7
  configOptions?: GetConfigurationOptions;