@intlayer/babel 9.0.0-canary.14 → 9.0.0-canary.16

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.
@@ -152,9 +152,28 @@ const walkObjectDestructuring = (babelTypes, refPath, renameMap) => {
152
152
  }
153
153
  };
154
154
  /**
155
- * Creates a Babel plugin that rewrites dictionary content field accesses in
156
- * source files to their short aliases defined in
157
- * `pruneContext.dictionaryKeyToFieldRenameMap`.
155
+ * Collects the local aliases under which `useIntlayer` / `getIntlayer` are
156
+ * imported in the given program (e.g. `import { useIntlayer as useI } …`
157
+ * yields `useI` → `useIntlayer`).
158
+ *
159
+ * Import declarations can only appear at the top level of a module, so the
160
+ * program body is scanned directly instead of traversing the whole AST.
161
+ */
162
+ const collectIntlayerCallerLocalNames = (babelTypes, programNode) => {
163
+ const intlayerCallerLocalNameMap = /* @__PURE__ */ new Map();
164
+ for (const statement of programNode.body) {
165
+ if (!babelTypes.isImportDeclaration(statement)) continue;
166
+ for (const importSpecifier of statement.specifiers) {
167
+ if (!babelTypes.isImportSpecifier(importSpecifier)) continue;
168
+ const importedName = babelTypes.isIdentifier(importSpecifier.imported) ? importSpecifier.imported.name : importSpecifier.imported.value;
169
+ if (require_babel_plugin_intlayer_usage_analyzer.INTLAYER_CALLER_NAMES.includes(importedName)) intlayerCallerLocalNameMap.set(importSpecifier.local.name, importedName);
170
+ }
171
+ }
172
+ return intlayerCallerLocalNameMap;
173
+ };
174
+ /**
175
+ * Rewrites dictionary content field accesses in the given program to the
176
+ * short aliases defined in `pruneContext.dictionaryKeyToFieldRenameMap`.
158
177
  *
159
178
  * Handled patterns (mirrors the usage analyser):
160
179
  *
@@ -172,6 +191,62 @@ const walkObjectDestructuring = (babelTypes, refPath, renameMap) => {
172
191
  * → const { shortA: fieldA } = useIntlayer('key');
173
192
  * const { shortN: nested } = fieldA;
174
193
  *
194
+ * Exposed as a standalone function so that both
195
+ * {@link makeFieldRenameBabelPlugin} and `intlayerMinifyBabelPlugin` can
196
+ * invoke it from their own `Program.exit` visitors.
197
+ */
198
+ const renameIntlayerFieldAccesses = (babelTypes, programPath, pruneContext) => {
199
+ if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return;
200
+ const intlayerCallerLocalNameMap = collectIntlayerCallerLocalNames(babelTypes, programPath.node);
201
+ if (intlayerCallerLocalNameMap.size === 0) return;
202
+ programPath.traverse({ CallExpression: (callExpressionPath) => {
203
+ const calleeNode = callExpressionPath.node.callee;
204
+ let localCallerName;
205
+ if (babelTypes.isIdentifier(calleeNode)) localCallerName = calleeNode.name;
206
+ else if (babelTypes.isMemberExpression(calleeNode) && babelTypes.isIdentifier(calleeNode.property)) localCallerName = calleeNode.property.name;
207
+ if (!localCallerName || !intlayerCallerLocalNameMap.has(localCallerName)) return;
208
+ const callArguments = callExpressionPath.node.arguments;
209
+ if (callArguments.length === 0) return;
210
+ const firstArgument = callArguments[0];
211
+ let dictionaryKey;
212
+ if (babelTypes.isStringLiteral(firstArgument)) dictionaryKey = firstArgument.value;
213
+ else if (babelTypes.isTemplateLiteral(firstArgument) && firstArgument.expressions.length === 0 && firstArgument.quasis.length === 1 && firstArgument.quasis[0]) dictionaryKey = firstArgument.quasis[0].value.cooked ?? firstArgument.quasis[0].value.raw;
214
+ if (!dictionaryKey) return;
215
+ const fieldRenameMap = pruneContext.dictionaryKeyToFieldRenameMap.get(dictionaryKey);
216
+ if (!fieldRenameMap || fieldRenameMap.size === 0) return;
217
+ const parentNode = callExpressionPath.parent;
218
+ if (babelTypes.isVariableDeclarator(parentNode) && babelTypes.isObjectPattern(parentNode.id)) {
219
+ walkObjectDestructuring(babelTypes, callExpressionPath, fieldRenameMap);
220
+ return;
221
+ }
222
+ if ((babelTypes.isMemberExpression(parentNode) || babelTypes.isOptionalMemberExpression(parentNode)) && parentNode.object === callExpressionPath.node) {
223
+ const { finalPath, finalRenameMap } = walkRenameChain(babelTypes, callExpressionPath, fieldRenameMap);
224
+ walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);
225
+ return;
226
+ }
227
+ if (babelTypes.isVariableDeclarator(parentNode) && babelTypes.isIdentifier(parentNode.id)) {
228
+ const variableBinding = callExpressionPath.scope.getBinding(parentNode.id.name);
229
+ if (!variableBinding) return;
230
+ for (const variableReferencePath of variableBinding.referencePaths) {
231
+ const { finalPath, finalRenameMap } = walkRenameChain(babelTypes, variableReferencePath, fieldRenameMap);
232
+ walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);
233
+ const refParent = variableReferencePath.parent;
234
+ if ((babelTypes.isCallExpression(refParent) || babelTypes.isOptionalCallExpression(refParent)) && refParent.callee === variableReferencePath.node) {
235
+ const callPath = variableReferencePath.parentPath;
236
+ if (callPath) {
237
+ const { finalPath: signalFinalPath, finalRenameMap: signalFinalRenameMap } = walkRenameChain(babelTypes, callPath, fieldRenameMap);
238
+ walkObjectDestructuring(babelTypes, signalFinalPath, signalFinalRenameMap);
239
+ }
240
+ }
241
+ }
242
+ }
243
+ } });
244
+ };
245
+ /**
246
+ * Creates a Babel plugin that rewrites dictionary content field accesses in
247
+ * source files to their short aliases via
248
+ * {@link renameIntlayerFieldAccesses}.
249
+ *
175
250
  * This plugin must run in a separate `transformAsync` pass **before**
176
251
  * `intlayerOptimizeBabelPlugin`, because the latter replaces `useIntlayer`
177
252
  * with `useDictionary`, erasing the dictionary-key information needed here.
@@ -179,76 +254,7 @@ const walkObjectDestructuring = (babelTypes, refPath, renameMap) => {
179
254
  const makeFieldRenameBabelPlugin = (pruneContext) => ({ types: babelTypes }) => ({
180
255
  name: "intlayer-field-rename",
181
256
  visitor: { Program: { exit: (programPath) => {
182
- if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return;
183
- const intlayerCallerLocalNameMap = /* @__PURE__ */ new Map();
184
- programPath.traverse({ ImportDeclaration: (importDeclarationPath) => {
185
- for (const importSpecifier of importDeclarationPath.node.specifiers) {
186
- if (!babelTypes.isImportSpecifier(importSpecifier)) continue;
187
- const importedName = babelTypes.isIdentifier(importSpecifier.imported) ? importSpecifier.imported.name : importSpecifier.imported.value;
188
- if (require_babel_plugin_intlayer_usage_analyzer.INTLAYER_CALLER_NAMES.includes(importedName)) intlayerCallerLocalNameMap.set(importSpecifier.local.name, importedName);
189
- }
190
- } });
191
- if (intlayerCallerLocalNameMap.size === 0) return;
192
- programPath.traverse({ CallExpression: (callExpressionPath) => {
193
- const calleeNode = callExpressionPath.node.callee;
194
- let localCallerName;
195
- if (babelTypes.isIdentifier(calleeNode)) localCallerName = calleeNode.name;
196
- else if (babelTypes.isMemberExpression(calleeNode) && babelTypes.isIdentifier(calleeNode.property)) localCallerName = calleeNode.property.name;
197
- if (!localCallerName || !intlayerCallerLocalNameMap.has(localCallerName)) return;
198
- const callArguments = callExpressionPath.node.arguments;
199
- if (callArguments.length === 0) return;
200
- const firstArgument = callArguments[0];
201
- let dictionaryKey;
202
- if (babelTypes.isStringLiteral(firstArgument)) dictionaryKey = firstArgument.value;
203
- else if (babelTypes.isTemplateLiteral(firstArgument) && firstArgument.expressions.length === 0 && firstArgument.quasis.length === 1 && firstArgument.quasis[0]) dictionaryKey = firstArgument.quasis[0].value.cooked ?? firstArgument.quasis[0].value.raw;
204
- if (!dictionaryKey) return;
205
- const fieldRenameMap = pruneContext.dictionaryKeyToFieldRenameMap.get(dictionaryKey);
206
- if (!fieldRenameMap || fieldRenameMap.size === 0) return;
207
- const parentNode = callExpressionPath.parent;
208
- if (babelTypes.isVariableDeclarator(parentNode) && babelTypes.isObjectPattern(parentNode.id)) {
209
- for (const property of parentNode.id.properties) {
210
- if (!babelTypes.isObjectProperty(property)) continue;
211
- const keyName = babelTypes.isIdentifier(property.key) ? property.key.name : babelTypes.isStringLiteral(property.key) ? property.key.value : null;
212
- if (!keyName) continue;
213
- const renameEntry = fieldRenameMap.get(keyName);
214
- if (!renameEntry) continue;
215
- if (property.shorthand) {
216
- property.shorthand = false;
217
- property.key = babelTypes.identifier(renameEntry.shortName);
218
- } else property.key = babelTypes.identifier(renameEntry.shortName);
219
- if (renameEntry.children.size > 0 && babelTypes.isIdentifier(property.value)) {
220
- const localVarBinding = callExpressionPath.scope.getBinding(property.value.name);
221
- if (localVarBinding) for (const refPath of localVarBinding.referencePaths) {
222
- const { finalPath, finalRenameMap } = walkRenameChain(babelTypes, refPath, renameEntry.children);
223
- walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);
224
- }
225
- }
226
- }
227
- return;
228
- }
229
- if ((babelTypes.isMemberExpression(parentNode) || babelTypes.isOptionalMemberExpression(parentNode)) && parentNode.object === callExpressionPath.node) {
230
- const { finalPath, finalRenameMap } = walkRenameChain(babelTypes, callExpressionPath, fieldRenameMap);
231
- walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);
232
- return;
233
- }
234
- if (babelTypes.isVariableDeclarator(parentNode) && babelTypes.isIdentifier(parentNode.id)) {
235
- const variableName = parentNode.id.name;
236
- const variableBinding = callExpressionPath.scope.getBinding(variableName);
237
- if (!variableBinding) return;
238
- for (const variableReferencePath of variableBinding.referencePaths) {
239
- const { finalPath, finalRenameMap } = walkRenameChain(babelTypes, variableReferencePath, fieldRenameMap);
240
- walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);
241
- const refParent = variableReferencePath.parent;
242
- if ((babelTypes.isCallExpression(refParent) || babelTypes.isOptionalCallExpression(refParent)) && refParent.callee === variableReferencePath.node) {
243
- const callPath = variableReferencePath.parentPath;
244
- if (callPath) {
245
- const { finalPath: signalFinalPath, finalRenameMap: signalFinalRenameMap } = walkRenameChain(babelTypes, callPath, fieldRenameMap);
246
- walkObjectDestructuring(babelTypes, signalFinalPath, signalFinalRenameMap);
247
- }
248
- }
249
- }
250
- }
251
- } });
257
+ renameIntlayerFieldAccesses(babelTypes, programPath, pruneContext);
252
258
  } } }
