@fluenti/cli 0.5.0 → 0.6.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/dist/cli/src/ai-provider.d.ts.map +1 -0
- package/dist/{catalog.d.ts → cli/src/catalog.d.ts} +1 -1
- package/dist/cli/src/catalog.d.ts.map +1 -0
- package/dist/cli/src/check.d.ts.map +1 -0
- package/dist/cli/src/cli.d.ts.map +1 -0
- package/dist/cli/src/codemod.d.ts +19 -0
- package/dist/cli/src/codemod.d.ts.map +1 -0
- package/dist/cli/src/compile-cache.d.ts.map +1 -0
- package/dist/cli/src/compile-runner.d.ts.map +1 -0
- package/dist/cli/src/compile-worker.d.ts.map +1 -0
- package/dist/cli/src/compile.d.ts.map +1 -0
- package/dist/cli/src/config-loader.d.ts.map +1 -0
- package/dist/{config.d.ts → cli/src/config.d.ts} +1 -1
- package/dist/cli/src/config.d.ts.map +1 -0
- package/dist/cli/src/doctor.d.ts +19 -0
- package/dist/cli/src/doctor.d.ts.map +1 -0
- package/dist/{extract-cache.d.ts → cli/src/extract-cache.d.ts} +1 -1
- package/dist/cli/src/extract-cache.d.ts.map +1 -0
- package/dist/cli/src/extract-runner.d.ts.map +1 -0
- package/dist/cli/src/glossary.d.ts.map +1 -0
- package/dist/{index.d.ts → cli/src/index.d.ts} +6 -2
- package/dist/cli/src/index.d.ts.map +1 -0
- package/dist/cli/src/init.d.ts.map +1 -0
- package/dist/cli/src/json-format.d.ts.map +1 -0
- package/dist/cli/src/lint.d.ts.map +1 -0
- package/dist/cli/src/migrate.d.ts.map +1 -0
- package/dist/cli/src/parallel-compile.d.ts.map +1 -0
- package/dist/cli/src/po-format.d.ts.map +1 -0
- package/dist/cli/src/stats-format.d.ts.map +1 -0
- package/dist/cli/src/translate-parse.d.ts.map +1 -0
- package/dist/cli/src/translate-prompt.d.ts.map +1 -0
- package/dist/cli/src/translate.d.ts.map +1 -0
- package/dist/{tsx-extractor.d.ts → cli/src/tsx-extractor.d.ts} +1 -1
- package/dist/cli/src/tsx-extractor.d.ts.map +1 -0
- package/dist/cli/src/validation.d.ts.map +1 -0
- package/dist/{vue-extractor.d.ts → cli/src/vue-extractor.d.ts} +1 -1
- package/dist/cli/src/vue-extractor.d.ts.map +1 -0
- package/dist/cli.cjs +10 -22
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +333 -406
- package/dist/cli.js.map +1 -1
- package/dist/compile-C3VLvhUf.cjs +8 -0
- package/dist/{compile-kXClO6q4.cjs.map → compile-C3VLvhUf.cjs.map} +1 -1
- package/dist/{compile-CdA4EZ-p.js → compile-CZVpE5Md.js} +2 -2
- package/dist/{compile-CdA4EZ-p.js.map → compile-CZVpE5Md.js.map} +1 -1
- package/dist/compile-worker.cjs +1 -1
- package/dist/compile-worker.cjs.map +1 -1
- package/dist/compile-worker.js +1 -1
- package/dist/doctor-BqXXxyST.js +670 -0
- package/dist/doctor-BqXXxyST.js.map +1 -0
- package/dist/doctor-xp8WS8sr.cjs +24 -0
- package/dist/doctor-xp8WS8sr.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -64
- package/dist/index.js.map +1 -1
- package/dist/tsx-extractor-AOjsbOmp.cjs +2 -0
- package/dist/{tsx-extractor-B0vFXziu.cjs.map → tsx-extractor-AOjsbOmp.cjs.map} +1 -1
- package/dist/tsx-extractor-C-HZNobu.js.map +1 -1
- package/dist/vue-extractor.cjs +1 -1
- package/dist/vue-extractor.cjs.map +1 -1
- package/dist/vue-extractor.js.map +1 -1
- package/package.json +2 -2
- package/dist/ai-provider.d.ts.map +0 -1
- package/dist/catalog.d.ts.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/compile-cache.d.ts.map +0 -1
- package/dist/compile-kXClO6q4.cjs +0 -8
- package/dist/compile-runner.d.ts.map +0 -1
- package/dist/compile-worker.d.ts.map +0 -1
- package/dist/compile.d.ts.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/extract-cache-BioSaoFo.cjs +0 -10
- package/dist/extract-cache-BioSaoFo.cjs.map +0 -1
- package/dist/extract-cache-C-MI1_ll.js +0 -325
- package/dist/extract-cache-C-MI1_ll.js.map +0 -1
- package/dist/extract-cache.d.ts.map +0 -1
- package/dist/extract-runner.d.ts.map +0 -1
- package/dist/glossary.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/json-format.d.ts.map +0 -1
- package/dist/lint.d.ts.map +0 -1
- package/dist/migrate.d.ts.map +0 -1
- package/dist/parallel-compile.d.ts.map +0 -1
- package/dist/po-format.d.ts.map +0 -1
- package/dist/stats-format.d.ts.map +0 -1
- package/dist/translate-parse.d.ts.map +0 -1
- package/dist/translate-prompt.d.ts.map +0 -1
- package/dist/translate.d.ts.map +0 -1
- package/dist/tsx-extractor-B0vFXziu.cjs +0 -2
- package/dist/tsx-extractor.d.ts.map +0 -1
- package/dist/validation.d.ts.map +0 -1
- package/dist/vue-extractor.d.ts.map +0 -1
- /package/dist/{ai-provider.d.ts → cli/src/ai-provider.d.ts} +0 -0
- /package/dist/{check.d.ts → cli/src/check.d.ts} +0 -0
- /package/dist/{cli.d.ts → cli/src/cli.d.ts} +0 -0
- /package/dist/{compile-cache.d.ts → cli/src/compile-cache.d.ts} +0 -0
- /package/dist/{compile-runner.d.ts → cli/src/compile-runner.d.ts} +0 -0
- /package/dist/{compile-worker.d.ts → cli/src/compile-worker.d.ts} +0 -0
- /package/dist/{compile.d.ts → cli/src/compile.d.ts} +0 -0
- /package/dist/{config-loader.d.ts → cli/src/config-loader.d.ts} +0 -0
- /package/dist/{extract-runner.d.ts → cli/src/extract-runner.d.ts} +0 -0
- /package/dist/{glossary.d.ts → cli/src/glossary.d.ts} +0 -0
- /package/dist/{init.d.ts → cli/src/init.d.ts} +0 -0
- /package/dist/{json-format.d.ts → cli/src/json-format.d.ts} +0 -0
- /package/dist/{lint.d.ts → cli/src/lint.d.ts} +0 -0
- /package/dist/{migrate.d.ts → cli/src/migrate.d.ts} +0 -0
- /package/dist/{parallel-compile.d.ts → cli/src/parallel-compile.d.ts} +0 -0
- /package/dist/{po-format.d.ts → cli/src/po-format.d.ts} +0 -0
- /package/dist/{stats-format.d.ts → cli/src/stats-format.d.ts} +0 -0
- /package/dist/{translate-parse.d.ts → cli/src/translate-parse.d.ts} +0 -0
- /package/dist/{translate-prompt.d.ts → cli/src/translate-prompt.d.ts} +0 -0
- /package/dist/{translate.d.ts → cli/src/translate.d.ts} +0 -0
- /package/dist/{validation.d.ts → cli/src/validation.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { i as e, n as t, r as n, t as r } from "./compile-
|
|
1
|
+
import { i as e, n as t, r as n, t as r } from "./compile-CZVpE5Md.js";
|
|
2
2
|
import { t as i } from "./tsx-extractor-C-HZNobu.js";
|
|
3
|
-
import { a, c as o,
|
|
4
|
-
import { createPluginRunner as
|
|
5
|
-
import { existsSync as
|
|
6
|
-
import { dirname as
|
|
7
|
-
import
|
|
8
|
-
import { createHash as
|
|
3
|
+
import { a, c as o, d as s, f as c, i as l, l as u, n as d, o as f, p, s as m, t as h, u as g } from "./doctor-BqXXxyST.js";
|
|
4
|
+
import { createPluginRunner as _, hashMessage as v, resolveLocaleCodes as y } from "@fluenti/core/compiler";
|
|
5
|
+
import { existsSync as b, mkdirSync as x, readFileSync as S, writeFileSync as C } from "node:fs";
|
|
6
|
+
import { dirname as w, extname as T, resolve as E } from "node:path";
|
|
7
|
+
import D from "fast-glob";
|
|
8
|
+
import { createHash as O } from "node:crypto";
|
|
9
9
|
//#region src/config.ts
|
|
10
|
-
function
|
|
10
|
+
function k(e) {
|
|
11
11
|
return e;
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/compile-runner.ts
|
|
15
|
-
function
|
|
16
|
-
if (!
|
|
17
|
-
let n =
|
|
18
|
-
return t === "json" ?
|
|
15
|
+
function A(e, t) {
|
|
16
|
+
if (!b(e)) return {};
|
|
17
|
+
let n = S(e, "utf-8");
|
|
18
|
+
return t === "json" ? s(n) : u(n);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function j(e) {
|
|
21
21
|
let t = {};
|
|
22
22
|
for (let [n, r] of Object.entries(e)) r.obsolete || (t[n] = r.translation ?? r.message ?? n);
|
|
23
23
|
return t;
|
|
24
24
|
}
|
|
25
|
-
async function
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
for (let e of
|
|
30
|
-
let
|
|
31
|
-
for (let e of
|
|
25
|
+
async function M(i, a) {
|
|
26
|
+
let s = await o(void 0, i), c = y(s.locales), l = s.format === "json" ? ".json" : ".po", u = E(i, s.compileOutDir);
|
|
27
|
+
x(u, { recursive: !0 });
|
|
28
|
+
let d = s.plugins?.length ? _(s.plugins) : void 0, f = {};
|
|
29
|
+
for (let e of c) f[e] = A(E(i, s.catalogDir, `${e}${l}`), s.format);
|
|
30
|
+
let p = r(f);
|
|
31
|
+
for (let e of c) if (d) {
|
|
32
32
|
let t = {
|
|
33
33
|
locale: e,
|
|
34
|
-
messages:
|
|
35
|
-
outDir:
|
|
36
|
-
config:
|
|
34
|
+
messages: j(f[e]),
|
|
35
|
+
outDir: u,
|
|
36
|
+
config: s
|
|
37
37
|
};
|
|
38
|
-
await
|
|
38
|
+
await d.runBeforeCompile(t);
|
|
39
39
|
}
|
|
40
|
-
if (a?.parallel &&
|
|
41
|
-
let e = await c
|
|
40
|
+
if (a?.parallel && c.length > 1) {
|
|
41
|
+
let e = await m(c.map((e) => ({
|
|
42
42
|
locale: e,
|
|
43
|
-
catalog:
|
|
44
|
-
allIds:
|
|
45
|
-
sourceLocale:
|
|
43
|
+
catalog: f[e],
|
|
44
|
+
allIds: p,
|
|
45
|
+
sourceLocale: s.sourceLocale
|
|
46
46
|
})));
|
|
47
|
-
for (let t of e)
|
|
48
|
-
} else for (let e of
|
|
49
|
-
let { code: n } = t(
|
|
50
|
-
|
|
47
|
+
for (let t of e) C(E(u, `${t.locale}.js`), t.code, "utf-8");
|
|
48
|
+
} else for (let e of c) {
|
|
49
|
+
let { code: n } = t(f[e], e, p, s.sourceLocale);
|
|
50
|
+
C(E(u, `${e}.js`), n, "utf-8");
|
|
51
51
|
}
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
for (let e of
|
|
52
|
+
let h = n(c, s.compileOutDir);
|
|
53
|
+
C(E(u, "index.js"), h, "utf-8");
|
|
54
|
+
let g = e(p, f, s.sourceLocale);
|
|
55
|
+
C(E(u, "messages.d.ts"), g, "utf-8");
|
|
56
|
+
for (let e of c) if (d) {
|
|
57
57
|
let t = {
|
|
58
58
|
locale: e,
|
|
59
|
-
messages:
|
|
60
|
-
outDir:
|
|
61
|
-
config:
|
|
59
|
+
messages: j(f[e]),
|
|
60
|
+
outDir: u,
|
|
61
|
+
config: s
|
|
62
62
|
};
|
|
63
|
-
await
|
|
63
|
+
await d.runAfterCompile(t);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
//#endregion
|
|
67
67
|
//#region src/extract-runner.ts
|
|
68
|
-
function
|
|
69
|
-
return
|
|
68
|
+
function N(e) {
|
|
69
|
+
return O("md5").update(e).digest("hex").slice(0, 8);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
if (!
|
|
73
|
-
let n =
|
|
74
|
-
return t === "json" ?
|
|
71
|
+
function P(e, t) {
|
|
72
|
+
if (!b(e)) return {};
|
|
73
|
+
let n = S(e, "utf-8");
|
|
74
|
+
return t === "json" ? s(n) : u(n);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
let r = n === "json" ?
|
|
76
|
+
function F(e, t, n) {
|
|
77
|
+
let r = n === "json" ? c(t) : g(t);
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
x(w(e), { recursive: !0 }), C(e, r, "utf-8");
|
|
80
80
|
} catch (t) {
|
|
81
81
|
let n = t instanceof Error ? t.message : String(t);
|
|
82
82
|
throw Error(`Failed to write catalog "${e}": ${n}`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
async function
|
|
86
|
-
if (
|
|
85
|
+
async function I(e, t) {
|
|
86
|
+
if (T(e) === ".vue") try {
|
|
87
87
|
let { extractFromVue: n } = await import("./vue-extractor.js");
|
|
88
88
|
return n(t, e);
|
|
89
89
|
} catch {
|
|
@@ -91,14 +91,14 @@ async function M(e, t) {
|
|
|
91
91
|
}
|
|
92
92
|
return i(t, e);
|
|
93
93
|
}
|
|
94
|
-
async function
|
|
95
|
-
let n = await
|
|
94
|
+
async function L(e, t) {
|
|
95
|
+
let n = await o(void 0, e), r = y(n.locales), i = await D(n.include, {
|
|
96
96
|
cwd: e,
|
|
97
97
|
ignore: n.exclude ?? [],
|
|
98
98
|
absolute: !1
|
|
99
|
-
}), a = [], s = t?.useCache === !1 ? null : new f(
|
|
99
|
+
}), a = [], s = t?.useCache === !1 ? null : new f(E(e, n.catalogDir), N(e));
|
|
100
100
|
for (let t of i) {
|
|
101
|
-
let n =
|
|
101
|
+
let n = E(e, t);
|
|
102
102
|
if (s) {
|
|
103
103
|
let e = s.get(n);
|
|
104
104
|
if (e) {
|
|
@@ -106,11 +106,11 @@ async function N(e, t) {
|
|
|
106
106
|
continue;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
let r = await
|
|
109
|
+
let r = await I(n, S(n, "utf-8"));
|
|
110
110
|
a.push(...r), s && s.set(n, r);
|
|
111
111
|
}
|
|
112
|
-
s && (s.prune(new Set(i.map((t) =>
|
|
113
|
-
let c = n.plugins?.length ?
|
|
112
|
+
s && (s.prune(new Set(i.map((t) => E(e, t)))), s.save());
|
|
113
|
+
let c = n.plugins?.length ? _(n.plugins) : void 0;
|
|
114
114
|
if (c) {
|
|
115
115
|
let e = /* @__PURE__ */ new Map();
|
|
116
116
|
for (let t of a) e.set(t.id, t);
|
|
@@ -122,13 +122,13 @@ async function N(e, t) {
|
|
|
122
122
|
};
|
|
123
123
|
await c.runAfterExtract(t);
|
|
124
124
|
}
|
|
125
|
-
let l = n.format === "json" ? ".json" : ".po",
|
|
125
|
+
let l = n.format === "json" ? ".json" : ".po", u = t?.clean ?? !1, d = t?.stripFuzzy ?? !1;
|
|
126
126
|
for (let t of r) {
|
|
127
|
-
let r =
|
|
128
|
-
|
|
127
|
+
let r = E(e, n.catalogDir, `${t}${l}`), { catalog: i } = p(P(r, n.format), a, { stripFuzzy: d });
|
|
128
|
+
F(r, u ? Object.fromEntries(Object.entries(i).filter(([, e]) => !e.obsolete)) : i, n.format);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
//#endregion
|
|
132
|
-
export { r as collectAllIds, t as compileCatalog, n as compileIndex,
|
|
132
|
+
export { r as collectAllIds, t as compileCatalog, n as compileIndex, k as defineConfig, i as extractFromTsx, h as formatDoctorReport, v as hashMessage, o as loadConfig, s as readJsonCatalog, u as readPoCatalog, l as rewriteFluentiImports, a as runCodemod, M as runCompile, d as runDoctor, L as runExtract, p as updateCatalog, c as writeJsonCatalog, g as writePoCatalog };
|
|
133
133
|
|
|
134
134
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/config.ts","../src/compile-runner.ts","../src/extract-runner.ts"],"sourcesContent":["import type { FluentiBuildConfig } from '@fluenti/core/internal'\n\n/**\n * Define a Fluenti configuration with full type inference and IDE autocompletion.\n *\n * @example\n * ```ts\n * // fluenti.config.ts\n * import { defineConfig } from '@fluenti/cli'\n *\n * export default defineConfig({\n * sourceLocale: 'en',\n * locales: ['en', 'ja', 'zh-CN'],\n * catalogDir: './locales',\n * format: 'po',\n * include: ['./src/**\\/*.{vue,tsx,ts}'],\n * compileOutDir: './src/locales/compiled',\n * })\n * ```\n */\nexport function defineConfig(config: Partial<FluentiBuildConfig>): Partial<FluentiBuildConfig> {\n return config\n}\n","import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginCompileContext } from '@fluenti/core/internal'\nimport { loadConfig } from './config-loader'\nimport { compileCatalog, compileIndex, collectAllIds, compileTypeDeclaration } from './compile'\nimport { parallelCompile } from './parallel-compile'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog } from './json-format'\nimport { readPoCatalog } from './po-format'\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\n/** Build a messages record (id → translation or message) from catalog data */\nfunction catalogToMessages(catalog: CatalogData): Record<string, string> {\n const messages: Record<string, string> = {}\n for (const [id, entry] of Object.entries(catalog)) {\n if (entry.obsolete) continue\n const text = entry.translation ?? entry.message ?? id\n messages[id] = text\n }\n return messages\n}\n\nexport interface RunCompileOptions {\n parallel?: boolean\n}\n\n/**\n * Programmatic compile entry point.\n * Loads config from `cwd`, reads catalogs, and writes compiled output.\n * This is the in-process equivalent of `fluenti compile`.\n */\nexport async function runCompile(cwd: string, options?: RunCompileOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n const ext = config.format === 'json' ? '.json' : '.po'\n\n const outDir = resolve(cwd, config.compileOutDir)\n mkdirSync(outDir, { recursive: true })\n\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n const allCatalogs: Record<string, CatalogData> = {}\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n allCatalogs[locale] = readCatalog(catalogPath, config.format)\n }\n\n const allIds = collectAllIds(allCatalogs)\n\n // Run plugin hooks around compilation\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runBeforeCompile(compileContext)\n }\n }\n\n if (options?.parallel && localeCodes.length > 1) {\n const tasks = localeCodes.map((locale) => ({\n locale,\n catalog: allCatalogs[locale]!,\n allIds,\n sourceLocale: config.sourceLocale,\n }))\n\n const results = await parallelCompile(tasks)\n\n for (const result of results) {\n writeFileSync(resolve(outDir, `${result.locale}.js`), result.code, 'utf-8')\n }\n } else {\n for (const locale of localeCodes) {\n const { code } = compileCatalog(allCatalogs[locale]!, locale, allIds, config.sourceLocale)\n writeFileSync(resolve(outDir, `${locale}.js`), code, 'utf-8')\n }\n }\n\n const indexCode = compileIndex(localeCodes, config.compileOutDir)\n writeFileSync(resolve(outDir, 'index.js'), indexCode, 'utf-8')\n\n const typesCode = compileTypeDeclaration(allIds, allCatalogs, config.sourceLocale)\n writeFileSync(resolve(outDir, 'messages.d.ts'), typesCode, 'utf-8')\n\n // Run after-compile hooks\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runAfterCompile(compileContext)\n }\n }\n}\n","import fg from 'fast-glob'\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\nimport { resolve, dirname, extname } from 'node:path'\nimport { extractFromTsx } from './tsx-extractor'\nimport { updateCatalog } from './catalog'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog, writeJsonCatalog } from './json-format'\nimport { readPoCatalog, writePoCatalog } from './po-format'\nimport { ExtractCache } from './extract-cache'\nimport { loadConfig } from './config-loader'\nimport type { ExtractedMessage } from '@fluenti/core/internal'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/internal'\nimport type { PluginExtractContext } from '@fluenti/core/internal'\n\nfunction deriveProjectId(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, 8)\n}\n\nexport interface RunExtractOptions {\n clean?: boolean\n stripFuzzy?: boolean\n useCache?: boolean\n}\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\nfunction writeCatalog(filePath: string, catalog: CatalogData, format: 'json' | 'po'): void {\n const content = format === 'json' ? writeJsonCatalog(catalog) : writePoCatalog(catalog)\n try {\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, content, 'utf-8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to write catalog \"${filePath}\": ${message}`)\n }\n}\n\nasync function extractFromFile(filePath: string, code: string): Promise<ExtractedMessage[]> {\n const ext = extname(filePath)\n if (ext === '.vue') {\n try {\n const { extractFromVue } = await import('./vue-extractor')\n return extractFromVue(code, filePath)\n } catch {\n return []\n }\n }\n return extractFromTsx(code, filePath)\n}\n\n/**\n * Programmatic extract entry point.\n * Loads config from `cwd`, extracts messages, and writes catalogs.\n * This is the in-process equivalent of `fluenti extract`.\n */\nexport async function runExtract(cwd: string, options?: RunExtractOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n\n const files = await fg(config.include, { cwd, ignore: config.exclude ?? [], absolute: false })\n const allMessages: ExtractedMessage[] = []\n const useCache = options?.useCache !== false\n const cache = useCache ? new ExtractCache(resolve(cwd, config.catalogDir), deriveProjectId(cwd)) : null\n\n for (const file of files) {\n const absFile = resolve(cwd, file)\n if (cache) {\n const cached = cache.get(absFile)\n if (cached) {\n allMessages.push(...cached)\n continue\n }\n }\n\n const code = readFileSync(absFile, 'utf-8')\n const messages = await extractFromFile(absFile, code)\n allMessages.push(...messages)\n\n if (cache) {\n cache.set(absFile, messages)\n }\n }\n\n if (cache) {\n cache.prune(new Set(files.map((f) => resolve(cwd, f))))\n cache.save()\n }\n\n // Run onAfterExtract plugin hooks\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n if (pluginRunner) {\n const messageMap = new Map<string, ExtractedMessage>()\n for (const msg of allMessages) {\n messageMap.set(msg.id, msg)\n }\n const extractContext: PluginExtractContext = {\n messages: messageMap,\n sourceLocale: config.sourceLocale,\n targetLocales: localeCodes.filter((l) => l !== config.sourceLocale),\n config,\n }\n await pluginRunner.runAfterExtract(extractContext)\n }\n\n const ext = config.format === 'json' ? '.json' : '.po'\n const clean = options?.clean ?? false\n const stripFuzzy = options?.stripFuzzy ?? false\n\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n const existing = readCatalog(catalogPath, config.format)\n const { catalog } = updateCatalog(existing, allMessages, { stripFuzzy })\n\n const finalCatalog = clean\n ? Object.fromEntries(Object.entries(catalog).filter(([, entry]) => !entry.obsolete))\n : catalog\n\n writeCatalog(catalogPath, finalCatalog, config.format)\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,EAAa,GAAkE;AAC7F,QAAO;;;;ACVT,SAAS,EAAY,GAAkB,GAAoC;AACzE,KAAI,CAAC,EAAW,EAAS,CAAE,QAAO,EAAE;CACpC,IAAM,IAAU,EAAa,GAAU,QAAQ;AAC/C,QAAO,MAAW,SAAS,EAAgB,EAAQ,GAAG,EAAc,EAAQ;;AAI9E,SAAS,EAAkB,GAA8C;CACvE,IAAM,IAAmC,EAAE;AAC3C,MAAK,IAAM,CAAC,GAAI,MAAU,OAAO,QAAQ,EAAQ,CAC3C,GAAM,aAEV,EAAS,KADI,EAAM,eAAe,EAAM,WAAW;AAGrD,QAAO;;AAYT,eAAsB,EAAW,GAAa,GAA4C;CACxF,IAAM,IAAS,MAAM,EAAW,KAAA,GAAW,EAAI,EACzC,IAAc,EAAmB,EAAO,QAAQ,EAChD,IAAM,EAAO,WAAW,SAAS,UAAU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C,MAAI,GAAO;GACT,IAAM,IAAS,EAAM,IAAI,EAAQ;AACjC,OAAI,GAAQ;AACV,MAAY,KAAK,GAAG,EAAO;AAC3B;;;EAKJ,IAAM,IAAW,MAAM,EAAgB,GAD1B,EAAa,GAAS,QAAQ,CACU;AAGrD,EAFA,EAAY,KAAK,GAAG,EAAS,EAEzB,KACF,EAAM,IAAI,GAAS,EAAS;;AAIhC,CAAI,MACF,EAAM,MAAM,IAAI,IAAI,EAAM,KAAK,MAAM,EAAQ,GAAK,EAAE,CAAC,CAAC,CAAC,EACvD,EAAM,MAAM;CAId,IAAM,IAAe,EAAO,SAAS,SACjC,EAAmB,EAAO,QAAQ,GAClC,KAAA;AAEJ,KAAI,GAAc;EAChB,IAAM,oBAAa,IAAI,KAA+B;AACtD,OAAK,IAAM,KAAO,EAChB,GAAW,IAAI,EAAI,IAAI,EAAI;EAE7B,IAAM,IAAuC;GAC3C,UAAU;GACV,cAAc,EAAO;GACrB,eAAe,EAAY,QAAQ,MAAM,MAAM,EAAO,aAAa;GACnE;GACD;AACD,QAAM,EAAa,gBAAgB,EAAe;;CAGpD,IAAM,IAAM,EAAO,WAAW,SAAS,UAAU,OAC3C,IAAQ,GAAS,SAAS,IAC1B,IAAa,GAAS,cAAc;AAE1C,MAAK,IAAM,KAAU,GAAa;EAChC,IAAM,IAAc,EAAQ,GAAK,EAAO,YAAY,GAAG,IAAS,IAAM,EAEhE,EAAE,eAAY,EADH,EAAY,GAAa,EAAO,OAAO,EACZ,GAAa,EAAE,eAAY,CAAC;AAMxE,IAAa,GAJQ,IACjB,OAAO,YAAY,OAAO,QAAQ,EAAQ,CAAC,QAAQ,GAAG,OAAW,CAAC,EAAM,SAAS,CAAC,GAClF,GAEoC,EAAO,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/config.ts","../src/compile-runner.ts","../src/extract-runner.ts"],"sourcesContent":["import type { FluentiBuildConfig } from '@fluenti/core/compiler'\n\n/**\n * Define a Fluenti configuration with full type inference and IDE autocompletion.\n *\n * @example\n * ```ts\n * // fluenti.config.ts\n * import { defineConfig } from '@fluenti/cli'\n *\n * export default defineConfig({\n * sourceLocale: 'en',\n * locales: ['en', 'ja', 'zh-CN'],\n * catalogDir: './locales',\n * format: 'po',\n * include: ['./src/**\\/*.{vue,tsx,ts}'],\n * compileOutDir: './src/locales/compiled',\n * })\n * ```\n */\nexport function defineConfig(config: Partial<FluentiBuildConfig>): Partial<FluentiBuildConfig> {\n return config\n}\n","import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/compiler'\nimport type { PluginCompileContext } from '@fluenti/core/compiler'\nimport { loadConfig } from './config-loader'\nimport { compileCatalog, compileIndex, collectAllIds, compileTypeDeclaration } from './compile'\nimport { parallelCompile } from './parallel-compile'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog } from './json-format'\nimport { readPoCatalog } from './po-format'\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\n/** Build a messages record (id → translation or message) from catalog data */\nfunction catalogToMessages(catalog: CatalogData): Record<string, string> {\n const messages: Record<string, string> = {}\n for (const [id, entry] of Object.entries(catalog)) {\n if (entry.obsolete) continue\n const text = entry.translation ?? entry.message ?? id\n messages[id] = text\n }\n return messages\n}\n\nexport interface RunCompileOptions {\n parallel?: boolean\n}\n\n/**\n * Programmatic compile entry point.\n * Loads config from `cwd`, reads catalogs, and writes compiled output.\n * This is the in-process equivalent of `fluenti compile`.\n */\nexport async function runCompile(cwd: string, options?: RunCompileOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n const ext = config.format === 'json' ? '.json' : '.po'\n\n const outDir = resolve(cwd, config.compileOutDir)\n mkdirSync(outDir, { recursive: true })\n\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n const allCatalogs: Record<string, CatalogData> = {}\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n allCatalogs[locale] = readCatalog(catalogPath, config.format)\n }\n\n const allIds = collectAllIds(allCatalogs)\n\n // Run plugin hooks around compilation\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runBeforeCompile(compileContext)\n }\n }\n\n if (options?.parallel && localeCodes.length > 1) {\n const tasks = localeCodes.map((locale) => ({\n locale,\n catalog: allCatalogs[locale]!,\n allIds,\n sourceLocale: config.sourceLocale,\n }))\n\n const results = await parallelCompile(tasks)\n\n for (const result of results) {\n writeFileSync(resolve(outDir, `${result.locale}.js`), result.code, 'utf-8')\n }\n } else {\n for (const locale of localeCodes) {\n const { code } = compileCatalog(allCatalogs[locale]!, locale, allIds, config.sourceLocale)\n writeFileSync(resolve(outDir, `${locale}.js`), code, 'utf-8')\n }\n }\n\n const indexCode = compileIndex(localeCodes, config.compileOutDir)\n writeFileSync(resolve(outDir, 'index.js'), indexCode, 'utf-8')\n\n const typesCode = compileTypeDeclaration(allIds, allCatalogs, config.sourceLocale)\n writeFileSync(resolve(outDir, 'messages.d.ts'), typesCode, 'utf-8')\n\n // Run after-compile hooks\n for (const locale of localeCodes) {\n if (pluginRunner) {\n const compileContext: PluginCompileContext = {\n locale,\n messages: catalogToMessages(allCatalogs[locale]!),\n outDir,\n config,\n }\n await pluginRunner.runAfterCompile(compileContext)\n }\n }\n}\n","import fg from 'fast-glob'\nimport { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\nimport { resolve, dirname, extname } from 'node:path'\nimport { extractFromTsx } from './tsx-extractor'\nimport { updateCatalog } from './catalog'\nimport type { CatalogData } from './catalog'\nimport { readJsonCatalog, writeJsonCatalog } from './json-format'\nimport { readPoCatalog, writePoCatalog } from './po-format'\nimport { ExtractCache } from './extract-cache'\nimport { loadConfig } from './config-loader'\nimport type { ExtractedMessage } from '@fluenti/core/compiler'\nimport { resolveLocaleCodes, createPluginRunner } from '@fluenti/core/compiler'\nimport type { PluginExtractContext } from '@fluenti/core/compiler'\n\nfunction deriveProjectId(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, 8)\n}\n\nexport interface RunExtractOptions {\n clean?: boolean\n stripFuzzy?: boolean\n useCache?: boolean\n}\n\nfunction readCatalog(filePath: string, format: 'json' | 'po'): CatalogData {\n if (!existsSync(filePath)) return {}\n const content = readFileSync(filePath, 'utf-8')\n return format === 'json' ? readJsonCatalog(content) : readPoCatalog(content)\n}\n\nfunction writeCatalog(filePath: string, catalog: CatalogData, format: 'json' | 'po'): void {\n const content = format === 'json' ? writeJsonCatalog(catalog) : writePoCatalog(catalog)\n try {\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, content, 'utf-8')\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(`Failed to write catalog \"${filePath}\": ${message}`)\n }\n}\n\nasync function extractFromFile(filePath: string, code: string): Promise<ExtractedMessage[]> {\n const ext = extname(filePath)\n if (ext === '.vue') {\n try {\n const { extractFromVue } = await import('./vue-extractor')\n return extractFromVue(code, filePath)\n } catch {\n return []\n }\n }\n return extractFromTsx(code, filePath)\n}\n\n/**\n * Programmatic extract entry point.\n * Loads config from `cwd`, extracts messages, and writes catalogs.\n * This is the in-process equivalent of `fluenti extract`.\n */\nexport async function runExtract(cwd: string, options?: RunExtractOptions): Promise<void> {\n const config = await loadConfig(undefined, cwd)\n const localeCodes = resolveLocaleCodes(config.locales)\n\n const files = await fg(config.include, { cwd, ignore: config.exclude ?? [], absolute: false })\n const allMessages: ExtractedMessage[] = []\n const useCache = options?.useCache !== false\n const cache = useCache ? new ExtractCache(resolve(cwd, config.catalogDir), deriveProjectId(cwd)) : null\n\n for (const file of files) {\n const absFile = resolve(cwd, file)\n if (cache) {\n const cached = cache.get(absFile)\n if (cached) {\n allMessages.push(...cached)\n continue\n }\n }\n\n const code = readFileSync(absFile, 'utf-8')\n const messages = await extractFromFile(absFile, code)\n allMessages.push(...messages)\n\n if (cache) {\n cache.set(absFile, messages)\n }\n }\n\n if (cache) {\n cache.prune(new Set(files.map((f) => resolve(cwd, f))))\n cache.save()\n }\n\n // Run onAfterExtract plugin hooks\n const pluginRunner = config.plugins?.length\n ? createPluginRunner(config.plugins)\n : undefined\n\n if (pluginRunner) {\n const messageMap = new Map<string, ExtractedMessage>()\n for (const msg of allMessages) {\n messageMap.set(msg.id, msg)\n }\n const extractContext: PluginExtractContext = {\n messages: messageMap,\n sourceLocale: config.sourceLocale,\n targetLocales: localeCodes.filter((l) => l !== config.sourceLocale),\n config,\n }\n await pluginRunner.runAfterExtract(extractContext)\n }\n\n const ext = config.format === 'json' ? '.json' : '.po'\n const clean = options?.clean ?? false\n const stripFuzzy = options?.stripFuzzy ?? false\n\n for (const locale of localeCodes) {\n const catalogPath = resolve(cwd, config.catalogDir, `${locale}${ext}`)\n const existing = readCatalog(catalogPath, config.format)\n const { catalog } = updateCatalog(existing, allMessages, { stripFuzzy })\n\n const finalCatalog = clean\n ? Object.fromEntries(Object.entries(catalog).filter(([, entry]) => !entry.obsolete))\n : catalog\n\n writeCatalog(catalogPath, finalCatalog, config.format)\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,EAAa,GAAkE;AAC7F,QAAO;;;;ACVT,SAAS,EAAY,GAAkB,GAAoC;AACzE,KAAI,CAAC,EAAW,EAAS,CAAE,QAAO,EAAE;CACpC,IAAM,IAAU,EAAa,GAAU,QAAQ;AAC/C,QAAO,MAAW,SAAS,EAAgB,EAAQ,GAAG,EAAc,EAAQ;;AAI9E,SAAS,EAAkB,GAA8C;CACvE,IAAM,IAAmC,EAAE;AAC3C,MAAK,IAAM,CA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AO,YAAY,OAAO,QAAQ,EAAQ,CAAC,QAAQ,GAAG,OAAW,CAAC,EAAM,SAAS,CAAC,GAClF,GAEoC,EAAO,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`./doctor-xp8WS8sr.cjs`);let e=require(`@fluenti/core/transform`);var t=new Set([`@fluenti/core`,`@fluenti/react`,`@fluenti/vue`,`@fluenti/solid`,`@fluenti/next`]);function n(e){let t=e.trim();if(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t))return t;if(/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(t)&&!t.endsWith(`.`)){let e=t.split(`.`);return e[e.length-1]}let n=t.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/);return n?n[1].replace(/\./g,`_`):``}function r(e,t){let r=``,i=0;for(let a=0;a<e.length;a++){if(r+=e[a],a>=t.length)continue;let o=n(t[a]);if(o===``){r+=`{arg${i}}`,i++;continue}r+=`{${o}}`}return r}function i(e,t,n){if(!e.message)return;let r=n.loc?.start.line??1,i=(n.loc?.start.column??0)+1;return{id:e.id,message:e.message,...e.context===void 0?{}:{context:e.context},...e.comment===void 0?{}:{comment:e.comment},origin:{file:t,line:r,column:i}}}function a(t,n){if(!t.message)return;let r=n??e.createMessageId;return{id:t.id??r(t.message,t.context),message:t.message,...t.context===void 0?{}:{context:t.context},...t.comment===void 0?{}:{comment:t.comment}}}function o(e,t){if(e.type===`StringLiteral`)return a({message:e.value},t);if(e.type===`TemplateLiteral`){let n=e;return n.expressions.length===0?a({message:n.quasis.map(e=>e.value.cooked??e.value.raw).join(``)},t):void 0}if(e.type!==`ObjectExpression`)return;let n={};for(let t of e.properties){if(t.type!==`ObjectProperty`)continue;let e=t;if(e.computed||!T(e.key))continue;let r=e.key.name;if(![`id`,`message`,`context`,`comment`].includes(r))continue;let i=p(e.value);i!==void 0&&(n[r]=i)}if(n.message)return a(n,t)}var s=new Set([`id`,`value`,`context`,`comment`,`options`,`other`,`tag`]);function c(e,t,n){let r=[];for(let[e,n]of Object.entries(t))r.push(`${e} {${n}}`);return r.push(`other {${n}}`),`{${e}, select, ${r.join(` `)}}`}function l(e,t){let r,i,a,o,c,l={};for(let u of e.attributes){if(u.type!==`JSXAttribute`)continue;let e=u;if(e.name.type!==`JSXIdentifier`)continue;let d=String(e.name.name);if(d===`id`){i=e.value?p(e.value):void 0;continue}if(d===`value`){let i=e.value?p(e.value)??m(e.value,t):void 0;r=i?n(i)||i:void 0;continue}if(d===`context`){a=e.value?p(e.value):void 0;continue}if(d===`comment`){o=e.value?p(e.value):void 0;continue}if(d===`other`){c=e.value?p(e.value):void 0;continue}if(s.has(d))continue;let f=e.value?p(e.value):void 0;f!==void 0&&(l[d]=f)}return{varName:r,id:i,context:a,comment:o,cases:l,other:c}}function u(e){let t=[`zero`,`one`,`two`,`few`,`many`,`other`],n=e.value??e.count??`count`,r=[],i=e.offset;for(let n of t){let t=e[n];if(t===void 0)continue;let i=n===`zero`?`=0`:n;r.push(`${i} {${t}}`)}return r.length===0?``:`{${n}, plural, ${i?`offset:${i} `:``}${r.join(` `)}}`}function d(e){let t=0;function n(e){let r=``;for(let i of e){if(i.type===`JSXText`){r+=f(i.value);continue}if(i.type===`JSXElement`){let e=t++,a=n(i.children);if(a===void 0)return;r+=`<${e}>${a}</${e}>`;continue}if(i.type===`JSXFragment`){let e=n(i.children);if(e===void 0)return;r+=e;continue}if(i.type===`JSXExpressionContainer`){let e=i.expression;if(e.type===`StringLiteral`){r+=e.value;continue}if(e.type===`NumericLiteral`){r+=String(e.value);continue}return}}return r}let r=n(e);if(r!==void 0)return r.replace(/\s+/g,` `).trim()||void 0}function f(e){return e.replace(/\s+/g,` `)}function p(e){if(e.type===`StringLiteral`)return e.value;if(e.type===`NumericLiteral`)return String(e.value);if(e.type===`JSXExpressionContainer`)return p(e.expression);if(e.type===`TemplateLiteral`){let t=e;if(t.expressions.length===0)return t.quasis.map(e=>e.value.cooked??e.value.raw).join(``)}}function m(e,t){if(!(e.start==null||e.end==null))return e.type===`JSXExpressionContainer`?m(e.expression,t):t.slice(e.start,e.end).trim()}function h(e,t){for(let n of e.attributes){if(n.type!==`JSXAttribute`)continue;let e=n;if(e.name.type===`JSXIdentifier`&&e.name.name===t)return e}}function g(e,t){let n={};for(let r of[`id`,`value`,`count`,`offset`,`zero`,`one`,`two`,`few`,`many`,`other`]){let i=h(e,r);if(!i?.value)continue;let a=p(i.value);if(a!==void 0){n[r]=a;continue}let o=m(i.value,t);o!==void 0&&(r===`value`||r===`count`||r===`offset`)&&(n[r]=o)}return n}function _(t,n,i){let a=r(n.quasi.quasis.map(e=>e.value.cooked??e.value.raw),n.quasi.expressions.map(e=>e.start==null||e.end==null?``:t.slice(e.start,e.end)));return{id:(i??e.createMessageId)(a),message:a}}function v(e){let n=new Map,r=Array.isArray(e.body)?e.body:[];for(let e of r)if(b(e)&&t.has(e.source.value))for(let t of e.specifiers){if(!x(t))continue;let e=S(t);(e===`t`||e===`msg`)&&n.set(t.local.name,e)}return n}function y(t,n,r){let a=(0,e.parseSourceModule)(t);if(!a)return console.warn(`[fluenti] Failed to parse ${n} — skipping message extraction`),[];let s=[],f=v(a);return(0,e.walkSourceAst)(a,a=>{if(a.type===`TaggedTemplateExpression`){let e=a;if(T(e.tag)&&(e.tag.name===`t`||f.has(e.tag.name))){let a=_(t,e,r);f.get(e.tag.name)===`msg`&&(a.comment=`msg tagged template`);let o=i(a,n,e);o&&s.push(o)}return}if(a.type===`CallExpression`){let e=a,t=f.get(e.callee&&T(e.callee)?e.callee.name:``);if(T(e.callee)&&(e.callee.name===`t`||f.has(e.callee.name)&&t===`t`)){if(f.has(e.callee.name)&&e.arguments[0]?.type!==`ObjectExpression`)return;let t=e.arguments[0]?o(e.arguments[0],r):void 0,a=t?i(t,n,e):void 0;a&&s.push(a)}else if(e.callee.type===`MemberExpression`&&T(e.callee.object)&&f.get(e.callee.object.name)===`msg`&&T(e.callee.property)&&e.callee.property.name===`descriptor`&&e.arguments[0]){let t=o(e.arguments[0],r),a=t?i(t,n,e):void 0;a&&s.push(a)}return}if(a.type!==`JSXElement`)return;let m=a,v=m.openingElement,y=C(v.name);if(y===`Trans`){let e=h(v,`message`),t=h(v,`id`),a=h(v,`context`),o=h(v,`comment`),c=e?.value?w({id:t?.value?p(t.value):void 0,message:p(e.value),context:a?.value?p(a.value):void 0,comment:o?.value?p(o.value):void 0},r):w({id:t?.value?p(t.value):void 0,message:d(m.children),context:a?.value?p(a.value):void 0,comment:o?.value?p(o.value):void 0},r),l=c?i(c,n,m):void 0;l&&s.push(l);return}if(y===`Plural`){let a=g(v,t),o=u(a);if(!o)return;let c=r??e.createMessageId,l=i({id:a.id??c(o),message:o},n,m);l&&s.push(l);return}if(y===`Select`){let{varName:a,id:o,context:u,comment:d,cases:f,other:p}=l(v,t);if(!a||!p||Object.keys(f).length===0)return;let h=c(a,f,p),g=i({id:o??(r??e.createMessageId)(h,u),message:h,...u===void 0?{}:{context:u},...d===void 0?{}:{comment:d}},n,m);g&&s.push(g)}}),s}function b(t){return(0,e.isSourceNode)(t)&&t.type===`ImportDeclaration`}function x(t){return(0,e.isSourceNode)(t)&&t.type===`ImportSpecifier`}function S(e){if(e.imported.type===`Identifier`)return e.imported.name;if(e.imported.type===`StringLiteral`)return e.imported.value}function C(e){if(e.type===`JSXIdentifier`)return String(e.name)}function w(e,t){let n={};return e.id!==void 0&&(n.id=e.id),e.message!==void 0&&(n.message=e.message),e.context!==void 0&&(n.context=e.context),e.comment!==void 0&&(n.comment=e.comment),a(n,t)}function T(t){return(0,e.isSourceNode)(t)&&t.type===`Identifier`}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return y}});
|
|
2
|
+
//# sourceMappingURL=tsx-extractor-AOjsbOmp.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsx-extractor-B0vFXziu.cjs","names":[],"sources":["../src/tsx-extractor.ts"],"sourcesContent":["import type { ExtractedMessage } from '@fluenti/core/internal'\nimport {\n createMessageId,\n isSourceNode,\n parseSourceModule,\n walkSourceAst,\n type SourceNode,\n} from '@fluenti/core/transform'\n\ninterface IdentifierNode extends SourceNode {\n type: 'Identifier'\n name: string\n}\n\ninterface StringLiteralNode extends SourceNode {\n type: 'StringLiteral'\n value: string\n}\n\ninterface NumericLiteralNode extends SourceNode {\n type: 'NumericLiteral'\n value: number\n}\n\ninterface TemplateElementNode extends SourceNode {\n type: 'TemplateElement'\n value: { raw: string; cooked: string | null }\n}\n\ninterface TemplateLiteralNode extends SourceNode {\n type: 'TemplateLiteral'\n quasis: TemplateElementNode[]\n expressions: SourceNode[]\n}\n\ninterface TaggedTemplateExpressionNode extends SourceNode {\n type: 'TaggedTemplateExpression'\n tag: SourceNode\n quasi: TemplateLiteralNode\n}\n\ninterface CallExpressionNode extends SourceNode {\n type: 'CallExpression'\n callee: SourceNode\n arguments: SourceNode[]\n}\n\ninterface ImportDeclarationNode extends SourceNode {\n type: 'ImportDeclaration'\n source: StringLiteralNode\n specifiers: SourceNode[]\n}\n\ninterface ImportSpecifierNode extends SourceNode {\n type: 'ImportSpecifier'\n imported: IdentifierNode | StringLiteralNode\n local: IdentifierNode\n}\n\ninterface ObjectExpressionNode extends SourceNode {\n type: 'ObjectExpression'\n properties: SourceNode[]\n}\n\ninterface ObjectPropertyNode extends SourceNode {\n type: 'ObjectProperty'\n key: SourceNode\n value: SourceNode\n computed?: boolean\n}\n\ninterface JSXElementNode extends SourceNode {\n type: 'JSXElement'\n openingElement: JSXOpeningElementNode\n children: SourceNode[]\n}\n\ninterface JSXFragmentNode extends SourceNode {\n type: 'JSXFragment'\n children: SourceNode[]\n}\n\ninterface JSXOpeningElementNode extends SourceNode {\n type: 'JSXOpeningElement'\n name: SourceNode\n attributes: SourceNode[]\n}\n\ninterface JSXAttributeNode extends SourceNode {\n type: 'JSXAttribute'\n name: SourceNode\n value?: SourceNode | null\n}\n\ninterface JSXExpressionContainerNode extends SourceNode {\n type: 'JSXExpressionContainer'\n expression: SourceNode\n}\n\ninterface JSXTextNode extends SourceNode {\n type: 'JSXText'\n value: string\n}\n\ninterface ExtractedDescriptor {\n id: string\n message?: string\n context?: string\n comment?: string\n}\n\nconst DIRECT_T_SOURCES = new Set([\n '@fluenti/core',\n '@fluenti/react',\n '@fluenti/vue',\n '@fluenti/solid',\n '@fluenti/next',\n])\n\nfunction classifyExpression(expr: string): string {\n const trimmed = expr.trim()\n // Simple identifier: name, count\n if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {\n return trimmed\n }\n // Dotted path: user.name → name\n if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(trimmed) && !trimmed.endsWith('.')) {\n const parts = trimmed.split('.')\n return parts[parts.length - 1]!\n }\n // Function call: fun() → fun, obj.method() → obj_method\n const callMatch = trimmed.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)\\s*\\(/)\n if (callMatch) {\n return callMatch[1]!.replace(/\\./g, '_')\n }\n return ''\n}\n\nfunction buildICUFromTemplate(\n strings: readonly string[],\n expressions: readonly string[],\n): string {\n let result = ''\n let positionalIndex = 0\n\n for (let index = 0; index < strings.length; index++) {\n result += strings[index]!\n if (index >= expressions.length) continue\n\n const name = classifyExpression(expressions[index]!)\n if (name === '') {\n result += `{arg${positionalIndex}}`\n positionalIndex++\n continue\n }\n\n result += `{${name}}`\n }\n\n return result\n}\n\nfunction createExtractedMessage(\n descriptor: ExtractedDescriptor,\n filename: string,\n node: SourceNode,\n): ExtractedMessage | undefined {\n if (!descriptor.message) {\n return undefined\n }\n\n const line = node.loc?.start.line ?? 1\n const column = (node.loc?.start.column ?? 0) + 1\n\n return {\n id: descriptor.id,\n message: descriptor.message,\n ...(descriptor.context !== undefined ? { context: descriptor.context } : {}),\n ...(descriptor.comment !== undefined ? { comment: descriptor.comment } : {}),\n origin: { file: filename, line, column },\n }\n}\n\nfunction descriptorFromStaticParts(\n parts: {\n id?: string\n message?: string\n context?: string\n comment?: string\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (!parts.message) {\n return undefined\n }\n\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: parts.id ?? generateId(parts.message, parts.context),\n message: parts.message,\n ...(parts.context !== undefined ? { context: parts.context } : {}),\n ...(parts.comment !== undefined ? { comment: parts.comment } : {}),\n }\n}\n\nfunction extractDescriptorFromCallArgument(\n argument: SourceNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (argument.type === 'StringLiteral') {\n return descriptorFromStaticParts({ message: (argument as StringLiteralNode).value }, idGenerator)\n }\n\n if (argument.type === 'TemplateLiteral') {\n const template = argument as TemplateLiteralNode\n if (template.expressions.length === 0) {\n const message = template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n return descriptorFromStaticParts({ message }, idGenerator)\n }\n return undefined\n }\n\n if (argument.type !== 'ObjectExpression') {\n return undefined\n }\n\n const staticParts: { id?: string; message?: string; context?: string; comment?: string } = {}\n for (const property of (argument as ObjectExpressionNode).properties) {\n if (property.type !== 'ObjectProperty') continue\n\n const objectProperty = property as ObjectPropertyNode\n if (objectProperty.computed || !isIdentifier(objectProperty.key)) continue\n\n const key = objectProperty.key.name\n if (!['id', 'message', 'context', 'comment'].includes(key)) continue\n\n const value = readStaticStringValue(objectProperty.value)\n if (value === undefined) continue\n staticParts[key as keyof typeof staticParts] = value\n }\n\n if (!staticParts.message) {\n return undefined\n }\n\n return descriptorFromStaticParts(staticParts, idGenerator)\n}\n\nconst SELECT_RESERVED_PROPS = new Set(['id', 'value', 'context', 'comment', 'options', 'other', 'tag'])\n\nfunction buildSelectICU(varName: string, cases: Record<string, string>, other: string): string {\n const options: string[] = []\n for (const [key, value] of Object.entries(cases)) {\n options.push(`${key} {${value}}`)\n }\n options.push(`other {${other}}`)\n return `{${varName}, select, ${options.join(' ')}}`\n}\n\nfunction extractSelectProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): { varName: string | undefined; id: string | undefined; context: string | undefined; comment: string | undefined; cases: Record<string, string>; other: string | undefined } {\n let varName: string | undefined\n let id: string | undefined\n let context: string | undefined\n let comment: string | undefined\n let other: string | undefined\n const cases: Record<string, string> = {}\n\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n const attr = attribute as JSXAttributeNode\n if (attr.name.type !== 'JSXIdentifier') continue\n const name = String(attr.name['name'])\n\n if (name === 'id') {\n id = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'value') {\n const raw = attr.value ? (readStaticStringValue(attr.value) ?? readExpressionSource(attr.value, code)) : undefined\n varName = raw ? classifyExpression(raw) || raw : undefined\n continue\n }\n if (name === 'context') {\n context = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'comment') {\n comment = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'other') {\n other = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (SELECT_RESERVED_PROPS.has(name)) continue\n\n const staticValue = attr.value ? readStaticStringValue(attr.value) : undefined\n if (staticValue === undefined) continue\n\n cases[name] = staticValue\n }\n\n return { varName, id, context, comment, cases, other }\n}\n\nfunction buildPluralICU(props: Record<string, string>): string {\n const categories = ['zero', 'one', 'two', 'few', 'many', 'other'] as const\n const countVar = props['value'] ?? props['count'] ?? 'count'\n const options: string[] = []\n const offset = props['offset']\n\n for (const category of categories) {\n const value = props[category]\n if (value === undefined) continue\n const key = category === 'zero' ? '=0' : category\n options.push(`${key} {${value}}`)\n }\n\n if (options.length === 0) {\n return ''\n }\n\n const offsetPrefix = offset ? `offset:${offset} ` : ''\n return `{${countVar}, plural, ${offsetPrefix}${options.join(' ')}}`\n}\n\nfunction extractRichTextMessage(children: readonly SourceNode[]): string | undefined {\n let nextIndex = 0\n\n function render(nodes: readonly SourceNode[]): string | undefined {\n let message = ''\n\n for (const node of nodes) {\n if (node.type === 'JSXText') {\n message += normalizeJsxText((node as JSXTextNode).value)\n continue\n }\n\n if (node.type === 'JSXElement') {\n const idx = nextIndex++\n const inner = render((node as JSXElementNode).children)\n if (inner === undefined) return undefined\n message += `<${idx}>${inner}</${idx}>`\n continue\n }\n\n if (node.type === 'JSXFragment') {\n const inner = render((node as JSXFragmentNode).children)\n if (inner === undefined) return undefined\n message += inner\n continue\n }\n\n if (node.type === 'JSXExpressionContainer') {\n const expression = (node as JSXExpressionContainerNode).expression\n if (expression.type === 'StringLiteral') {\n message += (expression as StringLiteralNode).value\n continue\n }\n if (expression.type === 'NumericLiteral') {\n message += String((expression as NumericLiteralNode).value)\n continue\n }\n return undefined\n }\n }\n\n return message\n }\n\n const message = render(children)\n if (message === undefined) return undefined\n\n const normalized = message.replace(/\\s+/g, ' ').trim()\n return normalized || undefined\n}\n\nfunction normalizeJsxText(value: string): string {\n return value.replace(/\\s+/g, ' ')\n}\n\nfunction readStaticStringValue(node: SourceNode): string | undefined {\n if (node.type === 'StringLiteral') {\n return (node as StringLiteralNode).value\n }\n\n if (node.type === 'NumericLiteral') {\n return String((node as NumericLiteralNode).value)\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readStaticStringValue((node as JSXExpressionContainerNode).expression)\n }\n\n if (node.type === 'TemplateLiteral') {\n const template = node as TemplateLiteralNode\n if (template.expressions.length === 0) {\n return template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n }\n }\n\n return undefined\n}\n\nfunction readExpressionSource(node: SourceNode, code: string): string | undefined {\n if (node.start == null || node.end == null) {\n return undefined\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readExpressionSource((node as JSXExpressionContainerNode).expression, code)\n }\n\n return code.slice(node.start, node.end).trim()\n}\n\nfunction getJsxAttribute(\n openingElement: JSXOpeningElementNode,\n name: string,\n): JSXAttributeNode | undefined {\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n\n const jsxAttribute = attribute as JSXAttributeNode\n if (jsxAttribute.name.type === 'JSXIdentifier' && jsxAttribute.name['name'] === name) {\n return jsxAttribute\n }\n }\n\n return undefined\n}\n\nfunction extractPluralProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): Record<string, string> {\n const props: Record<string, string> = {}\n const propNames = ['id', 'value', 'count', 'offset', 'zero', 'one', 'two', 'few', 'many', 'other']\n\n for (const name of propNames) {\n const attribute = getJsxAttribute(openingElement, name)\n if (!attribute?.value) continue\n\n const staticValue = readStaticStringValue(attribute.value)\n if (staticValue !== undefined) {\n props[name] = staticValue\n continue\n }\n\n const exprValue = readExpressionSource(attribute.value, code)\n if (exprValue !== undefined && (name === 'value' || name === 'count' || name === 'offset')) {\n props[name] = exprValue\n }\n }\n\n return props\n}\n\nfunction extractTaggedTemplateMessage(\n code: string,\n node: TaggedTemplateExpressionNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor {\n const strings = node.quasi.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw)\n const expressions = node.quasi.expressions.map((expression) => {\n if (expression.start == null || expression.end == null) {\n return ''\n }\n return code.slice(expression.start, expression.end)\n })\n const message = buildICUFromTemplate(strings, expressions)\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: generateId(message),\n message,\n }\n}\n\nfunction collectDirectBindings(ast: SourceNode): Map<string, 't' | 'msg'> {\n const bindings = new Map<string, 't' | 'msg'>()\n const body = Array.isArray(ast['body']) ? ast['body'] : []\n\n for (const entry of body) {\n if (!isImportDeclaration(entry)) continue\n if (!DIRECT_T_SOURCES.has(entry.source.value)) continue\n\n for (const specifier of entry.specifiers) {\n if (!isImportSpecifier(specifier)) continue\n const importedName = readImportedName(specifier)\n if (importedName === 't' || importedName === 'msg') {\n bindings.set(specifier.local.name, importedName as 't' | 'msg')\n }\n }\n }\n\n return bindings\n}\n\nexport function extractFromTsx(\n code: string,\n filename: string,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedMessage[] {\n const ast = parseSourceModule(code)\n if (!ast) {\n console.warn(`[fluenti] Failed to parse ${filename} — skipping message extraction`)\n return []\n }\n\n const messages: ExtractedMessage[] = []\n const directBindings = collectDirectBindings(ast)\n\n walkSourceAst(ast, (node: SourceNode) => {\n if (node.type === 'TaggedTemplateExpression') {\n const tagged = node as TaggedTemplateExpressionNode\n if (\n isIdentifier(tagged.tag)\n && (tagged.tag.name === 't' || directBindings.has(tagged.tag.name))\n ) {\n const descriptor = extractTaggedTemplateMessage(code, tagged, idGenerator)\n const bindingType = directBindings.get(tagged.tag.name)\n if (bindingType === 'msg') {\n descriptor.comment = 'msg tagged template'\n }\n const extracted = createExtractedMessage(\n descriptor,\n filename,\n tagged,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type === 'CallExpression') {\n const call = node as CallExpressionNode\n const callBindingType = directBindings.get(call.callee && isIdentifier(call.callee) ? call.callee.name : '')\n if (isIdentifier(call.callee) && (call.callee.name === 't' || (directBindings.has(call.callee.name) && callBindingType === 't'))) {\n if (directBindings.has(call.callee.name) && call.arguments[0]?.type !== 'ObjectExpression') {\n return\n }\n const descriptor = call.arguments[0] ? extractDescriptorFromCallArgument(call.arguments[0], idGenerator) : undefined\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, call)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n } else if (\n call.callee.type === 'MemberExpression'\n && isIdentifier(call.callee['object'])\n && directBindings.get((call.callee['object'] as IdentifierNode).name) === 'msg'\n && isIdentifier(call.callee['property'])\n && (call.callee['property'] as IdentifierNode).name === 'descriptor'\n && call.arguments[0]\n ) {\n const descriptor = extractDescriptorFromCallArgument(call.arguments[0], idGenerator)\n const extracted = descriptor ? createExtractedMessage(descriptor, filename, call) : undefined\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type !== 'JSXElement') {\n return\n }\n\n const element = node as JSXElementNode\n const openingElement = element.openingElement\n const elementName = readJsxElementName(openingElement.name)\n\n if (elementName === 'Trans') {\n const messageAttr = getJsxAttribute(openingElement, 'message')\n const idAttr = getJsxAttribute(openingElement, 'id')\n const contextAttr = getJsxAttribute(openingElement, 'context')\n const commentAttr = getJsxAttribute(openingElement, 'comment')\n\n const descriptor = messageAttr?.value\n ? buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: readStaticStringValue(messageAttr.value),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n : buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: extractRichTextMessage(element.children),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, element)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Plural') {\n const props = extractPluralProps(openingElement, code)\n const message = buildPluralICU(props)\n if (!message) {\n return\n }\n\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: props['id'] ?? generateId(message),\n message,\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Select') {\n const { varName, id, context, comment, cases, other } = extractSelectProps(openingElement, code)\n if (!varName || !other || Object.keys(cases).length === 0) {\n return\n }\n\n const message = buildSelectICU(varName, cases, other)\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: id ?? generateId(message, context),\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n })\n\n return messages\n}\n\nfunction isImportDeclaration(node: unknown): node is ImportDeclarationNode {\n return isSourceNode(node) && node.type === 'ImportDeclaration'\n}\n\nfunction isImportSpecifier(node: unknown): node is ImportSpecifierNode {\n return isSourceNode(node) && node.type === 'ImportSpecifier'\n}\n\nfunction readImportedName(specifier: ImportSpecifierNode): string | undefined {\n if (specifier.imported.type === 'Identifier') {\n return (specifier.imported as IdentifierNode).name\n }\n if (specifier.imported.type === 'StringLiteral') {\n return (specifier.imported as StringLiteralNode).value\n }\n return undefined\n}\n\nfunction readJsxElementName(node: SourceNode): string | undefined {\n if (node.type === 'JSXIdentifier') {\n return String(node['name'])\n }\n return undefined\n}\n\nfunction buildStaticTransDescriptor(\n parts: {\n id: string | undefined\n message: string | undefined\n context: string | undefined\n comment: string | undefined\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n const payload: {\n id?: string\n message?: string\n context?: string\n comment?: string\n } = {}\n\n if (parts.id !== undefined) payload.id = parts.id\n if (parts.message !== undefined) payload.message = parts.message\n if (parts.context !== undefined) payload.context = parts.context\n if (parts.comment !== undefined) payload.comment = parts.comment\n\n return descriptorFromStaticParts(payload, idGenerator)\n}\n\nfunction isIdentifier(node: unknown): node is IdentifierNode {\n return isSourceNode(node) && node.type === 'Identifier'\n}\n"],"mappings":"iFA+GA,IAAM,EAAmB,IAAI,IAAI,CAC/B,gBACA,iBACA,eACA,iBACA,gBACD,CAAC,CAEF,SAAS,EAAmB,EAAsB,CAChD,IAAM,EAAU,EAAK,MAAM,CAE3B,GAAI,6BAA6B,KAAK,EAAQ,CAC5C,OAAO,EAGT,GAAI,8BAA8B,KAAK,EAAQ,EAAI,CAAC,EAAQ,SAAS,IAAI,CAAE,CACzE,IAAM,EAAQ,EAAQ,MAAM,IAAI,CAChC,OAAO,EAAM,EAAM,OAAS,GAG9B,IAAM,EAAY,EAAQ,MAAM,oCAAoC,CAIpE,OAHI,EACK,EAAU,GAAI,QAAQ,MAAO,IAAI,CAEnC,GAGT,SAAS,EACP,EACA,EACQ,CACR,IAAI,EAAS,GACT,EAAkB,EAEtB,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAQ,OAAQ,IAAS,CAEnD,GADA,GAAU,EAAQ,GACd,GAAS,EAAY,OAAQ,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AAS"}
|
|
1
|
+
{"version":3,"file":"tsx-extractor-AOjsbOmp.cjs","names":[],"sources":["../src/tsx-extractor.ts"],"sourcesContent":["import type { ExtractedMessage } from '@fluenti/core/compiler'\nimport {\n createMessageId,\n isSourceNode,\n parseSourceModule,\n walkSourceAst,\n type SourceNode,\n} from '@fluenti/core/transform'\n\ninterface IdentifierNode extends SourceNode {\n type: 'Identifier'\n name: string\n}\n\ninterface StringLiteralNode extends SourceNode {\n type: 'StringLiteral'\n value: string\n}\n\ninterface NumericLiteralNode extends SourceNode {\n type: 'NumericLiteral'\n value: number\n}\n\ninterface TemplateElementNode extends SourceNode {\n type: 'TemplateElement'\n value: { raw: string; cooked: string | null }\n}\n\ninterface TemplateLiteralNode extends SourceNode {\n type: 'TemplateLiteral'\n quasis: TemplateElementNode[]\n expressions: SourceNode[]\n}\n\ninterface TaggedTemplateExpressionNode extends SourceNode {\n type: 'TaggedTemplateExpression'\n tag: SourceNode\n quasi: TemplateLiteralNode\n}\n\ninterface CallExpressionNode extends SourceNode {\n type: 'CallExpression'\n callee: SourceNode\n arguments: SourceNode[]\n}\n\ninterface ImportDeclarationNode extends SourceNode {\n type: 'ImportDeclaration'\n source: StringLiteralNode\n specifiers: SourceNode[]\n}\n\ninterface ImportSpecifierNode extends SourceNode {\n type: 'ImportSpecifier'\n imported: IdentifierNode | StringLiteralNode\n local: IdentifierNode\n}\n\ninterface ObjectExpressionNode extends SourceNode {\n type: 'ObjectExpression'\n properties: SourceNode[]\n}\n\ninterface ObjectPropertyNode extends SourceNode {\n type: 'ObjectProperty'\n key: SourceNode\n value: SourceNode\n computed?: boolean\n}\n\ninterface JSXElementNode extends SourceNode {\n type: 'JSXElement'\n openingElement: JSXOpeningElementNode\n children: SourceNode[]\n}\n\ninterface JSXFragmentNode extends SourceNode {\n type: 'JSXFragment'\n children: SourceNode[]\n}\n\ninterface JSXOpeningElementNode extends SourceNode {\n type: 'JSXOpeningElement'\n name: SourceNode\n attributes: SourceNode[]\n}\n\ninterface JSXAttributeNode extends SourceNode {\n type: 'JSXAttribute'\n name: SourceNode\n value?: SourceNode | null\n}\n\ninterface JSXExpressionContainerNode extends SourceNode {\n type: 'JSXExpressionContainer'\n expression: SourceNode\n}\n\ninterface JSXTextNode extends SourceNode {\n type: 'JSXText'\n value: string\n}\n\ninterface ExtractedDescriptor {\n id: string\n message?: string\n context?: string\n comment?: string\n}\n\nconst DIRECT_T_SOURCES = new Set([\n '@fluenti/core',\n '@fluenti/react',\n '@fluenti/vue',\n '@fluenti/solid',\n '@fluenti/next',\n])\n\nfunction classifyExpression(expr: string): string {\n const trimmed = expr.trim()\n // Simple identifier: name, count\n if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {\n return trimmed\n }\n // Dotted path: user.name → name\n if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(trimmed) && !trimmed.endsWith('.')) {\n const parts = trimmed.split('.')\n return parts[parts.length - 1]!\n }\n // Function call: fun() → fun, obj.method() → obj_method\n const callMatch = trimmed.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)\\s*\\(/)\n if (callMatch) {\n return callMatch[1]!.replace(/\\./g, '_')\n }\n return ''\n}\n\nfunction buildICUFromTemplate(\n strings: readonly string[],\n expressions: readonly string[],\n): string {\n let result = ''\n let positionalIndex = 0\n\n for (let index = 0; index < strings.length; index++) {\n result += strings[index]!\n if (index >= expressions.length) continue\n\n const name = classifyExpression(expressions[index]!)\n if (name === '') {\n result += `{arg${positionalIndex}}`\n positionalIndex++\n continue\n }\n\n result += `{${name}}`\n }\n\n return result\n}\n\nfunction createExtractedMessage(\n descriptor: ExtractedDescriptor,\n filename: string,\n node: SourceNode,\n): ExtractedMessage | undefined {\n if (!descriptor.message) {\n return undefined\n }\n\n const line = node.loc?.start.line ?? 1\n const column = (node.loc?.start.column ?? 0) + 1\n\n return {\n id: descriptor.id,\n message: descriptor.message,\n ...(descriptor.context !== undefined ? { context: descriptor.context } : {}),\n ...(descriptor.comment !== undefined ? { comment: descriptor.comment } : {}),\n origin: { file: filename, line, column },\n }\n}\n\nfunction descriptorFromStaticParts(\n parts: {\n id?: string\n message?: string\n context?: string\n comment?: string\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (!parts.message) {\n return undefined\n }\n\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: parts.id ?? generateId(parts.message, parts.context),\n message: parts.message,\n ...(parts.context !== undefined ? { context: parts.context } : {}),\n ...(parts.comment !== undefined ? { comment: parts.comment } : {}),\n }\n}\n\nfunction extractDescriptorFromCallArgument(\n argument: SourceNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (argument.type === 'StringLiteral') {\n return descriptorFromStaticParts({ message: (argument as StringLiteralNode).value }, idGenerator)\n }\n\n if (argument.type === 'TemplateLiteral') {\n const template = argument as TemplateLiteralNode\n if (template.expressions.length === 0) {\n const message = template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n return descriptorFromStaticParts({ message }, idGenerator)\n }\n return undefined\n }\n\n if (argument.type !== 'ObjectExpression') {\n return undefined\n }\n\n const staticParts: { id?: string; message?: string; context?: string; comment?: string } = {}\n for (const property of (argument as ObjectExpressionNode).properties) {\n if (property.type !== 'ObjectProperty') continue\n\n const objectProperty = property as ObjectPropertyNode\n if (objectProperty.computed || !isIdentifier(objectProperty.key)) continue\n\n const key = objectProperty.key.name\n if (!['id', 'message', 'context', 'comment'].includes(key)) continue\n\n const value = readStaticStringValue(objectProperty.value)\n if (value === undefined) continue\n staticParts[key as keyof typeof staticParts] = value\n }\n\n if (!staticParts.message) {\n return undefined\n }\n\n return descriptorFromStaticParts(staticParts, idGenerator)\n}\n\nconst SELECT_RESERVED_PROPS = new Set(['id', 'value', 'context', 'comment', 'options', 'other', 'tag'])\n\nfunction buildSelectICU(varName: string, cases: Record<string, string>, other: string): string {\n const options: string[] = []\n for (const [key, value] of Object.entries(cases)) {\n options.push(`${key} {${value}}`)\n }\n options.push(`other {${other}}`)\n return `{${varName}, select, ${options.join(' ')}}`\n}\n\nfunction extractSelectProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): { varName: string | undefined; id: string | undefined; context: string | undefined; comment: string | undefined; cases: Record<string, string>; other: string | undefined } {\n let varName: string | undefined\n let id: string | undefined\n let context: string | undefined\n let comment: string | undefined\n let other: string | undefined\n const cases: Record<string, string> = {}\n\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n const attr = attribute as JSXAttributeNode\n if (attr.name.type !== 'JSXIdentifier') continue\n const name = String(attr.name['name'])\n\n if (name === 'id') {\n id = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'value') {\n const raw = attr.value ? (readStaticStringValue(attr.value) ?? readExpressionSource(attr.value, code)) : undefined\n varName = raw ? classifyExpression(raw) || raw : undefined\n continue\n }\n if (name === 'context') {\n context = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'comment') {\n comment = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'other') {\n other = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (SELECT_RESERVED_PROPS.has(name)) continue\n\n const staticValue = attr.value ? readStaticStringValue(attr.value) : undefined\n if (staticValue === undefined) continue\n\n cases[name] = staticValue\n }\n\n return { varName, id, context, comment, cases, other }\n}\n\nfunction buildPluralICU(props: Record<string, string>): string {\n const categories = ['zero', 'one', 'two', 'few', 'many', 'other'] as const\n const countVar = props['value'] ?? props['count'] ?? 'count'\n const options: string[] = []\n const offset = props['offset']\n\n for (const category of categories) {\n const value = props[category]\n if (value === undefined) continue\n const key = category === 'zero' ? '=0' : category\n options.push(`${key} {${value}}`)\n }\n\n if (options.length === 0) {\n return ''\n }\n\n const offsetPrefix = offset ? `offset:${offset} ` : ''\n return `{${countVar}, plural, ${offsetPrefix}${options.join(' ')}}`\n}\n\nfunction extractRichTextMessage(children: readonly SourceNode[]): string | undefined {\n let nextIndex = 0\n\n function render(nodes: readonly SourceNode[]): string | undefined {\n let message = ''\n\n for (const node of nodes) {\n if (node.type === 'JSXText') {\n message += normalizeJsxText((node as JSXTextNode).value)\n continue\n }\n\n if (node.type === 'JSXElement') {\n const idx = nextIndex++\n const inner = render((node as JSXElementNode).children)\n if (inner === undefined) return undefined\n message += `<${idx}>${inner}</${idx}>`\n continue\n }\n\n if (node.type === 'JSXFragment') {\n const inner = render((node as JSXFragmentNode).children)\n if (inner === undefined) return undefined\n message += inner\n continue\n }\n\n if (node.type === 'JSXExpressionContainer') {\n const expression = (node as JSXExpressionContainerNode).expression\n if (expression.type === 'StringLiteral') {\n message += (expression as StringLiteralNode).value\n continue\n }\n if (expression.type === 'NumericLiteral') {\n message += String((expression as NumericLiteralNode).value)\n continue\n }\n return undefined\n }\n }\n\n return message\n }\n\n const message = render(children)\n if (message === undefined) return undefined\n\n const normalized = message.replace(/\\s+/g, ' ').trim()\n return normalized || undefined\n}\n\nfunction normalizeJsxText(value: string): string {\n return value.replace(/\\s+/g, ' ')\n}\n\nfunction readStaticStringValue(node: SourceNode): string | undefined {\n if (node.type === 'StringLiteral') {\n return (node as StringLiteralNode).value\n }\n\n if (node.type === 'NumericLiteral') {\n return String((node as NumericLiteralNode).value)\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readStaticStringValue((node as JSXExpressionContainerNode).expression)\n }\n\n if (node.type === 'TemplateLiteral') {\n const template = node as TemplateLiteralNode\n if (template.expressions.length === 0) {\n return template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n }\n }\n\n return undefined\n}\n\nfunction readExpressionSource(node: SourceNode, code: string): string | undefined {\n if (node.start == null || node.end == null) {\n return undefined\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readExpressionSource((node as JSXExpressionContainerNode).expression, code)\n }\n\n return code.slice(node.start, node.end).trim()\n}\n\nfunction getJsxAttribute(\n openingElement: JSXOpeningElementNode,\n name: string,\n): JSXAttributeNode | undefined {\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n\n const jsxAttribute = attribute as JSXAttributeNode\n if (jsxAttribute.name.type === 'JSXIdentifier' && jsxAttribute.name['name'] === name) {\n return jsxAttribute\n }\n }\n\n return undefined\n}\n\nfunction extractPluralProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): Record<string, string> {\n const props: Record<string, string> = {}\n const propNames = ['id', 'value', 'count', 'offset', 'zero', 'one', 'two', 'few', 'many', 'other']\n\n for (const name of propNames) {\n const attribute = getJsxAttribute(openingElement, name)\n if (!attribute?.value) continue\n\n const staticValue = readStaticStringValue(attribute.value)\n if (staticValue !== undefined) {\n props[name] = staticValue\n continue\n }\n\n const exprValue = readExpressionSource(attribute.value, code)\n if (exprValue !== undefined && (name === 'value' || name === 'count' || name === 'offset')) {\n props[name] = exprValue\n }\n }\n\n return props\n}\n\nfunction extractTaggedTemplateMessage(\n code: string,\n node: TaggedTemplateExpressionNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor {\n const strings = node.quasi.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw)\n const expressions = node.quasi.expressions.map((expression) => {\n if (expression.start == null || expression.end == null) {\n return ''\n }\n return code.slice(expression.start, expression.end)\n })\n const message = buildICUFromTemplate(strings, expressions)\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: generateId(message),\n message,\n }\n}\n\nfunction collectDirectBindings(ast: SourceNode): Map<string, 't' | 'msg'> {\n const bindings = new Map<string, 't' | 'msg'>()\n const body = Array.isArray(ast['body']) ? ast['body'] : []\n\n for (const entry of body) {\n if (!isImportDeclaration(entry)) continue\n if (!DIRECT_T_SOURCES.has(entry.source.value)) continue\n\n for (const specifier of entry.specifiers) {\n if (!isImportSpecifier(specifier)) continue\n const importedName = readImportedName(specifier)\n if (importedName === 't' || importedName === 'msg') {\n bindings.set(specifier.local.name, importedName as 't' | 'msg')\n }\n }\n }\n\n return bindings\n}\n\nexport function extractFromTsx(\n code: string,\n filename: string,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedMessage[] {\n const ast = parseSourceModule(code)\n if (!ast) {\n console.warn(`[fluenti] Failed to parse ${filename} — skipping message extraction`)\n return []\n }\n\n const messages: ExtractedMessage[] = []\n const directBindings = collectDirectBindings(ast)\n\n walkSourceAst(ast, (node: SourceNode) => {\n if (node.type === 'TaggedTemplateExpression') {\n const tagged = node as TaggedTemplateExpressionNode\n if (\n isIdentifier(tagged.tag)\n && (tagged.tag.name === 't' || directBindings.has(tagged.tag.name))\n ) {\n const descriptor = extractTaggedTemplateMessage(code, tagged, idGenerator)\n const bindingType = directBindings.get(tagged.tag.name)\n if (bindingType === 'msg') {\n descriptor.comment = 'msg tagged template'\n }\n const extracted = createExtractedMessage(\n descriptor,\n filename,\n tagged,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type === 'CallExpression') {\n const call = node as CallExpressionNode\n const callBindingType = directBindings.get(call.callee && isIdentifier(call.callee) ? call.callee.name : '')\n if (isIdentifier(call.callee) && (call.callee.name === 't' || (directBindings.has(call.callee.name) && callBindingType === 't'))) {\n if (directBindings.has(call.callee.name) && call.arguments[0]?.type !== 'ObjectExpression') {\n return\n }\n const descriptor = call.arguments[0] ? extractDescriptorFromCallArgument(call.arguments[0], idGenerator) : undefined\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, call)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n } else if (\n call.callee.type === 'MemberExpression'\n && isIdentifier(call.callee['object'])\n && directBindings.get((call.callee['object'] as IdentifierNode).name) === 'msg'\n && isIdentifier(call.callee['property'])\n && (call.callee['property'] as IdentifierNode).name === 'descriptor'\n && call.arguments[0]\n ) {\n const descriptor = extractDescriptorFromCallArgument(call.arguments[0], idGenerator)\n const extracted = descriptor ? createExtractedMessage(descriptor, filename, call) : undefined\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type !== 'JSXElement') {\n return\n }\n\n const element = node as JSXElementNode\n const openingElement = element.openingElement\n const elementName = readJsxElementName(openingElement.name)\n\n if (elementName === 'Trans') {\n const messageAttr = getJsxAttribute(openingElement, 'message')\n const idAttr = getJsxAttribute(openingElement, 'id')\n const contextAttr = getJsxAttribute(openingElement, 'context')\n const commentAttr = getJsxAttribute(openingElement, 'comment')\n\n const descriptor = messageAttr?.value\n ? buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: readStaticStringValue(messageAttr.value),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n : buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: extractRichTextMessage(element.children),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, element)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Plural') {\n const props = extractPluralProps(openingElement, code)\n const message = buildPluralICU(props)\n if (!message) {\n return\n }\n\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: props['id'] ?? generateId(message),\n message,\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Select') {\n const { varName, id, context, comment, cases, other } = extractSelectProps(openingElement, code)\n if (!varName || !other || Object.keys(cases).length === 0) {\n return\n }\n\n const message = buildSelectICU(varName, cases, other)\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: id ?? generateId(message, context),\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n })\n\n return messages\n}\n\nfunction isImportDeclaration(node: unknown): node is ImportDeclarationNode {\n return isSourceNode(node) && node.type === 'ImportDeclaration'\n}\n\nfunction isImportSpecifier(node: unknown): node is ImportSpecifierNode {\n return isSourceNode(node) && node.type === 'ImportSpecifier'\n}\n\nfunction readImportedName(specifier: ImportSpecifierNode): string | undefined {\n if (specifier.imported.type === 'Identifier') {\n return (specifier.imported as IdentifierNode).name\n }\n if (specifier.imported.type === 'StringLiteral') {\n return (specifier.imported as StringLiteralNode).value\n }\n return undefined\n}\n\nfunction readJsxElementName(node: SourceNode): string | undefined {\n if (node.type === 'JSXIdentifier') {\n return String(node['name'])\n }\n return undefined\n}\n\nfunction buildStaticTransDescriptor(\n parts: {\n id: string | undefined\n message: string | undefined\n context: string | undefined\n comment: string | undefined\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n const payload: {\n id?: string\n message?: string\n context?: string\n comment?: string\n } = {}\n\n if (parts.id !== undefined) payload.id = parts.id\n if (parts.message !== undefined) payload.message = parts.message\n if (parts.context !== undefined) payload.context = parts.context\n if (parts.comment !== undefined) payload.comment = parts.comment\n\n return descriptorFromStaticParts(payload, idGenerator)\n}\n\nfunction isIdentifier(node: unknown): node is IdentifierNode {\n return isSourceNode(node) && node.type === 'Identifier'\n}\n"],"mappings":"0EA+GA,IAAM,EAAmB,IAAI,IAAI,CAC/B,gBACA,iBACA,eACA,iBACA,gBACD,CAAC,CAEF,SAAS,EAAmB,EAAsB,CAChD,IAAM,EAAU,EAAK,MAAM,CAE3B,GAAI,6BAA6B,KAAK,EAAQ,CAC5C,OAAO,EAGT,GAAI,8BAA8B,KAAK,EAAQ,EAAI,CAAC,EAAQ,SAAS,IAAI,CAAE,CACzE,IAAM,EAAQ,EAAQ,MAAM,IAAI,CAChC,OAAO,EAAM,EAAM,OAAS,GAG9B,IAAM,EAAY,EAAQ,MAAM,oCAAoC,CAIpE,OAHI,EACK,EAAU,GAAI,QAAQ,MAAO,IAAI,CAEnC,GAGT,SAAS,EACP,EACA,EACQ,CACR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IAAA,KAAW,EAAQ,QAAU,EAAM,SAElD,EAA0B,EAAS,EAAY,CAGxD,SAAS,EAAa,EAAuC,CAC3D,OAAA,EAAA,EAAA,cAAoB,EAAK,EAAI,EAAK,OAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsx-extractor-C-HZNobu.js","names":[],"sources":["../src/tsx-extractor.ts"],"sourcesContent":["import type { ExtractedMessage } from '@fluenti/core/internal'\nimport {\n createMessageId,\n isSourceNode,\n parseSourceModule,\n walkSourceAst,\n type SourceNode,\n} from '@fluenti/core/transform'\n\ninterface IdentifierNode extends SourceNode {\n type: 'Identifier'\n name: string\n}\n\ninterface StringLiteralNode extends SourceNode {\n type: 'StringLiteral'\n value: string\n}\n\ninterface NumericLiteralNode extends SourceNode {\n type: 'NumericLiteral'\n value: number\n}\n\ninterface TemplateElementNode extends SourceNode {\n type: 'TemplateElement'\n value: { raw: string; cooked: string | null }\n}\n\ninterface TemplateLiteralNode extends SourceNode {\n type: 'TemplateLiteral'\n quasis: TemplateElementNode[]\n expressions: SourceNode[]\n}\n\ninterface TaggedTemplateExpressionNode extends SourceNode {\n type: 'TaggedTemplateExpression'\n tag: SourceNode\n quasi: TemplateLiteralNode\n}\n\ninterface CallExpressionNode extends SourceNode {\n type: 'CallExpression'\n callee: SourceNode\n arguments: SourceNode[]\n}\n\ninterface ImportDeclarationNode extends SourceNode {\n type: 'ImportDeclaration'\n source: StringLiteralNode\n specifiers: SourceNode[]\n}\n\ninterface ImportSpecifierNode extends SourceNode {\n type: 'ImportSpecifier'\n imported: IdentifierNode | StringLiteralNode\n local: IdentifierNode\n}\n\ninterface ObjectExpressionNode extends SourceNode {\n type: 'ObjectExpression'\n properties: SourceNode[]\n}\n\ninterface ObjectPropertyNode extends SourceNode {\n type: 'ObjectProperty'\n key: SourceNode\n value: SourceNode\n computed?: boolean\n}\n\ninterface JSXElementNode extends SourceNode {\n type: 'JSXElement'\n openingElement: JSXOpeningElementNode\n children: SourceNode[]\n}\n\ninterface JSXFragmentNode extends SourceNode {\n type: 'JSXFragment'\n children: SourceNode[]\n}\n\ninterface JSXOpeningElementNode extends SourceNode {\n type: 'JSXOpeningElement'\n name: SourceNode\n attributes: SourceNode[]\n}\n\ninterface JSXAttributeNode extends SourceNode {\n type: 'JSXAttribute'\n name: SourceNode\n value?: SourceNode | null\n}\n\ninterface JSXExpressionContainerNode extends SourceNode {\n type: 'JSXExpressionContainer'\n expression: SourceNode\n}\n\ninterface JSXTextNode extends SourceNode {\n type: 'JSXText'\n value: string\n}\n\ninterface ExtractedDescriptor {\n id: string\n message?: string\n context?: string\n comment?: string\n}\n\nconst DIRECT_T_SOURCES = new Set([\n '@fluenti/core',\n '@fluenti/react',\n '@fluenti/vue',\n '@fluenti/solid',\n '@fluenti/next',\n])\n\nfunction classifyExpression(expr: string): string {\n const trimmed = expr.trim()\n // Simple identifier: name, count\n if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {\n return trimmed\n }\n // Dotted path: user.name → name\n if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(trimmed) && !trimmed.endsWith('.')) {\n const parts = trimmed.split('.')\n return parts[parts.length - 1]!\n }\n // Function call: fun() → fun, obj.method() → obj_method\n const callMatch = trimmed.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)\\s*\\(/)\n if (callMatch) {\n return callMatch[1]!.replace(/\\./g, '_')\n }\n return ''\n}\n\nfunction buildICUFromTemplate(\n strings: readonly string[],\n expressions: readonly string[],\n): string {\n let result = ''\n let positionalIndex = 0\n\n for (let index = 0; index < strings.length; index++) {\n result += strings[index]!\n if (index >= expressions.length) continue\n\n const name = classifyExpression(expressions[index]!)\n if (name === '') {\n result += `{arg${positionalIndex}}`\n positionalIndex++\n continue\n }\n\n result += `{${name}}`\n }\n\n return result\n}\n\nfunction createExtractedMessage(\n descriptor: ExtractedDescriptor,\n filename: string,\n node: SourceNode,\n): ExtractedMessage | undefined {\n if (!descriptor.message) {\n return undefined\n }\n\n const line = node.loc?.start.line ?? 1\n const column = (node.loc?.start.column ?? 0) + 1\n\n return {\n id: descriptor.id,\n message: descriptor.message,\n ...(descriptor.context !== undefined ? { context: descriptor.context } : {}),\n ...(descriptor.comment !== undefined ? { comment: descriptor.comment } : {}),\n origin: { file: filename, line, column },\n }\n}\n\nfunction descriptorFromStaticParts(\n parts: {\n id?: string\n message?: string\n context?: string\n comment?: string\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (!parts.message) {\n return undefined\n }\n\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: parts.id ?? generateId(parts.message, parts.context),\n message: parts.message,\n ...(parts.context !== undefined ? { context: parts.context } : {}),\n ...(parts.comment !== undefined ? { comment: parts.comment } : {}),\n }\n}\n\nfunction extractDescriptorFromCallArgument(\n argument: SourceNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (argument.type === 'StringLiteral') {\n return descriptorFromStaticParts({ message: (argument as StringLiteralNode).value }, idGenerator)\n }\n\n if (argument.type === 'TemplateLiteral') {\n const template = argument as TemplateLiteralNode\n if (template.expressions.length === 0) {\n const message = template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n return descriptorFromStaticParts({ message }, idGenerator)\n }\n return undefined\n }\n\n if (argument.type !== 'ObjectExpression') {\n return undefined\n }\n\n const staticParts: { id?: string; message?: string; context?: string; comment?: string } = {}\n for (const property of (argument as ObjectExpressionNode).properties) {\n if (property.type !== 'ObjectProperty') continue\n\n const objectProperty = property as ObjectPropertyNode\n if (objectProperty.computed || !isIdentifier(objectProperty.key)) continue\n\n const key = objectProperty.key.name\n if (!['id', 'message', 'context', 'comment'].includes(key)) continue\n\n const value = readStaticStringValue(objectProperty.value)\n if (value === undefined) continue\n staticParts[key as keyof typeof staticParts] = value\n }\n\n if (!staticParts.message) {\n return undefined\n }\n\n return descriptorFromStaticParts(staticParts, idGenerator)\n}\n\nconst SELECT_RESERVED_PROPS = new Set(['id', 'value', 'context', 'comment', 'options', 'other', 'tag'])\n\nfunction buildSelectICU(varName: string, cases: Record<string, string>, other: string): string {\n const options: string[] = []\n for (const [key, value] of Object.entries(cases)) {\n options.push(`${key} {${value}}`)\n }\n options.push(`other {${other}}`)\n return `{${varName}, select, ${options.join(' ')}}`\n}\n\nfunction extractSelectProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): { varName: string | undefined; id: string | undefined; context: string | undefined; comment: string | undefined; cases: Record<string, string>; other: string | undefined } {\n let varName: string | undefined\n let id: string | undefined\n let context: string | undefined\n let comment: string | undefined\n let other: string | undefined\n const cases: Record<string, string> = {}\n\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n const attr = attribute as JSXAttributeNode\n if (attr.name.type !== 'JSXIdentifier') continue\n const name = String(attr.name['name'])\n\n if (name === 'id') {\n id = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'value') {\n const raw = attr.value ? (readStaticStringValue(attr.value) ?? readExpressionSource(attr.value, code)) : undefined\n varName = raw ? classifyExpression(raw) || raw : undefined\n continue\n }\n if (name === 'context') {\n context = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'comment') {\n comment = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'other') {\n other = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (SELECT_RESERVED_PROPS.has(name)) continue\n\n const staticValue = attr.value ? readStaticStringValue(attr.value) : undefined\n if (staticValue === undefined) continue\n\n cases[name] = staticValue\n }\n\n return { varName, id, context, comment, cases, other }\n}\n\nfunction buildPluralICU(props: Record<string, string>): string {\n const categories = ['zero', 'one', 'two', 'few', 'many', 'other'] as const\n const countVar = props['value'] ?? props['count'] ?? 'count'\n const options: string[] = []\n const offset = props['offset']\n\n for (const category of categories) {\n const value = props[category]\n if (value === undefined) continue\n const key = category === 'zero' ? '=0' : category\n options.push(`${key} {${value}}`)\n }\n\n if (options.length === 0) {\n return ''\n }\n\n const offsetPrefix = offset ? `offset:${offset} ` : ''\n return `{${countVar}, plural, ${offsetPrefix}${options.join(' ')}}`\n}\n\nfunction extractRichTextMessage(children: readonly SourceNode[]): string | undefined {\n let nextIndex = 0\n\n function render(nodes: readonly SourceNode[]): string | undefined {\n let message = ''\n\n for (const node of nodes) {\n if (node.type === 'JSXText') {\n message += normalizeJsxText((node as JSXTextNode).value)\n continue\n }\n\n if (node.type === 'JSXElement') {\n const idx = nextIndex++\n const inner = render((node as JSXElementNode).children)\n if (inner === undefined) return undefined\n message += `<${idx}>${inner}</${idx}>`\n continue\n }\n\n if (node.type === 'JSXFragment') {\n const inner = render((node as JSXFragmentNode).children)\n if (inner === undefined) return undefined\n message += inner\n continue\n }\n\n if (node.type === 'JSXExpressionContainer') {\n const expression = (node as JSXExpressionContainerNode).expression\n if (expression.type === 'StringLiteral') {\n message += (expression as StringLiteralNode).value\n continue\n }\n if (expression.type === 'NumericLiteral') {\n message += String((expression as NumericLiteralNode).value)\n continue\n }\n return undefined\n }\n }\n\n return message\n }\n\n const message = render(children)\n if (message === undefined) return undefined\n\n const normalized = message.replace(/\\s+/g, ' ').trim()\n return normalized || undefined\n}\n\nfunction normalizeJsxText(value: string): string {\n return value.replace(/\\s+/g, ' ')\n}\n\nfunction readStaticStringValue(node: SourceNode): string | undefined {\n if (node.type === 'StringLiteral') {\n return (node as StringLiteralNode).value\n }\n\n if (node.type === 'NumericLiteral') {\n return String((node as NumericLiteralNode).value)\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readStaticStringValue((node as JSXExpressionContainerNode).expression)\n }\n\n if (node.type === 'TemplateLiteral') {\n const template = node as TemplateLiteralNode\n if (template.expressions.length === 0) {\n return template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n }\n }\n\n return undefined\n}\n\nfunction readExpressionSource(node: SourceNode, code: string): string | undefined {\n if (node.start == null || node.end == null) {\n return undefined\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readExpressionSource((node as JSXExpressionContainerNode).expression, code)\n }\n\n return code.slice(node.start, node.end).trim()\n}\n\nfunction getJsxAttribute(\n openingElement: JSXOpeningElementNode,\n name: string,\n): JSXAttributeNode | undefined {\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n\n const jsxAttribute = attribute as JSXAttributeNode\n if (jsxAttribute.name.type === 'JSXIdentifier' && jsxAttribute.name['name'] === name) {\n return jsxAttribute\n }\n }\n\n return undefined\n}\n\nfunction extractPluralProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): Record<string, string> {\n const props: Record<string, string> = {}\n const propNames = ['id', 'value', 'count', 'offset', 'zero', 'one', 'two', 'few', 'many', 'other']\n\n for (const name of propNames) {\n const attribute = getJsxAttribute(openingElement, name)\n if (!attribute?.value) continue\n\n const staticValue = readStaticStringValue(attribute.value)\n if (staticValue !== undefined) {\n props[name] = staticValue\n continue\n }\n\n const exprValue = readExpressionSource(attribute.value, code)\n if (exprValue !== undefined && (name === 'value' || name === 'count' || name === 'offset')) {\n props[name] = exprValue\n }\n }\n\n return props\n}\n\nfunction extractTaggedTemplateMessage(\n code: string,\n node: TaggedTemplateExpressionNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor {\n const strings = node.quasi.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw)\n const expressions = node.quasi.expressions.map((expression) => {\n if (expression.start == null || expression.end == null) {\n return ''\n }\n return code.slice(expression.start, expression.end)\n })\n const message = buildICUFromTemplate(strings, expressions)\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: generateId(message),\n message,\n }\n}\n\nfunction collectDirectBindings(ast: SourceNode): Map<string, 't' | 'msg'> {\n const bindings = new Map<string, 't' | 'msg'>()\n const body = Array.isArray(ast['body']) ? ast['body'] : []\n\n for (const entry of body) {\n if (!isImportDeclaration(entry)) continue\n if (!DIRECT_T_SOURCES.has(entry.source.value)) continue\n\n for (const specifier of entry.specifiers) {\n if (!isImportSpecifier(specifier)) continue\n const importedName = readImportedName(specifier)\n if (importedName === 't' || importedName === 'msg') {\n bindings.set(specifier.local.name, importedName as 't' | 'msg')\n }\n }\n }\n\n return bindings\n}\n\nexport function extractFromTsx(\n code: string,\n filename: string,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedMessage[] {\n const ast = parseSourceModule(code)\n if (!ast) {\n console.warn(`[fluenti] Failed to parse ${filename} — skipping message extraction`)\n return []\n }\n\n const messages: ExtractedMessage[] = []\n const directBindings = collectDirectBindings(ast)\n\n walkSourceAst(ast, (node: SourceNode) => {\n if (node.type === 'TaggedTemplateExpression') {\n const tagged = node as TaggedTemplateExpressionNode\n if (\n isIdentifier(tagged.tag)\n && (tagged.tag.name === 't' || directBindings.has(tagged.tag.name))\n ) {\n const descriptor = extractTaggedTemplateMessage(code, tagged, idGenerator)\n const bindingType = directBindings.get(tagged.tag.name)\n if (bindingType === 'msg') {\n descriptor.comment = 'msg tagged template'\n }\n const extracted = createExtractedMessage(\n descriptor,\n filename,\n tagged,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type === 'CallExpression') {\n const call = node as CallExpressionNode\n const callBindingType = directBindings.get(call.callee && isIdentifier(call.callee) ? call.callee.name : '')\n if (isIdentifier(call.callee) && (call.callee.name === 't' || (directBindings.has(call.callee.name) && callBindingType === 't'))) {\n if (directBindings.has(call.callee.name) && call.arguments[0]?.type !== 'ObjectExpression') {\n return\n }\n const descriptor = call.arguments[0] ? extractDescriptorFromCallArgument(call.arguments[0], idGenerator) : undefined\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, call)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n } else if (\n call.callee.type === 'MemberExpression'\n && isIdentifier(call.callee['object'])\n && directBindings.get((call.callee['object'] as IdentifierNode).name) === 'msg'\n && isIdentifier(call.callee['property'])\n && (call.callee['property'] as IdentifierNode).name === 'descriptor'\n && call.arguments[0]\n ) {\n const descriptor = extractDescriptorFromCallArgument(call.arguments[0], idGenerator)\n const extracted = descriptor ? createExtractedMessage(descriptor, filename, call) : undefined\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type !== 'JSXElement') {\n return\n }\n\n const element = node as JSXElementNode\n const openingElement = element.openingElement\n const elementName = readJsxElementName(openingElement.name)\n\n if (elementName === 'Trans') {\n const messageAttr = getJsxAttribute(openingElement, 'message')\n const idAttr = getJsxAttribute(openingElement, 'id')\n const contextAttr = getJsxAttribute(openingElement, 'context')\n const commentAttr = getJsxAttribute(openingElement, 'comment')\n\n const descriptor = messageAttr?.value\n ? buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: readStaticStringValue(messageAttr.value),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n : buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: extractRichTextMessage(element.children),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, element)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Plural') {\n const props = extractPluralProps(openingElement, code)\n const message = buildPluralICU(props)\n if (!message) {\n return\n }\n\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: props['id'] ?? generateId(message),\n message,\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Select') {\n const { varName, id, context, comment, cases, other } = extractSelectProps(openingElement, code)\n if (!varName || !other || Object.keys(cases).length === 0) {\n return\n }\n\n const message = buildSelectICU(varName, cases, other)\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: id ?? generateId(message, context),\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n })\n\n return messages\n}\n\nfunction isImportDeclaration(node: unknown): node is ImportDeclarationNode {\n return isSourceNode(node) && node.type === 'ImportDeclaration'\n}\n\nfunction isImportSpecifier(node: unknown): node is ImportSpecifierNode {\n return isSourceNode(node) && node.type === 'ImportSpecifier'\n}\n\nfunction readImportedName(specifier: ImportSpecifierNode): string | undefined {\n if (specifier.imported.type === 'Identifier') {\n return (specifier.imported as IdentifierNode).name\n }\n if (specifier.imported.type === 'StringLiteral') {\n return (specifier.imported as StringLiteralNode).value\n }\n return undefined\n}\n\nfunction readJsxElementName(node: SourceNode): string | undefined {\n if (node.type === 'JSXIdentifier') {\n return String(node['name'])\n }\n return undefined\n}\n\nfunction buildStaticTransDescriptor(\n parts: {\n id: string | undefined\n message: string | undefined\n context: string | undefined\n comment: string | undefined\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n const payload: {\n id?: string\n message?: string\n context?: string\n comment?: string\n } = {}\n\n if (parts.id !== undefined) payload.id = parts.id\n if (parts.message !== undefined) payload.message = parts.message\n if (parts.context !== undefined) payload.context = parts.context\n if (parts.comment !== undefined) payload.comment = parts.comment\n\n return descriptorFromStaticParts(payload, idGenerator)\n}\n\nfunction isIdentifier(node: unknown): node is IdentifierNode {\n return isSourceNode(node) && node.type === 'Identifier'\n}\n"],"mappings":";;AA+GA,IAAM,IAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,EAAmB,GAAsB;CAChD,IAAM,IAAU,EAAK,MAAM;AAE3B,KAAI,6BAA6B,KAAK,EAAQ,CAC5C,QAAO;AAGT,KAAI,8BAA8B,KAAK,EAAQ,IAAI,CAAC,EAAQ,SAAS,IAAI,EAAE;EACzE,IAAM,IAAQ,EAAQ,MAAM,IAAI;AAChC,SAAO,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,GACiC;CACjC,IAAM,IAKF,EAAE;AAON,QALI,EAAM,OAAO,KAAA,MAAW,EAAQ,KAAK,EAAM,KAC3C,EAAM,YAAY,KAAA,MAAW,EAAQ,UAAU,EAAM,UACrD,EAAM,YAAY,KAAA,MAAW,EAAQ,UAAU,EAAM,UACrD,EAAM,YAAY,KAAA,MAAW,EAAQ,UAAU,EAAM,UAElD,EAA0B,GAAS,EAAY;;AAGxD,SAAS,EAAa,GAAuC;AAC3D,QAAO,EAAa,EAAK,IAAI,EAAK,SAAS"}
|
|
1
|
+
{"version":3,"file":"tsx-extractor-C-HZNobu.js","names":[],"sources":["../src/tsx-extractor.ts"],"sourcesContent":["import type { ExtractedMessage } from '@fluenti/core/compiler'\nimport {\n createMessageId,\n isSourceNode,\n parseSourceModule,\n walkSourceAst,\n type SourceNode,\n} from '@fluenti/core/transform'\n\ninterface IdentifierNode extends SourceNode {\n type: 'Identifier'\n name: string\n}\n\ninterface StringLiteralNode extends SourceNode {\n type: 'StringLiteral'\n value: string\n}\n\ninterface NumericLiteralNode extends SourceNode {\n type: 'NumericLiteral'\n value: number\n}\n\ninterface TemplateElementNode extends SourceNode {\n type: 'TemplateElement'\n value: { raw: string; cooked: string | null }\n}\n\ninterface TemplateLiteralNode extends SourceNode {\n type: 'TemplateLiteral'\n quasis: TemplateElementNode[]\n expressions: SourceNode[]\n}\n\ninterface TaggedTemplateExpressionNode extends SourceNode {\n type: 'TaggedTemplateExpression'\n tag: SourceNode\n quasi: TemplateLiteralNode\n}\n\ninterface CallExpressionNode extends SourceNode {\n type: 'CallExpression'\n callee: SourceNode\n arguments: SourceNode[]\n}\n\ninterface ImportDeclarationNode extends SourceNode {\n type: 'ImportDeclaration'\n source: StringLiteralNode\n specifiers: SourceNode[]\n}\n\ninterface ImportSpecifierNode extends SourceNode {\n type: 'ImportSpecifier'\n imported: IdentifierNode | StringLiteralNode\n local: IdentifierNode\n}\n\ninterface ObjectExpressionNode extends SourceNode {\n type: 'ObjectExpression'\n properties: SourceNode[]\n}\n\ninterface ObjectPropertyNode extends SourceNode {\n type: 'ObjectProperty'\n key: SourceNode\n value: SourceNode\n computed?: boolean\n}\n\ninterface JSXElementNode extends SourceNode {\n type: 'JSXElement'\n openingElement: JSXOpeningElementNode\n children: SourceNode[]\n}\n\ninterface JSXFragmentNode extends SourceNode {\n type: 'JSXFragment'\n children: SourceNode[]\n}\n\ninterface JSXOpeningElementNode extends SourceNode {\n type: 'JSXOpeningElement'\n name: SourceNode\n attributes: SourceNode[]\n}\n\ninterface JSXAttributeNode extends SourceNode {\n type: 'JSXAttribute'\n name: SourceNode\n value?: SourceNode | null\n}\n\ninterface JSXExpressionContainerNode extends SourceNode {\n type: 'JSXExpressionContainer'\n expression: SourceNode\n}\n\ninterface JSXTextNode extends SourceNode {\n type: 'JSXText'\n value: string\n}\n\ninterface ExtractedDescriptor {\n id: string\n message?: string\n context?: string\n comment?: string\n}\n\nconst DIRECT_T_SOURCES = new Set([\n '@fluenti/core',\n '@fluenti/react',\n '@fluenti/vue',\n '@fluenti/solid',\n '@fluenti/next',\n])\n\nfunction classifyExpression(expr: string): string {\n const trimmed = expr.trim()\n // Simple identifier: name, count\n if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {\n return trimmed\n }\n // Dotted path: user.name → name\n if (/^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(trimmed) && !trimmed.endsWith('.')) {\n const parts = trimmed.split('.')\n return parts[parts.length - 1]!\n }\n // Function call: fun() → fun, obj.method() → obj_method\n const callMatch = trimmed.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)\\s*\\(/)\n if (callMatch) {\n return callMatch[1]!.replace(/\\./g, '_')\n }\n return ''\n}\n\nfunction buildICUFromTemplate(\n strings: readonly string[],\n expressions: readonly string[],\n): string {\n let result = ''\n let positionalIndex = 0\n\n for (let index = 0; index < strings.length; index++) {\n result += strings[index]!\n if (index >= expressions.length) continue\n\n const name = classifyExpression(expressions[index]!)\n if (name === '') {\n result += `{arg${positionalIndex}}`\n positionalIndex++\n continue\n }\n\n result += `{${name}}`\n }\n\n return result\n}\n\nfunction createExtractedMessage(\n descriptor: ExtractedDescriptor,\n filename: string,\n node: SourceNode,\n): ExtractedMessage | undefined {\n if (!descriptor.message) {\n return undefined\n }\n\n const line = node.loc?.start.line ?? 1\n const column = (node.loc?.start.column ?? 0) + 1\n\n return {\n id: descriptor.id,\n message: descriptor.message,\n ...(descriptor.context !== undefined ? { context: descriptor.context } : {}),\n ...(descriptor.comment !== undefined ? { comment: descriptor.comment } : {}),\n origin: { file: filename, line, column },\n }\n}\n\nfunction descriptorFromStaticParts(\n parts: {\n id?: string\n message?: string\n context?: string\n comment?: string\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (!parts.message) {\n return undefined\n }\n\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: parts.id ?? generateId(parts.message, parts.context),\n message: parts.message,\n ...(parts.context !== undefined ? { context: parts.context } : {}),\n ...(parts.comment !== undefined ? { comment: parts.comment } : {}),\n }\n}\n\nfunction extractDescriptorFromCallArgument(\n argument: SourceNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n if (argument.type === 'StringLiteral') {\n return descriptorFromStaticParts({ message: (argument as StringLiteralNode).value }, idGenerator)\n }\n\n if (argument.type === 'TemplateLiteral') {\n const template = argument as TemplateLiteralNode\n if (template.expressions.length === 0) {\n const message = template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n return descriptorFromStaticParts({ message }, idGenerator)\n }\n return undefined\n }\n\n if (argument.type !== 'ObjectExpression') {\n return undefined\n }\n\n const staticParts: { id?: string; message?: string; context?: string; comment?: string } = {}\n for (const property of (argument as ObjectExpressionNode).properties) {\n if (property.type !== 'ObjectProperty') continue\n\n const objectProperty = property as ObjectPropertyNode\n if (objectProperty.computed || !isIdentifier(objectProperty.key)) continue\n\n const key = objectProperty.key.name\n if (!['id', 'message', 'context', 'comment'].includes(key)) continue\n\n const value = readStaticStringValue(objectProperty.value)\n if (value === undefined) continue\n staticParts[key as keyof typeof staticParts] = value\n }\n\n if (!staticParts.message) {\n return undefined\n }\n\n return descriptorFromStaticParts(staticParts, idGenerator)\n}\n\nconst SELECT_RESERVED_PROPS = new Set(['id', 'value', 'context', 'comment', 'options', 'other', 'tag'])\n\nfunction buildSelectICU(varName: string, cases: Record<string, string>, other: string): string {\n const options: string[] = []\n for (const [key, value] of Object.entries(cases)) {\n options.push(`${key} {${value}}`)\n }\n options.push(`other {${other}}`)\n return `{${varName}, select, ${options.join(' ')}}`\n}\n\nfunction extractSelectProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): { varName: string | undefined; id: string | undefined; context: string | undefined; comment: string | undefined; cases: Record<string, string>; other: string | undefined } {\n let varName: string | undefined\n let id: string | undefined\n let context: string | undefined\n let comment: string | undefined\n let other: string | undefined\n const cases: Record<string, string> = {}\n\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n const attr = attribute as JSXAttributeNode\n if (attr.name.type !== 'JSXIdentifier') continue\n const name = String(attr.name['name'])\n\n if (name === 'id') {\n id = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'value') {\n const raw = attr.value ? (readStaticStringValue(attr.value) ?? readExpressionSource(attr.value, code)) : undefined\n varName = raw ? classifyExpression(raw) || raw : undefined\n continue\n }\n if (name === 'context') {\n context = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'comment') {\n comment = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (name === 'other') {\n other = attr.value ? readStaticStringValue(attr.value) : undefined\n continue\n }\n if (SELECT_RESERVED_PROPS.has(name)) continue\n\n const staticValue = attr.value ? readStaticStringValue(attr.value) : undefined\n if (staticValue === undefined) continue\n\n cases[name] = staticValue\n }\n\n return { varName, id, context, comment, cases, other }\n}\n\nfunction buildPluralICU(props: Record<string, string>): string {\n const categories = ['zero', 'one', 'two', 'few', 'many', 'other'] as const\n const countVar = props['value'] ?? props['count'] ?? 'count'\n const options: string[] = []\n const offset = props['offset']\n\n for (const category of categories) {\n const value = props[category]\n if (value === undefined) continue\n const key = category === 'zero' ? '=0' : category\n options.push(`${key} {${value}}`)\n }\n\n if (options.length === 0) {\n return ''\n }\n\n const offsetPrefix = offset ? `offset:${offset} ` : ''\n return `{${countVar}, plural, ${offsetPrefix}${options.join(' ')}}`\n}\n\nfunction extractRichTextMessage(children: readonly SourceNode[]): string | undefined {\n let nextIndex = 0\n\n function render(nodes: readonly SourceNode[]): string | undefined {\n let message = ''\n\n for (const node of nodes) {\n if (node.type === 'JSXText') {\n message += normalizeJsxText((node as JSXTextNode).value)\n continue\n }\n\n if (node.type === 'JSXElement') {\n const idx = nextIndex++\n const inner = render((node as JSXElementNode).children)\n if (inner === undefined) return undefined\n message += `<${idx}>${inner}</${idx}>`\n continue\n }\n\n if (node.type === 'JSXFragment') {\n const inner = render((node as JSXFragmentNode).children)\n if (inner === undefined) return undefined\n message += inner\n continue\n }\n\n if (node.type === 'JSXExpressionContainer') {\n const expression = (node as JSXExpressionContainerNode).expression\n if (expression.type === 'StringLiteral') {\n message += (expression as StringLiteralNode).value\n continue\n }\n if (expression.type === 'NumericLiteral') {\n message += String((expression as NumericLiteralNode).value)\n continue\n }\n return undefined\n }\n }\n\n return message\n }\n\n const message = render(children)\n if (message === undefined) return undefined\n\n const normalized = message.replace(/\\s+/g, ' ').trim()\n return normalized || undefined\n}\n\nfunction normalizeJsxText(value: string): string {\n return value.replace(/\\s+/g, ' ')\n}\n\nfunction readStaticStringValue(node: SourceNode): string | undefined {\n if (node.type === 'StringLiteral') {\n return (node as StringLiteralNode).value\n }\n\n if (node.type === 'NumericLiteral') {\n return String((node as NumericLiteralNode).value)\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readStaticStringValue((node as JSXExpressionContainerNode).expression)\n }\n\n if (node.type === 'TemplateLiteral') {\n const template = node as TemplateLiteralNode\n if (template.expressions.length === 0) {\n return template.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('')\n }\n }\n\n return undefined\n}\n\nfunction readExpressionSource(node: SourceNode, code: string): string | undefined {\n if (node.start == null || node.end == null) {\n return undefined\n }\n\n if (node.type === 'JSXExpressionContainer') {\n return readExpressionSource((node as JSXExpressionContainerNode).expression, code)\n }\n\n return code.slice(node.start, node.end).trim()\n}\n\nfunction getJsxAttribute(\n openingElement: JSXOpeningElementNode,\n name: string,\n): JSXAttributeNode | undefined {\n for (const attribute of openingElement.attributes) {\n if (attribute.type !== 'JSXAttribute') continue\n\n const jsxAttribute = attribute as JSXAttributeNode\n if (jsxAttribute.name.type === 'JSXIdentifier' && jsxAttribute.name['name'] === name) {\n return jsxAttribute\n }\n }\n\n return undefined\n}\n\nfunction extractPluralProps(\n openingElement: JSXOpeningElementNode,\n code: string,\n): Record<string, string> {\n const props: Record<string, string> = {}\n const propNames = ['id', 'value', 'count', 'offset', 'zero', 'one', 'two', 'few', 'many', 'other']\n\n for (const name of propNames) {\n const attribute = getJsxAttribute(openingElement, name)\n if (!attribute?.value) continue\n\n const staticValue = readStaticStringValue(attribute.value)\n if (staticValue !== undefined) {\n props[name] = staticValue\n continue\n }\n\n const exprValue = readExpressionSource(attribute.value, code)\n if (exprValue !== undefined && (name === 'value' || name === 'count' || name === 'offset')) {\n props[name] = exprValue\n }\n }\n\n return props\n}\n\nfunction extractTaggedTemplateMessage(\n code: string,\n node: TaggedTemplateExpressionNode,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor {\n const strings = node.quasi.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw)\n const expressions = node.quasi.expressions.map((expression) => {\n if (expression.start == null || expression.end == null) {\n return ''\n }\n return code.slice(expression.start, expression.end)\n })\n const message = buildICUFromTemplate(strings, expressions)\n const generateId = idGenerator ?? createMessageId\n\n return {\n id: generateId(message),\n message,\n }\n}\n\nfunction collectDirectBindings(ast: SourceNode): Map<string, 't' | 'msg'> {\n const bindings = new Map<string, 't' | 'msg'>()\n const body = Array.isArray(ast['body']) ? ast['body'] : []\n\n for (const entry of body) {\n if (!isImportDeclaration(entry)) continue\n if (!DIRECT_T_SOURCES.has(entry.source.value)) continue\n\n for (const specifier of entry.specifiers) {\n if (!isImportSpecifier(specifier)) continue\n const importedName = readImportedName(specifier)\n if (importedName === 't' || importedName === 'msg') {\n bindings.set(specifier.local.name, importedName as 't' | 'msg')\n }\n }\n }\n\n return bindings\n}\n\nexport function extractFromTsx(\n code: string,\n filename: string,\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedMessage[] {\n const ast = parseSourceModule(code)\n if (!ast) {\n console.warn(`[fluenti] Failed to parse ${filename} — skipping message extraction`)\n return []\n }\n\n const messages: ExtractedMessage[] = []\n const directBindings = collectDirectBindings(ast)\n\n walkSourceAst(ast, (node: SourceNode) => {\n if (node.type === 'TaggedTemplateExpression') {\n const tagged = node as TaggedTemplateExpressionNode\n if (\n isIdentifier(tagged.tag)\n && (tagged.tag.name === 't' || directBindings.has(tagged.tag.name))\n ) {\n const descriptor = extractTaggedTemplateMessage(code, tagged, idGenerator)\n const bindingType = directBindings.get(tagged.tag.name)\n if (bindingType === 'msg') {\n descriptor.comment = 'msg tagged template'\n }\n const extracted = createExtractedMessage(\n descriptor,\n filename,\n tagged,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type === 'CallExpression') {\n const call = node as CallExpressionNode\n const callBindingType = directBindings.get(call.callee && isIdentifier(call.callee) ? call.callee.name : '')\n if (isIdentifier(call.callee) && (call.callee.name === 't' || (directBindings.has(call.callee.name) && callBindingType === 't'))) {\n if (directBindings.has(call.callee.name) && call.arguments[0]?.type !== 'ObjectExpression') {\n return\n }\n const descriptor = call.arguments[0] ? extractDescriptorFromCallArgument(call.arguments[0], idGenerator) : undefined\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, call)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n } else if (\n call.callee.type === 'MemberExpression'\n && isIdentifier(call.callee['object'])\n && directBindings.get((call.callee['object'] as IdentifierNode).name) === 'msg'\n && isIdentifier(call.callee['property'])\n && (call.callee['property'] as IdentifierNode).name === 'descriptor'\n && call.arguments[0]\n ) {\n const descriptor = extractDescriptorFromCallArgument(call.arguments[0], idGenerator)\n const extracted = descriptor ? createExtractedMessage(descriptor, filename, call) : undefined\n if (extracted) {\n messages.push(extracted)\n }\n }\n return\n }\n\n if (node.type !== 'JSXElement') {\n return\n }\n\n const element = node as JSXElementNode\n const openingElement = element.openingElement\n const elementName = readJsxElementName(openingElement.name)\n\n if (elementName === 'Trans') {\n const messageAttr = getJsxAttribute(openingElement, 'message')\n const idAttr = getJsxAttribute(openingElement, 'id')\n const contextAttr = getJsxAttribute(openingElement, 'context')\n const commentAttr = getJsxAttribute(openingElement, 'comment')\n\n const descriptor = messageAttr?.value\n ? buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: readStaticStringValue(messageAttr.value),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n : buildStaticTransDescriptor({\n id: idAttr?.value ? readStaticStringValue(idAttr.value) : undefined,\n message: extractRichTextMessage(element.children),\n context: contextAttr?.value ? readStaticStringValue(contextAttr.value) : undefined,\n comment: commentAttr?.value ? readStaticStringValue(commentAttr.value) : undefined,\n }, idGenerator)\n\n const extracted = descriptor\n ? createExtractedMessage(descriptor, filename, element)\n : undefined\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Plural') {\n const props = extractPluralProps(openingElement, code)\n const message = buildPluralICU(props)\n if (!message) {\n return\n }\n\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: props['id'] ?? generateId(message),\n message,\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n return\n }\n\n if (elementName === 'Select') {\n const { varName, id, context, comment, cases, other } = extractSelectProps(openingElement, code)\n if (!varName || !other || Object.keys(cases).length === 0) {\n return\n }\n\n const message = buildSelectICU(varName, cases, other)\n const generateId = idGenerator ?? createMessageId\n const extracted = createExtractedMessage(\n {\n id: id ?? generateId(message, context),\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n filename,\n element,\n )\n if (extracted) {\n messages.push(extracted)\n }\n }\n })\n\n return messages\n}\n\nfunction isImportDeclaration(node: unknown): node is ImportDeclarationNode {\n return isSourceNode(node) && node.type === 'ImportDeclaration'\n}\n\nfunction isImportSpecifier(node: unknown): node is ImportSpecifierNode {\n return isSourceNode(node) && node.type === 'ImportSpecifier'\n}\n\nfunction readImportedName(specifier: ImportSpecifierNode): string | undefined {\n if (specifier.imported.type === 'Identifier') {\n return (specifier.imported as IdentifierNode).name\n }\n if (specifier.imported.type === 'StringLiteral') {\n return (specifier.imported as StringLiteralNode).value\n }\n return undefined\n}\n\nfunction readJsxElementName(node: SourceNode): string | undefined {\n if (node.type === 'JSXIdentifier') {\n return String(node['name'])\n }\n return undefined\n}\n\nfunction buildStaticTransDescriptor(\n parts: {\n id: string | undefined\n message: string | undefined\n context: string | undefined\n comment: string | undefined\n },\n idGenerator?: (message: string, context?: string) => string,\n): ExtractedDescriptor | undefined {\n const payload: {\n id?: string\n message?: string\n context?: string\n comment?: string\n } = {}\n\n if (parts.id !== undefined) payload.id = parts.id\n if (parts.message !== undefined) payload.message = parts.message\n if (parts.context !== undefined) payload.context = parts.context\n if (parts.comment !== undefined) payload.comment = parts.comment\n\n return descriptorFromStaticParts(payload, idGenerator)\n}\n\nfunction isIdentifier(node: unknown): node is IdentifierNode {\n return isSourceNode(node) && node.type === 'Identifier'\n}\n"],"mappings":";;AA+GA,IAAM,IAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,EAAmB,GAAsB;CAChD,IAAM,IAAU,EAAK,MAAM;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