@intlayer/babel 9.5.1 → 9.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"optimizePass.mjs","names":[],"sources":["../../../src/compat/optimizePass.ts"],"sourcesContent":["import type * as BabelTypes from '@babel/types';\nimport {\n type CallerDescriptor,\n getRewritableCallers,\n} from '@intlayer/config/callers';\nimport type {\n DictionaryImportRegistry,\n ImportMode,\n} from '../dictionaryImports';\nimport { splitNamespace } from '../staticAstReaders';\nimport { resolveNamespaceForRewrite } from './namespaceResolution';\n\n/**\n * Compat half of the optimize pass.\n *\n * Every adapter-specific behaviour of the build-time rewrite lives here:\n * matching a compat caller's import, resolving its namespace, and re-pointing\n * the import specifier at the dictionary-accepting helper.\n *\n * The pass works on plain AST nodes rather than `NodePath`s: the optimize\n * plugin collects the call sites in its single traversal and hands them over,\n * so nothing here walks the tree.\n *\n * It is created only when compat descriptors were injected by a compat\n * package's bundler plugin, so a plain intlayer build never allocates it —\n * {@link createCompatOptimizePass} returns `null` for an empty registry.\n */\nexport type CompatOptimizePass = {\n /**\n * Whether `importSource` exports at least one rewritable compat caller, so\n * the optimize plugin knows the import is worth inspecting even though it is\n * not a native intlayer package.\n */\n ownsImportSource: (importSource: string) => boolean;\n /** Records the local alias one import specifier introduces. */\n noteImport: (\n importSource: string,\n importedName: string,\n localName: string\n ) => void;\n /** Whether `localName` was bound to a compat caller by an import. */\n ownsLocalName: (localName: string) => boolean;\n /** Whether the file imported any compat caller at all. */\n hasCallers: () => boolean;\n /**\n * Resolves the namespace of every collected call, dropping the callers that\n * cannot be rewritten and deciding the file-level helper family. Must run\n * after every import was noted and before any rewrite.\n */\n analyzeCalls: (callNodes: readonly BabelTypes.CallExpression[]) => void;\n /** Rewrites one compat call site, if its caller survived {@link analyzeCalls}. */\n rewriteCall: (callNode: BabelTypes.CallExpression) => void;\n /** Re-points the compat specifiers of one import declaration. */\n rewriteImportSpecifiers: (importNode: BabelTypes.ImportDeclaration) => void;\n};\n\n/**\n * Rewritable slice of a descriptor registry, cached by array reference.\n *\n * Babel reuses one plugin-options object for every file of a build, so the\n * filter runs once per build instead of once per transformed file.\n */\nconst rewritableCallersCache = new WeakMap<\n readonly CallerDescriptor[],\n readonly CallerDescriptor[]\n>();\n\nconst getCachedRewritableCallers = (\n compatCallers: readonly CallerDescriptor[]\n): readonly CallerDescriptor[] => {\n let rewritable = rewritableCallersCache.get(compatCallers);\n\n if (!rewritable) {\n rewritable = getRewritableCallers([...compatCallers]);\n rewritableCallersCache.set(compatCallers, rewritable);\n }\n\n return rewritable;\n};\n\n/**\n * `importSource` → the callers it exports, indexed by their imported name.\n *\n * Built once per descriptor registry so matching an import specifier is two\n * map lookups instead of a scan over every descriptor's `importSources`.\n */\ntype CallerIndex = Map<string, Map<string, CallerDescriptor>>;\n\nconst callerIndexCache = new WeakMap<\n readonly CallerDescriptor[],\n CallerIndex\n>();\n\nconst getCallerIndex = (\n rewritableCallers: readonly CallerDescriptor[]\n): CallerIndex => {\n let index = callerIndexCache.get(rewritableCallers);\n\n if (!index) {\n index = new Map();\n\n for (const descriptor of rewritableCallers) {\n for (const importSource of descriptor.importSources) {\n let byName = index.get(importSource);\n\n if (!byName) {\n byName = new Map();\n index.set(importSource, byName);\n }\n\n byName.set(descriptor.callerName, descriptor);\n }\n }\n\n callerIndexCache.set(rewritableCallers, index);\n }\n\n return index;\n};\n\n/**\n * Builds the compat optimize pass for one source file, or `null` when no\n * compat caller was injected.\n *\n * @param babelTypes - Babel's type helpers.\n * @param compatCallers - Descriptors injected by the compat packages' plugins.\n * @param imports - Shared dictionary-import registry for the file.\n * @param buildModes - The file's global import mode and per-dictionary overrides.\n */\nexport const createCompatOptimizePass = (\n babelTypes: typeof BabelTypes,\n compatCallers: readonly CallerDescriptor[],\n imports: DictionaryImportRegistry,\n buildModes: {\n importMode: ImportMode | undefined;\n dictionaryModeMap?: Record<string, ImportMode | undefined>;\n }\n): CompatOptimizePass | null => {\n const rewritableCallers = getCachedRewritableCallers(compatCallers);\n if (rewritableCallers.length === 0) return null;\n\n const callerIndex = getCallerIndex(rewritableCallers);\n const { importMode, dictionaryModeMap } = buildModes;\n\n /** Local alias → the descriptor it was imported as. */\n const callersByLocalName = new Map<string, CallerDescriptor>();\n\n /**\n * File-level decision: one import specifier serves every call in the file, so\n * a global dynamic/fetch mode — or any per-dictionary override reached from\n * this file — flips all rewritten compat calls to the dynamic helper.\n */\n let useDynamicHelpers = false;\n\n /** Narrows to the two modes that resolve through a per-locale loader. */\n const isDynamicMode = (\n mode: ImportMode | undefined\n ): mode is 'dynamic' | 'fetch' => mode === 'dynamic' || mode === 'fetch';\n\n /** Import mode a compat call site resolves to for `dictionaryKey`. */\n const importModeFor = (dictionaryKey: string): ImportMode => {\n if (!useDynamicHelpers) return 'static';\n\n const override = dictionaryModeMap?.[dictionaryKey];\n if (isDynamicMode(override)) return override;\n\n return isDynamicMode(importMode) ? importMode : 'dynamic';\n };\n\n return {\n ownsImportSource: (importSource) => callerIndex.has(importSource),\n\n noteImport: (importSource, importedName, localName) => {\n const descriptor = callerIndex.get(importSource)?.get(importedName);\n if (descriptor) callersByLocalName.set(localName, descriptor);\n },\n\n ownsLocalName: (localName) => callersByLocalName.has(localName),\n\n hasCallers: () => callersByLocalName.size > 0,\n\n analyzeCalls: (callNodes) => {\n if (callersByLocalName.size === 0) return;\n\n /**\n * Locals with at least one call site whose namespace could not be read:\n * one import specifier serves every call in the file, so re-pointing it\n * while leaving those calls untouched would hand a raw namespace string\n * — or nothing at all — to the dictionary-accepting helper.\n */\n const unresolvableLocalNames = new Set<string>();\n let hasDynamicCall = false;\n\n for (const callNode of callNodes) {\n const callee = callNode.callee;\n if (!babelTypes.isIdentifier(callee)) continue;\n\n const descriptor = callersByLocalName.get(callee.name);\n if (!descriptor) continue;\n\n const namespaceMatch = resolveNamespaceForRewrite(\n babelTypes,\n callNode.arguments,\n descriptor\n );\n\n // No readable namespace — a computed key, or a call that passes none\n // at all (`useTranslations()`). Either way the dictionary is unknown at\n // build time, so the call keeps resolving through the runtime registry\n // and holds back the siblings sharing its import.\n if (!namespaceMatch) {\n unresolvableLocalNames.add(callee.name);\n continue;\n }\n\n const { dictionaryKey } = splitNamespace(namespaceMatch.fullNamespace);\n if (isDynamicMode(dictionaryModeMap?.[dictionaryKey])) {\n hasDynamicCall = true;\n }\n }\n\n for (const localName of unresolvableLocalNames) {\n callersByLocalName.delete(localName);\n }\n\n useDynamicHelpers = isDynamicMode(importMode) || hasDynamicCall;\n },\n\n rewriteCall: (callNode) => {\n const callee = callNode.callee;\n if (!babelTypes.isIdentifier(callee)) return;\n\n const descriptor = callersByLocalName.get(callee.name);\n if (!descriptor) return;\n\n const callArguments = callNode.arguments;\n const namespaceMatch = resolveNamespaceForRewrite(\n babelTypes,\n callArguments,\n descriptor\n );\n // Filtered out by `analyzeCalls` — the import keeps its original specifier.\n if (!namespaceMatch) return;\n\n const { dictionaryKey, keyPrefix } = splitNamespace(\n namespaceMatch.fullNamespace\n );\n const mode = importModeFor(dictionaryKey);\n const ident = imports.identFor(dictionaryKey, mode);\n const isDynamicHelper = mode !== 'static';\n\n if (namespaceMatch.argumentIndex !== undefined) {\n // Positional namespace: replace the string with the dictionary, then\n // the (dynamic) key and the (nested) prefix.\n // useTranslation('about.counter', opts)\n // static → useDictionary(_hash, 'counter', opts)\n // dynamic → useDictionaryDynamic(_hash_dyn, 'about', 'counter', opts)\n callArguments[namespaceMatch.argumentIndex] = babelTypes.identifier(\n ident.name\n );\n\n const insertedArguments: BabelTypes.Expression[] = [];\n if (isDynamicHelper) {\n insertedArguments.push(babelTypes.stringLiteral(dictionaryKey));\n }\n if (keyPrefix) {\n insertedArguments.push(babelTypes.stringLiteral(keyPrefix));\n }\n callArguments.splice(\n namespaceMatch.argumentIndex + 1,\n 0,\n ...insertedArguments\n );\n } else if (isDynamicHelper) {\n // Fixed / option namespace: prepend the loader and the dictionary key.\n callArguments.unshift(\n babelTypes.identifier(ident.name),\n babelTypes.stringLiteral(dictionaryKey)\n );\n } else {\n // Fixed / option namespace, static helper: prepend the dictionary.\n // useLingui() → useDictionary(_hash)\n callArguments.unshift(babelTypes.identifier(ident.name));\n }\n\n // Option namespace: leave only the key-prefix remainder in the options\n // object (or drop the property entirely), so the runtime helper does not\n // re-apply the dictionary key as a lookup prefix.\n // useI18n({ namespace: 'about' }) → useDictionary(_hash, {})\n if (namespaceMatch.optionProperty && namespaceMatch.optionsObject) {\n if (keyPrefix) {\n namespaceMatch.optionProperty.value =\n babelTypes.stringLiteral(keyPrefix);\n } else {\n namespaceMatch.optionsObject.properties =\n namespaceMatch.optionsObject.properties.filter(\n (property) => property !== namespaceMatch.optionProperty\n );\n }\n }\n },\n\n rewriteImportSpecifiers: (importNode) => {\n const byName = callerIndex.get(importNode.source.value);\n if (!byName) return;\n\n for (const specifier of importNode.specifiers) {\n if (!babelTypes.isImportSpecifier(specifier)) continue;\n\n // Only a specifier still held by `callersByLocalName` is rewritable —\n // `analyzeCalls` removed the ones with an unresolvable call site.\n const descriptor = callersByLocalName.get(specifier.local.name);\n if (!descriptor || !byName.has(descriptor.callerName)) continue;\n\n // Keep the local alias so call sites read unchanged; only the imported\n // name moves to the dictionary-accepting helper.\n specifier.imported = babelTypes.identifier(\n useDynamicHelpers\n ? descriptor.dynamicReplacement!\n : descriptor.staticReplacement!\n );\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;;AA8DA,MAAM,yCAAyB,IAAI,QAGjC;AAEF,MAAM,8BACJ,kBACgC;CAChC,IAAI,aAAa,uBAAuB,IAAI,aAAa;CAEzD,IAAI,CAAC,YAAY;EACf,aAAa,qBAAqB,CAAC,GAAG,aAAa,CAAC;EACpD,uBAAuB,IAAI,eAAe,UAAU;CACtD;CAEA,OAAO;AACT;AAUA,MAAM,mCAAmB,IAAI,QAG3B;AAEF,MAAM,kBACJ,sBACgB;CAChB,IAAI,QAAQ,iBAAiB,IAAI,iBAAiB;CAElD,IA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AM,IAAI,CAAC;GAOzD,IAAI,eAAe,kBAAkB,eAAe,eAAe;IACjE,IAAI,WACF,eAAe,eAAe,QAC5B,WAAW,cAAc,SAAS;SAEpC,eAAe,cAAc,aAC3B,eAAe,cAAc,WAAW,QACrC,aAAa,aAAa,eAAe,cAC5C;GAEN;EACF;EAEA,0BAA0B,eAAe;GACvC,MAAM,SAAS,YAAY,IAAI,WAAW,OAAO,KAAK;GACtD,IAAI,CAAC,QAAQ;GAEb,KAAK,MAAM,aAAa,WAAW,YAAY;IAC7C,IAAI,CAAC,WAAW,kBAAkB,SAAS,GAAG;IAI9C,MAAM,aAAa,mBAAmB,IAAI,UAAU,MAAM,IAAI;IAC9D,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,WAAW,UAAU,GAAG;IAIvD,UAAU,WAAW,WAAW,WAC9B,oBACI,WAAW,qBACX,WAAW,iBACjB;GACF;EACF;CACF;AACF"}
1
+ {"version":3,"file":"optimizePass.mjs","names":[],"sources":["../../../src/compat/optimizePass.ts"],"sourcesContent":["import type * as BabelTypes from '@babel/types';\nimport {\n type CallerDescriptor,\n getRewritableCallers,\n} from '@intlayer/config/callers';\nimport type {\n DictionaryImportRegistry,\n ImportMode,\n} from '../dictionaryImports';\nimport {\n ABSENT_VALUE,\n readJsxAttributeString,\n readObjectPropertyNode,\n readStaticString,\n splitNamespace,\n} from '../staticAstReaders';\nimport {\n resolveNamespaceForAnalysis,\n resolveNamespaceForRewrite,\n} from './namespaceResolution';\n\n/**\n * Compat half of the optimize pass.\n *\n * Every adapter-specific behaviour of the build-time rewrite lives here:\n * matching a compat caller's import, resolving its namespace, and re-pointing\n * the import specifier at the dictionary-accepting helper.\n *\n * The pass works on plain AST nodes rather than `NodePath`s: the optimize\n * plugin collects the call sites in its single traversal and hands them over,\n * so nothing here walks the tree.\n *\n * It is created only when compat descriptors were injected by a compat\n * package's bundler plugin, so a plain intlayer build never allocates it —\n * {@link createCompatOptimizePass} returns `null` for an empty registry.\n */\nexport type CompatOptimizePass = {\n /**\n * Whether `importSource` exports at least one rewritable compat caller, so\n * the optimize plugin knows the import is worth inspecting even though it is\n * not a native intlayer package.\n */\n ownsImportSource: (importSource: string) => boolean;\n /** Records the local alias one import specifier introduces. */\n noteImport: (\n importSource: string,\n importedName: string,\n localName: string\n ) => void;\n /** Whether `localName` was bound to a compat caller by an import. */\n ownsLocalName: (localName: string) => boolean;\n /**\n * Records the names a compat call's result was destructured into\n * (`const { i18n, _, t } = useLingui()`), so a bare `t('…')` call in the\n * file is read as a message-id site of that library. Names that are not\n * message callers of the library are ignored.\n */\n noteDestructuredResult: (localCallerName: string, names: string[]) => void;\n /** Whether the file imported any compat caller at all. */\n hasCallers: () => boolean;\n /**\n * Whether the file imported a root-scope caller whose dictionaries are\n * named by message ids (`useLingui()`), so the traversal must also hand\n * over the id-carrying sites through {@link collectMessageIdSite}. Valid\n * once every import was noted.\n */\n needsMessageIdSites: () => boolean;\n /**\n * Records one node that may carry a message id for a root-scope caller: a\n * call (`i18n._('footer.github')`, `t({ id })`), a tagged template\n * (``t`…` ``) or a JSX opening element (`<Trans id=\"…\" />`). Nodes that\n * match no message caller are ignored.\n */\n collectMessageIdSite: (\n node:\n | BabelTypes.CallExpression\n | BabelTypes.TaggedTemplateExpression\n | BabelTypes.JSXOpeningElement\n ) => void;\n /**\n * Whether the node is an element of a compat JSX caller bound by its id\n * attribute (`<Trans id=\"…\" />`) imported by the file — as source JSX, or\n * already compiled by the framework plugin into `jsx(Trans, { id })`.\n */\n ownsJsxSite: (node: JsxSiteNode) => boolean;\n /**\n * Resolves the namespace of every collected call and element, dropping the\n * callers that cannot be rewritten and deciding the file-level helper\n * family. Must run after every import was noted and every message-id site\n * collected, and before any rewrite.\n *\n * @param countReferences - Number of references a local name has in the\n * file. A JSX caller is only re-pointed when every reference is a bound\n * element: one passed around as a value (`component={Trans}`) would reach\n * the dictionary-accepting replacement without its dictionary.\n */\n analyzeCalls: (\n callNodes: readonly BabelTypes.CallExpression[],\n jsxSites?: readonly JsxSiteNode[],\n countReferences?: (localName: string) => number\n ) => void;\n /** Rewrites one compat call site, if its caller survived {@link analyzeCalls}. */\n rewriteCall: (callNode: BabelTypes.CallExpression) => void;\n /**\n * Binds one compat JSX element, if its caller survived {@link analyzeCalls}:\n * adds the `dictionary` prop naming the dictionary its id addresses.\n */\n rewriteJsxSite: (node: JsxSiteNode) => void;\n /** Re-points the compat specifiers of one import declaration. */\n rewriteImportSpecifiers: (importNode: BabelTypes.ImportDeclaration) => void;\n};\n\n/**\n * A compat JSX element as the pass may meet it: the source element, or the\n * call the automatic/classic JSX runtime compiled it into — the optimize\n * transform runs after the framework plugin, so on Vite the compiled form is\n * the usual one.\n */\nexport type JsxSiteNode =\n | BabelTypes.JSXOpeningElement\n | BabelTypes.CallExpression;\n\n/**\n * Factories a JSX element compiles into — `jsx(Trans, props)` /\n * `_jsxs(Trans, props)` / `jsxRuntime.jsxDEV(Trans, props)` for the automatic\n * runtime, `React.createElement(Trans, props)` for the classic one. The\n * transform aliases the import (`_jsx`), hence the optional underscores.\n */\nconst COMPILED_JSX_FACTORY_PATTERN = /^_*(jsxs?|jsxDEV|createElement)$/;\n\n/**\n * Rewritable slice of a descriptor registry, cached by array reference.\n *\n * Babel reuses one plugin-options object for every file of a build, so the\n * filter runs once per build instead of once per transformed file.\n */\nconst rewritableCallersCache = new WeakMap<\n readonly CallerDescriptor[],\n readonly CallerDescriptor[]\n>();\n\nconst getCachedRewritableCallers = (\n compatCallers: readonly CallerDescriptor[]\n): readonly CallerDescriptor[] => {\n let rewritable = rewritableCallersCache.get(compatCallers);\n\n if (!rewritable) {\n rewritable = getRewritableCallers([...compatCallers]);\n rewritableCallersCache.set(compatCallers, rewritable);\n }\n\n return rewritable;\n};\n\n/**\n * `importSource` → the callers it exports, indexed by their imported name.\n *\n * Built once per descriptor registry so matching an import specifier is two\n * map lookups instead of a scan over every descriptor's `importSources`.\n */\ntype CallerIndex = Map<string, Map<string, CallerDescriptor>>;\n\nconst callerIndexCache = new WeakMap<\n readonly CallerDescriptor[],\n CallerIndex\n>();\n\nconst getCallerIndex = (\n rewritableCallers: readonly CallerDescriptor[]\n): CallerIndex => {\n let index = callerIndexCache.get(rewritableCallers);\n\n if (!index) {\n index = new Map();\n\n for (const descriptor of rewritableCallers) {\n for (const importSource of descriptor.importSources) {\n let byName = index.get(importSource);\n\n if (!byName) {\n byName = new Map();\n index.set(importSource, byName);\n }\n\n byName.set(descriptor.callerName, descriptor);\n }\n }\n\n callerIndexCache.set(rewritableCallers, index);\n }\n\n return index;\n};\n\n/**\n * Prop through which a bound compat JSX element (`<Trans>`) receives its\n * dictionary — the static dictionary, or a `[loader, key]` pair in dynamic\n * mode. The compat package's replacement component reads it.\n */\nconst JSX_DICTIONARY_ATTRIBUTE = 'dictionary';\n\n/**\n * Whether a descriptor's call sites carry the message id themselves, with the\n * dictionary named by the id's first dot-segment (lingui's `_` / `t` /\n * `<Trans>`, react-intl's `formatMessage`). These are the sites a root-scope\n * binding reads its dictionaries from.\n */\nconst isMessageIdCaller = (descriptor: CallerDescriptor): boolean =>\n descriptor.translationFunction === 'self' &&\n descriptor.namespaceSources.some(\n (source) => source.from === 'path-first-segment'\n );\n\n/**\n * `library` → its message-id callers, cached by registry reference.\n *\n * Read from the full registry rather than its rewritable slice: the id\n * callers are matched as methods or JSX and are never rewritten themselves —\n * they only name the dictionaries a root-scope call in the same file binds.\n */\nconst messageIdCallersCache = new WeakMap<\n readonly CallerDescriptor[],\n Map<string, CallerDescriptor[]>\n>();\n\nconst getMessageIdCallersByLibrary = (\n compatCallers: readonly CallerDescriptor[]\n): Map<string, CallerDescriptor[]> => {\n let byLibrary = messageIdCallersCache.get(compatCallers);\n\n if (!byLibrary) {\n byLibrary = new Map();\n\n for (const descriptor of compatCallers) {\n if (!isMessageIdCaller(descriptor)) continue;\n\n let descriptors = byLibrary.get(descriptor.library);\n\n if (!descriptors) {\n descriptors = [];\n byLibrary.set(descriptor.library, descriptors);\n }\n\n descriptors.push(descriptor);\n }\n\n messageIdCallersCache.set(compatCallers, byLibrary);\n }\n\n return byLibrary;\n};\n\n/**\n * The dictionaries a library's root-scope calls bind in the current file:\n * the first segment of every static message id, or `undefined` once a single\n * id could not be read — a computed id may address any dictionary, so the\n * calls must keep resolving through the runtime registry.\n */\ntype RootScopeBinding = Set<string> | undefined;\n\n/**\n * Builds the compat optimize pass for one source file, or `null` when no\n * compat caller was injected.\n *\n * @param babelTypes - Babel's type helpers.\n * @param compatCallers - Descriptors injected by the compat packages' plugins.\n * @param imports - Shared dictionary-import registry for the file.\n * @param buildModes - The file's global import mode and per-dictionary overrides.\n */\nexport const createCompatOptimizePass = (\n babelTypes: typeof BabelTypes,\n compatCallers: readonly CallerDescriptor[],\n imports: DictionaryImportRegistry,\n buildModes: {\n importMode: ImportMode | undefined;\n dictionaryModeMap?: Record<string, ImportMode | undefined>;\n }\n): CompatOptimizePass | null => {\n const rewritableCallers = getCachedRewritableCallers(compatCallers);\n if (rewritableCallers.length === 0) return null;\n\n const callerIndex = getCallerIndex(rewritableCallers);\n const messageIdCallersByLibrary = getMessageIdCallersByLibrary(compatCallers);\n const { importMode, dictionaryModeMap } = buildModes;\n\n /** Local alias → the descriptor it was imported as. */\n const callersByLocalName = new Map<string, CallerDescriptor>();\n\n /**\n * Root-scope binding per library, filled from the message-id sites the\n * traversal hands over. A library is present only once a root-scope caller\n * of it was imported, so the sites of other libraries are never read.\n */\n const rootScopeBindings = new Map<string, RootScopeBinding>();\n\n /**\n * Local names a bare message call may use per library: message callers\n * imported from the library (`import { t } from '@lingui/macro'`) and\n * names destructured from a root-scope call's result\n * (`const { _ } = useLingui()`). A bare `t('…')` bound to anything else —\n * say a local wrapper — is not a message-id site, mirroring the usage\n * analyser; method calls (`i18n._('…')`) match by method name alone.\n */\n const bareMessageCallerNames = new Map<string, Set<string>>();\n\n /**\n * Bare calls met during the traversal, decided once every binding name is\n * known — a destructuring may sit below the call sites in source order.\n */\n const pendingBareCalls: {\n library: string;\n name: string;\n node: BabelTypes.CallExpression;\n }[] = [];\n\n const addBareMessageCallerName = (library: string, name: string): void => {\n let names = bareMessageCallerNames.get(library);\n if (!names) {\n names = new Set();\n bareMessageCallerNames.set(library, names);\n }\n names.add(name);\n };\n\n /**\n * File-level decision: one import specifier serves every call in the file, so\n * a global dynamic/fetch mode — or any per-dictionary override reached from\n * this file — flips all rewritten compat calls to the dynamic helper.\n */\n let useDynamicHelpers = false;\n\n /** Narrows to the two modes that resolve through a per-locale loader. */\n const isDynamicMode = (\n mode: ImportMode | undefined\n ): mode is 'dynamic' | 'fetch' => mode === 'dynamic' || mode === 'fetch';\n\n /** Import mode a compat call site resolves to for `dictionaryKey`. */\n const importModeFor = (dictionaryKey: string): ImportMode => {\n if (!useDynamicHelpers) return 'static';\n\n const override = dictionaryModeMap?.[dictionaryKey];\n if (isDynamicMode(override)) return override;\n\n return isDynamicMode(importMode) ? importMode : 'dynamic';\n };\n\n /**\n * Whether a call binds through the root-scope path: its descriptor allows\n * it, the library has id callers to read from, and the call itself names\n * no dictionary (`useLingui()`).\n */\n const isRootScopeCall = (\n descriptor: CallerDescriptor,\n callArguments: BabelTypes.CallExpression['arguments']\n ): boolean =>\n descriptor.allowRootScope === true &&\n messageIdCallersByLibrary.has(descriptor.library) &&\n resolveNamespaceForRewrite(babelTypes, callArguments, descriptor) ===\n undefined;\n\n /** Name a callee or tag reads as, whether bare (`t`) or a method (`i18n.t`). */\n const readCalleeName = (\n node: BabelTypes.Node\n ): { name: string; isMethod: boolean } | undefined => {\n if (babelTypes.isIdentifier(node)) {\n return { name: node.name, isMethod: false };\n }\n if (\n babelTypes.isMemberExpression(node) &&\n babelTypes.isIdentifier(node.property) &&\n !node.computed\n ) {\n return { name: node.property.name, isMethod: true };\n }\n return undefined;\n };\n\n /** The id descriptor of `library` matching a callee name, if any. */\n const findMessageIdCaller = (\n library: string,\n callee: { name: string; isMethod: boolean } | undefined,\n shape: 'call' | 'tagged-template'\n ): CallerDescriptor | undefined => {\n if (!callee) return undefined;\n\n return messageIdCallersByLibrary\n .get(library)\n ?.find(\n (descriptor) =>\n descriptor.callerName === callee.name &&\n (shape === 'tagged-template'\n ? descriptor.matchAsTaggedTemplate === true\n : !callee.isMethod || descriptor.matchAsMethod === true)\n );\n };\n\n /** Records the dictionary key read from one message call's arguments. */\n const recordMessageCall = (\n library: string,\n descriptor: CallerDescriptor,\n callArguments: BabelTypes.CallExpression['arguments']\n ): void => {\n const resolved = resolveNamespaceForAnalysis(\n babelTypes,\n callArguments,\n descriptor.namespaceSources\n );\n\n recordRootScopeKey(\n library,\n typeof resolved === 'string' && resolved !== ABSENT_VALUE\n ? resolved\n : undefined\n );\n };\n\n /** Records one dictionary key for `library`, or poisons its binding. */\n const recordRootScopeKey = (\n library: string,\n dictionaryKey: string | undefined\n ): void => {\n const binding = rootScopeBindings.get(library);\n // Already poisoned: nothing can un-poison a file.\n if (binding === undefined) return;\n\n if (dictionaryKey === undefined) {\n rootScopeBindings.set(library, undefined);\n return;\n }\n\n binding.add(dictionaryKey);\n };\n\n /**\n * The dictionary an id-derived key binds: the key itself when the build\n * produced such a dictionary, else the library's whole-file catalog\n * (`messages` for lingui, `index` otherwise) with the id kept intact, else\n * `undefined` — nothing to bind safely.\n *\n * Id-derived keys are guesses, so the set of dictionaries the build actually\n * produced is required to tell a dictionary from a group inside the\n * whole-file catalog.\n */\n const settleDictionaryKey = (\n key: string,\n descriptor: CallerDescriptor\n ): string | undefined => {\n if (!dictionaryModeMap) return undefined;\n if (key in dictionaryModeMap) return key;\n\n const rootKey = descriptor.rootDictionaryKey ?? 'index';\n return rootKey in dictionaryModeMap ? rootKey : undefined;\n };\n\n /**\n * Settles every collected key of a library's root-scope binding, poisoning\n * it when one key has nothing to bind — or when no id was read at all, since\n * a call with nothing to bind must keep the registry.\n */\n const settleRootScopeBinding = (\n library: string,\n descriptor: CallerDescriptor\n ): void => {\n const binding = rootScopeBindings.get(library);\n if (binding === undefined || binding.size === 0) {\n rootScopeBindings.set(library, undefined);\n return;\n }\n\n const settled = new Set<string>();\n\n for (const key of binding) {\n const dictionaryKey = settleDictionaryKey(key, descriptor);\n if (dictionaryKey === undefined) {\n rootScopeBindings.set(library, undefined);\n return;\n }\n settled.add(dictionaryKey);\n }\n\n rootScopeBindings.set(library, settled);\n };\n\n /**\n * A JSX element in either of its shapes, reduced to what the pass needs:\n * the component's local name, its static id, and a way to add a prop.\n */\n type JsxSite = {\n localName: string;\n /** The static id attribute as a string node, `undefined` when dynamic or absent. */\n readId: (attributeName: string) => BabelTypes.StringLiteral | undefined;\n addProp: (name: string, value: BabelTypes.Expression) => void;\n };\n\n const readJsxSite = (node: JsxSiteNode): JsxSite | undefined => {\n if (babelTypes.isJSXOpeningElement(node)) {\n if (!babelTypes.isJSXIdentifier(node.name)) return undefined;\n\n return {\n localName: node.name.name,\n readId: (attributeName) =>\n readJsxAttributeString(babelTypes, node, attributeName),\n addProp: (name, value) => {\n node.attributes.push(\n babelTypes.jsxAttribute(\n babelTypes.jsxIdentifier(name),\n babelTypes.jsxExpressionContainer(value)\n )\n );\n },\n };\n }\n\n // Compiled form: `jsx(Trans, { id: \"…\" })` / `React.createElement(Trans, {…})`.\n const callee = readCalleeName(node.callee);\n if (!callee || !COMPILED_JSX_FACTORY_PATTERN.test(callee.name)) {\n return undefined;\n }\n\n const [component, props] = node.arguments;\n if (\n !babelTypes.isIdentifier(component) ||\n !babelTypes.isObjectExpression(props)\n ) {\n return undefined;\n }\n\n return {\n localName: component.name,\n readId: (attributeName) => {\n const idNode = readObjectPropertyNode(babelTypes, props, attributeName);\n if (idNode === ABSENT_VALUE) return undefined;\n const id = readStaticString(babelTypes, idNode);\n return id === undefined ? undefined : babelTypes.stringLiteral(id);\n },\n addProp: (name, value) => {\n props.properties.push(\n babelTypes.objectProperty(babelTypes.identifier(name), value)\n );\n },\n };\n };\n\n /** The compat JSX descriptor a site's component was imported as, if any. */\n const jsxDescriptorFor = (\n site: JsxSite | undefined\n ): CallerDescriptor | undefined => {\n if (!site) return undefined;\n const descriptor = callersByLocalName.get(site.localName);\n return descriptor?.jsxIdAttribute !== undefined ? descriptor : undefined;\n };\n\n /**\n * The dictionary a compat JSX element binds, read from the first segment of\n * its static id attribute — `undefined` when the id is dynamic or names\n * nothing the build produced.\n */\n const resolveJsxDictionaryKey = (\n site: JsxSite,\n descriptor: CallerDescriptor\n ): string | undefined => {\n const idAttribute = site.readId(descriptor.jsxIdAttribute!);\n if (!idAttribute) return undefined;\n\n const resolved = resolveNamespaceForAnalysis(\n babelTypes,\n [idAttribute],\n descriptor.namespaceSources\n );\n if (typeof resolved !== 'string' || resolved === ABSENT_VALUE) {\n return undefined;\n }\n\n return settleDictionaryKey(resolved, descriptor);\n };\n\n return {\n ownsImportSource: (importSource) => callerIndex.has(importSource),\n\n noteImport: (importSource, importedName, localName) => {\n for (const [library, descriptors] of messageIdCallersByLibrary) {\n if (\n descriptors.some(\n (candidate) =>\n candidate.callerName === importedName &&\n candidate.importSources.includes(importSource)\n )\n ) {\n addBareMessageCallerName(library, localName);\n }\n }\n\n const descriptor = callerIndex.get(importSource)?.get(importedName);\n if (!descriptor) return;\n\n callersByLocalName.set(localName, descriptor);\n\n if (\n descriptor.allowRootScope &&\n messageIdCallersByLibrary.has(descriptor.library) &&\n !rootScopeBindings.has(descriptor.library)\n ) {\n rootScopeBindings.set(descriptor.library, new Set());\n }\n },\n\n ownsLocalName: (localName) => callersByLocalName.has(localName),\n\n noteDestructuredResult: (localCallerName, names) => {\n const descriptor = callersByLocalName.get(localCallerName);\n if (!descriptor?.allowRootScope) return;\n\n const messageCallers = messageIdCallersByLibrary.get(descriptor.library);\n if (!messageCallers) return;\n\n for (const name of names) {\n if (messageCallers.some((candidate) => candidate.callerName === name)) {\n addBareMessageCallerName(descriptor.library, name);\n }\n }\n },\n\n hasCallers: () => callersByLocalName.size > 0,\n\n needsMessageIdSites: () => rootScopeBindings.size > 0,\n\n ownsJsxSite: (node) => jsxDescriptorFor(readJsxSite(node)) !== undefined,\n\n collectMessageIdSite: (node) => {\n for (const library of rootScopeBindings.keys()) {\n // An element — as JSX or as the call it compiled into — matched by\n // the component's name against the library's JSX id callers.\n const jsxSite = babelTypes.isTaggedTemplateExpression(node)\n ? undefined\n : readJsxSite(node);\n if (jsxSite) {\n const descriptor = messageIdCallersByLibrary\n .get(library)\n ?.find(\n (candidate) =>\n candidate.callerName === jsxSite.localName &&\n candidate.jsxIdAttribute !== undefined\n );\n if (!descriptor) continue;\n\n const idAttribute = jsxSite.readId(descriptor.jsxIdAttribute!);\n const resolved = idAttribute\n ? resolveNamespaceForAnalysis(\n babelTypes,\n [idAttribute],\n descriptor.namespaceSources\n )\n : undefined;\n\n recordRootScopeKey(\n library,\n typeof resolved === 'string' && resolved !== ABSENT_VALUE\n ? resolved\n : undefined\n );\n continue;\n }\n\n if (babelTypes.isJSXOpeningElement(node)) continue;\n\n if (babelTypes.isTaggedTemplateExpression(node)) {\n // A macro template (``t`Hello ${name}` ``) has no id until the\n // lingui macro plugin compiles it, so reaching one here means the\n // id is unknowable.\n const descriptor = findMessageIdCaller(\n library,\n readCalleeName(node.tag),\n 'tagged-template'\n );\n if (descriptor) recordRootScopeKey(library, undefined);\n continue;\n }\n\n const callee = readCalleeName(node.callee);\n const descriptor = findMessageIdCaller(library, callee, 'call');\n if (!descriptor || !callee) continue;\n\n if (!callee.isMethod) {\n pendingBareCalls.push({ library, name: callee.name, node });\n continue;\n }\n\n recordMessageCall(library, descriptor, node.arguments);\n }\n },\n\n analyzeCalls: (callNodes, jsxSites = [], countReferences) => {\n if (callersByLocalName.size === 0) return;\n\n /**\n * Locals with at least one call site whose namespace could not be read:\n * one import specifier serves every call in the file, so re-pointing it\n * while leaving those calls untouched would hand a raw namespace string\n * — or nothing at all — to the dictionary-accepting helper.\n */\n const unresolvableLocalNames = new Set<string>();\n let hasDynamicCall = false;\n const settledLibraries = new Set<string>();\n\n for (const { library, name, node } of pendingBareCalls) {\n if (!bareMessageCallerNames.get(library)?.has(name)) continue;\n\n const descriptor = findMessageIdCaller(\n library,\n { name, isMethod: false },\n 'call'\n );\n if (descriptor) recordMessageCall(library, descriptor, node.arguments);\n }\n pendingBareCalls.length = 0;\n\n for (const callNode of callNodes) {\n const callee = callNode.callee;\n if (!babelTypes.isIdentifier(callee)) continue;\n\n const descriptor = callersByLocalName.get(callee.name);\n if (!descriptor) continue;\n\n if (isRootScopeCall(descriptor, callNode.arguments)) {\n if (!settledLibraries.has(descriptor.library)) {\n settleRootScopeBinding(descriptor.library, descriptor);\n settledLibraries.add(descriptor.library);\n }\n\n const binding = rootScopeBindings.get(descriptor.library);\n if (binding === undefined) {\n unresolvableLocalNames.add(callee.name);\n continue;\n }\n\n for (const dictionaryKey of binding) {\n if (isDynamicMode(dictionaryModeMap?.[dictionaryKey])) {\n hasDynamicCall = true;\n }\n }\n continue;\n }\n\n const namespaceMatch = resolveNamespaceForRewrite(\n babelTypes,\n callNode.arguments,\n descriptor\n );\n\n // No readable namespace — a computed key, or a call that passes none\n // at all (`useTranslations()`). Either way the dictionary is unknown at\n // build time, so the call keeps resolving through the runtime registry\n // and holds back the siblings sharing its import.\n if (!namespaceMatch) {\n unresolvableLocalNames.add(callee.name);\n continue;\n }\n\n const { dictionaryKey } = splitNamespace(namespaceMatch.fullNamespace);\n if (isDynamicMode(dictionaryModeMap?.[dictionaryKey])) {\n hasDynamicCall = true;\n }\n }\n\n /** Bound elements seen per JSX caller local, to match against references. */\n const jsxSiteCounts = new Map<string, number>();\n\n for (const jsxNode of jsxSites) {\n const site = readJsxSite(jsxNode);\n const descriptor = jsxDescriptorFor(site);\n if (!site || !descriptor) continue;\n\n jsxSiteCounts.set(\n site.localName,\n (jsxSiteCounts.get(site.localName) ?? 0) + 1\n );\n\n const dictionaryKey = resolveJsxDictionaryKey(site, descriptor);\n if (dictionaryKey === undefined) {\n unresolvableLocalNames.add(site.localName);\n continue;\n }\n\n if (isDynamicMode(dictionaryModeMap?.[dictionaryKey])) {\n hasDynamicCall = true;\n }\n }\n\n // A JSX caller is re-pointed only when every reference to it is an\n // element the pass binds — the import specifier serves them all.\n for (const [localName, descriptor] of callersByLocalName) {\n if (descriptor.jsxIdAttribute === undefined) continue;\n\n const boundSites = jsxSiteCounts.get(localName) ?? 0;\n const references = countReferences?.(localName) ?? boundSites;\n if (boundSites === 0 || references !== boundSites) {\n unresolvableLocalNames.add(localName);\n }\n }\n\n for (const localName of unresolvableLocalNames) {\n callersByLocalName.delete(localName);\n }\n\n useDynamicHelpers = isDynamicMode(importMode) || hasDynamicCall;\n },\n\n rewriteCall: (callNode) => {\n const callee = callNode.callee;\n if (!babelTypes.isIdentifier(callee)) return;\n\n const descriptor = callersByLocalName.get(callee.name);\n if (!descriptor) return;\n\n const callArguments = callNode.arguments;\n\n if (isRootScopeCall(descriptor, callArguments)) {\n // Filtered out by `analyzeCalls` when poisoned — never reached here.\n const binding = rootScopeBindings.get(descriptor.library);\n if (binding === undefined) return;\n\n // Root scope: every dictionary named in the file, ids kept intact so\n // the runtime picks the dictionary by first segment.\n // useLingui()\n // static → useDictionary(_footer, _header)\n // dynamic → useDictionaryDynamic([_footer_dyn, 'footer'], …)\n for (const dictionaryKey of binding) {\n const mode = importModeFor(dictionaryKey);\n const ident = babelTypes.identifier(\n imports.identFor(dictionaryKey, mode).name\n );\n\n callArguments.push(\n mode === 'static'\n ? ident\n : babelTypes.arrayExpression([\n ident,\n babelTypes.stringLiteral(dictionaryKey),\n ])\n );\n }\n return;\n }\n\n const namespaceMatch = resolveNamespaceForRewrite(\n babelTypes,\n callArguments,\n descriptor\n );\n // Filtered out by `analyzeCalls` — the import keeps its original specifier.\n if (!namespaceMatch) return;\n\n const { dictionaryKey, keyPrefix } = splitNamespace(\n namespaceMatch.fullNamespace\n );\n const mode = importModeFor(dictionaryKey);\n const ident = imports.identFor(dictionaryKey, mode);\n const isDynamicHelper = mode !== 'static';\n\n if (namespaceMatch.argumentIndex !== undefined) {\n // Positional namespace: replace the string with the dictionary, then\n // the (dynamic) key and the (nested) prefix.\n // useTranslation('about.counter', opts)\n // static → useDictionary(_hash, 'counter', opts)\n // dynamic → useDictionaryDynamic(_hash_dyn, 'about', 'counter', opts)\n callArguments[namespaceMatch.argumentIndex] = babelTypes.identifier(\n ident.name\n );\n\n const insertedArguments: BabelTypes.Expression[] = [];\n if (isDynamicHelper) {\n insertedArguments.push(babelTypes.stringLiteral(dictionaryKey));\n }\n if (keyPrefix) {\n insertedArguments.push(babelTypes.stringLiteral(keyPrefix));\n }\n callArguments.splice(\n namespaceMatch.argumentIndex + 1,\n 0,\n ...insertedArguments\n );\n } else if (isDynamicHelper) {\n // Fixed / option namespace: prepend the loader and the dictionary key.\n callArguments.unshift(\n babelTypes.identifier(ident.name),\n babelTypes.stringLiteral(dictionaryKey)\n );\n } else {\n // Fixed / option namespace, static helper: prepend the dictionary.\n callArguments.unshift(babelTypes.identifier(ident.name));\n }\n\n // Option namespace: leave only the key-prefix remainder in the options\n // object (or drop the property entirely), so the runtime helper does not\n // re-apply the dictionary key as a lookup prefix.\n // useI18n({ namespace: 'about' }) → useDictionary(_hash, {})\n if (namespaceMatch.optionProperty && namespaceMatch.optionsObject) {\n if (keyPrefix) {\n namespaceMatch.optionProperty.value =\n babelTypes.stringLiteral(keyPrefix);\n } else {\n namespaceMatch.optionsObject.properties =\n namespaceMatch.optionsObject.properties.filter(\n (property) => property !== namespaceMatch.optionProperty\n );\n }\n }\n },\n\n rewriteJsxSite: (node) => {\n const site = readJsxSite(node);\n const descriptor = jsxDescriptorFor(site);\n if (!site || !descriptor) return;\n\n // Filtered out by `analyzeCalls` when unresolvable — never reached here.\n const dictionaryKey = resolveJsxDictionaryKey(site, descriptor);\n if (dictionaryKey === undefined) return;\n\n const mode = importModeFor(dictionaryKey);\n const ident = babelTypes.identifier(\n imports.identFor(dictionaryKey, mode).name\n );\n\n // The id stays intact; the element receives the dictionary it names.\n // <Trans id=\"footer.github\" />\n // static → <Trans id=\"footer.github\" dictionary={_footer} />\n // dynamic → <Trans id=\"footer.github\" dictionary={[_footer_dyn, 'footer']} />\n site.addProp(\n JSX_DICTIONARY_ATTRIBUTE,\n mode === 'static'\n ? ident\n : babelTypes.arrayExpression([\n ident,\n babelTypes.stringLiteral(dictionaryKey),\n ])\n );\n },\n\n rewriteImportSpecifiers: (importNode) => {\n const byName = callerIndex.get(importNode.source.value);\n if (!byName) return;\n\n for (const specifier of importNode.specifiers) {\n if (!babelTypes.isImportSpecifier(specifier)) continue;\n\n // Only a specifier still held by `callersByLocalName` is rewritable —\n // `analyzeCalls` removed the ones with an unresolvable call site.\n const descriptor = callersByLocalName.get(specifier.local.name);\n if (!descriptor || !byName.has(descriptor.callerName)) continue;\n\n // Keep the local alias so call sites read unchanged; only the imported\n // name moves to the dictionary-accepting helper.\n specifier.imported = babelTypes.identifier(\n useDynamicHelpers\n ? descriptor.dynamicReplacement!\n : descriptor.staticReplacement!\n );\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;;AAgIA,MAAM,+BAA+B;;;;;;;AAQrC,MAAM,yCAAyB,IAAI,QAGjC;AAEF,MAAM,8BACJ,kBACgC;CAChC,IAAI,aAAa,uBAAuB,IAAI,aAAa;CAEzD,IAAI,CAAC,YAAY;EACf,aAAa,qBAAqB,CAAC,GAAG,aAAa,CAAC;EACpD,uBAAuB,IAAI,eAAe,UAAU;CACtD;CAEA,OAAO;AACT;AAUA,MAAM,mCAAmB,IAAI,QAG3B;AAEF,MAAM,kBACJ,sBACgB;CAChB,IAAI,QAAQ,iBAAiB,IAAI,iBAAiB;CAElD,IAAI,CAAC,OAAO;EACV,wBAAQ,IAAI,IAAI;EAEhB,KAAK,MAAM,cAAc,mBACvB,KAAK,MAAM,gBAAgB,WAAW,eAAe;GACnD,IAAI,SAAS,MAAM,IAAI,YAAY;GAEnC,IAAI,CAAC,QAAQ;IACX,yBAAS,IAAI,IAAI;IACjB,MAAM,IAAI,cAAc,MAAM;GAChC;GAEA,OAAO,IAAI,WAAW,YAAY,UAAU;EAC9C;EAGF,iBAAiB,IAAI,mBAAmB,KAA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AI9C,MAAM,aAAa,mBAAmB,IAAI,UAAU,MAAM,IAAI;IAC9D,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,WAAW,UAAU,GAAG;IAIvD,UAAU,WAAW,WAAW,WAC9B,oBACI,WAAW,qBACX,WAAW,iBACjB;GACF;EACF;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-optimize.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-optimize.ts"],"mappings":";;;;;;;YA8FY;;;;EAIV;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;;;;;;;;;;;;EAeA;;;;EAIA;;;;EAIA,oBAAoB;;;;EAOpB;;;;EAIA;;;;;;;;;;;;;;EAcA,gBAAgB;;;;;;;;;KAUb,QAAQ;EACX,MAAM;;EAEN;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgTW,8BAA2B;EACtC,cAAc;MACZ,aAAa"}
1
+ {"version":3,"file":"babel-plugin-intlayer-optimize.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-optimize.ts"],"mappings":";;;;;;;YAiGY;;;;EAIV;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;EAIA;;;;;;;;;;;;;;;EAeA;;;;EAIA;;;;EAIA,oBAAoB;;;;EAOpB;;;;EAIA;;;;;;;;;;;;;;EAcA,gBAAgB;;;;;;;;;KAUb,QAAQ;EACX,MAAM;;EAEN;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgTW,8BAA2B;EACtC,cAAc;MACZ,aAAa"}
@@ -28,19 +28,64 @@ export type CompatOptimizePass = {
28
28
  noteImport: (importSource: string, importedName: string, localName: string) => void;
29
29
  /** Whether `localName` was bound to a compat caller by an import. */
30
30
  ownsLocalName: (localName: string) => boolean;
31
+ /**
32
+ * Records the names a compat call's result was destructured into
33
+ * (`const { i18n, _, t } = useLingui()`), so a bare `t('…')` call in the
34
+ * file is read as a message-id site of that library. Names that are not
35
+ * message callers of the library are ignored.
36
+ */
37
+ noteDestructuredResult: (localCallerName: string, names: string[]) => void;
31
38
  /** Whether the file imported any compat caller at all. */
32
39
  hasCallers: () => boolean;
33
40
  /**
34
- * Resolves the namespace of every collected call, dropping the callers that
35
- * cannot be rewritten and deciding the file-level helper family. Must run
36
- * after every import was noted and before any rewrite.
41
+ * Whether the file imported a root-scope caller whose dictionaries are
42
+ * named by message ids (`useLingui()`), so the traversal must also hand
43
+ * over the id-carrying sites through {@link collectMessageIdSite}. Valid
44
+ * once every import was noted.
45
+ */
46
+ needsMessageIdSites: () => boolean;
47
+ /**
48
+ * Records one node that may carry a message id for a root-scope caller: a
49
+ * call (`i18n._('footer.github')`, `t({ id })`), a tagged template
50
+ * (``t`…` ``) or a JSX opening element (`<Trans id="…" />`). Nodes that
51
+ * match no message caller are ignored.
52
+ */
53
+ collectMessageIdSite: (node: BabelTypes.CallExpression | BabelTypes.TaggedTemplateExpression | BabelTypes.JSXOpeningElement) => void;
54
+ /**
55
+ * Whether the node is an element of a compat JSX caller bound by its id
56
+ * attribute (`<Trans id="…" />`) imported by the file — as source JSX, or
57
+ * already compiled by the framework plugin into `jsx(Trans, { id })`.
37
58
  */
38
- analyzeCalls: (callNodes: readonly BabelTypes.CallExpression[]) => void;
59
+ ownsJsxSite: (node: JsxSiteNode) => boolean;
60
+ /**
61
+ * Resolves the namespace of every collected call and element, dropping the
62
+ * callers that cannot be rewritten and deciding the file-level helper
63
+ * family. Must run after every import was noted and every message-id site
64
+ * collected, and before any rewrite.
65
+ *
66
+ * @param countReferences - Number of references a local name has in the
67
+ * file. A JSX caller is only re-pointed when every reference is a bound
68
+ * element: one passed around as a value (`component={Trans}`) would reach
69
+ * the dictionary-accepting replacement without its dictionary.
70
+ */
71
+ analyzeCalls: (callNodes: readonly BabelTypes.CallExpression[], jsxSites?: readonly JsxSiteNode[], countReferences?: (localName: string) => number) => void;
39
72
  /** Rewrites one compat call site, if its caller survived {@link analyzeCalls}. */
40
73
  rewriteCall: (callNode: BabelTypes.CallExpression) => void;
74
+ /**
75
+ * Binds one compat JSX element, if its caller survived {@link analyzeCalls}:
76
+ * adds the `dictionary` prop naming the dictionary its id addresses.
77
+ */
78
+ rewriteJsxSite: (node: JsxSiteNode) => void;
41
79
  /** Re-points the compat specifiers of one import declaration. */
42
80
  rewriteImportSpecifiers: (importNode: BabelTypes.ImportDeclaration) => void;
43
81
  };