253
259
  });
254
260
 
@@ -256,4 +262,5 @@ const makeFieldRenameBabelPlugin = (pruneContext) => ({ types: babelTypes }) =>
256
262
  exports.buildNestedRenameMapFromContent = buildNestedRenameMapFromContent;
257
263
  exports.generateShortFieldName = generateShortFieldName;
258
264
  exports.makeFieldRenameBabelPlugin = makeFieldRenameBabelPlugin;
265
+ exports.renameIntlayerFieldAccesses = renameIntlayerFieldAccesses;
259
266
  //# sourceMappingURL=babel-plugin-intlayer-field-rename.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-field-rename.cjs","names":["INTLAYER_CALLER_NAMES"],"sources":["../../src/babel-plugin-intlayer-field-rename.ts"],"sourcesContent":["import type { NodePath, PluginObject } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport {\n INTLAYER_CALLER_NAMES,\n type IntlayerCallerName,\n type NestedRenameMap,\n type PruneContext,\n} from './babel-plugin-intlayer-usage-analyzer';\n\n// ── Field-name helpers ────────────────────────────────────────────────────────\n\n/**\n * Intlayer internal property names that must never be used as short-name\n * targets. These appear inside content-node values (e.g. `{ nodeType:\n * \"translation\", … }`) and are read by the intlayer runtime.\n */\nconst RESERVED_CONTENT_FIELD_NAMES = new Set(['nodeType']);\n\n/** Alphabet used to derive short field aliases (`a`, `b`, …, `aa`, `ab`, …). */\nconst SHORT_NAME_ALPHABET = 'abcdefghijklmnopqrstuvwxyz';\n\n/**\n * Converts a zero-based index to a short alphabetic identifier.\n * 0 → 'a', 1 → 'b', …, 25 → 'z', 26 → 'aa', 27 → 'ab', …\n */\nexport const generateShortFieldName = (index: number): string => {\n const remainder = index % SHORT_NAME_ALPHABET.length;\n const quotient = Math.floor(index / SHORT_NAME_ALPHABET.length);\n\n return quotient === 0 && SHORT_NAME_ALPHABET[remainder]\n ? SHORT_NAME_ALPHABET[remainder]\n : generateShortFieldName(quotient - 1) + SHORT_NAME_ALPHABET[remainder];\n};\n\n/**\n * Recursively builds a `NestedRenameMap` from a compiled dictionary content\n * value by traversing the intlayer node structure.\n *\n * Rules:\n * - If the value has `nodeType: 'translation'`, user-defined fields live\n * inside `translation[locale]`. Recurse into the first locale's value.\n * - All other intlayer runtime nodes (enumeration, condition, gender, …) are\n * treated as leaves — their internal keys must never be renamed.\n * - Arrays produce an empty children map. Array elements are not traversed\n * because consumers may access them via `.map()` / `.filter()` callbacks,\n * which the source-code rename walk cannot enter. Renaming element fields\n * in the JSON without the matching source-code rename would produce\n * mismatched key names and runtime crashes.\n * The `[0]` pass-through in `walkRenameChain` is preserved so that direct\n * indexed access (`field[0].sub`) silently terminates at the empty children\n * map without breaking anything.\n * - Plain objects are user-defined records: ALL non-reserved keys are renamed\n * with short alphabetic aliases (a, b, c, …) and each value is recursed into.\n * - Primitives produce an empty map (no further renaming).\n *\n * The rename map is built from ALL user-defined fields (not just consumed ones).\n * Both the JSON rename and the source-code rename use the same map, so the\n * short names are always consistent regardless of which fields are pruned.\n *\n * @param contentValue - The dictionary content value to analyse.\n */\nexport const buildNestedRenameMapFromContent = (\n contentValue: unknown\n): NestedRenameMap => {\n if (\n !contentValue ||\n typeof contentValue !== 'object' ||\n Array.isArray(contentValue)\n ) {\n return new Map();\n }\n\n const record = contentValue as Record<string, unknown>;\n\n // Any object with `nodeType: string` is an intlayer runtime node.\n if (typeof record.nodeType === 'string') {\n // Translation node: user-defined fields live inside translation[locale].\n if (\n record.nodeType === 'translation' &&\n record.translation &&\n typeof record.translation === 'object' &&\n !Array.isArray(record.translation)\n ) {\n const firstLocaleValue = Object.values(\n record.translation as Record<string, unknown>\n )[0];\n return buildNestedRenameMapFromContent(firstLocaleValue);\n }\n\n // Enumeration node: user-defined keys live inside enumeration.\n if (\n record.nodeType === 'enumeration' &&\n record.enumeration &&\n typeof record.enumeration === 'object' &&\n !Array.isArray(record.enumeration)\n ) {\n const values = Object.values(\n record.enumeration as Record<string, unknown>\n );\n if (values.length > 0) {\n return buildNestedRenameMapFromContent(values[0]);\n }\n }\n\n // All other intlayer nodes (pluralization, conditions, etc.) resolve to a\n // single value at runtime – return an empty map so they are treated\n // as leaves unless they contain nested user records.\n return new Map();\n }\n\n // Exclude React elements from being treated as user-defined records.\n // JSX elements in the compiled JSON have a $$typeof property (usually Symbol(react.element)).\n if (\n record.$$typeof ||\n (record.type && record.props && Object.hasOwn(record, 'ref'))\n ) {\n return new Map();\n }\n\n // User-defined record: rename ALL non-reserved keys with stable alphabetic\n // aliases sorted alphabetically so the mapping is deterministic.\n const sortedKeys = Object.keys(record)\n .filter((key) => !RESERVED_CONTENT_FIELD_NAMES.has(key))\n .sort();\n\n const renameMap: NestedRenameMap = new Map();\n\n for (let i = 0; i < sortedKeys.length; i++) {\n const key = sortedKeys[i];\n\n if (!key) continue;\n\n const children = buildNestedRenameMapFromContent(record[key]);\n\n renameMap.set(key, { shortName: generateShortFieldName(i), children });\n }\n\n return renameMap;\n};\n\n// ── Field-rename Babel plugin ─────────────────────────────────────────────────\n\n/**\n * Walks a MemberExpression chain starting from `startPath`, renaming each\n * property found in `currentRenameMap` at the corresponding nesting level.\n *\n * Numeric computed accesses (array indices such as `[0]`, `[1]`) are treated\n * as transparent pass-throughs: the rename map is kept unchanged and the walk\n * continues past the index. This means `content.field[0].sub` is handled\n * correctly — `field` and `sub` are both renamed while `[0]` is left intact.\n */\nconst walkRenameChain = (\n babelTypes: typeof BabelTypes,\n startPath: NodePath<BabelTypes.Node>,\n currentRenameMap: NestedRenameMap\n): {\n finalPath: NodePath<BabelTypes.Node>;\n finalRenameMap: NestedRenameMap;\n} => {\n let refPath: NodePath<BabelTypes.Node> = startPath;\n let renameMap = currentRenameMap;\n\n while (true) {\n const parentPath = refPath.parentPath;\n if (!parentPath) break;\n\n const parentNode = parentPath.node;\n\n if (\n (!babelTypes.isMemberExpression(parentNode) &&\n !babelTypes.isOptionalMemberExpression(parentNode)) ||\n (parentNode as BabelTypes.MemberExpression).object !== refPath.node\n ) {\n break;\n }\n\n const memberNode = parentNode as BabelTypes.MemberExpression;\n\n // Numeric index access ([0], [1], …): advance past the array accessor\n // without touching the rename map. The next iteration will attempt to\n // rename the property that follows the index.\n if (\n memberNode.computed &&\n babelTypes.isNumericLiteral(memberNode.property)\n ) {\n refPath = parentPath;\n continue;\n }\n\n // Nothing left to rename at this level — stop.\n if (renameMap.size === 0) break;\n\n let fieldName: string | undefined;\n\n if (!memberNode.computed && babelTypes.isIdentifier(memberNode.property)) {\n fieldName = memberNode.property.name;\n } else if (\n memberNode.computed &&\n babelTypes.isStringLiteral(memberNode.property)\n ) {\n fieldName = memberNode.property.value;\n } else {\n break; // dynamic computed key – stop\n }\n\n const renameEntry = renameMap.get(fieldName);\n if (!renameEntry) break; // not in map – stop\n\n // Apply the rename\n if (!memberNode.computed && babelTypes.isIdentifier(memberNode.property)) {\n memberNode.property.name = renameEntry.shortName;\n } else if (\n memberNode.computed &&\n babelTypes.isStringLiteral(memberNode.property)\n ) {\n memberNode.property.value = renameEntry.shortName;\n }\n\n refPath = parentPath;\n renameMap = renameEntry.children;\n }\n\n return { finalPath: refPath, finalRenameMap: renameMap };\n};\n\n/**\n * Walks an object-destructuring assignment whose right-hand side is `refPath`,\n * renaming each destructured key that is found in `renameMap`.\n *\n * Handles the \"secondary destructuring\" pattern that `walkRenameChain` cannot\n * reach because the reference is not a MemberExpression:\n *\n * const { webhooksSection } = useIntlayer('build-settings');\n * const { modal, validationErrors } = webhooksSection;\n * → const { a: modal, b: validationErrors } = webhooksSection;\n *\n * After renaming each key the function recursively walks references to the\n * newly-bound local variable, calling both `walkRenameChain` (for subsequent\n * member-access chains like `validationErrors.invalidUrl`) and itself (for\n * further levels of secondary destructuring).\n */\nconst walkObjectDestructuring = (\n babelTypes: typeof BabelTypes,\n refPath: NodePath<BabelTypes.Node>,\n renameMap: NestedRenameMap\n): void => {\n if (renameMap.size === 0) return;\n\n const parentNode = refPath.parent;\n\n // Only handle: const { a, b } = refVar\n if (\n !babelTypes.isVariableDeclarator(parentNode) ||\n !babelTypes.isObjectPattern(parentNode.id) ||\n parentNode.init !== refPath.node\n ) {\n return;\n }\n\n for (const property of (parentNode.id as BabelTypes.ObjectPattern)\n .properties) {\n if (!babelTypes.isObjectProperty(property)) continue;\n\n const keyName = babelTypes.isIdentifier(property.key)\n ? property.key.name\n : babelTypes.isStringLiteral(property.key)\n ? property.key.value\n : null;\n if (!keyName) continue;\n\n const renameEntry = renameMap.get(keyName);\n if (!renameEntry) continue;\n\n // { fieldA } → { shortA: fieldA }\n // { fieldA: localVar } → { shortA: localVar }\n if (property.shorthand) {\n property.shorthand = false;\n }\n property.key = babelTypes.identifier(renameEntry.shortName);\n\n // Recursively walk references to the local variable bound by this key.\n if (\n renameEntry.children.size > 0 &&\n babelTypes.isIdentifier(property.value)\n ) {\n const localVarName = (property.value as BabelTypes.Identifier).name;\n const localVarBinding = refPath.scope.getBinding(localVarName);\n if (localVarBinding) {\n for (const nestedRefPath of localVarBinding.referencePaths) {\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n nestedRefPath,\n renameEntry.children\n );\n walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);\n }\n }\n }\n }\n};\n\n/**\n * Creates a Babel plugin that rewrites dictionary content field accesses in\n * source files to their short aliases defined in\n * `pruneContext.dictionaryKeyToFieldRenameMap`.\n *\n * Handled patterns (mirrors the usage analyser):\n *\n * const { fieldA, fieldB } = useIntlayer('key')\n * → const { shortA: fieldA, shortB: fieldB } = useIntlayer('key')\n *\n * useIntlayer('key').fieldA\n * → useIntlayer('key').shortA\n *\n * const result = useIntlayer('key'); result.fieldA\n * → const result = useIntlayer('key'); result.shortA\n *\n * const { fieldA } = useIntlayer('key');\n * const { nested } = fieldA; // secondary destructuring\n * → const { shortA: fieldA } = useIntlayer('key');\n * const { shortN: nested } = fieldA;\n *\n * This plugin must run in a separate `transformAsync` pass **before**\n * `intlayerOptimizeBabelPlugin`, because the latter replaces `useIntlayer`\n * with `useDictionary`, erasing the dictionary-key information needed here.\n */\nexport const makeFieldRenameBabelPlugin =\n (pruneContext: PruneContext) =>\n ({ types: babelTypes }: { types: typeof BabelTypes }): PluginObject => ({\n name: 'intlayer-field-rename',\n visitor: {\n Program: {\n exit: (programPath) => {\n if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return;\n\n // Collect local aliases for useIntlayer / getIntlayer\n const intlayerCallerLocalNameMap = new Map<string, string>();\n\n programPath.traverse({\n ImportDeclaration: (importDeclarationPath) => {\n for (const importSpecifier of importDeclarationPath.node\n .specifiers) {\n if (!babelTypes.isImportSpecifier(importSpecifier)) continue;\n\n const importedName = babelTypes.isIdentifier(\n importSpecifier.imported\n )\n ? importSpecifier.imported.name\n : (importSpecifier.imported as BabelTypes.StringLiteral)\n .value;\n\n if (\n INTLAYER_CALLER_NAMES.includes(\n importedName as IntlayerCallerName\n )\n ) {\n intlayerCallerLocalNameMap.set(\n importSpecifier.local.name,\n importedName\n );\n }\n }\n },\n });\n\n if (intlayerCallerLocalNameMap.size === 0) return;\n\n // Visit all useIntlayer / getIntlayer call-sites and rename field accesses\n programPath.traverse({\n CallExpression: (callExpressionPath) => {\n const calleeNode = callExpressionPath.node.callee;\n let localCallerName: string | undefined;\n\n if (babelTypes.isIdentifier(calleeNode)) {\n localCallerName = calleeNode.name;\n } else if (\n babelTypes.isMemberExpression(calleeNode) &&\n babelTypes.isIdentifier(calleeNode.property)\n ) {\n localCallerName = calleeNode.property.name;\n }\n\n if (\n !localCallerName ||\n !intlayerCallerLocalNameMap.has(localCallerName)\n )\n return;\n\n const callArguments = callExpressionPath.node.arguments;\n if (callArguments.length === 0) return;\n\n const firstArgument = callArguments[0];\n let dictionaryKey: string | undefined;\n\n if (babelTypes.isStringLiteral(firstArgument)) {\n dictionaryKey = firstArgument.value;\n } else if (\n babelTypes.isTemplateLiteral(firstArgument) &&\n firstArgument.expressions.length === 0 &&\n firstArgument.quasis.length === 1 &&\n firstArgument.quasis[0]\n ) {\n dictionaryKey =\n firstArgument.quasis[0].value.cooked ??\n firstArgument.quasis[0].value.raw;\n }\n\n if (!dictionaryKey) return;\n\n const fieldRenameMap =\n pruneContext.dictionaryKeyToFieldRenameMap.get(dictionaryKey);\n if (!fieldRenameMap || fieldRenameMap.size === 0) return;\n\n const parentNode = callExpressionPath.parent;\n\n // ── Case 1: const { fieldA, fieldB } = useIntlayer('key') ────────\n if (\n babelTypes.isVariableDeclarator(parentNode) &&\n babelTypes.isObjectPattern(parentNode.id)\n ) {\n for (const property of parentNode.id.properties) {\n if (!babelTypes.isObjectProperty(property)) continue;\n\n const keyName = babelTypes.isIdentifier(property.key)\n ? property.key.name\n : babelTypes.isStringLiteral(property.key)\n ? property.key.value\n : null;\n if (!keyName) continue;\n\n const renameEntry = fieldRenameMap.get(keyName);\n if (!renameEntry) continue;\n\n // { fieldA } → { shortA: fieldA }\n // { fieldA: localVar } → { shortA: localVar }\n if (property.shorthand) {\n property.shorthand = false;\n property.key = babelTypes.identifier(renameEntry.shortName);\n } else {\n property.key = babelTypes.identifier(renameEntry.shortName);\n }\n\n // Walk nested member accesses and secondary destructurings\n // on the local variable.\n if (\n renameEntry.children.size > 0 &&\n babelTypes.isIdentifier(property.value)\n ) {\n const localVarBinding = callExpressionPath.scope.getBinding(\n (property.value as BabelTypes.Identifier).name\n );\n if (localVarBinding) {\n for (const refPath of localVarBinding.referencePaths) {\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n refPath,\n renameEntry.children\n );\n walkObjectDestructuring(\n babelTypes,\n finalPath,\n finalRenameMap\n );\n }\n }\n }\n }\n return;\n }\n\n // ── Case 2: useIntlayer('key').fieldA.nested ─────────────────────\n if (\n (babelTypes.isMemberExpression(parentNode) ||\n babelTypes.isOptionalMemberExpression(parentNode)) &&\n (parentNode as BabelTypes.MemberExpression).object ===\n callExpressionPath.node\n ) {\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n callExpressionPath,\n fieldRenameMap\n );\n walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);\n return;\n }\n\n // ── Case 3: const result = useIntlayer('key'); result.fieldA ─────\n if (\n babelTypes.isVariableDeclarator(parentNode) &&\n babelTypes.isIdentifier(parentNode.id)\n ) {\n const variableName = parentNode.id.name;\n const variableBinding =\n callExpressionPath.scope.getBinding(variableName);\n if (!variableBinding) return;\n\n for (const variableReferencePath of variableBinding.referencePaths) {\n // Direct access: result.fieldA or const { fieldA } = result\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n variableReferencePath,\n fieldRenameMap\n );\n walkObjectDestructuring(\n babelTypes,\n finalPath,\n finalRenameMap\n );\n\n // Signal accessor: result().fieldA or const { fieldA } = result()\n // walkRenameChain stops at a CallExpression parent, so we need to\n // start a new walk from the call-expression node itself.\n const refParent = variableReferencePath.parent;\n if (\n (babelTypes.isCallExpression(refParent) ||\n babelTypes.isOptionalCallExpression(refParent)) &&\n (refParent as BabelTypes.CallExpression).callee ===\n variableReferencePath.node\n ) {\n const callPath = variableReferencePath.parentPath;\n if (callPath) {\n const {\n finalPath: signalFinalPath,\n finalRenameMap: signalFinalRenameMap,\n } = walkRenameChain(babelTypes, callPath, fieldRenameMap);\n walkObjectDestructuring(\n babelTypes,\n signalFinalPath,\n signalFinalRenameMap\n );\n }\n }\n }\n }\n },\n });\n },\n },\n },\n });\n"],"mappings":";;;;;;;;;AAgBA,MAAM,+BAA+B,IAAI,IAAI,CAAC,WAAW,CAAC;;AAG1D,MAAM,sBAAsB;;;;;AAM5B,MAAa,0BAA0B,UAA0B;CAC/D,MAAM,YAAY,QAAQ;CAC1B,MAAM,WAAW,KAAK,MAAM,QAAQ,GAA2B;AAE/D,QAAO,aAAa,KAAK,oBAAoB,aACzC,oBAAoB,aACpB,uBAAuB,WAAW,EAAE,GAAG,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BjE,MAAa,mCACX,iBACoB;AACpB,KACE,CAAC,gBACD,OAAO,iBAAiB,YACxB,MAAM,QAAQ,aAAa,CAE3B,wBAAO,IAAI,KAAK;CAGlB,MAAM,SAAS;AAGf,KAAI,OAAO,OAAO,aAAa,UAAU;AAEvC,MACE,OAAO,aAAa,iBACpB,OAAO,eACP,OAAO,OAAO,gBAAgB,YAC9B,CAAC,MAAM,QAAQ,OAAO,YAAY,EAClC;GACA,MA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QAAI,CAAC,gBAAiB;AAEtB,SAAK,MAAM,yBAAyB,gBAAgB,gBAAgB;KAElE,MAAM,EAAE,WAAW,mBAAmB,gBACpC,YACA,uBACA,eACD;AACD,6BACE,YACA,WACA,eACD;KAKD,MAAM,YAAY,sBAAsB;AACxC,UACG,WAAW,iBAAiB,UAAU,IACrC,WAAW,yBAAyB,UAAU,KAC/C,UAAwC,WACvC,sBAAsB,MACxB;MACA,MAAM,WAAW,sBAAsB;AACvC,UAAI,UAAU;OACZ,MAAM,EACJ,WAAW,iBACX,gBAAgB,yBACd,gBAAgB,YAAY,UAAU,eAAe;AACzD,+BACE,YACA,iBACA,qBACD;;;;;KAMZ,CAAC;IAEL,EACF;CACF"}
