@fluentic/i18n 0.1.0-beta.1 → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +9 -1
- package/dist/adapter.d.ts +6 -4
- package/dist/adapter.js +4 -3
- package/dist/compiled.d.ts +26 -24
- package/dist/compiled.js +4 -2
- package/dist/compiled.js.map +1 -1
- package/dist/compiler-support.d.ts +4 -0
- package/dist/compiler-support.js +4 -0
- package/dist/core/format.d.ts +11 -0
- package/dist/core/i18n.d.ts +26 -0
- package/dist/core/index.d.ts +1 -5
- package/dist/core/index.js +3 -2
- package/dist/core/types.d.ts +79 -0
- package/dist/hash-VJlyT31Z.js +90 -0
- package/dist/hash-VJlyT31Z.js.map +1 -0
- package/dist/hydration-store-BK6UxrtJ.js +13 -0
- package/dist/hydration-store-BK6UxrtJ.js.map +1 -0
- package/dist/hydration-store.d.ts +29 -0
- package/dist/hydration.d.ts +7 -0
- package/dist/hydration.js +35 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -2
- package/dist/{interpreter-Dld8QyOI.js → interpreter-BfzvLLrD.js} +4 -3
- package/dist/interpreter-BfzvLLrD.js.map +1 -0
- package/dist/{manager-BW778X1Y.js → manager-BgMJWXWY.js} +21 -31
- package/dist/manager-BgMJWXWY.js.map +1 -0
- package/dist/manager.d.ts +62 -0
- package/dist/message-D4jK2Lzc.js +9 -0
- package/dist/message-D4jK2Lzc.js.map +1 -0
- package/dist/react.d.ts +41 -46
- package/dist/react.js +12 -8
- package/dist/react.js.map +1 -1
- package/dist/registry-manager.d.ts +7 -0
- package/dist/runtime-DXnGeCBw.js +110 -0
- package/dist/runtime-DXnGeCBw.js.map +1 -0
- package/dist/shared/compact.d.ts +5 -0
- package/dist/shared/formatting.d.ts +11 -0
- package/dist/shared/hash.d.ts +7 -0
- package/dist/shared/interpreter.d.ts +2 -0
- package/dist/shared/message.d.ts +2 -0
- package/dist/shared/runtime.d.ts +49 -0
- package/dist/{src-BovRx-mX.js → src-ON68XIog.js} +9 -7
- package/dist/src-ON68XIog.js.map +1 -0
- package/dist/state-manager.d.ts +6 -0
- package/dist/state.d.ts +8 -0
- package/dist/storage-manager.d.ts +14 -0
- package/dist/{translation-manager-C79eKu2K.js → translation-manager-BkmFnlb_.js} +5 -104
- package/dist/translation-manager-BkmFnlb_.js.map +1 -0
- package/dist/translation-manager.d.ts +34 -0
- package/dist/translation.d.ts +20 -0
- package/dist/types-BkDsJfVD.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/package.json +20 -54
- package/dist/adapter-CWC8rng-.d.ts +0 -178
- package/dist/analyze-CdXCxQDg.d.ts +0 -14
- package/dist/compact-CJ0OWoIv.d.ts +0 -7
- package/dist/compiler-BZtB9WLi.js +0 -365
- package/dist/compiler-BZtB9WLi.js.map +0 -1
- package/dist/compiler.d.ts +0 -35
- package/dist/compiler.js +0 -3
- package/dist/i18n-CfYNwubL.d.ts +0 -25
- package/dist/interpreter-Dld8QyOI.js.map +0 -1
- package/dist/manager-BW778X1Y.js.map +0 -1
- package/dist/options-DE7vYj0e.d.ts +0 -7
- package/dist/options-Dxxx0aOz.js +0 -23
- package/dist/options-Dxxx0aOz.js.map +0 -1
- package/dist/plugin/babel.d.ts +0 -11
- package/dist/plugin/babel.js +0 -31
- package/dist/plugin/babel.js.map +0 -1
- package/dist/plugin/esbuild.d.ts +0 -7
- package/dist/plugin/esbuild.js +0 -37
- package/dist/plugin/esbuild.js.map +0 -1
- package/dist/plugin/rollup.d.ts +0 -30
- package/dist/plugin/rollup.js +0 -34
- package/dist/plugin/rollup.js.map +0 -1
- package/dist/plugin/vite.d.ts +0 -31
- package/dist/plugin/vite.js +0 -11
- package/dist/plugin/vite.js.map +0 -1
- package/dist/plugin/webpack-loader.d.ts +0 -3
- package/dist/plugin/webpack-loader.js +0 -21
- package/dist/plugin/webpack-loader.js.map +0 -1
- package/dist/plugin/webpack.d.ts +0 -8
- package/dist/plugin/webpack.js +0 -22
- package/dist/plugin/webpack.js.map +0 -1
- package/dist/src-BovRx-mX.js.map +0 -1
- package/dist/translation-manager-C79eKu2K.js.map +0 -1
- package/dist/types-BuGoCU3P.d.ts +0 -75
- package/dist-cjs/babel.cjs +0 -379
- package/dist-cjs/babel.cjs.map +0 -1
- package/src/adapter.ts +0 -6
- package/src/compiled.ts +0 -116
- package/src/compiler/analyze.ts +0 -182
- package/src/compiler/index.ts +0 -208
- package/src/compiler/message.ts +0 -74
- package/src/core/format.ts +0 -40
- package/src/core/i18n.ts +0 -124
- package/src/core/index.ts +0 -1
- package/src/core/types.ts +0 -121
- package/src/index.ts +0 -9
- package/src/manager.ts +0 -175
- package/src/plugin/babel.ts +0 -34
- package/src/plugin/esbuild.ts +0 -45
- package/src/plugin/options.ts +0 -24
- package/src/plugin/rollup.ts +0 -29
- package/src/plugin/vite.ts +0 -6
- package/src/plugin/webpack-loader.ts +0 -22
- package/src/plugin/webpack.ts +0 -15
- package/src/react.ts +0 -97
- package/src/registry-manager.ts +0 -3
- package/src/shared/compact.ts +0 -51
- package/src/shared/formatting.ts +0 -121
- package/src/shared/interpreter.ts +0 -128
- package/src/shared/runtime.ts +0 -131
- package/src/state-manager.ts +0 -29
- package/src/state.ts +0 -20
- package/src/storage-manager.ts +0 -47
- package/src/translation-manager.ts +0 -82
- package/src/translation.ts +0 -106
- package/src/types.ts +0 -2
package/dist-cjs/babel.cjs
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
// \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
let _babel_generator = require("@babel/generator");
|
|
23
|
-
_babel_generator = __toESM(_babel_generator, 1);
|
|
24
|
-
let _babel_types = require("@babel/types");
|
|
25
|
-
_babel_types = __toESM(_babel_types, 1);
|
|
26
|
-
let _babel_parser = require("@babel/parser");
|
|
27
|
-
let _babel_traverse = require("@babel/traverse");
|
|
28
|
-
_babel_traverse = __toESM(_babel_traverse, 1);
|
|
29
|
-
let _formatjs_icu_messageformat_parser = require("@formatjs/icu-messageformat-parser");
|
|
30
|
-
let node_crypto = require("node:crypto");
|
|
31
|
-
let jiti = require("jiti");
|
|
32
|
-
let node_fs = require("node:fs");
|
|
33
|
-
let node_path = require("node:path");
|
|
34
|
-
// src/compiler/analyze.ts
|
|
35
|
-
const traverse = _babel_traverse.default.default ?? _babel_traverse.default;
|
|
36
|
-
const importMap = {
|
|
37
|
-
"@fluentic/i18n": "@fluentic/i18n/compiled",
|
|
38
|
-
"@fluentic/i18n/core": "@fluentic/i18n/compiled"
|
|
39
|
-
};
|
|
40
|
-
function parseSource(code, filename) {
|
|
41
|
-
return (0, _babel_parser.parse)(code, {
|
|
42
|
-
sourceFilename: filename,
|
|
43
|
-
sourceType: "unambiguous",
|
|
44
|
-
plugins: [
|
|
45
|
-
.../\.[cm]?tsx?$/.test(filename) ? ["typescript"] : [],
|
|
46
|
-
...!/\.[cm]?ts$/.test(filename) ? ["jsx"] : [],
|
|
47
|
-
"decorators-legacy",
|
|
48
|
-
"importAttributes"
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function unwrap(path) {
|
|
53
|
-
while (path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() || path.isTypeCastExpression() || path.isParenthesizedExpression()) path = path.get("expression");
|
|
54
|
-
return path;
|
|
55
|
-
}
|
|
56
|
-
function literal(path, seen = /* @__PURE__ */ new Set()) {
|
|
57
|
-
path = unwrap(path);
|
|
58
|
-
if (path.isStringLiteral()) return path.node.value;
|
|
59
|
-
if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? "";
|
|
60
|
-
if (path.isIdentifier()) {
|
|
61
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
62
|
-
if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {
|
|
63
|
-
seen.add(binding);
|
|
64
|
-
return literal(binding.path.get("init"), seen);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
function memberName(path) {
|
|
70
|
-
if (!path.isMemberExpression()) return null;
|
|
71
|
-
const property = path.get("property");
|
|
72
|
-
return !path.node.computed && property.isIdentifier() ? property.node.name : property.isStringLiteral() ? property.node.value : null;
|
|
73
|
-
}
|
|
74
|
-
function analyzer(imports = Object.keys(importMap)) {
|
|
75
|
-
const memo = /* @__PURE__ */ new Map();
|
|
76
|
-
const scopedBindings = /* @__PURE__ */ new Set();
|
|
77
|
-
const scopeCalls = /* @__PURE__ */ new Set();
|
|
78
|
-
const resolve = (path, visiting = /* @__PURE__ */ new Set()) => {
|
|
79
|
-
path = unwrap(path);
|
|
80
|
-
if (path.isIdentifier()) {
|
|
81
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
82
|
-
if (!binding) return null;
|
|
83
|
-
if (memo.has(binding)) return memo.get(binding);
|
|
84
|
-
if (visiting.has(binding)) throw new Error("[i18n] circular translator alias");
|
|
85
|
-
if (binding.path.isImportSpecifier()) {
|
|
86
|
-
const declaration = binding.path.parentPath;
|
|
87
|
-
const imported = binding.path.node.imported;
|
|
88
|
-
return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) && (_babel_types.isIdentifier(imported) ? imported.name : imported.value) === "t" && declaration.node.importKind !== "type" ? {
|
|
89
|
-
context: null,
|
|
90
|
-
notes: []
|
|
91
|
-
} : null;
|
|
92
|
-
}
|
|
93
|
-
if (binding.path.isVariableDeclarator()) {
|
|
94
|
-
visiting.add(binding);
|
|
95
|
-
const scope = resolve(binding.path.get("init"), visiting);
|
|
96
|
-
visiting.delete(binding);
|
|
97
|
-
if (scope && !binding.constant) throw new Error("[i18n] translator aliases must not be reassigned: " + path.node.name);
|
|
98
|
-
memo.set(binding, scope);
|
|
99
|
-
if (scope) scopedBindings.add(binding);
|
|
100
|
-
return scope;
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
if (path.isMemberExpression() && memberName(path) === "t") {
|
|
105
|
-
const object = path.get("object");
|
|
106
|
-
if (!object.isIdentifier()) return null;
|
|
107
|
-
const binding = object.scope.getBinding(object.node.name);
|
|
108
|
-
const declaration = binding?.path.parentPath;
|
|
109
|
-
if (binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() && imports.includes(declaration.node.source.value)) return {
|
|
110
|
-
context: null,
|
|
111
|
-
notes: []
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
if (!path.isCallExpression()) return null;
|
|
115
|
-
const callee = path.get("callee");
|
|
116
|
-
const method = memberName(callee);
|
|
117
|
-
if (!method || ![
|
|
118
|
-
"context",
|
|
119
|
-
"note",
|
|
120
|
-
"meta"
|
|
121
|
-
].includes(method)) return null;
|
|
122
|
-
const parent = resolve(callee.get("object"), visiting);
|
|
123
|
-
if (!parent) return null;
|
|
124
|
-
if (path.node.arguments.length !== 1) throw new Error("[i18n] scope methods require one static argument");
|
|
125
|
-
const argument = path.get("arguments.0");
|
|
126
|
-
scopeCalls.add(path);
|
|
127
|
-
if (method === "meta") {
|
|
128
|
-
const evaluated = argument.evaluate();
|
|
129
|
-
if (!evaluated.confident) throw new Error("[i18n] metadata must be statically known");
|
|
130
|
-
return {
|
|
131
|
-
...parent,
|
|
132
|
-
meta: evaluated.value
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
const value = literal(argument);
|
|
136
|
-
if (value === null) throw new Error("[i18n] " + method + " must be a static string");
|
|
137
|
-
return method === "note" ? {
|
|
138
|
-
...parent,
|
|
139
|
-
notes: [...parent.notes, value]
|
|
140
|
-
} : {
|
|
141
|
-
...parent,
|
|
142
|
-
context: parent.context ? `${parent.context}.${value}` : value
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
return {
|
|
146
|
-
resolve,
|
|
147
|
-
scopedBindings,
|
|
148
|
-
scopeCalls
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
// src/compiler/message.ts
|
|
152
|
-
function messageIdentity(context, source) {
|
|
153
|
-
return context ? `${context}\0${source}` : source;
|
|
154
|
-
}
|
|
155
|
-
function messageId(context, source) {
|
|
156
|
-
return (0, node_crypto.createHash)("sha256").update(messageIdentity(context, source)).digest("hex").slice(0, 24);
|
|
157
|
-
}
|
|
158
|
-
function compileMessage(source) {
|
|
159
|
-
const compact = (elements) => {
|
|
160
|
-
const result = elements.map((element) => {
|
|
161
|
-
switch (element.type) {
|
|
162
|
-
case _formatjs_icu_messageformat_parser.TYPE.literal: return element.value;
|
|
163
|
-
case _formatjs_icu_messageformat_parser.TYPE.argument: return [0, element.value];
|
|
164
|
-
case _formatjs_icu_messageformat_parser.TYPE.number:
|
|
165
|
-
case _formatjs_icu_messageformat_parser.TYPE.date:
|
|
166
|
-
case _formatjs_icu_messageformat_parser.TYPE.time: return [
|
|
167
|
-
element.type === _formatjs_icu_messageformat_parser.TYPE.number ? 1 : element.type === _formatjs_icu_messageformat_parser.TYPE.date ? 2 : 3,
|
|
168
|
-
element.value,
|
|
169
|
-
typeof element.style === "object" && element.style ? element.style.parsedOptions : element.style ?? null
|
|
170
|
-
];
|
|
171
|
-
case _formatjs_icu_messageformat_parser.TYPE.select: return [
|
|
172
|
-
4,
|
|
173
|
-
element.value,
|
|
174
|
-
Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
|
|
175
|
-
];
|
|
176
|
-
case _formatjs_icu_messageformat_parser.TYPE.plural: return [
|
|
177
|
-
5,
|
|
178
|
-
element.value,
|
|
179
|
-
element.offset,
|
|
180
|
-
element.pluralType === "ordinal" ? 1 : 0,
|
|
181
|
-
Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
|
|
182
|
-
];
|
|
183
|
-
case _formatjs_icu_messageformat_parser.TYPE.pound: return [6];
|
|
184
|
-
case _formatjs_icu_messageformat_parser.TYPE.tag: return [
|
|
185
|
-
7,
|
|
186
|
-
element.value,
|
|
187
|
-
compact(element.children)
|
|
188
|
-
];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
return result.every((part) => typeof part === "string") ? result.join("") : result;
|
|
192
|
-
};
|
|
193
|
-
return compact((0, _formatjs_icu_messageformat_parser.parse)(source, { captureLocation: false }));
|
|
194
|
-
}
|
|
195
|
-
_babel_generator.default.default ?? _babel_generator.default;
|
|
196
|
-
function compileProgram(code, filename, options = {}) {
|
|
197
|
-
const ast = parseSource(code, filename);
|
|
198
|
-
const messages = [];
|
|
199
|
-
if (options.compiled === false) return {
|
|
200
|
-
ast,
|
|
201
|
-
messages,
|
|
202
|
-
changed: false
|
|
203
|
-
};
|
|
204
|
-
const analysis = analyzer();
|
|
205
|
-
const plans = [];
|
|
206
|
-
const declarations = [];
|
|
207
|
-
let program;
|
|
208
|
-
traverse(ast, {
|
|
209
|
-
Program(path) {
|
|
210
|
-
program = path;
|
|
211
|
-
},
|
|
212
|
-
ExportAllDeclaration(path) {
|
|
213
|
-
if (importMap[path.node.source.value]) throw new Error("[i18n] do not re-export the translator in compiled mode; import t directly at each use");
|
|
214
|
-
},
|
|
215
|
-
ExportNamedDeclaration(path) {
|
|
216
|
-
if (path.node.source && importMap[path.node.source.value] && path.node.specifiers.some((specifier) => _babel_types.isExportSpecifier(specifier) && (_babel_types.isIdentifier(specifier.local) ? specifier.local.name : "") === "t")) throw new Error("[i18n] do not re-export the translator in compiled mode; export message descriptors instead");
|
|
217
|
-
},
|
|
218
|
-
ImportDeclaration(path) {
|
|
219
|
-
if (importMap[path.node.source.value] && path.node.importKind !== "type") declarations.push(path);
|
|
220
|
-
},
|
|
221
|
-
CallExpression(path) {
|
|
222
|
-
const callee = path.get("callee");
|
|
223
|
-
const method = memberName(callee);
|
|
224
|
-
if (!method || ![
|
|
225
|
-
"msg",
|
|
226
|
-
"jsx",
|
|
227
|
-
"text"
|
|
228
|
-
].includes(method)) return;
|
|
229
|
-
const scope = analysis.resolve(callee.get("object"));
|
|
230
|
-
if (!scope) return;
|
|
231
|
-
const source = literal(path.get("arguments.0"));
|
|
232
|
-
if (source === null && method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
|
|
233
|
-
plans.push({
|
|
234
|
-
path,
|
|
235
|
-
source,
|
|
236
|
-
scope
|
|
237
|
-
});
|
|
238
|
-
if (source !== null) messages.push({
|
|
239
|
-
...scope,
|
|
240
|
-
source,
|
|
241
|
-
id: scope.context ? `${scope.context}\0${source}` : source
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
traverse(ast, {
|
|
246
|
-
VariableDeclarator(path) {
|
|
247
|
-
analysis.resolve(path.get("id"));
|
|
248
|
-
},
|
|
249
|
-
CallExpression(path) {
|
|
250
|
-
const name = memberName(path.get("callee"));
|
|
251
|
-
if (name && [
|
|
252
|
-
"context",
|
|
253
|
-
"note",
|
|
254
|
-
"meta"
|
|
255
|
-
].includes(name)) analysis.resolve(path);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
const expressionUse = (path) => {
|
|
259
|
-
while (path.parentPath && (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() || path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() || path.parentPath.isParenthesizedExpression())) path = path.parentPath;
|
|
260
|
-
return path;
|
|
261
|
-
};
|
|
262
|
-
for (const path of analysis.scopeCalls) {
|
|
263
|
-
const use = expressionUse(path);
|
|
264
|
-
const parent = use.parentPath;
|
|
265
|
-
if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;
|
|
266
|
-
if (parent?.isMemberExpression() && parent.get("object") === use && parent.parentPath?.isCallExpression()) continue;
|
|
267
|
-
throw new Error("[i18n] scoped translator escapes same-file message calls");
|
|
268
|
-
}
|
|
269
|
-
for (const binding of analysis.scopedBindings) {
|
|
270
|
-
if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) throw new Error("[i18n] scoped translators cannot be exported; repeat the context in the consuming file");
|
|
271
|
-
for (const reference of binding.referencePaths) {
|
|
272
|
-
if (reference.findParent((parent) => parent.isTSType())) continue;
|
|
273
|
-
const use = expressionUse(reference);
|
|
274
|
-
const parent = use.parentPath;
|
|
275
|
-
if (parent?.isVariableDeclarator() && parent.get("init") === use) continue;
|
|
276
|
-
if (parent?.isMemberExpression() && parent.get("object") === use) {
|
|
277
|
-
const method = memberName(parent);
|
|
278
|
-
if (method && [
|
|
279
|
-
"msg",
|
|
280
|
-
"text",
|
|
281
|
-
"jsx",
|
|
282
|
-
"context",
|
|
283
|
-
"note",
|
|
284
|
-
"meta"
|
|
285
|
-
].includes(method) && parent.parentPath?.isCallExpression()) continue;
|
|
286
|
-
}
|
|
287
|
-
throw new Error("[i18n] scoped translator escapes same-file message calls: " + binding.identifier.name);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (!declarations.length) return {
|
|
291
|
-
ast,
|
|
292
|
-
messages,
|
|
293
|
-
changed: false
|
|
294
|
-
};
|
|
295
|
-
const helper = program.scope.generateUidIdentifier("tc");
|
|
296
|
-
if (plans.length) program.unshiftContainer("body", _babel_types.importDeclaration([_babel_types.importSpecifier(helper, _babel_types.identifier("t"))], _babel_types.stringLiteral("@fluentic/i18n/compiled")));
|
|
297
|
-
for (const { path, source, scope } of plans) {
|
|
298
|
-
path.get("callee").get("object").replaceWith(_babel_types.cloneNode(helper));
|
|
299
|
-
if (source !== null) {
|
|
300
|
-
const replacement = _babel_types.valueToNode([messageId(scope.context, source), compileMessage(source)]);
|
|
301
|
-
_babel_types.inherits(replacement, path.node.arguments[0]);
|
|
302
|
-
path.node.arguments[0] = replacement;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
let removed = true;
|
|
306
|
-
while (removed) {
|
|
307
|
-
removed = false;
|
|
308
|
-
program.scope.crawl();
|
|
309
|
-
for (const binding of analysis.scopedBindings) {
|
|
310
|
-
if (binding.path.removed) continue;
|
|
311
|
-
const current = binding.path.scope.getBinding(binding.identifier.name);
|
|
312
|
-
if (current && !current.referenced) {
|
|
313
|
-
binding.path.remove();
|
|
314
|
-
removed = true;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
for (const path of analysis.scopeCalls) if (!path.removed) {
|
|
319
|
-
const use = expressionUse(path);
|
|
320
|
-
if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();
|
|
321
|
-
}
|
|
322
|
-
for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];
|
|
323
|
-
program.scope.crawl();
|
|
324
|
-
for (const declaration of declarations) {
|
|
325
|
-
declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {
|
|
326
|
-
if (!_babel_types.isImportSpecifier(specifier) || (_babel_types.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== "t") return true;
|
|
327
|
-
return Boolean(program.scope.getBinding(specifier.local.name)?.referenced);
|
|
328
|
-
});
|
|
329
|
-
if (!declaration.node.specifiers.length) declaration.remove();
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
ast,
|
|
333
|
-
messages,
|
|
334
|
-
changed: true
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
// src/plugin/options.ts
|
|
338
|
-
function loadOptions(options = {}, root = process.cwd()) {
|
|
339
|
-
const file = options.config ? (0, node_path.resolve)(root, options.config) : [
|
|
340
|
-
"i18n.config.ts",
|
|
341
|
-
"i18n.config.js",
|
|
342
|
-
"i18n.config.mjs"
|
|
343
|
-
].map((name) => (0, node_path.resolve)(root, name)).find(node_fs.existsSync);
|
|
344
|
-
const config = file ? (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, { moduleCache: false })(file) : {};
|
|
345
|
-
return {
|
|
346
|
-
...config.default ?? config,
|
|
347
|
-
...options,
|
|
348
|
-
configFile: file
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
// src/plugin/babel.ts
|
|
352
|
-
/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */
|
|
353
|
-
function fluenticBabel(_api, options = {}) {
|
|
354
|
-
const config = loadOptions(options);
|
|
355
|
-
const handled = /* @__PURE__ */ new WeakSet();
|
|
356
|
-
const enabled = (code) => config.compiled && code.includes("@fluentic/i18n");
|
|
357
|
-
const compile = (code, filename) => {
|
|
358
|
-
const { ast } = compileProgram(code, filename, config);
|
|
359
|
-
traverse.cache.clear();
|
|
360
|
-
handled.add(ast.program);
|
|
361
|
-
return ast;
|
|
362
|
-
};
|
|
363
|
-
return {
|
|
364
|
-
name: "fluentic-i18n",
|
|
365
|
-
parserOverride(code, parserOptions) {
|
|
366
|
-
if (!enabled(code)) return void 0;
|
|
367
|
-
return compile(code, parserOptions.sourceFilename ?? "source.tsx");
|
|
368
|
-
},
|
|
369
|
-
pre(file) {
|
|
370
|
-
if (!enabled(file.code) || handled.has(file.path.node)) return;
|
|
371
|
-
const ast = compile(file.code, file.opts.filename ?? "source.tsx");
|
|
372
|
-
file.path.replaceWith(ast.program);
|
|
373
|
-
file.scope.crawl();
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
module.exports = fluenticBabel;
|
|
378
|
-
|
|
379
|
-
//# sourceMappingURL=babel.cjs.map
|
package/dist-cjs/babel.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel.cjs","names":["traverseModule","parse","b","createHash","TYPE","parse","generatorModule","b","resolve","existsSync","createJiti"],"sources":["../src/compiler/analyze.ts","../src/compiler/message.ts","../src/compiler/index.ts","../src/plugin/options.ts","../src/plugin/babel.ts"],"sourcesContent":["import { parse } from '@babel/parser';\nimport * as traverseModule from '@babel/traverse';\nimport type { Binding, NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\n\nconst traverse = ((traverseModule.default as unknown as { default?: typeof traverseModule.default; }).default ??\n traverseModule.default) as typeof traverseModule.default;\nexport { traverse };\n\nexport const importMap: Record<string, string> = {\n '@fluentic/i18n': '@fluentic/i18n/compiled',\n '@fluentic/i18n/core': '@fluentic/i18n/compiled',\n};\nexport type Scope = { context: string | null; notes: string[]; meta?: unknown; };\nexport type ExtractedMessage = Scope & { id: string; source: string; };\n\nexport function parseSource(code: string, filename: string) {\n return parse(code, {\n sourceFilename: filename,\n sourceType: 'unambiguous',\n plugins: [\n ...(/\\.[cm]?tsx?$/.test(filename) ? ['typescript' as const] : []),\n ...(!/\\.[cm]?ts$/.test(filename) ? ['jsx' as const] : []),\n 'decorators-legacy',\n 'importAttributes',\n ],\n });\n}\n\nexport function unwrap(path: NodePath): NodePath {\n while (\n path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() ||\n path.isTypeCastExpression() || path.isParenthesizedExpression()\n ) path = path.get('expression') as NodePath;\n\n return path;\n}\n\nexport function literal(path: NodePath, seen = new Set<Binding>()): string | null {\n path = unwrap(path);\n if (path.isStringLiteral()) return path.node.value;\n if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? '';\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {\n seen.add(binding);\n\n return literal(binding.path.get('init') as NodePath, seen);\n }\n }\n\n return null;\n}\n\nexport function memberName(path: NodePath): string | null {\n if (!path.isMemberExpression()) return null;\n\n const property = path.get('property');\n\n return !path.node.computed && property.isIdentifier()\n ? property.node.name\n : property.isStringLiteral()\n ? property.node.value\n : null;\n}\n\nexport function analyzer(imports = Object.keys(importMap)) {\n const memo = new Map<Binding, Scope | null>();\n const scopedBindings = new Set<Binding>();\n const scopeCalls = new Set<NodePath>();\n\n const resolve = (path: NodePath, visiting = new Set<Binding>()): Scope | null => {\n path = unwrap(path);\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (!binding) return null;\n if (memo.has(binding)) return memo.get(binding)!;\n if (visiting.has(binding)) throw new Error('[i18n] circular translator alias');\n if (binding.path.isImportSpecifier()) {\n const declaration = binding.path.parentPath;\n const imported = binding.path.node.imported;\n\n return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) &&\n (b.isIdentifier(imported) ? imported.name : imported.value) === 't' &&\n declaration.node.importKind !== 'type'\n ? { context: null, notes: [] }\n : null;\n }\n if (binding.path.isVariableDeclarator()) {\n visiting.add(binding);\n const scope = resolve(binding.path.get('init') as NodePath, visiting);\n visiting.delete(binding);\n if (scope && !binding.constant) {\n throw new Error('[i18n] translator aliases must not be reassigned: ' + path.node.name);\n }\n memo.set(binding, scope);\n if (scope) scopedBindings.add(binding);\n\n return scope;\n }\n\n return null;\n }\n if (path.isMemberExpression() && memberName(path) === 't') {\n const object = path.get('object');\n\n if (!object.isIdentifier()) return null;\n\n const binding = object.scope.getBinding(object.node.name);\n const declaration = binding?.path.parentPath;\n\n if (\n binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() &&\n imports.includes(declaration.node.source.value)\n ) return { context: null, notes: [] };\n }\n if (!path.isCallExpression()) return null;\n\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['context', 'note', 'meta'].includes(method)) return null;\n\n const parent = resolve((callee as NodePath<b.MemberExpression>).get('object'), visiting);\n\n if (!parent) return null;\n if (path.node.arguments.length !== 1) throw new Error('[i18n] scope methods require one static argument');\n\n const argument = path.get('arguments.0') as NodePath;\n scopeCalls.add(path);\n if (method === 'meta') {\n const evaluated = argument.evaluate();\n\n if (!evaluated.confident) throw new Error('[i18n] metadata must be statically known');\n\n return { ...parent, meta: evaluated.value };\n }\n\n const value = literal(argument);\n\n if (value === null) throw new Error('[i18n] ' + method + ' must be a static string');\n\n return method === 'note'\n ? { ...parent, notes: [...parent.notes, value] }\n : { ...parent, context: parent.context ? `${parent.context}.${value}` : value };\n };\n\n return { resolve, scopedBindings, scopeCalls };\n}\n\nexport function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[] {\n const ast = parseSource(code, filename);\n const { resolve } = analyzer(imports);\n const messages: ExtractedMessage[] = [];\n traverse(ast, {\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'text', 'jsx'].includes(method)) return;\n\n const scope = resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null) {\n if (method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n\n return;\n }\n messages.push({ ...scope, id: scope.context ? `${scope.context}\\0${source}` : source, source });\n },\n });\n\n return [...new Map(messages.map((message) => [message.id, message])).values()];\n}\n","import { type MessageFormatElement, parse, TYPE } from '@formatjs/icu-messageformat-parser';\nimport { createHash } from 'node:crypto';\nimport type { CompactMessage, CompactPart } from '../shared/compact';\n\nexport { COMPACT_VERSION } from '../shared/compact';\n\nexport function messageIdentity(context: string | null, source: string): string {\n return context ? `${context}\\0${source}` : source;\n}\n\nexport function messageId(context: string | null, source: string): string {\n return createHash('sha256').update(messageIdentity(context, source)).digest('hex').slice(0, 24);\n}\n\nexport function compileMessage(source: string): CompactMessage {\n const compact = (elements: MessageFormatElement[]): CompactMessage => {\n const result: CompactPart[] = elements.map((element): CompactPart => {\n switch (element.type) {\n case TYPE.literal:\n return element.value;\n case TYPE.argument:\n return [0, element.value];\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n return [\n element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,\n element.value,\n typeof element.style === 'object' && element.style\n ? element.style.parsedOptions as Record<string, unknown>\n : element.style ?? null,\n ];\n case TYPE.select:\n return [\n 4,\n element.value,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.plural:\n return [\n 5,\n element.value,\n element.offset,\n element.pluralType === 'ordinal' ? 1 : 0,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.pound:\n return [6];\n case TYPE.tag:\n return [7, element.value, compact(element.children)];\n }\n });\n\n return result.every((part) => typeof part === 'string') ? result.join('') : result;\n };\n\n return compact(parse(source, { captureLocation: false }));\n}\n\nexport function compileCatalog(\n records: Array<{ source: string; context: string | null; translation: string; }>,\n): Array<[string, CompactMessage]> {\n const seen = new Map<string, string>();\n\n return records.flatMap((record) => {\n const id = messageId(record.context, record.source);\n const identity = messageIdentity(record.context, record.source);\n\n if (seen.has(id) && seen.get(id) !== identity) throw new Error('[i18n] message hash collision: ' + id);\n seen.set(id, identity);\n\n return record.translation === '' ? [] : [[id, compileMessage(record.translation)] as [string, CompactMessage]];\n });\n}\n","import * as generatorModule from '@babel/generator';\nimport type { NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\nimport {\n analyzer,\n collectMessages,\n type ExtractedMessage,\n importMap,\n literal,\n memberName,\n parseSource,\n traverse,\n} from './analyze';\nimport { compileMessage, messageId } from './message';\n\nexport { collectMessages } from './analyze';\nexport * from './message';\n\nconst generate = ((generatorModule.default as unknown as { default?: typeof generatorModule.default; }).default ??\n generatorModule.default) as typeof generatorModule.default;\nexport type CompilerOptions = { compiled?: boolean; filename?: string; };\n\nexport function compileProgram(code: string, filename: string, options: CompilerOptions = {}) {\n const ast = parseSource(code, filename);\n const messages: ExtractedMessage[] = [];\n\n if (options.compiled === false) return { ast, messages, changed: false };\n\n const analysis = analyzer();\n\n const plans: Array<\n {\n path: NodePath<b.CallExpression>;\n source: string | null;\n scope: NonNullable<ReturnType<typeof analysis.resolve>>;\n }\n > = [];\n const declarations: NodePath<b.ImportDeclaration>[] = [];\n\n let program: NodePath<b.Program> | undefined;\n traverse(ast, {\n Program(path) {\n program = path;\n },\n ExportAllDeclaration(path) {\n if (importMap[path.node.source.value]) {\n throw new Error('[i18n] do not re-export the translator in compiled mode; import t directly at each use');\n }\n },\n ExportNamedDeclaration(path) {\n if (\n path.node.source && importMap[path.node.source.value] &&\n path.node.specifiers.some((specifier) =>\n b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : '') === 't'\n )\n ) throw new Error('[i18n] do not re-export the translator in compiled mode; export message descriptors instead');\n },\n ImportDeclaration(path) {\n if (importMap[path.node.source.value] && path.node.importKind !== 'type') declarations.push(path);\n },\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'jsx', 'text'].includes(method)) return;\n\n const scope = analysis.resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null && method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n plans.push({ path, source, scope });\n if (source !== null) {\n messages.push({ ...scope, source, id: scope.context ? `${scope.context}\\0${source}` : source });\n }\n },\n });\n // Discover unused/escaping scopes as well as scopes reached by message calls.\n traverse(ast, {\n VariableDeclarator(path) {\n analysis.resolve(path.get('id') as NodePath);\n },\n CallExpression(path) {\n const name = memberName(path.get('callee'));\n\n if (name && ['context', 'note', 'meta'].includes(name)) analysis.resolve(path);\n },\n });\n const expressionUse = (path: NodePath): NodePath => {\n while (\n path.parentPath &&\n (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() ||\n path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() ||\n path.parentPath.isParenthesizedExpression())\n ) path = path.parentPath;\n\n return path;\n };\n\n for (const path of analysis.scopeCalls) {\n const use = expressionUse(path);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use && parent.parentPath?.isCallExpression()) continue;\n throw new Error('[i18n] scoped translator escapes same-file message calls');\n }\n for (const binding of analysis.scopedBindings) {\n if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) {\n throw new Error('[i18n] scoped translators cannot be exported; repeat the context in the consuming file');\n }\n\n for (const reference of binding.referencePaths) {\n if (reference.findParent((parent) => parent.isTSType())) continue;\n\n const use = expressionUse(reference);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() && parent.get('init') === use) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use) {\n const method = memberName(parent);\n\n if (\n method && ['msg', 'text', 'jsx', 'context', 'note', 'meta'].includes(method) &&\n parent.parentPath?.isCallExpression()\n ) continue;\n }\n throw new Error('[i18n] scoped translator escapes same-file message calls: ' + binding.identifier.name);\n }\n }\n if (!declarations.length) return { ast, messages, changed: false };\n\n const helper = program!.scope.generateUidIdentifier('tc');\n\n if (plans.length) {\n program!.unshiftContainer(\n 'body',\n b.importDeclaration([b.importSpecifier(helper, b.identifier('t'))], b.stringLiteral('@fluentic/i18n/compiled')),\n );\n }\n\n for (const { path, source, scope } of plans) {\n const callee = path.get('callee') as NodePath<b.MemberExpression>;\n callee.get('object').replaceWith(b.cloneNode(helper));\n if (source !== null) {\n const replacement = b.valueToNode([messageId(scope.context, source), compileMessage(source)]);\n b.inherits(replacement, path.node.arguments[0]);\n path.node.arguments[0] = replacement;\n }\n }\n // All scope uses were checked before mutation. Remove aliases from leaves to roots.\n let removed = true;\n\n while (removed) {\n removed = false;\n program!.scope.crawl();\n\n for (const binding of analysis.scopedBindings) {\n if (binding.path.removed) continue;\n\n const current = binding.path.scope.getBinding(binding.identifier.name);\n\n if (current && !current.referenced) {\n binding.path.remove();\n removed = true;\n }\n }\n }\n\n for (const path of analysis.scopeCalls) {\n if (!path.removed) {\n const use = expressionUse(path);\n\n if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();\n }\n }\n for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];\n program!.scope.crawl();\n\n for (const declaration of declarations) {\n declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {\n if (\n !b.isImportSpecifier(specifier) ||\n (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== 't'\n ) return true;\n\n return Boolean(program!.scope.getBinding(specifier.local.name)?.referenced);\n });\n if (!declaration.node.specifiers.length) declaration.remove();\n }\n\n return { ast, messages, changed: true };\n}\n\nexport function transform(code: string, options: CompilerOptions = {}) {\n const filename = options.filename ?? 'source.tsx';\n const result = compileProgram(code, filename, options);\n\n if (!result.changed) return null;\n\n const output = generate(result.ast, { sourceMaps: true, sourceFileName: filename, comments: true }, code);\n\n return { code: output.code, map: output.map, messages: result.messages };\n}\n","import { createJiti } from 'jiti';\nimport { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nexport type PluginOptions = { compiled?: boolean; config?: string; includeDependencies?: boolean; };\n\nexport function loadOptions(\n options: PluginOptions = {},\n root = process.cwd(),\n): PluginOptions & { configFile?: string; } {\n const file = options.config\n ? resolve(root, options.config)\n : ['i18n.config.ts', 'i18n.config.js', 'i18n.config.mjs'].map((name) => resolve(root, name)).find(existsSync);\n\n const config = file\n ? createJiti(import.meta.url, { moduleCache: false })(file) as { default?: PluginOptions; } & PluginOptions\n : {};\n\n return { ...((config.default ?? config) as PluginOptions), ...options, configFile: file };\n}\n\nexport function accepts(id: string, options: PluginOptions) {\n return /\\.[cm]?[jt]sx?$/.test(id.split('?')[0]) && (options.includeDependencies || !id.includes('/node_modules/'));\n}\n","import { compileProgram } from '../compiler';\nimport { traverse } from '../compiler/analyze';\nimport { loadOptions, type PluginOptions } from './options';\n/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */\nexport default function fluenticBabel(_api: unknown, options: PluginOptions = {}) {\n const config = loadOptions(options);\n const handled = new WeakSet<object>();\n const enabled = (code: string) => config.compiled && code.includes('@fluentic/i18n');\n\n const compile = (code: string, filename: string) => {\n const { ast } = compileProgram(code, filename, config);\n // Standalone paths have a default Hub. Babel must create its own paths for presets.\n traverse.cache.clear();\n handled.add(ast.program);\n\n return ast;\n };\n\n return {\n name: 'fluentic-i18n',\n parserOverride(code: string, parserOptions: { sourceFilename?: string; }) {\n if (!enabled(code)) return undefined;\n\n return compile(code, parserOptions.sourceFilename ?? 'source.tsx');\n },\n pre(file: any) {\n if (!enabled(file.code) || handled.has(file.path.node)) return;\n\n const ast = compile(file.code, file.opts.filename ?? 'source.tsx');\n file.path.replaceWith(ast.program);\n file.scope.crawl();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,WAAaA,gBAAe,QAAoE,WACpGA,gBAAe;AAGjB,MAAa,YAAoC;CAC/C,kBAAkB;CAClB,uBAAuB;AACzB;AAIA,SAAgB,YAAY,MAAc,UAAkB;CAC1D,QAAA,GAAOC,cAAAA,MAAAA,CAAM,MAAM;EACjB,gBAAgB;EAChB,YAAY;EACZ,SAAS;GACP,GAAI,eAAe,KAAK,QAAQ,IAAI,CAAC,YAAqB,IAAI,CAAC;GAC/D,GAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,CAAC,KAAc,IAAI,CA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AS,YAAY,OAAO;CAClC,MAAM,0BAAU,IAAI,QAAgB;CACpC,MAAM,WAAW,SAAiB,OAAO,YAAY,KAAK,SAAS,gBAAgB;CAEnF,MAAM,WAAW,MAAc,aAAqB;EAClD,MAAM,EAAE,QAAQ,eAAe,MAAM,UAAU,MAAM;EAErD,SAAS,MAAM,MAAM;EACrB,QAAQ,IAAI,IAAI,OAAO;EAEvB,OAAO;CACT;CAEA,OAAO;EACL,MAAM;EACN,eAAe,MAAc,eAA6C;GACxE,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO,KAAA;GAE3B,OAAO,QAAQ,MAAM,cAAc,kBAAkB,YAAY;EACnE;EACA,IAAI,MAAW;GACb,IAAI,CAAC,QAAQ,KAAK,IAAI,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,GAAG;GAExD,MAAM,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK,YAAY,YAAY;GACjE,KAAK,KAAK,YAAY,IAAI,OAAO;GACjC,KAAK,MAAM,MAAM;EACnB;CACF;AACF"}
|
package/src/adapter.ts
DELETED
package/src/compiled.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { type TApi } from './core/i18n';
|
|
2
|
-
import { isMessageDescriptor } from './core/types';
|
|
3
|
-
import type {
|
|
4
|
-
DescriptorRenderArgs,
|
|
5
|
-
I18nJsxOutput,
|
|
6
|
-
I18nTagValue,
|
|
7
|
-
MessageDescriptor,
|
|
8
|
-
MessageParams,
|
|
9
|
-
MessageSchema,
|
|
10
|
-
TryRenderArgs,
|
|
11
|
-
} from './core/types';
|
|
12
|
-
import type { CompactMessage } from './shared/compact';
|
|
13
|
-
import { createFormatting } from './shared/formatting';
|
|
14
|
-
import { interpret } from './shared/interpreter';
|
|
15
|
-
import { createTagHandler, getRuntime, noTranslate } from './shared/runtime';
|
|
16
|
-
|
|
17
|
-
export type CompiledPayload = readonly [id: string, fallback: CompactMessage];
|
|
18
|
-
|
|
19
|
-
export type CompiledTextRenderer = {
|
|
20
|
-
(message: CompiledPayload, params?: MessageParams): string;
|
|
21
|
-
<Text extends string, Schema extends MessageSchema | undefined>(
|
|
22
|
-
message: MessageDescriptor<Text, Schema>,
|
|
23
|
-
...args: DescriptorRenderArgs<Schema>
|
|
24
|
-
): string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type CompiledJsxRenderer = {
|
|
28
|
-
(message: CompiledPayload, params?: MessageParams): I18nJsxOutput;
|
|
29
|
-
<Text extends string, Schema extends MessageSchema | undefined>(
|
|
30
|
-
message: MessageDescriptor<Text, Schema>,
|
|
31
|
-
...args: DescriptorRenderArgs<Schema>
|
|
32
|
-
): I18nJsxOutput;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type CompiledTApi =
|
|
36
|
-
& Omit<TApi<I18nJsxOutput, I18nTagValue>, 'msg' | 'text' | 'jsx' | 'try' | 'context' | 'note' | 'meta'>
|
|
37
|
-
& {
|
|
38
|
-
msg<Schema extends MessageSchema | undefined = undefined>(
|
|
39
|
-
message: CompiledPayload,
|
|
40
|
-
schema?: Schema,
|
|
41
|
-
): MessageDescriptor<string, Schema>;
|
|
42
|
-
text: CompiledTextRenderer;
|
|
43
|
-
jsx: CompiledJsxRenderer;
|
|
44
|
-
try<T>(
|
|
45
|
-
renderer: CompiledTextRenderer,
|
|
46
|
-
value: T,
|
|
47
|
-
...args: TryRenderArgs<T>
|
|
48
|
-
): T extends { readonly __fluenticMessage: true; } ? string
|
|
49
|
-
: T;
|
|
50
|
-
try<T>(
|
|
51
|
-
renderer: CompiledJsxRenderer,
|
|
52
|
-
value: T,
|
|
53
|
-
...args: TryRenderArgs<T>
|
|
54
|
-
): T extends { readonly __fluenticMessage: true; } ? I18nJsxOutput : T;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const formatting = /* @__PURE__ */ createFormatting(interpret, true);
|
|
58
|
-
|
|
59
|
-
function descriptor<Schema extends MessageSchema | undefined = undefined>(
|
|
60
|
-
payload: CompiledPayload,
|
|
61
|
-
schema?: Schema,
|
|
62
|
-
): MessageDescriptor<string, Schema> {
|
|
63
|
-
if (!Array.isArray(payload) || payload.length !== 2 || typeof payload[0] !== 'string') {
|
|
64
|
-
throw new TypeError('[i18n] compiled runtime requires compiled messages; enable the Fluentic plugin');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return Object.freeze({
|
|
68
|
-
__fluenticMessage: true,
|
|
69
|
-
text: payload[0],
|
|
70
|
-
compiled: payload,
|
|
71
|
-
context: null,
|
|
72
|
-
schema: schema ?? {},
|
|
73
|
-
notes: [],
|
|
74
|
-
meta: undefined,
|
|
75
|
-
}) as unknown as MessageDescriptor<string, Schema>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function options(
|
|
79
|
-
message: CompiledPayload | MessageDescriptor<string, MessageSchema | undefined>,
|
|
80
|
-
params?: MessageParams,
|
|
81
|
-
) {
|
|
82
|
-
return { msg: isMessageDescriptor(message) ? message : descriptor(message), params };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const t = {
|
|
86
|
-
msg: descriptor,
|
|
87
|
-
text(message: CompiledPayload | MessageDescriptor<string, MessageSchema | undefined>, params?: MessageParams) {
|
|
88
|
-
return formatting.getText(options(message, params));
|
|
89
|
-
},
|
|
90
|
-
jsx(message: CompiledPayload | MessageDescriptor<string, MessageSchema | undefined>, params?: MessageParams) {
|
|
91
|
-
return formatting.getJsx(options(message, params));
|
|
92
|
-
},
|
|
93
|
-
clone(message: MessageDescriptor) {
|
|
94
|
-
return Object.freeze({ ...message });
|
|
95
|
-
},
|
|
96
|
-
params(params: MessageParams | null = {}) {
|
|
97
|
-
return params ?? {};
|
|
98
|
-
},
|
|
99
|
-
tag(value: unknown) {
|
|
100
|
-
if (typeof value === 'function') return createTagHandler(value as (chunks: unknown[]) => unknown);
|
|
101
|
-
|
|
102
|
-
const adapt = getRuntime().tagElement;
|
|
103
|
-
|
|
104
|
-
if (!adapt) throw new Error('[i18n] element tags require a platform adapter');
|
|
105
|
-
|
|
106
|
-
return createTagHandler(adapt(value));
|
|
107
|
-
},
|
|
108
|
-
try(renderer: (message: unknown, params?: MessageParams) => unknown, value: unknown, params?: MessageParams) {
|
|
109
|
-
return isMessageDescriptor(value) ? renderer(value, params) : value;
|
|
110
|
-
},
|
|
111
|
-
notranslate: noTranslate,
|
|
112
|
-
} as unknown as CompiledTApi;
|
|
113
|
-
export * from './core/types';
|
|
114
|
-
export type { CompactMessage, CompactPart } from './shared/compact';
|
|
115
|
-
export { I18nRegistry, noTranslate, setFormats } from './shared/runtime';
|
|
116
|
-
export { defineTranslationLoader } from './translation-manager';
|