@fluentic/i18n 0.0.0-stage → 0.1.0-beta.1
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.
- package/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/adapter-CWC8rng-.d.ts +178 -0
- package/dist/adapter.d.ts +4 -0
- package/dist/adapter.js +4 -0
- package/dist/analyze-CdXCxQDg.d.ts +14 -0
- package/dist/compact-CJ0OWoIv.d.ts +7 -0
- package/dist/compact-E3zj3Z8d.js +34 -0
- package/dist/compact-E3zj3Z8d.js.map +1 -0
- package/dist/compiled.d.ts +27 -0
- package/dist/compiled.js +51 -0
- package/dist/compiled.js.map +1 -0
- package/dist/compiler-BZtB9WLi.js +365 -0
- package/dist/compiler-BZtB9WLi.js.map +1 -0
- package/dist/compiler.d.ts +35 -0
- package/dist/compiler.js +3 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +4 -0
- package/dist/i18n-CfYNwubL.d.ts +25 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/interpreter-Dld8QyOI.js +186 -0
- package/dist/interpreter-Dld8QyOI.js.map +1 -0
- package/dist/manager-BW778X1Y.js +193 -0
- package/dist/manager-BW778X1Y.js.map +1 -0
- package/dist/options-DE7vYj0e.d.ts +7 -0
- package/dist/options-Dxxx0aOz.js +23 -0
- package/dist/options-Dxxx0aOz.js.map +1 -0
- package/dist/plugin/babel.d.ts +11 -0
- package/dist/plugin/babel.js +31 -0
- package/dist/plugin/babel.js.map +1 -0
- package/dist/plugin/esbuild.d.ts +7 -0
- package/dist/plugin/esbuild.js +37 -0
- package/dist/plugin/esbuild.js.map +1 -0
- package/dist/plugin/rollup.d.ts +30 -0
- package/dist/plugin/rollup.js +34 -0
- package/dist/plugin/rollup.js.map +1 -0
- package/dist/plugin/vite.d.ts +31 -0
- package/dist/plugin/vite.js +11 -0
- package/dist/plugin/vite.js.map +1 -0
- package/dist/plugin/webpack-loader.d.ts +3 -0
- package/dist/plugin/webpack-loader.js +21 -0
- package/dist/plugin/webpack-loader.js.map +1 -0
- package/dist/plugin/webpack.d.ts +8 -0
- package/dist/plugin/webpack.js +22 -0
- package/dist/plugin/webpack.js.map +1 -0
- package/dist/react.d.ts +53 -0
- package/dist/react.js +60 -0
- package/dist/react.js.map +1 -0
- package/dist/src-BovRx-mX.js +142 -0
- package/dist/src-BovRx-mX.js.map +1 -0
- package/dist/translation-manager-C79eKu2K.js +213 -0
- package/dist/translation-manager-C79eKu2K.js.map +1 -0
- package/dist/types-BkDsJfVD.js +13 -0
- package/dist/types-BkDsJfVD.js.map +1 -0
- package/dist/types-BuGoCU3P.d.ts +75 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist-cjs/babel.cjs +379 -0
- package/dist-cjs/babel.cjs.map +1 -0
- package/package.json +130 -3
- package/src/adapter.ts +6 -0
- package/src/compiled.ts +116 -0
- package/src/compiler/analyze.ts +182 -0
- package/src/compiler/index.ts +208 -0
- package/src/compiler/message.ts +74 -0
- package/src/core/format.ts +40 -0
- package/src/core/i18n.ts +124 -0
- package/src/core/index.ts +1 -0
- package/src/core/types.ts +121 -0
- package/src/index.ts +9 -0
- package/src/manager.ts +175 -0
- package/src/plugin/babel.ts +34 -0
- package/src/plugin/esbuild.ts +45 -0
- package/src/plugin/options.ts +24 -0
- package/src/plugin/rollup.ts +29 -0
- package/src/plugin/vite.ts +6 -0
- package/src/plugin/webpack-loader.ts +22 -0
- package/src/plugin/webpack.ts +15 -0
- package/src/react.ts +97 -0
- package/src/registry-manager.ts +3 -0
- package/src/shared/compact.ts +51 -0
- package/src/shared/formatting.ts +121 -0
- package/src/shared/interpreter.ts +128 -0
- package/src/shared/runtime.ts +131 -0
- package/src/state-manager.ts +29 -0
- package/src/state.ts +20 -0
- package/src/storage-manager.ts +47 -0
- package/src/translation-manager.ts +82 -0
- package/src/translation.ts +106 -0
- package/src/types.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-manager-C79eKu2K.js","names":[],"sources":["../src/shared/runtime.ts","../src/translation.ts","../src/translation-manager.ts"],"sourcesContent":["import type { MessageFormatOptions, MessageTagHandler, TranslationGetter } from '../core/types';\n\nexport type Formats = {\n number: Record<string, Intl.NumberFormatOptions>;\n date: Record<string, Intl.DateTimeFormatOptions>;\n time: Record<string, Intl.DateTimeFormatOptions>;\n};\n\nexport type FormatContext = { languageId: string; };\nexport type FormatFactory<T> = T | ((context: FormatContext) => T);\nexport type RegistryConfig = { [K in keyof Formats]: Record<string, FormatFactory<Formats[K][string]>>; };\nexport type PartsRenderer = (runtime?: Runtime) => unknown[];\n\nexport type Runtime = {\n languageId: string;\n ready: boolean;\n translationsEnabled: boolean;\n translationGetter: TranslationGetter | null;\n formats: Partial<Formats>;\n registry: RegistryConfig;\n jsxLineBreak: unknown;\n jsxHandler: ((options: MessageFormatOptions, render: PartsRenderer) => unknown) | null;\n tagElement: ((element: unknown) => (chunks: unknown[]) => unknown) | null;\n subscribe: (listener: () => void) => () => void;\n getSnapshot: () => unknown;\n};\n\nexport function createRuntime(): Runtime {\n return {\n languageId: 'en',\n ready: false,\n translationsEnabled: true,\n translationGetter: null,\n formats: {},\n registry: { number: {}, date: {}, time: {} },\n jsxLineBreak: '\\n',\n jsxHandler: null,\n tagElement: null,\n subscribe: () => () => {},\n getSnapshot: () => null,\n };\n}\n\nexport const defaultRuntime = createRuntime();\nlet resolver = () => defaultRuntime;\n\nexport function setRuntimeResolver(next: () => Runtime): void {\n resolver = next;\n}\n\nexport function getRuntime(): Runtime {\n return resolver();\n}\n\nexport function setTranslationGetter(getter: TranslationGetter | null): void {\n getRuntime().translationGetter = getter;\n}\n\nexport function setLanguageId(languageId: string): void {\n getRuntime().languageId = languageId;\n}\n\nexport function setFormats(formats: Partial<Formats>): void {\n getRuntime().formats = formats;\n}\n\nexport function setGetJsxHandler(handler: Runtime['jsxHandler']): void {\n getRuntime().jsxHandler = handler;\n}\n\nexport const I18nRegistry = {\n addNumberFormat(name: string, format: FormatFactory<Intl.NumberFormatOptions>) {\n getRuntime().registry.number[name] = format;\n },\n addDateFormat(name: string, format: FormatFactory<Intl.DateTimeFormatOptions>) {\n getRuntime().registry.date[name] = format;\n },\n addTimeFormat(name: string, format: FormatFactory<Intl.DateTimeFormatOptions>) {\n getRuntime().registry.time[name] = format;\n },\n setLanguageId,\n getConfig(): RegistryConfig {\n const r = getRuntime().registry;\n\n return { number: { ...r.number }, date: { ...r.date }, time: { ...r.time } };\n },\n};\n\nexport function getFormats(runtime: Runtime, languageId: string): Partial<Formats> {\n const resolve = <T>(entries: Record<string, FormatFactory<T>>) =>\n Object.fromEntries(\n Object.entries(entries).map((\n [key, value],\n ) => [key, typeof value === 'function' ? (value as (context: FormatContext) => T)({ languageId }) : value]),\n );\n\n return {\n number: { ...runtime.formats.number, ...resolve(runtime.registry.number) },\n date: { ...runtime.formats.date, ...resolve(runtime.registry.date) },\n time: { ...runtime.formats.time, ...resolve(runtime.registry.time) },\n };\n}\n\nexport function noTranslate<T>(fn: () => T): T {\n const runtime = getRuntime();\n const previous = runtime.translationsEnabled;\n runtime.translationsEnabled = false;\n\n try {\n return fn();\n } finally {\n runtime.translationsEnabled = previous;\n }\n}\n\nexport function createTagHandler<T, R>(handler: (chunks: Array<string | T>) => R): MessageTagHandler<T, R> {\n Object.defineProperty(handler, '__fluenticTagHandler', { value: true });\n\n return handler as MessageTagHandler<T, R>;\n}\n/** Synchronous binding only: async callers must keep and use their own instance. */\nexport function withRuntime<T>(runtime: Runtime, fn: () => T): T {\n const previous = resolver;\n resolver = () => runtime;\n\n try {\n return fn();\n } finally {\n resolver = previous;\n }\n}\n","import { type CompactMessage, validateCompact } from './shared/compact';\n\nexport type TranslationItem = { id: string; translation: string; };\nexport type TranslationRow = [id: string, translation: string] | [context: string, id: string, translation: string];\nexport type CompiledTranslationItem = [id: string, message: CompactMessage];\nexport type CompiledCatalogHeader = { compiled: true; };\nexport type TranslationJsonl = string;\n\nexport type TranslationData =\n | unknown[]\n | TranslationJsonl\n | { jsonl: TranslationJsonl; };\n\nexport type Catalog = Record<string, CompactMessage>;\n\ntype TranslationItemRaw = {\n id?: string;\n source?: string;\n context?: string;\n message?: string | [string, string];\n translation?: string;\n};\n\nexport function normalizeCatalog(data: TranslationData): Catalog {\n return parseCatalog(data).catalog;\n}\n\nexport function parseCatalog(data: TranslationData): { catalog: Catalog; compiled: boolean; } {\n const catalog: Catalog = Object.create(null);\n const rows = parseRows(data);\n const header = rows[0];\n const hasHeader = isCompiledHeader(header);\n const compiled = hasHeader ||\n (Array.isArray(data) && rows.some((row) => Array.isArray(row) && row.length === 2 && Array.isArray(row[1])));\n\n if (hasHeader) rows.shift();\n if (Array.isArray(data) && rows.at(-1) === null) rows.pop();\n\n for (const row of rows) {\n if (Array.isArray(row)) {\n const [id, message] = compiled ? parseCompiledRow(row) : parseTranslationRow(row, Array.isArray(data));\n\n if (compiled || message !== '') catalog[id] = message;\n } else {\n if (compiled) throw new TypeError('[i18n] invalid compiled catalog row');\n\n const item = parseTranslationItem(row);\n\n if (item.translation !== '') catalog[item.id] = item.translation;\n }\n }\n\n return { catalog, compiled };\n}\n\nfunction parseRows(data: TranslationData): unknown[] {\n if (Array.isArray(data)) return [...data];\n\n const jsonl = typeof data === 'string' ? data : data.jsonl;\n\n return jsonl.split(/\\r?\\n/).filter((line) => line.trim()).map((line) => JSON.parse(line));\n}\n\nfunction isCompiledHeader(row: unknown): row is CompiledCatalogHeader {\n return typeof row === 'object' && row !== null && !Array.isArray(row) &&\n 'compiled' in row && row.compiled === true;\n}\n\nfunction parseCompiledRow(row: unknown[]): CompiledTranslationItem {\n if (row.length !== 2 || typeof row[0] !== 'string') {\n throw new TypeError('[i18n] invalid compiled catalog row');\n }\n\n validateCompact(row[1]);\n\n return [row[0], row[1]];\n}\n\nfunction parseTranslationRow(row: unknown[], allowCompact: boolean): [string, CompactMessage] {\n if (row.length === 2 && typeof row[0] === 'string') {\n // Programmatic compileCatalog() results can be passed directly as arrays.\n if (allowCompact) validateCompact(row[1]);\n else if (typeof row[1] !== 'string') throw new TypeError('[i18n] invalid translation row');\n\n return [row[0], row[1]];\n }\n if (row.length === 3 && row.every((value) => typeof value === 'string')) {\n return [`${row[0]}\\0${row[1]}`, row[2] as string];\n }\n\n throw new TypeError('[i18n] invalid translation row');\n}\n\nfunction parseTranslationItem(row: unknown): TranslationItem {\n const item = row as TranslationItemRaw;\n\n if (!item || typeof item.translation !== 'string') throw new TypeError('[i18n] invalid translation item');\n\n const source = item.source ?? (Array.isArray(item.message) ? item.message[1] : item.message);\n const context = Array.isArray(item.message) ? item.message[0] : item.context;\n const id = item.id ?? (source === undefined ? undefined : context ? `${context}\\0${source}` : source);\n\n if (typeof id !== 'string') throw new TypeError('[i18n] translation id is missing');\n\n return { id, translation: item.translation };\n}\n","import type { LanguageId, MessageContext } from './core/types';\nimport { type Catalog, parseCatalog, type TranslationData } from './translation';\n\nexport type * from './translation';\nexport { normalizeCatalog } from './translation';\n\nexport type TranslationLoaderArgs = { languageId: LanguageId; };\nexport type TranslationLookupArgs = { languageId: LanguageId; context: MessageContext | null; message: string; };\nexport type TranslationLoader = (args: TranslationLoaderArgs) => TranslationData | Promise<TranslationData>;\nexport type TranslationModule = { default: TranslationData; };\nexport type TranslationSource = TranslationData | TranslationModule;\n\nexport type TranslationLoaderEntry =\n | TranslationSource\n | Promise<TranslationSource>\n | (() => TranslationSource | Promise<TranslationSource>);\n\nexport type TranslationLoaderMap = Record<string, TranslationLoaderEntry>;\n\nexport function defineTranslationLoader(loader: TranslationLoader | TranslationLoaderMap): TranslationLoader {\n if (typeof loader === 'function') return loader;\n\n return async ({ languageId }) => {\n if (!Object.prototype.hasOwnProperty.call(loader, languageId)) return [];\n\n const entry = loader[languageId];\n const source = await (typeof entry === 'function' ? entry() : entry);\n\n return typeof source === 'object' && source !== null && 'default' in source\n ? source.default\n : source as TranslationData;\n };\n}\n\nexport function createTranslationManager() {\n const catalogs: Record<string, Catalog> = Object.create(null);\n const pending = new Map<string, Promise<void>>();\n const compiledCatalogs: Record<string, boolean> = Object.create(null);\n\n let loader: TranslationLoader | null = null;\n let generation = 0;\n\n const setTranslationLoader = (next: TranslationLoader | null) => {\n loader = next;\n generation++;\n pending.clear();\n\n for (const key of Object.keys(catalogs)) delete catalogs[key];\n for (const key of Object.keys(compiledCatalogs)) delete compiledCatalogs[key];\n };\n\n const loadTranslations = async (languageId: string) => {\n if (!loader || Object.prototype.hasOwnProperty.call(catalogs, languageId)) return;\n if (pending.has(languageId)) return pending.get(languageId);\n\n const version = generation;\n const currentLoader = loader;\n\n const task = Promise.resolve().then(() => currentLoader({ languageId })).then((data) => {\n if (version === generation) {\n const result = parseCatalog(data);\n catalogs[languageId] = result.catalog;\n compiledCatalogs[languageId] = result.compiled;\n }\n }).finally(() => {\n if (version === generation) pending.delete(languageId);\n });\n\n pending.set(languageId, task);\n\n return task;\n };\n\n const getTranslation = (args: TranslationLookupArgs) => {\n const catalog = catalogs[args.languageId];\n const id = args.context ? `${args.context}\\0${args.message}` : args.message;\n\n return catalog?.[id] ?? catalog?.[args.message] ?? null;\n };\n\n return { catalogs, compiledCatalogs, setTranslationLoader, loadTranslations, getTranslation };\n}\n"],"mappings":";;AA2BA,SAAgB,gBAAyB;CACvC,OAAO;EACL,YAAY;EACZ,OAAO;EACP,qBAAqB;EACrB,mBAAmB;EACnB,SAAS,CAAC;EACV,UAAU;GAAE,QAAQ,CAAC;GAAG,MAAM,CAAC;GAAG,MAAM,CAAC;EAAE;EAC3C,cAAc;EACd,YAAY;EACZ,YAAY;EACZ,uBAAuB,CAAC;EACxB,mBAAmB;CACrB;AACF;AAEA,MAAa,iBAAiB,cAAc;AAC5C,IAAI,iBAAiB;AAErB,SAAgB,mBAAmB,MAA2B;CAC5D,WAAW;AACb;AAEA,SAAgB,aAAsB;CACpC,OAAO,SAAS;AAClB;AAEA,SAAgB,qBAAqB,QAAwC;CAC3E,WAAW,C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AAc,OAAO;GACxC;EACF,CAAC,CAAC,CAAC,cAAc;GACf,IAAI,YAAY,YAAY,QAAQ,OAAO,UAAU;EACvD,CAAC;EAED,QAAQ,IAAI,YAAY,IAAI;EAE5B,OAAO;CACT;CAEA,MAAM,kBAAkB,SAAgC;EACtD,MAAM,UAAU,SAAS,KAAK;EAC9B,MAAM,KAAK,KAAK,UAAU,GAAG,KAAK,QAAQ,IAAI,KAAK,YAAY,KAAK;EAEpE,OAAO,UAAU,OAAO,UAAU,KAAK,YAAY;CACrD;CAEA,OAAO;EAAE;EAAU;EAAkB;EAAsB;EAAkB;CAAe;AAC9F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/core/types.ts
|
|
2
|
+
function isMessageDescriptor(value) {
|
|
3
|
+
return value !== null && typeof value === "object" && "__fluenticMessage" in value && value.__fluenticMessage === true;
|
|
4
|
+
}
|
|
5
|
+
function isMessageTagHandler(value) {
|
|
6
|
+
return typeof value === "function" && "__fluenticTagHandler" in value && value.__fluenticTagHandler === true;
|
|
7
|
+
}
|
|
8
|
+
function isMessageSchemaValue(value) {
|
|
9
|
+
return value === String || value === Number || value === Boolean || value === Date;
|
|
10
|
+
}
|
|
11
|
+
export { isMessageSchemaValue as n, isMessageTagHandler as r, isMessageDescriptor as t };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=types-BkDsJfVD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-BkDsJfVD.js","names":[],"sources":["../src/core/types.ts"],"sourcesContent":["import type { CompactMessage } from '../shared/compact';\nimport type { I18nJsxConfig } from '../types';\n\nexport type { I18nJsxConfig } from '../types';\n\nexport type I18nJsxOutput = I18nJsxConfig extends { JSX: infer Output; } ? NonNullable<Output> : unknown;\nexport type I18nTagElement = I18nJsxConfig extends { Element: infer Element; } ? Element : never;\nexport type I18nTagValue = I18nJsxConfig extends { Value: infer Value; } ? Value : unknown;\nexport type PrimitiveType = string | number | boolean | null | undefined;\n\nexport type LanguageId = string;\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; };\nexport type MessageMeta = JsonValue;\nexport type MessageContext = string;\n\nexport type MessageSchemaValue = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;\nexport type MessageSchema = Partial<Record<string, MessageSchemaValue>>;\n\nexport type InferMessageSchema<Schema extends MessageSchema> = {\n [Key in keyof Schema]: Schema[Key] extends StringConstructor ? string\n : Schema[Key] extends NumberConstructor ? number\n : Schema[Key] extends BooleanConstructor ? boolean\n : Schema[Key] extends DateConstructor ? Date\n : never;\n};\n\nexport type MessageDescriptor<Text extends string = string, Schema extends MessageSchema | undefined = MessageSchema> =\n {\n readonly __fluenticMessage: true;\n readonly text: Text;\n readonly compiled?: readonly [string, CompactMessage];\n readonly context: MessageContext | null;\n readonly schema: Schema extends MessageSchema ? Schema : MessageSchema;\n readonly notes: readonly string[];\n readonly meta: MessageMeta | undefined;\n };\n\nexport type AnyMessageDescriptor = MessageDescriptor<string, MessageSchema | undefined>;\n\nexport type MessageValueContext = { languageId: LanguageId; };\nexport type MessageValueFactory<T = unknown> = (context: MessageValueContext) => T;\n\nexport type MessageTagHandler<T = unknown, R = unknown> = ((chunks: Array<string | T>) => R) & {\n readonly __fluenticTagHandler: true;\n};\n\nexport type MessageRuntimeValue =\n | PrimitiveType\n | Date\n | AnyMessageDescriptor\n | MessageValueFactory\n | Pick<MessageTagHandler, '__fluenticTagHandler'>;\n\nexport type MessageParam = MessageRuntimeValue;\nexport type MessageParams = Record<string, MessageParam>;\nexport type MessageInput = string | AnyMessageDescriptor;\n\nexport type InferRuntimeParams<Schema extends MessageSchema> = {\n [Key in keyof InferMessageSchema<Schema>]:\n | InferMessageSchema<Schema>[Key]\n | MessageValueFactory<InferMessageSchema<Schema>[Key]>;\n};\n\nexport type DescriptorRenderArgs<Schema extends MessageSchema | undefined> = Schema extends undefined\n ? [params?: MessageParams]\n : keyof Schema extends never ? []\n : Schema extends MessageSchema ? [params: InferRuntimeParams<Schema>]\n : never;\n\nexport type TryRenderArgs<Value> = Value extends { readonly __fluenticMessage: true; }\n ? Value extends MessageDescriptor<string, infer Schema>\n ? Schema extends MessageSchema | undefined ? DescriptorRenderArgs<Schema>\n : [params: MessageParams]\n : [params: MessageParams]\n : [params?: MessageParams];\n\nexport type TextRenderer = {\n <Text extends string>(message: Text, params?: MessageParams): string;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): string;\n};\n\nexport type JsxRenderer<Output = unknown> = {\n <Text extends string>(message: Text, params?: MessageParams): Output;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): Output;\n};\n\nexport type MessageFormatOptions = {\n msg: MessageInput;\n params?: MessageParams;\n languageId?: LanguageId;\n};\n\nexport type GetJsxHandler<Output = unknown> = (options: MessageFormatOptions) => Output;\n\nexport type CompiledTranslation = { compiled: CompactMessage; };\n\nexport type TranslationGetter = (args: {\n languageId: LanguageId;\n context: MessageContext | null;\n message: string;\n getCompiledId?: () => string;\n}) => CompactMessage | CompiledTranslation | null;\n\nexport function isMessageDescriptor(value: unknown): value is AnyMessageDescriptor {\n return value !== null && typeof value === 'object' && '__fluenticMessage' in value &&\n value.__fluenticMessage === true;\n}\n\nexport function isMessageTagHandler(value: unknown): value is MessageTagHandler {\n return typeof value === 'function' && '__fluenticTagHandler' in value && value.__fluenticTagHandler === true;\n}\n\nexport function isMessageSchemaValue(value: unknown): value is MessageSchemaValue {\n return value === String || value === Number || value === Boolean || value === Date;\n}\n"],"mappings":";AA6GA,SAAgB,oBAAoB,OAA+C;CACjF,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,uBAAuB,SAC3E,MAAM,sBAAsB;AAChC;AAEA,SAAgB,oBAAoB,OAA4C;CAC9E,OAAO,OAAO,UAAU,cAAc,0BAA0B,SAAS,MAAM,yBAAyB;AAC1G;AAEA,SAAgB,qBAAqB,OAA6C;CAChF,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,WAAW,UAAU;AAChF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { n as CompactMessage } from "./compact-CJ0OWoIv.js";
|
|
2
|
+
interface I18nJsxConfig {}
|
|
3
|
+
type I18nJsxOutput = I18nJsxConfig extends {
|
|
4
|
+
JSX: infer Output;
|
|
5
|
+
} ? NonNullable<Output> : unknown;
|
|
6
|
+
type I18nTagElement = I18nJsxConfig extends {
|
|
7
|
+
Element: infer Element;
|
|
8
|
+
} ? Element : never;
|
|
9
|
+
type I18nTagValue = I18nJsxConfig extends {
|
|
10
|
+
Value: infer Value;
|
|
11
|
+
} ? Value : unknown;
|
|
12
|
+
type PrimitiveType = string | number | boolean | null | undefined;
|
|
13
|
+
type LanguageId = string;
|
|
14
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
15
|
+
[key: string]: JsonValue;
|
|
16
|
+
};
|
|
17
|
+
type MessageMeta = JsonValue;
|
|
18
|
+
type MessageContext = string;
|
|
19
|
+
type MessageSchemaValue = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;
|
|
20
|
+
type MessageSchema = Partial<Record<string, MessageSchemaValue>>;
|
|
21
|
+
type InferMessageSchema<Schema extends MessageSchema> = { [Key in keyof Schema]: Schema[Key] extends StringConstructor ? string : Schema[Key] extends NumberConstructor ? number : Schema[Key] extends BooleanConstructor ? boolean : Schema[Key] extends DateConstructor ? Date : never; };
|
|
22
|
+
type MessageDescriptor<Text extends string = string, Schema extends MessageSchema | undefined = MessageSchema> = {
|
|
23
|
+
readonly __fluenticMessage: true;
|
|
24
|
+
readonly text: Text;
|
|
25
|
+
readonly compiled?: readonly [string, CompactMessage];
|
|
26
|
+
readonly context: MessageContext | null;
|
|
27
|
+
readonly schema: Schema extends MessageSchema ? Schema : MessageSchema;
|
|
28
|
+
readonly notes: readonly string[];
|
|
29
|
+
readonly meta: MessageMeta | undefined;
|
|
30
|
+
};
|
|
31
|
+
type AnyMessageDescriptor = MessageDescriptor<string, MessageSchema | undefined>;
|
|
32
|
+
type MessageValueContext = {
|
|
33
|
+
languageId: LanguageId;
|
|
34
|
+
};
|
|
35
|
+
type MessageValueFactory<T = unknown> = (context: MessageValueContext) => T;
|
|
36
|
+
type MessageTagHandler<T = unknown, R = unknown> = ((chunks: Array<string | T>) => R) & {
|
|
37
|
+
readonly __fluenticTagHandler: true;
|
|
38
|
+
};
|
|
39
|
+
type MessageRuntimeValue = PrimitiveType | Date | AnyMessageDescriptor | MessageValueFactory | Pick<MessageTagHandler, '__fluenticTagHandler'>;
|
|
40
|
+
type MessageParam = MessageRuntimeValue;
|
|
41
|
+
type MessageParams = Record<string, MessageParam>;
|
|
42
|
+
type MessageInput = string | AnyMessageDescriptor;
|
|
43
|
+
type InferRuntimeParams<Schema extends MessageSchema> = { [Key in keyof InferMessageSchema<Schema>]: InferMessageSchema<Schema>[Key] | MessageValueFactory<InferMessageSchema<Schema>[Key]>; };
|
|
44
|
+
type DescriptorRenderArgs<Schema extends MessageSchema | undefined> = Schema extends undefined ? [params?: MessageParams] : keyof Schema extends never ? [] : Schema extends MessageSchema ? [params: InferRuntimeParams<Schema>] : never;
|
|
45
|
+
type TryRenderArgs<Value> = Value extends {
|
|
46
|
+
readonly __fluenticMessage: true;
|
|
47
|
+
} ? Value extends MessageDescriptor<string, infer Schema> ? Schema extends MessageSchema | undefined ? DescriptorRenderArgs<Schema> : [params: MessageParams] : [params: MessageParams] : [params?: MessageParams];
|
|
48
|
+
type TextRenderer = {
|
|
49
|
+
<Text extends string>(message: Text, params?: MessageParams): string;
|
|
50
|
+
<Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): string;
|
|
51
|
+
};
|
|
52
|
+
type JsxRenderer<Output = unknown> = {
|
|
53
|
+
<Text extends string>(message: Text, params?: MessageParams): Output;
|
|
54
|
+
<Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): Output;
|
|
55
|
+
};
|
|
56
|
+
type MessageFormatOptions = {
|
|
57
|
+
msg: MessageInput;
|
|
58
|
+
params?: MessageParams;
|
|
59
|
+
languageId?: LanguageId;
|
|
60
|
+
};
|
|
61
|
+
type GetJsxHandler<Output = unknown> = (options: MessageFormatOptions) => Output;
|
|
62
|
+
type CompiledTranslation = {
|
|
63
|
+
compiled: CompactMessage;
|
|
64
|
+
};
|
|
65
|
+
type TranslationGetter = (args: {
|
|
66
|
+
languageId: LanguageId;
|
|
67
|
+
context: MessageContext | null;
|
|
68
|
+
message: string;
|
|
69
|
+
getCompiledId?: () => string;
|
|
70
|
+
}) => CompactMessage | CompiledTranslation | null;
|
|
71
|
+
declare function isMessageDescriptor(value: unknown): value is AnyMessageDescriptor;
|
|
72
|
+
declare function isMessageTagHandler(value: unknown): value is MessageTagHandler;
|
|
73
|
+
declare function isMessageSchemaValue(value: unknown): value is MessageSchemaValue;
|
|
74
|
+
export { isMessageDescriptor as A, MessageTagHandler as C, TextRenderer as D, PrimitiveType as E, isMessageTagHandler as M, I18nJsxConfig as N, TranslationGetter as O, MessageSchemaValue as S, MessageValueFactory as T, MessageMeta as _, I18nJsxOutput as a, MessageRuntimeValue as b, InferMessageSchema as c, JsxRenderer as d, LanguageId as f, MessageInput as g, MessageFormatOptions as h, GetJsxHandler as i, isMessageSchemaValue as j, TryRenderArgs as k, InferRuntimeParams as l, MessageDescriptor as m, CompiledTranslation as n, I18nTagElement as o, MessageContext as p, DescriptorRenderArgs as r, I18nTagValue as s, AnyMessageDescriptor as t, JsonValue as u, MessageParam as v, MessageValueContext as w, MessageSchema as x, MessageParams as y };
|
|
75
|
+
//# sourceMappingURL=types-BuGoCU3P.d.ts.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { A as isMessageDescriptor, C as MessageTagHandler, D as TextRenderer, E as PrimitiveType, M as isMessageTagHandler, N as I18nJsxConfig, O as TranslationGetter, S as MessageSchemaValue, T as MessageValueFactory, _ as MessageMeta, a as I18nJsxOutput, b as MessageRuntimeValue, c as InferMessageSchema, d as JsxRenderer, f as LanguageId, g as MessageInput, h as MessageFormatOptions, i as GetJsxHandler, j as isMessageSchemaValue, k as TryRenderArgs, l as InferRuntimeParams, m as MessageDescriptor, n as CompiledTranslation, o as I18nTagElement, p as MessageContext, r as DescriptorRenderArgs, s as I18nTagValue, t as AnyMessageDescriptor, u as JsonValue, v as MessageParam, w as MessageValueContext, x as MessageSchema, y as MessageParams } from "./types-BuGoCU3P.js";
|
|
2
|
+
export { AnyMessageDescriptor, CompiledTranslation, DescriptorRenderArgs, GetJsxHandler, I18nJsxConfig, I18nJsxOutput, I18nTagElement, I18nTagValue, InferMessageSchema, InferRuntimeParams, JsonValue, JsxRenderer, LanguageId, MessageContext, MessageDescriptor, MessageFormatOptions, MessageInput, MessageMeta, MessageParam, MessageParams, MessageRuntimeValue, MessageSchema, MessageSchemaValue, MessageTagHandler, MessageValueContext, MessageValueFactory, PrimitiveType, TextRenderer, TranslationGetter, TryRenderArgs, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as isMessageDescriptor, n as isMessageSchemaValue, r as isMessageTagHandler } from "./types-BkDsJfVD.js";
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
let _babel_generator = require("@babel/generator");
|
|
23
|
+
_babel_generator = __toESM(_babel_generator, 1);
|
|
24
|
+
let _babel_types = require("@babel/types");
|
|
25
|
+
_babel_types = __toESM(_babel_types, 1);
|
|
26
|
+
let _babel_parser = require("@babel/parser");
|
|
27
|
+
let _babel_traverse = require("@babel/traverse");
|
|
28
|
+
_babel_traverse = __toESM(_babel_traverse, 1);
|
|
29
|
+
let _formatjs_icu_messageformat_parser = require("@formatjs/icu-messageformat-parser");
|
|
30
|
+
let node_crypto = require("node:crypto");
|
|
31
|
+
let jiti = require("jiti");
|
|
32
|
+
let node_fs = require("node:fs");
|
|
33
|
+
let node_path = require("node:path");
|
|
34
|
+
// src/compiler/analyze.ts
|
|
35
|
+
const traverse = _babel_traverse.default.default ?? _babel_traverse.default;
|
|
36
|
+
const importMap = {
|
|
37
|
+
"@fluentic/i18n": "@fluentic/i18n/compiled",
|
|
38
|
+
"@fluentic/i18n/core": "@fluentic/i18n/compiled"
|
|
39
|
+
};
|
|
40
|
+
function parseSource(code, filename) {
|
|
41
|
+
return (0, _babel_parser.parse)(code, {
|
|
42
|
+
sourceFilename: filename,
|
|
43
|
+
sourceType: "unambiguous",
|
|
44
|
+
plugins: [
|
|
45
|
+
.../\.[cm]?tsx?$/.test(filename) ? ["typescript"] : [],
|
|
46
|
+
...!/\.[cm]?ts$/.test(filename) ? ["jsx"] : [],
|
|
47
|
+
"decorators-legacy",
|
|
48
|
+
"importAttributes"
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function unwrap(path) {
|
|
53
|
+
while (path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() || path.isTypeCastExpression() || path.isParenthesizedExpression()) path = path.get("expression");
|
|
54
|
+
return path;
|
|
55
|
+
}
|
|
56
|
+
function literal(path, seen = /* @__PURE__ */ new Set()) {
|
|
57
|
+
path = unwrap(path);
|
|
58
|
+
if (path.isStringLiteral()) return path.node.value;
|
|
59
|
+
if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? "";
|
|
60
|
+
if (path.isIdentifier()) {
|
|
61
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
62
|
+
if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {
|
|
63
|
+
seen.add(binding);
|
|
64
|
+
return literal(binding.path.get("init"), seen);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
function memberName(path) {
|
|
70
|
+
if (!path.isMemberExpression()) return null;
|
|
71
|
+
const property = path.get("property");
|
|
72
|
+
return !path.node.computed && property.isIdentifier() ? property.node.name : property.isStringLiteral() ? property.node.value : null;
|
|
73
|
+
}
|
|
74
|
+
function analyzer(imports = Object.keys(importMap)) {
|
|
75
|
+
const memo = /* @__PURE__ */ new Map();
|
|
76
|
+
const scopedBindings = /* @__PURE__ */ new Set();
|
|
77
|
+
const scopeCalls = /* @__PURE__ */ new Set();
|
|
78
|
+
const resolve = (path, visiting = /* @__PURE__ */ new Set()) => {
|
|
79
|
+
path = unwrap(path);
|
|
80
|
+
if (path.isIdentifier()) {
|
|
81
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
82
|
+
if (!binding) return null;
|
|
83
|
+
if (memo.has(binding)) return memo.get(binding);
|
|
84
|
+
if (visiting.has(binding)) throw new Error("[i18n] circular translator alias");
|
|
85
|
+
if (binding.path.isImportSpecifier()) {
|
|
86
|
+
const declaration = binding.path.parentPath;
|
|
87
|
+
const imported = binding.path.node.imported;
|
|
88
|
+
return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) && (_babel_types.isIdentifier(imported) ? imported.name : imported.value) === "t" && declaration.node.importKind !== "type" ? {
|
|
89
|
+
context: null,
|
|
90
|
+
notes: []
|
|
91
|
+
} : null;
|
|
92
|
+
}
|
|
93
|
+
if (binding.path.isVariableDeclarator()) {
|
|
94
|
+
visiting.add(binding);
|
|
95
|
+
const scope = resolve(binding.path.get("init"), visiting);
|
|
96
|
+
visiting.delete(binding);
|
|
97
|
+
if (scope && !binding.constant) throw new Error("[i18n] translator aliases must not be reassigned: " + path.node.name);
|
|
98
|
+
memo.set(binding, scope);
|
|
99
|
+
if (scope) scopedBindings.add(binding);
|
|
100
|
+
return scope;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (path.isMemberExpression() && memberName(path) === "t") {
|
|
105
|
+
const object = path.get("object");
|
|
106
|
+
if (!object.isIdentifier()) return null;
|
|
107
|
+
const binding = object.scope.getBinding(object.node.name);
|
|
108
|
+
const declaration = binding?.path.parentPath;
|
|
109
|
+
if (binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() && imports.includes(declaration.node.source.value)) return {
|
|
110
|
+
context: null,
|
|
111
|
+
notes: []
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (!path.isCallExpression()) return null;
|
|
115
|
+
const callee = path.get("callee");
|
|
116
|
+
const method = memberName(callee);
|
|
117
|
+
if (!method || ![
|
|
118
|
+
"context",
|
|
119
|
+
"note",
|
|
120
|
+
"meta"
|
|
121
|
+
].includes(method)) return null;
|
|
122
|
+
const parent = resolve(callee.get("object"), visiting);
|
|
123
|
+
if (!parent) return null;
|
|
124
|
+
if (path.node.arguments.length !== 1) throw new Error("[i18n] scope methods require one static argument");
|
|
125
|
+
const argument = path.get("arguments.0");
|
|
126
|
+
scopeCalls.add(path);
|
|
127
|
+
if (method === "meta") {
|
|
128
|
+
const evaluated = argument.evaluate();
|
|
129
|
+
if (!evaluated.confident) throw new Error("[i18n] metadata must be statically known");
|
|
130
|
+
return {
|
|
131
|
+
...parent,
|
|
132
|
+
meta: evaluated.value
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const value = literal(argument);
|
|
136
|
+
if (value === null) throw new Error("[i18n] " + method + " must be a static string");
|
|
137
|
+
return method === "note" ? {
|
|
138
|
+
...parent,
|
|
139
|
+
notes: [...parent.notes, value]
|
|
140
|
+
} : {
|
|
141
|
+
...parent,
|
|
142
|
+
context: parent.context ? `${parent.context}.${value}` : value
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
resolve,
|
|
147
|
+
scopedBindings,
|
|
148
|
+
scopeCalls
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// src/compiler/message.ts
|
|
152
|
+
function messageIdentity(context, source) {
|
|
153
|
+
return context ? `${context}\0${source}` : source;
|
|
154
|
+
}
|
|
155
|
+
function messageId(context, source) {
|
|
156
|
+
return (0, node_crypto.createHash)("sha256").update(messageIdentity(context, source)).digest("hex").slice(0, 24);
|
|
157
|
+
}
|
|
158
|
+
function compileMessage(source) {
|
|
159
|
+
const compact = (elements) => {
|
|
160
|
+
const result = elements.map((element) => {
|
|
161
|
+
switch (element.type) {
|
|
162
|
+
case _formatjs_icu_messageformat_parser.TYPE.literal: return element.value;
|
|
163
|
+
case _formatjs_icu_messageformat_parser.TYPE.argument: return [0, element.value];
|
|
164
|
+
case _formatjs_icu_messageformat_parser.TYPE.number:
|
|
165
|
+
case _formatjs_icu_messageformat_parser.TYPE.date:
|
|
166
|
+
case _formatjs_icu_messageformat_parser.TYPE.time: return [
|
|
167
|
+
element.type === _formatjs_icu_messageformat_parser.TYPE.number ? 1 : element.type === _formatjs_icu_messageformat_parser.TYPE.date ? 2 : 3,
|
|
168
|
+
element.value,
|
|
169
|
+
typeof element.style === "object" && element.style ? element.style.parsedOptions : element.style ?? null
|
|
170
|
+
];
|
|
171
|
+
case _formatjs_icu_messageformat_parser.TYPE.select: return [
|
|
172
|
+
4,
|
|
173
|
+
element.value,
|
|
174
|
+
Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
|
|
175
|
+
];
|
|
176
|
+
case _formatjs_icu_messageformat_parser.TYPE.plural: return [
|
|
177
|
+
5,
|
|
178
|
+
element.value,
|
|
179
|
+
element.offset,
|
|
180
|
+
element.pluralType === "ordinal" ? 1 : 0,
|
|
181
|
+
Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
|
|
182
|
+
];
|
|
183
|
+
case _formatjs_icu_messageformat_parser.TYPE.pound: return [6];
|
|
184
|
+
case _formatjs_icu_messageformat_parser.TYPE.tag: return [
|
|
185
|
+
7,
|
|
186
|
+
element.value,
|
|
187
|
+
compact(element.children)
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
return result.every((part) => typeof part === "string") ? result.join("") : result;
|
|
192
|
+
};
|
|
193
|
+
return compact((0, _formatjs_icu_messageformat_parser.parse)(source, { captureLocation: false }));
|
|
194
|
+
}
|
|
195
|
+
_babel_generator.default.default ?? _babel_generator.default;
|
|
196
|
+
function compileProgram(code, filename, options = {}) {
|
|
197
|
+
const ast = parseSource(code, filename);
|
|
198
|
+
const messages = [];
|
|
199
|
+
if (options.compiled === false) return {
|
|
200
|
+
ast,
|
|
201
|
+
messages,
|
|
202
|
+
changed: false
|
|
203
|
+
};
|
|
204
|
+
const analysis = analyzer();
|
|
205
|
+
const plans = [];
|
|
206
|
+
const declarations = [];
|
|
207
|
+
let program;
|
|
208
|
+
traverse(ast, {
|
|
209
|
+
Program(path) {
|
|
210
|
+
program = path;
|
|
211
|
+
},
|
|
212
|
+
ExportAllDeclaration(path) {
|
|
213
|
+
if (importMap[path.node.source.value]) throw new Error("[i18n] do not re-export the translator in compiled mode; import t directly at each use");
|
|
214
|
+
},
|
|
215
|
+
ExportNamedDeclaration(path) {
|
|
216
|
+
if (path.node.source && importMap[path.node.source.value] && path.node.specifiers.some((specifier) => _babel_types.isExportSpecifier(specifier) && (_babel_types.isIdentifier(specifier.local) ? specifier.local.name : "") === "t")) throw new Error("[i18n] do not re-export the translator in compiled mode; export message descriptors instead");
|
|
217
|
+
},
|
|
218
|
+
ImportDeclaration(path) {
|
|
219
|
+
if (importMap[path.node.source.value] && path.node.importKind !== "type") declarations.push(path);
|
|
220
|
+
},
|
|
221
|
+
CallExpression(path) {
|
|
222
|
+
const callee = path.get("callee");
|
|
223
|
+
const method = memberName(callee);
|
|
224
|
+
if (!method || ![
|
|
225
|
+
"msg",
|
|
226
|
+
"jsx",
|
|
227
|
+
"text"
|
|
228
|
+
].includes(method)) return;
|
|
229
|
+
const scope = analysis.resolve(callee.get("object"));
|
|
230
|
+
if (!scope) return;
|
|
231
|
+
const source = literal(path.get("arguments.0"));
|
|
232
|
+
if (source === null && method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
|
|
233
|
+
plans.push({
|
|
234
|
+
path,
|
|
235
|
+
source,
|
|
236
|
+
scope
|
|
237
|
+
});
|
|
238
|
+
if (source !== null) messages.push({
|
|
239
|
+
...scope,
|
|
240
|
+
source,
|
|
241
|
+
id: scope.context ? `${scope.context}\0${source}` : source
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
traverse(ast, {
|
|
246
|
+
VariableDeclarator(path) {
|
|
247
|
+
analysis.resolve(path.get("id"));
|
|
248
|
+
},
|
|
249
|
+
CallExpression(path) {
|
|
250
|
+
const name = memberName(path.get("callee"));
|
|
251
|
+
if (name && [
|
|
252
|
+
"context",
|
|
253
|
+
"note",
|
|
254
|
+
"meta"
|
|
255
|
+
].includes(name)) analysis.resolve(path);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
const expressionUse = (path) => {
|
|
259
|
+
while (path.parentPath && (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() || path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() || path.parentPath.isParenthesizedExpression())) path = path.parentPath;
|
|
260
|
+
return path;
|
|
261
|
+
};
|
|
262
|
+
for (const path of analysis.scopeCalls) {
|
|
263
|
+
const use = expressionUse(path);
|
|
264
|
+
const parent = use.parentPath;
|
|
265
|
+
if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;
|
|
266
|
+
if (parent?.isMemberExpression() && parent.get("object") === use && parent.parentPath?.isCallExpression()) continue;
|
|
267
|
+
throw new Error("[i18n] scoped translator escapes same-file message calls");
|
|
268
|
+
}
|
|
269
|
+
for (const binding of analysis.scopedBindings) {
|
|
270
|
+
if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) throw new Error("[i18n] scoped translators cannot be exported; repeat the context in the consuming file");
|
|
271
|
+
for (const reference of binding.referencePaths) {
|
|
272
|
+
if (reference.findParent((parent) => parent.isTSType())) continue;
|
|
273
|
+
const use = expressionUse(reference);
|
|
274
|
+
const parent = use.parentPath;
|
|
275
|
+
if (parent?.isVariableDeclarator() && parent.get("init") === use) continue;
|
|
276
|
+
if (parent?.isMemberExpression() && parent.get("object") === use) {
|
|
277
|
+
const method = memberName(parent);
|
|
278
|
+
if (method && [
|
|
279
|
+
"msg",
|
|
280
|
+
"text",
|
|
281
|
+
"jsx",
|
|
282
|
+
"context",
|
|
283
|
+
"note",
|
|
284
|
+
"meta"
|
|
285
|
+
].includes(method) && parent.parentPath?.isCallExpression()) continue;
|
|
286
|
+
}
|
|
287
|
+
throw new Error("[i18n] scoped translator escapes same-file message calls: " + binding.identifier.name);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (!declarations.length) return {
|
|
291
|
+
ast,
|
|
292
|
+
messages,
|
|
293
|
+
changed: false
|
|
294
|
+
};
|
|
295
|
+
const helper = program.scope.generateUidIdentifier("tc");
|
|
296
|
+
if (plans.length) program.unshiftContainer("body", _babel_types.importDeclaration([_babel_types.importSpecifier(helper, _babel_types.identifier("t"))], _babel_types.stringLiteral("@fluentic/i18n/compiled")));
|
|
297
|
+
for (const { path, source, scope } of plans) {
|
|
298
|
+
path.get("callee").get("object").replaceWith(_babel_types.cloneNode(helper));
|
|
299
|
+
if (source !== null) {
|
|
300
|
+
const replacement = _babel_types.valueToNode([messageId(scope.context, source), compileMessage(source)]);
|
|
301
|
+
_babel_types.inherits(replacement, path.node.arguments[0]);
|
|
302
|
+
path.node.arguments[0] = replacement;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let removed = true;
|
|
306
|
+
while (removed) {
|
|
307
|
+
removed = false;
|
|
308
|
+
program.scope.crawl();
|
|
309
|
+
for (const binding of analysis.scopedBindings) {
|
|
310
|
+
if (binding.path.removed) continue;
|
|
311
|
+
const current = binding.path.scope.getBinding(binding.identifier.name);
|
|
312
|
+
if (current && !current.referenced) {
|
|
313
|
+
binding.path.remove();
|
|
314
|
+
removed = true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
for (const path of analysis.scopeCalls) if (!path.removed) {
|
|
319
|
+
const use = expressionUse(path);
|
|
320
|
+
if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();
|
|
321
|
+
}
|
|
322
|
+
for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];
|
|
323
|
+
program.scope.crawl();
|
|
324
|
+
for (const declaration of declarations) {
|
|
325
|
+
declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {
|
|
326
|
+
if (!_babel_types.isImportSpecifier(specifier) || (_babel_types.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== "t") return true;
|
|
327
|
+
return Boolean(program.scope.getBinding(specifier.local.name)?.referenced);
|
|
328
|
+
});
|
|
329
|
+
if (!declaration.node.specifiers.length) declaration.remove();
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
ast,
|
|
333
|
+
messages,
|
|
334
|
+
changed: true
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
// src/plugin/options.ts
|
|
338
|
+
function loadOptions(options = {}, root = process.cwd()) {
|
|
339
|
+
const file = options.config ? (0, node_path.resolve)(root, options.config) : [
|
|
340
|
+
"i18n.config.ts",
|
|
341
|
+
"i18n.config.js",
|
|
342
|
+
"i18n.config.mjs"
|
|
343
|
+
].map((name) => (0, node_path.resolve)(root, name)).find(node_fs.existsSync);
|
|
344
|
+
const config = file ? (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, { moduleCache: false })(file) : {};
|
|
345
|
+
return {
|
|
346
|
+
...config.default ?? config,
|
|
347
|
+
...options,
|
|
348
|
+
configFile: file
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
// src/plugin/babel.ts
|
|
352
|
+
/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */
|
|
353
|
+
function fluenticBabel(_api, options = {}) {
|
|
354
|
+
const config = loadOptions(options);
|
|
355
|
+
const handled = /* @__PURE__ */ new WeakSet();
|
|
356
|
+
const enabled = (code) => config.compiled && code.includes("@fluentic/i18n");
|
|
357
|
+
const compile = (code, filename) => {
|
|
358
|
+
const { ast } = compileProgram(code, filename, config);
|
|
359
|
+
traverse.cache.clear();
|
|
360
|
+
handled.add(ast.program);
|
|
361
|
+
return ast;
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
name: "fluentic-i18n",
|
|
365
|
+
parserOverride(code, parserOptions) {
|
|
366
|
+
if (!enabled(code)) return void 0;
|
|
367
|
+
return compile(code, parserOptions.sourceFilename ?? "source.tsx");
|
|
368
|
+
},
|
|
369
|
+
pre(file) {
|
|
370
|
+
if (!enabled(file.code) || handled.has(file.path.node)) return;
|
|
371
|
+
const ast = compile(file.code, file.opts.filename ?? "source.tsx");
|
|
372
|
+
file.path.replaceWith(ast.program);
|
|
373
|
+
file.scope.crawl();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
module.exports = fluenticBabel;
|
|
378
|
+
|
|
379
|
+
//# sourceMappingURL=babel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babel.cjs","names":["traverseModule","parse","b","createHash","TYPE","parse","generatorModule","b","resolve","existsSync","createJiti"],"sources":["../src/compiler/analyze.ts","../src/compiler/message.ts","../src/compiler/index.ts","../src/plugin/options.ts","../src/plugin/babel.ts"],"sourcesContent":["import { parse } from '@babel/parser';\nimport * as traverseModule from '@babel/traverse';\nimport type { Binding, NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\n\nconst traverse = ((traverseModule.default as unknown as { default?: typeof traverseModule.default; }).default ??\n traverseModule.default) as typeof traverseModule.default;\nexport { traverse };\n\nexport const importMap: Record<string, string> = {\n '@fluentic/i18n': '@fluentic/i18n/compiled',\n '@fluentic/i18n/core': '@fluentic/i18n/compiled',\n};\nexport type Scope = { context: string | null; notes: string[]; meta?: unknown; };\nexport type ExtractedMessage = Scope & { id: string; source: string; };\n\nexport function parseSource(code: string, filename: string) {\n return parse(code, {\n sourceFilename: filename,\n sourceType: 'unambiguous',\n plugins: [\n ...(/\\.[cm]?tsx?$/.test(filename) ? ['typescript' as const] : []),\n ...(!/\\.[cm]?ts$/.test(filename) ? ['jsx' as const] : []),\n 'decorators-legacy',\n 'importAttributes',\n ],\n });\n}\n\nexport function unwrap(path: NodePath): NodePath {\n while (\n path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() ||\n path.isTypeCastExpression() || path.isParenthesizedExpression()\n ) path = path.get('expression') as NodePath;\n\n return path;\n}\n\nexport function literal(path: NodePath, seen = new Set<Binding>()): string | null {\n path = unwrap(path);\n if (path.isStringLiteral()) return path.node.value;\n if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? '';\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {\n seen.add(binding);\n\n return literal(binding.path.get('init') as NodePath, seen);\n }\n }\n\n return null;\n}\n\nexport function memberName(path: NodePath): string | null {\n if (!path.isMemberExpression()) return null;\n\n const property = path.get('property');\n\n return !path.node.computed && property.isIdentifier()\n ? property.node.name\n : property.isStringLiteral()\n ? property.node.value\n : null;\n}\n\nexport function analyzer(imports = Object.keys(importMap)) {\n const memo = new Map<Binding, Scope | null>();\n const scopedBindings = new Set<Binding>();\n const scopeCalls = new Set<NodePath>();\n\n const resolve = (path: NodePath, visiting = new Set<Binding>()): Scope | null => {\n path = unwrap(path);\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (!binding) return null;\n if (memo.has(binding)) return memo.get(binding)!;\n if (visiting.has(binding)) throw new Error('[i18n] circular translator alias');\n if (binding.path.isImportSpecifier()) {\n const declaration = binding.path.parentPath;\n const imported = binding.path.node.imported;\n\n return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) &&\n (b.isIdentifier(imported) ? imported.name : imported.value) === 't' &&\n declaration.node.importKind !== 'type'\n ? { context: null, notes: [] }\n : null;\n }\n if (binding.path.isVariableDeclarator()) {\n visiting.add(binding);\n const scope = resolve(binding.path.get('init') as NodePath, visiting);\n visiting.delete(binding);\n if (scope && !binding.constant) {\n throw new Error('[i18n] translator aliases must not be reassigned: ' + path.node.name);\n }\n memo.set(binding, scope);\n if (scope) scopedBindings.add(binding);\n\n return scope;\n }\n\n return null;\n }\n if (path.isMemberExpression() && memberName(path) === 't') {\n const object = path.get('object');\n\n if (!object.isIdentifier()) return null;\n\n const binding = object.scope.getBinding(object.node.name);\n const declaration = binding?.path.parentPath;\n\n if (\n binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() &&\n imports.includes(declaration.node.source.value)\n ) return { context: null, notes: [] };\n }\n if (!path.isCallExpression()) return null;\n\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['context', 'note', 'meta'].includes(method)) return null;\n\n const parent = resolve((callee as NodePath<b.MemberExpression>).get('object'), visiting);\n\n if (!parent) return null;\n if (path.node.arguments.length !== 1) throw new Error('[i18n] scope methods require one static argument');\n\n const argument = path.get('arguments.0') as NodePath;\n scopeCalls.add(path);\n if (method === 'meta') {\n const evaluated = argument.evaluate();\n\n if (!evaluated.confident) throw new Error('[i18n] metadata must be statically known');\n\n return { ...parent, meta: evaluated.value };\n }\n\n const value = literal(argument);\n\n if (value === null) throw new Error('[i18n] ' + method + ' must be a static string');\n\n return method === 'note'\n ? { ...parent, notes: [...parent.notes, value] }\n : { ...parent, context: parent.context ? `${parent.context}.${value}` : value };\n };\n\n return { resolve, scopedBindings, scopeCalls };\n}\n\nexport function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[] {\n const ast = parseSource(code, filename);\n const { resolve } = analyzer(imports);\n const messages: ExtractedMessage[] = [];\n traverse(ast, {\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'text', 'jsx'].includes(method)) return;\n\n const scope = resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null) {\n if (method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n\n return;\n }\n messages.push({ ...scope, id: scope.context ? `${scope.context}\\0${source}` : source, source });\n },\n });\n\n return [...new Map(messages.map((message) => [message.id, message])).values()];\n}\n","import { type MessageFormatElement, parse, TYPE } from '@formatjs/icu-messageformat-parser';\nimport { createHash } from 'node:crypto';\nimport type { CompactMessage, CompactPart } from '../shared/compact';\n\nexport { COMPACT_VERSION } from '../shared/compact';\n\nexport function messageIdentity(context: string | null, source: string): string {\n return context ? `${context}\\0${source}` : source;\n}\n\nexport function messageId(context: string | null, source: string): string {\n return createHash('sha256').update(messageIdentity(context, source)).digest('hex').slice(0, 24);\n}\n\nexport function compileMessage(source: string): CompactMessage {\n const compact = (elements: MessageFormatElement[]): CompactMessage => {\n const result: CompactPart[] = elements.map((element): CompactPart => {\n switch (element.type) {\n case TYPE.literal:\n return element.value;\n case TYPE.argument:\n return [0, element.value];\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n return [\n element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,\n element.value,\n typeof element.style === 'object' && element.style\n ? element.style.parsedOptions as Record<string, unknown>\n : element.style ?? null,\n ];\n case TYPE.select:\n return [\n 4,\n element.value,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.plural:\n return [\n 5,\n element.value,\n element.offset,\n element.pluralType === 'ordinal' ? 1 : 0,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.pound:\n return [6];\n case TYPE.tag:\n return [7, element.value, compact(element.children)];\n }\n });\n\n return result.every((part) => typeof part === 'string') ? result.join('') : result;\n };\n\n return compact(parse(source, { captureLocation: false }));\n}\n\nexport function compileCatalog(\n records: Array<{ source: string; context: string | null; translation: string; }>,\n): Array<[string, CompactMessage]> {\n const seen = new Map<string, string>();\n\n return records.flatMap((record) => {\n const id = messageId(record.context, record.source);\n const identity = messageIdentity(record.context, record.source);\n\n if (seen.has(id) && seen.get(id) !== identity) throw new Error('[i18n] message hash collision: ' + id);\n seen.set(id, identity);\n\n return record.translation === '' ? [] : [[id, compileMessage(record.translation)] as [string, CompactMessage]];\n });\n}\n","import * as generatorModule from '@babel/generator';\nimport type { NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\nimport {\n analyzer,\n collectMessages,\n type ExtractedMessage,\n importMap,\n literal,\n memberName,\n parseSource,\n traverse,\n} from './analyze';\nimport { compileMessage, messageId } from './message';\n\nexport { collectMessages } from './analyze';\nexport * from './message';\n\nconst generate = ((generatorModule.default as unknown as { default?: typeof generatorModule.default; }).default ??\n generatorModule.default) as typeof generatorModule.default;\nexport type CompilerOptions = { compiled?: boolean; filename?: string; };\n\nexport function compileProgram(code: string, filename: string, options: CompilerOptions = {}) {\n const ast = parseSource(code, filename);\n const messages: ExtractedMessage[] = [];\n\n if (options.compiled === false) return { ast, messages, changed: false };\n\n const analysis = analyzer();\n\n const plans: Array<\n {\n path: NodePath<b.CallExpression>;\n source: string | null;\n scope: NonNullable<ReturnType<typeof analysis.resolve>>;\n }\n > = [];\n const declarations: NodePath<b.ImportDeclaration>[] = [];\n\n let program: NodePath<b.Program> | undefined;\n traverse(ast, {\n Program(path) {\n program = path;\n },\n ExportAllDeclaration(path) {\n if (importMap[path.node.source.value]) {\n throw new Error('[i18n] do not re-export the translator in compiled mode; import t directly at each use');\n }\n },\n ExportNamedDeclaration(path) {\n if (\n path.node.source && importMap[path.node.source.value] &&\n path.node.specifiers.some((specifier) =>\n b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : '') === 't'\n )\n ) throw new Error('[i18n] do not re-export the translator in compiled mode; export message descriptors instead');\n },\n ImportDeclaration(path) {\n if (importMap[path.node.source.value] && path.node.importKind !== 'type') declarations.push(path);\n },\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'jsx', 'text'].includes(method)) return;\n\n const scope = analysis.resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null && method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n plans.push({ path, source, scope });\n if (source !== null) {\n messages.push({ ...scope, source, id: scope.context ? `${scope.context}\\0${source}` : source });\n }\n },\n });\n // Discover unused/escaping scopes as well as scopes reached by message calls.\n traverse(ast, {\n VariableDeclarator(path) {\n analysis.resolve(path.get('id') as NodePath);\n },\n CallExpression(path) {\n const name = memberName(path.get('callee'));\n\n if (name && ['context', 'note', 'meta'].includes(name)) analysis.resolve(path);\n },\n });\n const expressionUse = (path: NodePath): NodePath => {\n while (\n path.parentPath &&\n (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() ||\n path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() ||\n path.parentPath.isParenthesizedExpression())\n ) path = path.parentPath;\n\n return path;\n };\n\n for (const path of analysis.scopeCalls) {\n const use = expressionUse(path);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use && parent.parentPath?.isCallExpression()) continue;\n throw new Error('[i18n] scoped translator escapes same-file message calls');\n }\n for (const binding of analysis.scopedBindings) {\n if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) {\n throw new Error('[i18n] scoped translators cannot be exported; repeat the context in the consuming file');\n }\n\n for (const reference of binding.referencePaths) {\n if (reference.findParent((parent) => parent.isTSType())) continue;\n\n const use = expressionUse(reference);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() && parent.get('init') === use) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use) {\n const method = memberName(parent);\n\n if (\n method && ['msg', 'text', 'jsx', 'context', 'note', 'meta'].includes(method) &&\n parent.parentPath?.isCallExpression()\n ) continue;\n }\n throw new Error('[i18n] scoped translator escapes same-file message calls: ' + binding.identifier.name);\n }\n }\n if (!declarations.length) return { ast, messages, changed: false };\n\n const helper = program!.scope.generateUidIdentifier('tc');\n\n if (plans.length) {\n program!.unshiftContainer(\n 'body',\n b.importDeclaration([b.importSpecifier(helper, b.identifier('t'))], b.stringLiteral('@fluentic/i18n/compiled')),\n );\n }\n\n for (const { path, source, scope } of plans) {\n const callee = path.get('callee') as NodePath<b.MemberExpression>;\n callee.get('object').replaceWith(b.cloneNode(helper));\n if (source !== null) {\n const replacement = b.valueToNode([messageId(scope.context, source), compileMessage(source)]);\n b.inherits(replacement, path.node.arguments[0]);\n path.node.arguments[0] = replacement;\n }\n }\n // All scope uses were checked before mutation. Remove aliases from leaves to roots.\n let removed = true;\n\n while (removed) {\n removed = false;\n program!.scope.crawl();\n\n for (const binding of analysis.scopedBindings) {\n if (binding.path.removed) continue;\n\n const current = binding.path.scope.getBinding(binding.identifier.name);\n\n if (current && !current.referenced) {\n binding.path.remove();\n removed = true;\n }\n }\n }\n\n for (const path of analysis.scopeCalls) {\n if (!path.removed) {\n const use = expressionUse(path);\n\n if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();\n }\n }\n for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];\n program!.scope.crawl();\n\n for (const declaration of declarations) {\n declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {\n if (\n !b.isImportSpecifier(specifier) ||\n (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== 't'\n ) return true;\n\n return Boolean(program!.scope.getBinding(specifier.local.name)?.referenced);\n });\n if (!declaration.node.specifiers.length) declaration.remove();\n }\n\n return { ast, messages, changed: true };\n}\n\nexport function transform(code: string, options: CompilerOptions = {}) {\n const filename = options.filename ?? 'source.tsx';\n const result = compileProgram(code, filename, options);\n\n if (!result.changed) return null;\n\n const output = generate(result.ast, { sourceMaps: true, sourceFileName: filename, comments: true }, code);\n\n return { code: output.code, map: output.map, messages: result.messages };\n}\n","import { createJiti } from 'jiti';\nimport { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nexport type PluginOptions = { compiled?: boolean; config?: string; includeDependencies?: boolean; };\n\nexport function loadOptions(\n options: PluginOptions = {},\n root = process.cwd(),\n): PluginOptions & { configFile?: string; } {\n const file = options.config\n ? resolve(root, options.config)\n : ['i18n.config.ts', 'i18n.config.js', 'i18n.config.mjs'].map((name) => resolve(root, name)).find(existsSync);\n\n const config = file\n ? createJiti(import.meta.url, { moduleCache: false })(file) as { default?: PluginOptions; } & PluginOptions\n : {};\n\n return { ...((config.default ?? config) as PluginOptions), ...options, configFile: file };\n}\n\nexport function accepts(id: string, options: PluginOptions) {\n return /\\.[cm]?[jt]sx?$/.test(id.split('?')[0]) && (options.includeDependencies || !id.includes('/node_modules/'));\n}\n","import { compileProgram } from '../compiler';\nimport { traverse } from '../compiler/analyze';\nimport { loadOptions, type PluginOptions } from './options';\n/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */\nexport default function fluenticBabel(_api: unknown, options: PluginOptions = {}) {\n const config = loadOptions(options);\n const handled = new WeakSet<object>();\n const enabled = (code: string) => config.compiled && code.includes('@fluentic/i18n');\n\n const compile = (code: string, filename: string) => {\n const { ast } = compileProgram(code, filename, config);\n // Standalone paths have a default Hub. Babel must create its own paths for presets.\n traverse.cache.clear();\n handled.add(ast.program);\n\n return ast;\n };\n\n return {\n name: 'fluentic-i18n',\n parserOverride(code: string, parserOptions: { sourceFilename?: string; }) {\n if (!enabled(code)) return undefined;\n\n return compile(code, parserOptions.sourceFilename ?? 'source.tsx');\n },\n pre(file: any) {\n if (!enabled(file.code) || handled.has(file.path.node)) return;\n\n const ast = compile(file.code, file.opts.filename ?? 'source.tsx');\n file.path.replaceWith(ast.program);\n file.scope.crawl();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,WAAaA,gBAAe,QAAoE,WACpGA,gBAAe;AAGjB,MAAa,YAAoC;CAC/C,kBAAkB;CAClB,uBAAuB;AACzB;AAIA,SAAgB,YAAY,MAAc,UAAkB;CAC1D,QAAA,GAAOC,cAAAA,MAAAA,CAAM,MAAM;EACjB,gBAAgB;EAChB,YAAY;EACZ,SAAS;GACP,GAAI,eAAe,KAAK,QAAQ,IAAI,CAAC,YAAqB,IAAI,CAAC;GAC/D,GAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,CAAC,KAAc,IAAI,CAAC;GACvD;GACA;EACF;CACF,CAAC;AACH;AAEA,SAAgB,OAAO,MAA0B;CA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