1
+ {"version":3,"file":"babel-plugin-intlayer-field-rename.cjs","names":["INTLAYER_CALLER_NAMES"],"sources":["../../src/babel-plugin-intlayer-field-rename.ts"],"sourcesContent":["import type { NodePath, PluginObject } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport {\n INTLAYER_CALLER_NAMES,\n type IntlayerCallerName,\n type NestedRenameMap,\n type PruneContext,\n} from './babel-plugin-intlayer-usage-analyzer';\n\n// ── Field-name helpers ────────────────────────────────────────────────────────\n\n/**\n * Intlayer internal property names that must never be used as short-name\n * targets. These appear inside content-node values (e.g. `{ nodeType:\n * \"translation\", … }`) and are read by the intlayer runtime.\n */\nconst RESERVED_CONTENT_FIELD_NAMES = new Set(['nodeType']);\n\n/** Alphabet used to derive short field aliases (`a`, `b`, …, `aa`, `ab`, …). */\nconst SHORT_NAME_ALPHABET = 'abcdefghijklmnopqrstuvwxyz';\n\n/**\n * Converts a zero-based index to a short alphabetic identifier.\n * 0 → 'a', 1 → 'b', …, 25 → 'z', 26 → 'aa', 27 → 'ab', …\n */\nexport const generateShortFieldName = (index: number): string => {\n const remainder = index % SHORT_NAME_ALPHABET.length;\n const quotient = Math.floor(index / SHORT_NAME_ALPHABET.length);\n\n return quotient === 0 && SHORT_NAME_ALPHABET[remainder]\n ? SHORT_NAME_ALPHABET[remainder]\n : generateShortFieldName(quotient - 1) + SHORT_NAME_ALPHABET[remainder];\n};\n\n/**\n * Recursively builds a `NestedRenameMap` from a compiled dictionary content\n * value by traversing the intlayer node structure.\n *\n * Rules:\n * - If the value has `nodeType: 'translation'`, user-defined fields live\n * inside `translation[locale]`. Recurse into the first locale's value.\n * - All other intlayer runtime nodes (enumeration, condition, gender, …) are\n * treated as leaves — their internal keys must never be renamed.\n * - Arrays produce an empty children map. Array elements are not traversed\n * because consumers may access them via `.map()` / `.filter()` callbacks,\n * which the source-code rename walk cannot enter. Renaming element fields\n * in the JSON without the matching source-code rename would produce\n * mismatched key names and runtime crashes.\n * The `[0]` pass-through in `walkRenameChain` is preserved so that direct\n * indexed access (`field[0].sub`) silently terminates at the empty children\n * map without breaking anything.\n * - Plain objects are user-defined records: ALL non-reserved keys are renamed\n * with short alphabetic aliases (a, b, c, …) and each value is recursed into.\n * - Primitives produce an empty map (no further renaming).\n *\n * The rename map is built from ALL user-defined fields (not just consumed ones).\n * Both the JSON rename and the source-code rename use the same map, so the\n * short names are always consistent regardless of which fields are pruned.\n *\n * @param contentValue - The dictionary content value to analyse.\n */\nexport const buildNestedRenameMapFromContent = (\n contentValue: unknown\n): NestedRenameMap => {\n if (\n !contentValue ||\n typeof contentValue !== 'object' ||\n Array.isArray(contentValue)\n ) {\n return new Map();\n }\n\n const record = contentValue as Record<string, unknown>;\n\n // Any object with `nodeType: string` is an intlayer runtime node.\n if (typeof record.nodeType === 'string') {\n // Translation node: user-defined fields live inside translation[locale].\n if (\n record.nodeType === 'translation' &&\n record.translation &&\n typeof record.translation === 'object' &&\n !Array.isArray(record.translation)\n ) {\n const firstLocaleValue = Object.values(\n record.translation as Record<string, unknown>\n )[0];\n return buildNestedRenameMapFromContent(firstLocaleValue);\n }\n\n // Enumeration node: user-defined keys live inside enumeration.\n if (\n record.nodeType === 'enumeration' &&\n record.enumeration &&\n typeof record.enumeration === 'object' &&\n !Array.isArray(record.enumeration)\n ) {\n const values = Object.values(\n record.enumeration as Record<string, unknown>\n );\n if (values.length > 0) {\n return buildNestedRenameMapFromContent(values[0]);\n }\n }\n\n // All other intlayer nodes (pluralization, conditions, etc.) resolve to a\n // single value at runtime – return an empty map so they are treated\n // as leaves unless they contain nested user records.\n return new Map();\n }\n\n // Exclude React elements from being treated as user-defined records.\n // JSX elements in the compiled JSON have a $$typeof property (usually Symbol(react.element)).\n if (\n record.$$typeof ||\n (record.type && record.props && Object.hasOwn(record, 'ref'))\n ) {\n return new Map();\n }\n\n // User-defined record: rename ALL non-reserved keys with stable alphabetic\n // aliases sorted alphabetically so the mapping is deterministic.\n const sortedKeys = Object.keys(record)\n .filter((key) => !RESERVED_CONTENT_FIELD_NAMES.has(key))\n .sort();\n\n const renameMap: NestedRenameMap = new Map();\n\n for (let i = 0; i < sortedKeys.length; i++) {\n const key = sortedKeys[i];\n\n if (!key) continue;\n\n const children = buildNestedRenameMapFromContent(record[key]);\n\n renameMap.set(key, { shortName: generateShortFieldName(i), children });\n }\n\n return renameMap;\n};\n\n// ── Field-rename Babel plugin ─────────────────────────────────────────────────\n\n/**\n * Walks a MemberExpression chain starting from `startPath`, renaming each\n * property found in `currentRenameMap` at the corresponding nesting level.\n *\n * Numeric computed accesses (array indices such as `[0]`, `[1]`) are treated\n * as transparent pass-throughs: the rename map is kept unchanged and the walk\n * continues past the index. This means `content.field[0].sub` is handled\n * correctly — `field` and `sub` are both renamed while `[0]` is left intact.\n */\nconst walkRenameChain = (\n babelTypes: typeof BabelTypes,\n startPath: NodePath<BabelTypes.Node>,\n currentRenameMap: NestedRenameMap\n): {\n finalPath: NodePath<BabelTypes.Node>;\n finalRenameMap: NestedRenameMap;\n} => {\n let refPath: NodePath<BabelTypes.Node> = startPath;\n let renameMap = currentRenameMap;\n\n while (true) {\n const parentPath = refPath.parentPath;\n if (!parentPath) break;\n\n const parentNode = parentPath.node;\n\n if (\n (!babelTypes.isMemberExpression(parentNode) &&\n !babelTypes.isOptionalMemberExpression(parentNode)) ||\n (parentNode as BabelTypes.MemberExpression).object !== refPath.node\n ) {\n break;\n }\n\n const memberNode = parentNode as BabelTypes.MemberExpression;\n\n // Numeric index access ([0], [1], …): advance past the array accessor\n // without touching the rename map. The next iteration will attempt to\n // rename the property that follows the index.\n if (\n memberNode.computed &&\n babelTypes.isNumericLiteral(memberNode.property)\n ) {\n refPath = parentPath;\n continue;\n }\n\n // Nothing left to rename at this level — stop.\n if (renameMap.size === 0) break;\n\n let fieldName: string | undefined;\n\n if (!memberNode.computed && babelTypes.isIdentifier(memberNode.property)) {\n fieldName = memberNode.property.name;\n } else if (\n memberNode.computed &&\n babelTypes.isStringLiteral(memberNode.property)\n ) {\n fieldName = memberNode.property.value;\n } else {\n break; // dynamic computed key – stop\n }\n\n const renameEntry = renameMap.get(fieldName);\n if (!renameEntry) break; // not in map – stop\n\n // Apply the rename\n if (!memberNode.computed && babelTypes.isIdentifier(memberNode.property)) {\n memberNode.property.name = renameEntry.shortName;\n } else if (\n memberNode.computed &&\n babelTypes.isStringLiteral(memberNode.property)\n ) {\n memberNode.property.value = renameEntry.shortName;\n }\n\n refPath = parentPath;\n renameMap = renameEntry.children;\n }\n\n return { finalPath: refPath, finalRenameMap: renameMap };\n};\n\n/**\n * Walks an object-destructuring assignment whose right-hand side is `refPath`,\n * renaming each destructured key that is found in `renameMap`.\n *\n * Handles the \"secondary destructuring\" pattern that `walkRenameChain` cannot\n * reach because the reference is not a MemberExpression:\n *\n * const { webhooksSection } = useIntlayer('build-settings');\n * const { modal, validationErrors } = webhooksSection;\n * → const { a: modal, b: validationErrors } = webhooksSection;\n *\n * After renaming each key the function recursively walks references to the\n * newly-bound local variable, calling both `walkRenameChain` (for subsequent\n * member-access chains like `validationErrors.invalidUrl`) and itself (for\n * further levels of secondary destructuring).\n */\nconst walkObjectDestructuring = (\n babelTypes: typeof BabelTypes,\n refPath: NodePath<BabelTypes.Node>,\n renameMap: NestedRenameMap\n): void => {\n if (renameMap.size === 0) return;\n\n const parentNode = refPath.parent;\n\n // Only handle: const { a, b } = refVar\n if (\n !babelTypes.isVariableDeclarator(parentNode) ||\n !babelTypes.isObjectPattern(parentNode.id) ||\n parentNode.init !== refPath.node\n ) {\n return;\n }\n\n for (const property of (parentNode.id as BabelTypes.ObjectPattern)\n .properties) {\n if (!babelTypes.isObjectProperty(property)) continue;\n\n const keyName = babelTypes.isIdentifier(property.key)\n ? property.key.name\n : babelTypes.isStringLiteral(property.key)\n ? property.key.value\n : null;\n if (!keyName) continue;\n\n const renameEntry = renameMap.get(keyName);\n if (!renameEntry) continue;\n\n // { fieldA } → { shortA: fieldA }\n // { fieldA: localVar } → { shortA: localVar }\n if (property.shorthand) {\n property.shorthand = false;\n }\n property.key = babelTypes.identifier(renameEntry.shortName);\n\n // Recursively walk references to the local variable bound by this key.\n if (\n renameEntry.children.size > 0 &&\n babelTypes.isIdentifier(property.value)\n ) {\n const localVarName = (property.value as BabelTypes.Identifier).name;\n const localVarBinding = refPath.scope.getBinding(localVarName);\n if (localVarBinding) {\n for (const nestedRefPath of localVarBinding.referencePaths) {\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n nestedRefPath,\n renameEntry.children\n );\n walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);\n }\n }\n }\n }\n};\n\n/**\n * Collects the local aliases under which `useIntlayer` / `getIntlayer` are\n * imported in the given program (e.g. `import { useIntlayer as useI } …`\n * yields `useI` → `useIntlayer`).\n *\n * Import declarations can only appear at the top level of a module, so the\n * program body is scanned directly instead of traversing the whole AST.\n */\nconst collectIntlayerCallerLocalNames = (\n babelTypes: typeof BabelTypes,\n programNode: BabelTypes.Program\n): Map<string, string> => {\n const intlayerCallerLocalNameMap = new Map<string, string>();\n\n for (const statement of programNode.body) {\n if (!babelTypes.isImportDeclaration(statement)) continue;\n\n for (const importSpecifier of statement.specifiers) {\n if (!babelTypes.isImportSpecifier(importSpecifier)) continue;\n\n const importedName = babelTypes.isIdentifier(importSpecifier.imported)\n ? importSpecifier.imported.name\n : importSpecifier.imported.value;\n\n if (INTLAYER_CALLER_NAMES.includes(importedName as IntlayerCallerName)) {\n intlayerCallerLocalNameMap.set(\n importSpecifier.local.name,\n importedName\n );\n }\n }\n }\n\n return intlayerCallerLocalNameMap;\n};\n\n/**\n * Rewrites dictionary content field accesses in the given program to the\n * short aliases defined in `pruneContext.dictionaryKeyToFieldRenameMap`.\n *\n * Handled patterns (mirrors the usage analyser):\n *\n * const { fieldA, fieldB } = useIntlayer('key')\n * → const { shortA: fieldA, shortB: fieldB } = useIntlayer('key')\n *\n * useIntlayer('key').fieldA\n * → useIntlayer('key').shortA\n *\n * const result = useIntlayer('key'); result.fieldA\n * → const result = useIntlayer('key'); result.shortA\n *\n * const { fieldA } = useIntlayer('key');\n * const { nested } = fieldA; // secondary destructuring\n * → const { shortA: fieldA } = useIntlayer('key');\n * const { shortN: nested } = fieldA;\n *\n * Exposed as a standalone function so that both\n * {@link makeFieldRenameBabelPlugin} and `intlayerMinifyBabelPlugin` can\n * invoke it from their own `Program.exit` visitors.\n */\nexport const renameIntlayerFieldAccesses = (\n babelTypes: typeof BabelTypes,\n programPath: NodePath<BabelTypes.Program>,\n pruneContext: PruneContext\n): void => {\n if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return;\n\n const intlayerCallerLocalNameMap = collectIntlayerCallerLocalNames(\n babelTypes,\n programPath.node\n );\n if (intlayerCallerLocalNameMap.size === 0) return;\n\n // Visit all useIntlayer / getIntlayer call-sites and rename field accesses\n programPath.traverse({\n CallExpression: (callExpressionPath) => {\n const calleeNode = callExpressionPath.node.callee;\n let localCallerName: string | undefined;\n\n if (babelTypes.isIdentifier(calleeNode)) {\n localCallerName = calleeNode.name;\n } else if (\n babelTypes.isMemberExpression(calleeNode) &&\n babelTypes.isIdentifier(calleeNode.property)\n ) {\n localCallerName = calleeNode.property.name;\n }\n\n if (!localCallerName || !intlayerCallerLocalNameMap.has(localCallerName))\n return;\n\n const callArguments = callExpressionPath.node.arguments;\n if (callArguments.length === 0) return;\n\n const firstArgument = callArguments[0];\n let dictionaryKey: string | undefined;\n\n if (babelTypes.isStringLiteral(firstArgument)) {\n dictionaryKey = firstArgument.value;\n } else if (\n babelTypes.isTemplateLiteral(firstArgument) &&\n firstArgument.expressions.length === 0 &&\n firstArgument.quasis.length === 1 &&\n firstArgument.quasis[0]\n ) {\n dictionaryKey =\n firstArgument.quasis[0].value.cooked ??\n firstArgument.quasis[0].value.raw;\n }\n\n if (!dictionaryKey) return;\n\n const fieldRenameMap =\n pruneContext.dictionaryKeyToFieldRenameMap.get(dictionaryKey);\n if (!fieldRenameMap || fieldRenameMap.size === 0) return;\n\n const parentNode = callExpressionPath.parent;\n\n // ── Case 1: const { fieldA, fieldB } = useIntlayer('key') ────────\n if (\n babelTypes.isVariableDeclarator(parentNode) &&\n babelTypes.isObjectPattern(parentNode.id)\n ) {\n walkObjectDestructuring(babelTypes, callExpressionPath, fieldRenameMap);\n return;\n }\n\n // ── Case 2: useIntlayer('key').fieldA.nested ─────────────────────\n if (\n (babelTypes.isMemberExpression(parentNode) ||\n babelTypes.isOptionalMemberExpression(parentNode)) &&\n (parentNode as BabelTypes.MemberExpression).object ===\n callExpressionPath.node\n ) {\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n callExpressionPath,\n fieldRenameMap\n );\n walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);\n return;\n }\n\n // ── Case 3: const result = useIntlayer('key'); result.fieldA ─────\n if (\n babelTypes.isVariableDeclarator(parentNode) &&\n babelTypes.isIdentifier(parentNode.id)\n ) {\n const variableBinding = callExpressionPath.scope.getBinding(\n parentNode.id.name\n );\n if (!variableBinding) return;\n\n for (const variableReferencePath of variableBinding.referencePaths) {\n // Direct access: result.fieldA or const { fieldA } = result\n const { finalPath, finalRenameMap } = walkRenameChain(\n babelTypes,\n variableReferencePath,\n fieldRenameMap\n );\n walkObjectDestructuring(babelTypes, finalPath, finalRenameMap);\n\n // Signal accessor: result().fieldA or const { fieldA } = result()\n // walkRenameChain stops at a CallExpression parent, so we need to\n // start a new walk from the call-expression node itself.\n const refParent = variableReferencePath.parent;\n if (\n (babelTypes.isCallExpression(refParent) ||\n babelTypes.isOptionalCallExpression(refParent)) &&\n (refParent as BabelTypes.CallExpression).callee ===\n variableReferencePath.node\n ) {\n const callPath = variableReferencePath.parentPath;\n if (callPath) {\n const {\n finalPath: signalFinalPath,\n finalRenameMap: signalFinalRenameMap,\n } = walkRenameChain(babelTypes, callPath, fieldRenameMap);\n walkObjectDestructuring(\n babelTypes,\n signalFinalPath,\n signalFinalRenameMap\n );\n }\n }\n }\n }\n },\n });\n};\n\n/**\n * Creates a Babel plugin that rewrites dictionary content field accesses in\n * source files to their short aliases via\n * {@link renameIntlayerFieldAccesses}.\n *\n * This plugin must run in a separate `transformAsync` pass **before**\n * `intlayerOptimizeBabelPlugin`, because the latter replaces `useIntlayer`\n * with `useDictionary`, erasing the dictionary-key information needed here.\n */\nexport const makeFieldRenameBabelPlugin =\n (pruneContext: PruneContext) =>\n ({ types: babelTypes }: { types: typeof BabelTypes }): PluginObject => ({\n name: 'intlayer-field-rename',\n visitor: {\n Program: {\n exit: (programPath) => {\n renameIntlayerFieldAccesses(babelTypes, programPath, pruneContext);\n },\n },\n },\n });\n"],"mappings":";;;;;;;;;AAgBA,MAAM,+BAA+B,IAAI,IAAI,CAAC,WAAW,CAAC;;AAG1D,MAAM,sBAAsB;;;;;AAM5B,MAAa,0BAA0B,UAA0B;CAC/D,MAAM,YAAY,QAAQ;CAC1B,MAAM,WAAW,KAAK,MAAM,QAAQ,GAA2B;AAE/D,QAAO,aAAa,KAAK,oBAAoB,aACzC,oBAAoB,aACpB,uBAAuB,WAAW,EAAE,GAAG,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BjE,MAAa,mCACX,iBACoB;AACpB,KACE,CAAC,gBACD,OAAO,iBAAiB,YACxB,MAAM,QAAQ,aAAa,CAE3B,wBAAO,IAAI,KAAK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;;;;;AAYJ,MAAa,8BACV,kBACA,EAAE,OAAO,kBAA8D;CACtE,MAAM;CACN,SAAS,EACP,SAAS,EACP,OAAO,gBAAgB;AACrB,8BAA4B,YAAY,aAAa,aAAa;IAErE,EACF;CACF"}
@@ -49,34 +49,17 @@ const require_babel_plugin_intlayer_purge = require('./babel-plugin-intlayer-pur
49
49
  * `useDictionary`, erasing the dictionary-key information needed to look up
50
50
  * the rename map.
51
51
  */
52
- const intlayerMinifyBabelPlugin = (babel) => {
53
- /**
54
- * The field-rename `Program.exit` handler extracted from
55
- * {@link makeFieldRenameBabelPlugin}. Resolved once per plugin-instance
56
- * (i.e. once per babel.config.js registration, not once per file).
57
- */
58
- let fieldRenameExitVisitor = null;
59
- /** The `baseDir` for which the visitor was last resolved. */
60
- let resolvedBaseDir = null;
61
- return {
62
- name: "intlayer-minify",
63
- pre() {
64
- const { baseDir, minify, optimize, editorEnabled } = this.opts;
65
- if (!minify || optimize === false || editorEnabled) return;
66
- if (resolvedBaseDir === baseDir && fieldRenameExitVisitor !== null) return;
67
- const pruneContext = require_babel_plugin_intlayer_purge.getSharedPruneContext(baseDir);
68
- if (!pruneContext || pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return;
69
- resolvedBaseDir = baseDir;
70
- const programVisitor = require_babel_plugin_intlayer_field_rename.makeFieldRenameBabelPlugin(pruneContext)(babel).visitor.Program;
71
- if (programVisitor && typeof programVisitor === "object" && "exit" in programVisitor && typeof programVisitor.exit === "function") fieldRenameExitVisitor = programVisitor.exit;
72
- },
73
- visitor: { Program: { exit(programPath, state) {
74
- if (!fieldRenameExitVisitor) return;
75
- if (!require_transformers.INTLAYER_USAGE_REGEX.test(state.file.code)) return;
76
- fieldRenameExitVisitor(programPath);
77
- } } }
78
- };
79
- };
52
+ const intlayerMinifyBabelPlugin = (babel) => ({
53
+ name: "intlayer-minify",
54
+ visitor: { Program: { exit(programPath, state) {
55
+ const { baseDir, minify, optimize, editorEnabled } = state.opts;
56
+ if (!minify || optimize === false || editorEnabled) return;
57
+ if (!require_transformers.INTLAYER_USAGE_REGEX.test(state.file.code)) return;
58
+ const pruneContext = require_babel_plugin_intlayer_purge.getSharedPruneContext(baseDir);
59
+ if (!pruneContext) return;
60
+ require_babel_plugin_intlayer_field_rename.renameIntlayerFieldAccesses(babel.types, programPath, pruneContext);
61
+ } } }
62
+ });
80
63
 
81
64
  //#endregion
82
65
  exports.intlayerMinifyBabelPlugin = intlayerMinifyBabelPlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-minify.cjs","names":["getSharedPruneContext","makeFieldRenameBabelPlugin","INTLAYER_USAGE_REGEX"],"sources":["../../src/babel-plugin-intlayer-minify.ts"],"sourcesContent":["import type { NodePath, PluginObject, PluginPass } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport { makeFieldRenameBabelPlugin } from './babel-plugin-intlayer-field-rename';\nimport { getSharedPruneContext } from './babel-plugin-intlayer-purge';\nimport type { PruneContext } from './babel-plugin-intlayer-usage-analyzer';\nimport { INTLAYER_USAGE_REGEX } from './transformers';\n\n// ── Plugin options ────────────────────────────────────────────────────────────\n\n/**\n * Pre-resolved options accepted by {@link intlayerMinifyBabelPlugin}.\n *\n * All values are resolved at babel.config.js load time (via\n * {@link getMinifyPluginOptions}) so the plugin does not read the intlayer\n * configuration file on every file transform.\n */\nexport type MinifyPluginOptions = {\n /**\n * Absolute path to the project root. Used to look up the shared\n * {@link PruneContext} built by {@link intlayerPurgeBabelPlugin}.\n */\n baseDir: string;\n\n /**\n * When `true`, rewrite source-file property accesses to use the short\n * alphabetic aliases assigned during the minification pass\n * (e.g. `content.title` → `content.a`). Mirrors `build.minify`.\n */\n minify: boolean;\n\n /**\n * Build optimisation toggle. When explicitly `false`, the plugin is a\n * no-op. Mirrors `build.optimize`.\n */\n optimize: boolean | undefined;\n\n /**\n * When `true` the plugin is a no-op. Mirrors `editor.enabled`.\n */\n editorEnabled: boolean;\n};\n\n// ── Babel plugin ──────────────────────────────────────────────────────────────\n\n/**\n * Babel plugin that rewrites component source files to use the short\n * alphabetic aliases assigned to dictionary content fields during the\n * minification pass (e.g. `content.title` → `content.a`).\n *\n * This plugin relies on the field-rename map built by\n * {@link intlayerPurgeBabelPlugin} during its `pre()` hook. Both plugins\n * share the same module-level {@link PruneContext} via\n * {@link getSharedPruneContext}, so **`intlayerPurgeBabelPlugin` must be\n * listed before this plugin** in `babel.config.js` so that its `pre()` runs\n * first and the shared context is populated before this plugin's\n * `Program.exit` visitor fires.\n *\n * All option values must be pre-resolved via {@link getMinifyPluginOptions}.\n *\n * @example\n * ```js\n * // babel.config.js\n * const {\n * intlayerPurgeBabelPlugin,\n * intlayerMinifyBabelPlugin,\n * intlayerOptimizeBabelPlugin,\n * getPurgePluginOptions,\n * getMinifyPluginOptions,\n * getOptimizePluginOptions,\n * } = require(\"@intlayer/babel\");\n *\n * module.exports = {\n * presets: [\"next/babel\"],\n * plugins: [\n * [intlayerPurgeBabelPlugin, getPurgePluginOptions()],\n * [intlayerMinifyBabelPlugin, getMinifyPluginOptions()],\n * [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],\n * ],\n * };\n * ```\n *\n * @remarks\n * - This plugin is a no-op when `minify` is `false`, `optimize` is `false`,\n * or `editorEnabled` is `true`.\n * - Source-code renames must run **before** {@link intlayerOptimizeBabelPlugin}\n * because the optimize pass replaces `useIntlayer` calls with\n * `useDictionary`, erasing the dictionary-key information needed to look up\n * the rename map.\n */\nexport const intlayerMinifyBabelPlugin = (babel: {\n types: typeof BabelTypes;\n}): PluginObject => {\n /**\n * The field-rename `Program.exit` handler extracted from\n * {@link makeFieldRenameBabelPlugin}. Resolved once per plugin-instance\n * (i.e. once per babel.config.js registration, not once per file).\n */\n let fieldRenameExitVisitor:\n | ((programPath: NodePath<BabelTypes.Program>) => void)\n | null = null;\n\n /** The `baseDir` for which the visitor was last resolved. */\n let resolvedBaseDir: string | null = null;\n\n return {\n name: 'intlayer-minify',\n\n pre(this: PluginPass & { opts: MinifyPluginOptions }) {\n const { baseDir, minify, optimize, editorEnabled } = this.opts;\n\n if (!minify || optimize === false || editorEnabled) return;\n\n // Re-resolve when the baseDir changes (edge case in monorepos where the\n // same process handles multiple workspaces with different configs).\n if (resolvedBaseDir === baseDir && fieldRenameExitVisitor !== null)\n return;\n\n const pruneContext: PruneContext | null = getSharedPruneContext(baseDir);\n if (\n !pruneContext ||\n pruneContext.dictionaryKeyToFieldRenameMap.size === 0\n )\n return;\n\n resolvedBaseDir = baseDir;\n\n // Instantiate makeFieldRenameBabelPlugin and extract its Program.exit\n // handler so we can invoke it from our own visitor.\n const fieldRenamePlugin = makeFieldRenameBabelPlugin(pruneContext)(babel);\n const programVisitor = fieldRenamePlugin.visitor.Program;\n\n if (\n programVisitor &&\n typeof programVisitor === 'object' &&\n 'exit' in programVisitor &&\n typeof (\n programVisitor as {\n exit: (path: NodePath<BabelTypes.Program>) => void;\n }\n ).exit === 'function'\n ) {\n fieldRenameExitVisitor = (\n programVisitor as {\n exit: (path: NodePath<BabelTypes.Program>) => void;\n }\n ).exit;\n }\n },\n\n visitor: {\n Program: {\n exit(\n programPath: NodePath<BabelTypes.Program>,\n state: PluginPass\n ): void {\n if (!fieldRenameExitVisitor) return;\n if (!INTLAYER_USAGE_REGEX.test(state.file.code)) return;\n\n fieldRenameExitVisitor(programPath);\n },\n },\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,MAAa,6BAA6B,UAEtB;;;;;;CAMlB,IAAI,yBAEO;;CAGX,IAAI,kBAAiC;AAErC,QAAO;EACL,MAAM;EAEN,MAAsD;GACpD,MAAM,EAAE,SAAS,QAAQ,UAAU,kBAAkB,KAAK;AAE1D,OAAI,CAAC,UAAU,aAAa,SAAS,cAAe;AAIpD,OAAI,oBAAoB,WAAW,2BAA2B,KAC5D;GAEF,MAAM,eAAoCA,0DAAsB,QAAQ;AACxE,OACE,CAAC,gBACD,aAAa,8BAA8B,SAAS,EAEpD;AAEF,qBAAkB;GAKlB,MAAM,iBADoBC,sEAA2B,aAAa,CAAC,MAC3B,CAAC,QAAQ;AAEjD,OACE,kBACA,OAAO,mBAAmB,YAC1B,UAAU,kBACV,OACE,eAGA,SAAS,WAEX,0BACE,eAGA;;EAIN,SAAS,EACP,SAAS,EACP,KACE,aACA,OACM;AACN,OAAI,CAAC,uBAAwB;AAC7B,OAAI,CAACC,0CAAqB,KAAK,MAAM,KAAK,KAAK,CAAE;AAEjD,0BAAuB,YAAY;KAEtC,EACF;EACF"}
1
+ {"version":3,"file":"babel-plugin-intlayer-minify.cjs","names":["INTLAYER_USAGE_REGEX","getSharedPruneContext"],"sources":["../../src/babel-plugin-intlayer-minify.ts"],"sourcesContent":["import type { NodePath, PluginObject, PluginPass } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport { renameIntlayerFieldAccesses } from './babel-plugin-intlayer-field-rename';\nimport { getSharedPruneContext } from './babel-plugin-intlayer-purge';\nimport type { PruneContext } from './babel-plugin-intlayer-usage-analyzer';\nimport { INTLAYER_USAGE_REGEX } from './transformers';\n\n// ── Plugin options ────────────────────────────────────────────────────────────\n\n/**\n * Pre-resolved options accepted by {@link intlayerMinifyBabelPlugin}.\n *\n * All values are resolved at babel.config.js load time (via\n * {@link getMinifyPluginOptions}) so the plugin does not read the intlayer\n * configuration file on every file transform.\n */\nexport type MinifyPluginOptions = {\n /**\n * Absolute path to the project root. Used to look up the shared\n * {@link PruneContext} built by {@link intlayerPurgeBabelPlugin}.\n */\n baseDir: string;\n\n /**\n * When `true`, rewrite source-file property accesses to use the short\n * alphabetic aliases assigned during the minification pass\n * (e.g. `content.title` → `content.a`). Mirrors `build.minify`.\n */\n minify: boolean;\n\n /**\n * Build optimisation toggle. When explicitly `false`, the plugin is a\n * no-op. Mirrors `build.optimize`.\n */\n optimize: boolean | undefined;\n\n /**\n * When `true` the plugin is a no-op. Mirrors `editor.enabled`.\n */\n editorEnabled: boolean;\n};\n\n// ── Babel plugin ──────────────────────────────────────────────────────────────\n\n/**\n * Babel plugin that rewrites component source files to use the short\n * alphabetic aliases assigned to dictionary content fields during the\n * minification pass (e.g. `content.title` → `content.a`).\n *\n * This plugin relies on the field-rename map built by\n * {@link intlayerPurgeBabelPlugin} during its `pre()` hook. Both plugins\n * share the same module-level {@link PruneContext} via\n * {@link getSharedPruneContext}, so **`intlayerPurgeBabelPlugin` must be\n * listed before this plugin** in `babel.config.js` so that its `pre()` runs\n * first and the shared context is populated before this plugin's\n * `Program.exit` visitor fires.\n *\n * All option values must be pre-resolved via {@link getMinifyPluginOptions}.\n *\n * @example\n * ```js\n * // babel.config.js\n * const {\n * intlayerPurgeBabelPlugin,\n * intlayerMinifyBabelPlugin,\n * intlayerOptimizeBabelPlugin,\n * getPurgePluginOptions,\n * getMinifyPluginOptions,\n * getOptimizePluginOptions,\n * } = require(\"@intlayer/babel\");\n *\n * module.exports = {\n * presets: [\"next/babel\"],\n * plugins: [\n * [intlayerPurgeBabelPlugin, getPurgePluginOptions()],\n * [intlayerMinifyBabelPlugin, getMinifyPluginOptions()],\n * [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],\n * ],\n * };\n * ```\n *\n * @remarks\n * - This plugin is a no-op when `minify` is `false`, `optimize` is `false`,\n * or `editorEnabled` is `true`.\n * - Source-code renames must run **before** {@link intlayerOptimizeBabelPlugin}\n * because the optimize pass replaces `useIntlayer` calls with\n * `useDictionary`, erasing the dictionary-key information needed to look up\n * the rename map.\n */\nexport const intlayerMinifyBabelPlugin = (babel: {\n types: typeof BabelTypes;\n}): PluginObject => ({\n name: 'intlayer-minify',\n\n visitor: {\n Program: {\n exit(programPath: NodePath<BabelTypes.Program>, state: PluginPass): void {\n const { baseDir, minify, optimize, editorEnabled } =\n state.opts as MinifyPluginOptions;\n\n if (!minify || optimize === false || editorEnabled) return;\n if (!INTLAYER_USAGE_REGEX.test(state.file.code)) return;\n\n const pruneContext: PruneContext | null =\n getSharedPruneContext(baseDir);\n if (!pruneContext) return;\n\n renameIntlayerFieldAccesses(babel.types, programPath, pruneContext);\n },\n },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,MAAa,6BAA6B,WAErB;CACnB,MAAM;CAEN,SAAS,EACP,SAAS,EACP,KAAK,aAA2C,OAAyB;EACvE,MAAM,EAAE,SAAS,QAAQ,UAAU,kBACjC,MAAM;AAER,MAAI,CAAC,UAAU,aAAa,SAAS,cAAe;AACpD,MAAI,CAACA,0CAAqB,KAAK,MAAM,KAAK,KAAK,CAAE;EAEjD,MAAM,eACJC,0DAAsB,QAAQ;AAChC,MAAI,CAAC,aAAc;AAEnB,yEAA4B,MAAM,OAAO,aAAa,aAAa;IAEtE,EACF;CACF"}
@@ -11,15 +11,12 @@ let _babel_core = require("@babel/core");
11
11
  //#region src/babel-plugin-intlayer-purge.ts
12
12
  /**
13
13
  * Cache of built {@link PruneContext} objects, keyed by the project's
14
- * `baseDir`. Each context is built exactly once per Node.js process.
14
+ * `baseDir`. Each context is built exactly once per Node.js process:
15
+ * {@link runPurgePipeline} registers the context before running so every
16
+ * subsequent transform is a no-op cache hit.
15
17
  */
16
18
  const _pruneContextCache = /* @__PURE__ */ new Map();
17
19
  /**
18
- * Tracks base directories whose full analysis + dictionary-write cycle has
19
- * already completed, to avoid repeating work across file transforms.
20
- */
21
- const _completedBaseDirs = /* @__PURE__ */ new Set();
22
- /**
23
20
  * Returns the shared {@link PruneContext} for the given base directory, or
24
21
  * `null` if {@link intlayerPurgeBabelPlugin} has not yet been initialised for
25
22
  * that directory.
@@ -30,6 +27,12 @@ const _completedBaseDirs = /* @__PURE__ */ new Set();
30
27
  const getSharedPruneContext = (baseDir) => _pruneContextCache.get(baseDir) ?? null;
31
28
  const isTranslationNode = (value) => typeof value === "object" && value !== null && value.nodeType === "translation" && typeof value.translation === "object";
32
29
  const isPlainRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
30
+ /** Returns a copy of `record` keeping only the keys listed in `usedFieldNames`. */
31
+ const filterRecordByUsedFields = (record, usedFieldNames) => {
32
+ const filteredRecord = {};
33
+ for (const [fieldName, fieldValue] of Object.entries(record)) if (usedFieldNames.has(fieldName)) filteredRecord[fieldName] = fieldValue;
34
+ return filteredRecord;
35
+ };
33
36
  /**
34
37
  * Removes unused fields from a **static** dictionary (all locales in one
35
38
  * file). Supports shape A (translation node at the root) and shape B (flat
@@ -41,15 +44,7 @@ const pruneStaticDictionaryContent = (dictionary, usedFieldNames) => {
41
44
  const firstLocaleValue = Object.values(content.translation)[0];
42
45
  if (isPlainRecord(firstLocaleValue)) {
43
46
  const prunedTranslation = {};
44
- for (const [locale, localeContent] of Object.entries(content.translation)) {
45
- if (!isPlainRecord(localeContent)) {
46
- prunedTranslation[locale] = localeContent;
47
- continue;
48
- }
49
- const prunedLocaleFields = {};
50
- for (const [fieldName, fieldValue] of Object.entries(localeContent)) if (usedFieldNames.has(fieldName)) prunedLocaleFields[fieldName] = fieldValue;
51
- prunedTranslation[locale] = prunedLocaleFields;
52
- }
47
+ for (const [locale, localeContent] of Object.entries(content.translation)) prunedTranslation[locale] = isPlainRecord(localeContent) ? filterRecordByUsedFields(localeContent, usedFieldNames) : localeContent;
53
48
  return {
54
49
  prunedDictionary: {
55
50
  ...dictionary,
@@ -62,17 +57,13 @@ const pruneStaticDictionaryContent = (dictionary, usedFieldNames) => {
62
57
  };
63
58
  }
64
59
  }
65
- if (isPlainRecord(content) && !isTranslationNode(content)) {
66
- const prunedContent = {};
67
- for (const [fieldName, fieldValue] of Object.entries(content)) if (usedFieldNames.has(fieldName)) prunedContent[fieldName] = fieldValue;
68
- return {
69
- prunedDictionary: {
70
- ...dictionary,
71
- content: prunedContent
72
- },
73
- wasRecognised: true
74
- };
75
- }
60
+ if (isPlainRecord(content) && !isTranslationNode(content)) return {
61
+ prunedDictionary: {
62
+ ...dictionary,
63
+ content: filterRecordByUsedFields(content, usedFieldNames)
64
+ },
65
+ wasRecognised: true
66
+ };
76
67
  return {
77
68
  prunedDictionary: dictionary,
78
69
  wasRecognised: false
@@ -88,12 +79,10 @@ const pruneDynamicDictionaryContent = (dictionary, usedFieldNames) => {
88
79
  prunedDictionary: dictionary,
89
80
  wasRecognised: false
90
81
  };
91
- const prunedContent = {};
92
- for (const [fieldName, fieldValue] of Object.entries(content)) if (usedFieldNames.has(fieldName)) prunedContent[fieldName] = fieldValue;
93
82
  return {
94
83
  prunedDictionary: {
95
84
  ...dictionary,
96
- content: prunedContent
85
+ content: filterRecordByUsedFields(content, usedFieldNames)
97
86
  },
98
87
  wasRecognised: true
99
88
  };
@@ -201,26 +190,25 @@ const buildRenameMapsSynchronously = (dictionariesDir, dynamicDictionariesDir, d
201
190
  if (!dictionaryContent) continue;
202
191
  const nestedRenameMap = require_babel_plugin_intlayer_field_rename.buildNestedRenameMapFromContent(dictionaryContent);
203
192
  const opaqueFieldMap = pruneContext.dictionaryKeysWithOpaqueTopLevelFields.get(dictionaryKey);
204
- if (opaqueFieldMap) {
205
- const dangerousEntries = [...opaqueFieldMap.entries()].filter(([fieldName]) => (nestedRenameMap.get(fieldName)?.children.size ?? 0) > 0);
206
- for (const [fieldName] of dangerousEntries) {
207
- const entry = nestedRenameMap.get(fieldName);
208
- if (entry) entry.children = /* @__PURE__ */ new Map();
209
- }
193
+ if (opaqueFieldMap) for (const fieldName of opaqueFieldMap.keys()) {
194
+ const renameEntry = nestedRenameMap.get(fieldName);
195
+ if (renameEntry && renameEntry.children.size > 0) renameEntry.children = /* @__PURE__ */ new Map();
210
196
  }
211
197
  if (nestedRenameMap.size > 0) pruneContext.dictionaryKeyToFieldRenameMap.set(dictionaryKey, nestedRenameMap);
212
198
  }
213
199
  };