82
+ /**
83
+ * A compat JSX element as the pass may meet it: the source element, or the
84
+ * call the automatic/classic JSX runtime compiled it into — the optimize
85
+ * transform runs after the framework plugin, so on Vite the compiled form is
86
+ * the usual one.
87
+ */
88
+ export type JsxSiteNode = BabelTypes.JSXOpeningElement | BabelTypes.CallExpression;
44
89
  /**
45
90
  * Builds the compat optimize pass for one source file, or `null` when no
46
91
  * compat caller was injected.
@@ -1 +1 @@
1
- {"version":3,"file":"optimizePass.d.ts","names":[],"sources":["../../../src/compat/optimizePass.ts"],"mappings":";;;;;;;;;;;;;;;;;;;YA2BY;;;;;;EAMV,mBAAmB;;EAEnB,aACE,sBACA,sBACA;;EAGF,gBAAgB;;EAEhB;;;;;;EAMA,eAAe,oBAAoB,WAAW;;EAE9C,cAAc,UAAU,WAAW;;EAEnC,0BAA0B,YAAY,WAAW;;;;;;;;;;;qBA4EtC,2BAAwB,mBAChB,YAAU,wBACL,oBAAkB,SACjC,0BAAwB;EAE/B,YAAY;EACZ,oBAAoB,eAAe;MAEpC"}
1
+ {"version":3,"file":"optimizePass.d.ts","names":[],"sources":["../../../src/compat/optimizePass.ts"],"mappings":";;;;;;;;;;;;;;;;;;;YAoCY;;;;;;EAMV,mBAAmB;;EAEnB,aACE,sBACA,sBACA;;EAGF,gBAAgB;;;;;;;EAOhB,yBAAyB,yBAAyB;;EAElD;;;;;;;EAOA;;;;;;;EAOA,uBACE,MACI,WAAW,iBACX,WAAW,2BACX,WAAW;;;;;;EAOjB,cAAc,MAAM;;;;;;;;;;;;EAYpB,eACE,oBAAoB,WAAW,kBAC/B,oBAAoB,eACpB,mBAAmB;;EAGrB,cAAc,UAAU,WAAW;;;;;EAKnC,iBAAiB,MAAM;;EAEvB,0BAA0B,YAAY,WAAW;;;;;;;;YASvC,cACR,WAAW,oBACX,WAAW;;;;;;;;;;qBAqJF,2BAAwB,mBAChB,YAAU,wBACL,oBAAkB,SACjC,0BAAwB;EAE/B,YAAY;EACZ,oBAAoB,eAAe;MAEpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/babel",
3
- "version": "9.5.1",
3
+ "version": "9.5.3",
4
4
  "private": false,
5
5
  "description": "A Babel plugin for Intlayer that transforms declaration files and provides internationalization features during the build process according to the Intlayer configuration.",
6
6
  "keywords": [
@@ -89,19 +89,19 @@
89
89
  "@babel/plugin-syntax-jsx": "8.0.1",
90
90
  "@babel/traverse": "8.0.4",
91
91
  "@babel/types": "8.0.4",
92
- "@intlayer/config": "9.5.1",
93
- "@intlayer/core": "9.5.1",
94
- "@intlayer/dictionaries-entry": "9.5.1",
95
- "@intlayer/engine": "9.5.1",
96
- "@intlayer/types": "9.5.1",
97
- "@intlayer/unmerged-dictionaries-entry": "9.5.1"
92
+ "@intlayer/config": "9.5.3",
93
+ "@intlayer/core": "9.5.3",
94
+ "@intlayer/dictionaries-entry": "9.5.3",
95
+ "@intlayer/engine": "9.5.3",
96
+ "@intlayer/types": "9.5.3",
97
+ "@intlayer/unmerged-dictionaries-entry": "9.5.3"
98
98
  },
99
99
  "devDependencies": {
100
100
  "@babel/plugin-syntax-jsx": "8.0.1",
101
101
  "@types/babel__core": "7.20.5",
102
102
  "@types/babel__generator": "7.27.0",
103
103
  "@types/babel__traverse": "7.28.0",
104
- "@types/node": "26.5.0",
104
+ "@types/node": "^22",
105
105
  "@utils/ts-config": "1.0.4",
106
106
  "@utils/ts-config-types": "1.0.4",
107
107
  "@utils/tsdown-config": "1.0.4",
@@ -112,8 +112,8 @@
112
112
  "vitest": "5.0.0"
113
113
  },
114
114
  "peerDependencies": {
115
- "@intlayer/svelte-compiler": "9.5.1",
116
- "@intlayer/vue-compiler": "9.5.1"
115
+ "@intlayer/svelte-compiler": "9.5.3",
116
+ "@intlayer/vue-compiler": "9.5.3"
117
117
  },
118
118
  "peerDependenciesMeta": {
119
119
  "@intlayer/svelte-compiler": {