@inlang/paraglide-js 2.29.0 → 2.29.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/compiler/compile-bundle.js +58 -12
- package/dist/compiler/compile-bundle.js.map +1 -1
- package/dist/compiler/compile-bundle.test.js +208 -26
- package/dist/compiler/compile-bundle.test.js.map +1 -1
- package/dist/compiler/compile-lifecycle.test.js +83 -0
- package/dist/compiler/compile-lifecycle.test.js.map +1 -1
- package/dist/compiler/compile-message.d.ts +9 -0
- package/dist/compiler/compile-message.js +29 -12
- package/dist/compiler/compile-message.js.map +1 -1
- package/dist/compiler/compile-project.test.js +157 -0
- package/dist/compiler/compile-project.test.js.map +1 -1
- package/dist/compiler/compile.js +12 -0
- package/dist/compiler/compile.js.map +1 -1
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/env-variables/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -181,6 +181,163 @@ test("inlines static text and retains only fallback helpers under strict checkJs
|
|
|
181
181
|
expect(m.plain_greeting({}, { locale: "de" })).toBe("Hallo");
|
|
182
182
|
expect(m.plain_greeting({}, { locale: "de-AT" })).toBe("Hallo");
|
|
183
183
|
});
|
|
184
|
+
test("inlines messages with inputs and plurals under strict checkJs", async () => {
|
|
185
|
+
const project = await loadProjectInMemory({
|
|
186
|
+
blob: await newProject({
|
|
187
|
+
settings: {
|
|
188
|
+
baseLocale: "en",
|
|
189
|
+
locales: ["en", "de", "de-AT"],
|
|
190
|
+
},
|
|
191
|
+
}),
|
|
192
|
+
});
|
|
193
|
+
const text = (value) => [{ type: "text", value }];
|
|
194
|
+
await insertBundleNested(project.db, createBundleNested({
|
|
195
|
+
id: "welcome",
|
|
196
|
+
declarations: [{ type: "input-variable", name: "name" }],
|
|
197
|
+
messages: ["Hello", "Hallo"].map((greeting, index) => ({
|
|
198
|
+
locale: index === 0 ? "en" : "de",
|
|
199
|
+
variants: [
|
|
200
|
+
{
|
|
201
|
+
pattern: [
|
|
202
|
+
{ type: "text", value: `${greeting} ` },
|
|
203
|
+
{
|
|
204
|
+
type: "expression",
|
|
205
|
+
arg: { type: "variable-reference", name: "name" },
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
})),
|
|
211
|
+
}));
|
|
212
|
+
await insertBundleNested(project.db, createBundleNested({
|
|
213
|
+
id: "cats",
|
|
214
|
+
declarations: [
|
|
215
|
+
{ type: "input-variable", name: "count" },
|
|
216
|
+
{
|
|
217
|
+
type: "local-variable",
|
|
218
|
+
name: "countPlural",
|
|
219
|
+
value: {
|
|
220
|
+
type: "expression",
|
|
221
|
+
arg: { type: "variable-reference", name: "count" },
|
|
222
|
+
annotation: {
|
|
223
|
+
type: "function-reference",
|
|
224
|
+
name: "plural",
|
|
225
|
+
options: [],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
// de-AT has its own plural, so every locale declares `countPlural`.
|
|
231
|
+
messages: [
|
|
232
|
+
["en", "One cat", " cats"],
|
|
233
|
+
["de", "Eine Katze", " Katzen"],
|
|
234
|
+
["de-AT", "Ein Katzerl", " Katzerl"],
|
|
235
|
+
].map(([locale, one, other]) => ({
|
|
236
|
+
locale: locale,
|
|
237
|
+
selectors: [{ type: "variable-reference", name: "countPlural" }],
|
|
238
|
+
variants: [
|
|
239
|
+
{
|
|
240
|
+
matches: [
|
|
241
|
+
{ type: "literal-match", key: "countPlural", value: "one" },
|
|
242
|
+
],
|
|
243
|
+
pattern: text(one),
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
matches: [{ type: "catchall-match", key: "countPlural" }],
|
|
247
|
+
pattern: [
|
|
248
|
+
{
|
|
249
|
+
type: "expression",
|
|
250
|
+
arg: { type: "variable-reference", name: "count" },
|
|
251
|
+
},
|
|
252
|
+
{ type: "text", value: other },
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
})),
|
|
257
|
+
}));
|
|
258
|
+
// The only declared input is never read, so the dispatcher marks it used.
|
|
259
|
+
await insertBundleNested(project.db, createBundleNested({
|
|
260
|
+
id: "unit_label",
|
|
261
|
+
declarations: [
|
|
262
|
+
{ type: "input-variable", name: "unused" },
|
|
263
|
+
{
|
|
264
|
+
type: "local-variable",
|
|
265
|
+
name: "unit",
|
|
266
|
+
value: {
|
|
267
|
+
type: "expression",
|
|
268
|
+
arg: { type: "literal", value: "kg" },
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
messages: [
|
|
273
|
+
["en", "Weight in "],
|
|
274
|
+
["de", "Gewicht in "],
|
|
275
|
+
["de-AT", "Gewicht in "],
|
|
276
|
+
].map(([locale, label]) => ({
|
|
277
|
+
locale: locale,
|
|
278
|
+
variants: [
|
|
279
|
+
{
|
|
280
|
+
pattern: [
|
|
281
|
+
{ type: "text", value: label },
|
|
282
|
+
{
|
|
283
|
+
type: "expression",
|
|
284
|
+
arg: { type: "variable-reference", name: "unit" },
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
})),
|
|
290
|
+
}));
|
|
291
|
+
const output = await compileProject({
|
|
292
|
+
project,
|
|
293
|
+
compilerOptions: { outputStructure: "message-modules" },
|
|
294
|
+
});
|
|
295
|
+
// Only the message that de-AT's missing-locale alias calls keeps its function.
|
|
296
|
+
expect(output["messages/welcome.js"]).not.toContain("const en_welcome =");
|
|
297
|
+
expect(output["messages/welcome.js"]).toContain("const de_welcome =");
|
|
298
|
+
expect(output["messages/cats.js"]).not.toMatch(/const \w+_cats =/);
|
|
299
|
+
expect(output["messages/unit_label.js"]).not.toMatch(/const \w+_unit_label =/);
|
|
300
|
+
const tsProject = await typescriptProject({
|
|
301
|
+
useInMemoryFileSystem: true,
|
|
302
|
+
compilerOptions: {
|
|
303
|
+
outDir: "dist",
|
|
304
|
+
declaration: true,
|
|
305
|
+
allowJs: true,
|
|
306
|
+
checkJs: true,
|
|
307
|
+
noImplicitAny: true,
|
|
308
|
+
noUnusedLocals: true,
|
|
309
|
+
noUnusedParameters: true,
|
|
310
|
+
noImplicitReturns: true,
|
|
311
|
+
noImplicitThis: true,
|
|
312
|
+
noUncheckedIndexedAccess: true,
|
|
313
|
+
noPropertyAccessFromIndexSignature: true,
|
|
314
|
+
module: ts.ModuleKind.Node16,
|
|
315
|
+
strict: true,
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
for (const [fileName, code] of Object.entries(output)) {
|
|
319
|
+
if (fileName.endsWith(".js") || fileName.endsWith(".ts")) {
|
|
320
|
+
tsProject.createSourceFile(fileName, code);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const diagnostics = ts
|
|
324
|
+
.getPreEmitDiagnostics(tsProject.createProgram())
|
|
325
|
+
.map((d) => `${d.file?.fileName}: ${ts.flattenDiagnosticMessageText(d.messageText, "\n")}`)
|
|
326
|
+
.filter((text) => !text.includes("Cannot find module 'async_hooks'"));
|
|
327
|
+
expect(diagnostics).toEqual([]);
|
|
328
|
+
const { m } = await importCode(await bundleCode(output, `export * as m from "./paraglide/messages.js"`));
|
|
329
|
+
expect(m.welcome({ name: "Ada" }, { locale: "en" })).toBe("Hello Ada");
|
|
330
|
+
expect(m.welcome({ name: "Ada" }, { locale: "de" })).toBe("Hallo Ada");
|
|
331
|
+
expect(m.welcome({ name: "Ada" }, { locale: "de-AT" })).toBe("Hallo Ada");
|
|
332
|
+
expect(m.cats({ count: 1 }, { locale: "en" })).toBe("One cat");
|
|
333
|
+
expect(m.cats({ count: 3 }, { locale: "en" })).toBe("3 cats");
|
|
334
|
+
expect(m.cats({ count: 3 }, { locale: "de" })).toBe("3 Katzen");
|
|
335
|
+
expect(m.cats({ count: 1 }, { locale: "de" })).toBe("Eine Katze");
|
|
336
|
+
expect(m.cats({ count: 1 }, { locale: "de-AT" })).toBe("Ein Katzerl");
|
|
337
|
+
expect(m.cats({ count: 3 }, { locale: "de-AT" })).toBe("3 Katzerl");
|
|
338
|
+
expect(m.unit_label({ unused: 1 }, { locale: "en" })).toBe("Weight in kg");
|
|
339
|
+
expect(m.unit_label({ unused: 1 }, { locale: "de-AT" })).toBe("Gewicht in kg");
|
|
340
|
+
});
|
|
184
341
|
test("emitPrettierIgnore", async () => {
|
|
185
342
|
const project = await loadProjectInMemory({
|
|
186
343
|
blob: await newProject({
|