214
- const processStaticDictionaryFile = (filePath, pruneContext, shouldPurge, shouldMinify) => {
215
- let rawJson;
216
- try {
217
- rawJson = (0, node_fs.readFileSync)(filePath, "utf-8");
218
- } catch {
219
- return;
220
- }
200
+ /**
201
+ * Reads a compiled dictionary JSON file, applies the purge and/or minify
202
+ * transformations, and writes it back in-place when something changed.
203
+ *
204
+ * `dictionaryKind` selects the prune strategy and the minified output shape:
205
+ * static dictionaries keep `{ key, content }`, dynamic per-locale
206
+ * dictionaries additionally keep `locale`.
207
+ */
208
+ const processDictionaryFile = (filePath, dictionaryKind, pruneContext, shouldPurge, shouldMinify) => {
221
209
  let parsedDict;
222
210
  try {
223
- parsedDict = JSON.parse(rawJson);
211
+ parsedDict = JSON.parse((0, node_fs.readFileSync)(filePath, "utf-8"));
224
212
  } catch {
225
213
  return;
226
214
  }
@@ -231,7 +219,7 @@ const processStaticDictionaryFile = (filePath, pruneContext, shouldPurge, should
231
219
  if (shouldPurge) {
232
220
  const fieldUsage = pruneContext.dictionaryKeyToFieldUsageMap.get(dictionaryKey);
233
221
  if (fieldUsage && fieldUsage !== "all") {
234
- const { prunedDictionary, wasRecognised } = pruneStaticDictionaryContent(parsedDict, fieldUsage);
222
+ const { prunedDictionary, wasRecognised } = (dictionaryKind === "static" ? pruneStaticDictionaryContent : pruneDynamicDictionaryContent)(parsedDict, fieldUsage);
235
223
  if (!wasRecognised) {
236
224
  pruneContext.dictionariesWithEdgeCases.add(dictionaryKey);
237
225
  return;
@@ -248,52 +236,10 @@ const processStaticDictionaryFile = (filePath, pruneContext, shouldPurge, should
248
236
  }
249
237
  }
250
238
  if (!modified) return;
251
- const outputDict = shouldMinify ? {
239
+ const outputDict = shouldMinify ? dictionaryKind === "static" ? {
252
240
  key: parsedDict.key,
253
241
  content: parsedDict.content
254
- } : parsedDict;
255
- try {
256
- (0, node_fs.writeFileSync)(filePath, JSON.stringify(outputDict), "utf-8");
257
- } catch {}
258
- };
259
- const processDynamicDictionaryFile = (filePath, pruneContext, shouldPurge, shouldMinify) => {
260
- let rawJson;
261
- try {
262
- rawJson = (0, node_fs.readFileSync)(filePath, "utf-8");
263
- } catch {
264
- return;
265
- }
266
- let parsedDict;
267
- try {
268
- parsedDict = JSON.parse(rawJson);
269
- } catch {
270
- return;
271
- }
272
- const { key: dictionaryKey } = parsedDict;
273
- if (!dictionaryKey) return;
274
- if (pruneContext.dictionariesWithEdgeCases.has(dictionaryKey)) return;
275
- let modified = false;
276
- if (shouldPurge) {
277
- const fieldUsage = pruneContext.dictionaryKeyToFieldUsageMap.get(dictionaryKey);
278
- if (fieldUsage && fieldUsage !== "all") {
279
- const { prunedDictionary, wasRecognised } = pruneDynamicDictionaryContent(parsedDict, fieldUsage);
280
- if (!wasRecognised) {
281
- pruneContext.dictionariesWithEdgeCases.add(dictionaryKey);
282
- return;
283
- }
284
- parsedDict = prunedDictionary;
285
- modified = true;
286
- }
287
- }
288
- if (shouldMinify) {
289
- const fieldRenameMap = pruneContext.dictionaryKeyToFieldRenameMap.get(dictionaryKey);
290
- if (fieldRenameMap && fieldRenameMap.size > 0) {
291
- parsedDict = applyFieldRenameToDict(parsedDict, fieldRenameMap);
292
- modified = true;
293
- }
294
- }
295
- if (!modified) return;
296
- const outputDict = shouldMinify ? {
242
+ } : {
297
243
  key: parsedDict.key,
298
244
  content: parsedDict.content,
299
245
  locale: parsedDict.locale
@@ -305,14 +251,14 @@ const processDynamicDictionaryFile = (filePath, pruneContext, shouldPurge, shoul
305
251
  const processAllDictionaryFiles = (dictionariesDir, dynamicDictionariesDir, pruneContext, shouldPurge, shouldMinify) => {
306
252
  if ((0, node_fs.existsSync)(dictionariesDir)) for (const entry of (0, node_fs.readdirSync)(dictionariesDir)) {
307
253
  if (!entry.endsWith(".json")) continue;
308
- processStaticDictionaryFile((0, node_path.join)(dictionariesDir, entry), pruneContext, shouldPurge, shouldMinify);
254
+ processDictionaryFile((0, node_path.join)(dictionariesDir, entry), "static", pruneContext, shouldPurge, shouldMinify);
309
255
  }
310
256
  if ((0, node_fs.existsSync)(dynamicDictionariesDir)) for (const keyDir of (0, node_fs.readdirSync)(dynamicDictionariesDir)) {
311
257
  const keyDirPath = (0, node_path.join)(dynamicDictionariesDir, keyDir);
312
258
  try {
313
259
  for (const localeFile of (0, node_fs.readdirSync)(keyDirPath)) {
314
260
  if (!localeFile.endsWith(".json")) continue;
315
- processDynamicDictionaryFile((0, node_path.join)(keyDirPath, localeFile), pruneContext, shouldPurge, shouldMinify);
261
+ processDictionaryFile((0, node_path.join)(keyDirPath, localeFile), "dynamic", pruneContext, shouldPurge, shouldMinify);
316
262
  }
317
263
  } catch {}
318
264
  }
@@ -390,9 +336,6 @@ const runPurgePipeline = (options) => {
390
336
  const intlayerPurgeBabelPlugin = (_babel) => ({
391
337
  name: "intlayer-purge",
392
338
  pre() {
393
- const { baseDir } = this.opts;
394
- if (_completedBaseDirs.has(baseDir)) return;
395
- _completedBaseDirs.add(baseDir);
396
339
  runPurgePipeline(this.opts);
397
340
  },
398
341
  visitor: {}