@inlang/paraglide-js 2.26.0 → 2.27.0

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.
Files changed (100) hide show
  1. package/README.md +2 -1
  2. package/dist/bundler-plugins/per-locale-build/vite-environments.test.js +2 -2
  3. package/dist/bundler-plugins/per-locale-build/vite-environments.test.js.map +1 -1
  4. package/dist/cli/commands/init/command.js +19 -1
  5. package/dist/cli/commands/init/command.js.map +1 -1
  6. package/dist/cli/defaults.js +2 -2
  7. package/dist/cli/defaults.js.map +1 -1
  8. package/dist/cli/steps/add-inlang-check.d.ts +19 -0
  9. package/dist/cli/steps/add-inlang-check.js +60 -0
  10. package/dist/cli/steps/add-inlang-check.js.map +1 -0
  11. package/dist/cli/steps/add-inlang-check.test.d.ts +1 -0
  12. package/dist/cli/steps/add-inlang-check.test.js +88 -0
  13. package/dist/cli/steps/add-inlang-check.test.js.map +1 -0
  14. package/dist/cli/steps/agents-md-suggestion.d.ts +11 -0
  15. package/dist/cli/steps/agents-md-suggestion.js +19 -0
  16. package/dist/cli/steps/agents-md-suggestion.js.map +1 -0
  17. package/dist/cli/steps/agents-md-suggestion.test.d.ts +1 -0
  18. package/dist/cli/steps/agents-md-suggestion.test.js +36 -0
  19. package/dist/cli/steps/agents-md-suggestion.test.js.map +1 -0
  20. package/dist/cli/steps/maybe-add-machine-translation.js +3 -2
  21. package/dist/cli/steps/maybe-add-machine-translation.js.map +1 -1
  22. package/dist/cli/steps/maybe-add-sherlock.js +1 -1
  23. package/dist/cli/steps/maybe-add-sherlock.js.map +1 -1
  24. package/dist/cli/utils.d.ts +9 -0
  25. package/dist/cli/utils.js +15 -0
  26. package/dist/cli/utils.js.map +1 -1
  27. package/dist/compiler/compile-annotation.d.ts +48 -1
  28. package/dist/compiler/compile-annotation.js +238 -10
  29. package/dist/compiler/compile-annotation.js.map +1 -1
  30. package/dist/compiler/compile-bundle.d.ts +3 -2
  31. package/dist/compiler/compile-bundle.js +30 -1
  32. package/dist/compiler/compile-bundle.js.map +1 -1
  33. package/dist/compiler/compile-bundle.test.js +18 -18
  34. package/dist/compiler/compile-bundle.test.js.map +1 -1
  35. package/dist/compiler/compile-local-variable.d.ts +3 -0
  36. package/dist/compiler/compile-local-variable.js +5 -2
  37. package/dist/compiler/compile-local-variable.js.map +1 -1
  38. package/dist/compiler/compile-local-variable.test.js +44 -4
  39. package/dist/compiler/compile-local-variable.test.js.map +1 -1
  40. package/dist/compiler/compile-message.d.ts +29 -1
  41. package/dist/compiler/compile-message.exact-number.test.d.ts +1 -0
  42. package/dist/compiler/compile-message.exact-number.test.js +786 -0
  43. package/dist/compiler/compile-message.exact-number.test.js.map +1 -0
  44. package/dist/compiler/compile-message.js +162 -66
  45. package/dist/compiler/compile-message.js.map +1 -1
  46. package/dist/compiler/compile-message.locals.test.d.ts +1 -0
  47. package/dist/compiler/compile-message.locals.test.js +498 -0
  48. package/dist/compiler/compile-message.locals.test.js.map +1 -0
  49. package/dist/compiler/compile-message.test.js +111 -20
  50. package/dist/compiler/compile-message.test.js.map +1 -1
  51. package/dist/compiler/compile-pattern.d.ts +5 -0
  52. package/dist/compiler/compile-pattern.js +6 -18
  53. package/dist/compiler/compile-pattern.js.map +1 -1
  54. package/dist/compiler/compile-pattern.test.js +165 -1
  55. package/dist/compiler/compile-pattern.test.js.map +1 -1
  56. package/dist/compiler/compile-project.js +4 -1
  57. package/dist/compiler/compile-project.js.map +1 -1
  58. package/dist/compiler/compile-project.test.js +1013 -31
  59. package/dist/compiler/compile-project.test.js.map +1 -1
  60. package/dist/compiler/compile.test.js +1 -1
  61. package/dist/compiler/compile.test.js.map +1 -1
  62. package/dist/compiler/create-readme.d.ts +4 -1
  63. package/dist/compiler/create-readme.js +33 -125
  64. package/dist/compiler/create-readme.js.map +1 -1
  65. package/dist/compiler/emit-ts-declarations.interop.test.js +2 -2
  66. package/dist/compiler/emit-ts-declarations.interop.test.js.map +1 -1
  67. package/dist/compiler/emit-ts-declarations.test.js +4 -4
  68. package/dist/compiler/emit-ts-declarations.test.js.map +1 -1
  69. package/dist/compiler/index.d.ts +1 -1
  70. package/dist/compiler/index.js +1 -1
  71. package/dist/compiler/index.js.map +1 -1
  72. package/dist/compiler/input-alias.d.ts +21 -0
  73. package/dist/compiler/input-alias.js +42 -0
  74. package/dist/compiler/input-alias.js.map +1 -0
  75. package/dist/compiler/input-alias.test.d.ts +1 -0
  76. package/dist/compiler/input-alias.test.js +58 -0
  77. package/dist/compiler/input-alias.test.js.map +1 -0
  78. package/dist/compiler/message-locals.d.ts +46 -0
  79. package/dist/compiler/message-locals.js +129 -0
  80. package/dist/compiler/message-locals.js.map +1 -0
  81. package/dist/compiler/output-structure/locale-modules.js +7 -1
  82. package/dist/compiler/output-structure/locale-modules.js.map +1 -1
  83. package/dist/compiler/output-structure/locale-modules.test.js +35 -0
  84. package/dist/compiler/output-structure/locale-modules.test.js.map +1 -1
  85. package/dist/compiler/output-structure/message-modules.js +5 -3
  86. package/dist/compiler/output-structure/message-modules.js.map +1 -1
  87. package/dist/compiler/output-structure/message-modules.test.js +35 -0
  88. package/dist/compiler/output-structure/message-modules.test.js.map +1 -1
  89. package/dist/compiler/registry.d.ts +12 -0
  90. package/dist/compiler/registry.js +97 -28
  91. package/dist/compiler/registry.js.map +1 -1
  92. package/dist/compiler/server/create-server-file.js +24 -0
  93. package/dist/compiler/server/create-server-file.js.map +1 -1
  94. package/dist/compiler/server/create-server-file.test.js +8 -2
  95. package/dist/compiler/server/create-server-file.test.js.map +1 -1
  96. package/dist/compiler/server/middleware.js +29 -4
  97. package/dist/compiler/server/middleware.js.map +1 -1
  98. package/dist/services/env-variables/index.js +1 -1
  99. package/dist/services/env-variables/index.js.map +1 -1
  100. package/package.json +3 -3
@@ -0,0 +1,498 @@
1
+ import { describe, expect, test, vi } from "vitest";
2
+ import { compileMessage } from "./compile-message.js";
3
+ import { createRegistry } from "./registry.js";
4
+ import { Logger } from "../services/logger/index.js";
5
+ /**
6
+ * Compiles a message and imports it together with an inlined registry so the
7
+ * generated code can be executed.
8
+ */
9
+ async function compileAndImport(args) {
10
+ const code = compile(args);
11
+ const source = createRegistry() +
12
+ "\nexport const locals_message = " +
13
+ code.replaceAll("registry.", "");
14
+ const module = await import("data:text/javascript;base64," + Buffer.from(source).toString("base64"));
15
+ return {
16
+ code,
17
+ message: module.locals_message,
18
+ };
19
+ }
20
+ function compile(args) {
21
+ const message = {
22
+ id: "message-id",
23
+ bundleId: "locals_message",
24
+ locale: args.locale ?? "en",
25
+ selectors: (args.selectors ?? []).map((name) => ({
26
+ type: "variable-reference",
27
+ name,
28
+ })),
29
+ };
30
+ const variants = args.variants.map((variant, index) => ({
31
+ id: String(index),
32
+ messageId: message.id,
33
+ matches: variant.matches ?? [],
34
+ pattern: variant.pattern,
35
+ }));
36
+ return compileMessage(args.declarations, message, variants).code;
37
+ }
38
+ const input = (name) => ({
39
+ type: "input-variable",
40
+ name,
41
+ });
42
+ const local = (name, arg, annotation) => ({
43
+ type: "local-variable",
44
+ name,
45
+ value: {
46
+ type: "expression",
47
+ arg: { type: "variable-reference", name: arg },
48
+ ...(annotation ? { annotation } : {}),
49
+ },
50
+ });
51
+ const plural = () => ({
52
+ type: "function-reference",
53
+ name: "plural",
54
+ options: [],
55
+ });
56
+ const ref = (name) => ({
57
+ type: "expression",
58
+ arg: { type: "variable-reference", name },
59
+ });
60
+ const literal = (key, value) => ({
61
+ type: "literal-match",
62
+ key,
63
+ value,
64
+ });
65
+ const catchall = (key) => ({ type: "catchall-match", key });
66
+ const text = (value) => ({ type: "text", value });
67
+ describe("emits only the locals a message reads", () => {
68
+ test("a locale that does not read a bundle local does not declare it", async () => {
69
+ const { code, message } = await compileAndImport({
70
+ declarations: [input("status"), local("statusExact", "status")],
71
+ selectors: ["status"],
72
+ variants: [
73
+ { matches: [literal("status", "active")], pattern: [text("Active")] },
74
+ { matches: [catchall("status")], pattern: [text("Other")] },
75
+ ],
76
+ });
77
+ expect(code).not.toContain("statusExact");
78
+ expect(message({ status: "active" })).toBe("Active");
79
+ expect(message({ status: "inactive" })).toBe("Other");
80
+ });
81
+ test("locals read through selectors, patterns and other locals are declared", async () => {
82
+ const { code, message } = await compileAndImport({
83
+ declarations: [
84
+ input("count"),
85
+ input("name"),
86
+ local("countValue", "count"),
87
+ local("countPlural", "countValue", plural()),
88
+ local("unusedPlural", "count", plural()),
89
+ local("nameValue", "name"),
90
+ local("unusedName", "name"),
91
+ ],
92
+ selectors: ["countPlural"],
93
+ variants: [
94
+ {
95
+ matches: [literal("countPlural", "one")],
96
+ pattern: [text("One for "), ref("nameValue")],
97
+ },
98
+ {
99
+ matches: [catchall("countPlural")],
100
+ pattern: [text("Many for "), ref("nameValue")],
101
+ },
102
+ ],
103
+ });
104
+ expect(code).toContain("const countValue = i?.count;");
105
+ expect(code).toContain('const countPlural = registry.plural("en", countValue, {});');
106
+ expect(code).toContain("const nameValue = i?.name;");
107
+ expect(code).not.toContain("unusedPlural");
108
+ expect(code).not.toContain("unusedName");
109
+ expect(message({ count: 1, name: "Ada" })).toBe("One for Ada");
110
+ expect(message({ count: 2, name: "Ada" })).toBe("Many for Ada");
111
+ });
112
+ test("locals read through annotation options are declared", async () => {
113
+ const { code, message } = await compileAndImport({
114
+ declarations: [
115
+ input("amount"),
116
+ input("digits"),
117
+ input("unit"),
118
+ input("value"),
119
+ local("digitsValue", "digits"),
120
+ local("unitValue", "unit"),
121
+ ],
122
+ variants: [
123
+ {
124
+ pattern: [
125
+ {
126
+ type: "expression",
127
+ arg: { type: "variable-reference", name: "amount" },
128
+ annotation: {
129
+ type: "function-reference",
130
+ name: "number",
131
+ options: [
132
+ {
133
+ name: "minimumFractionDigits",
134
+ value: { type: "variable-reference", name: "digitsValue" },
135
+ },
136
+ ],
137
+ },
138
+ },
139
+ text(" / "),
140
+ {
141
+ type: "expression",
142
+ arg: { type: "variable-reference", name: "value" },
143
+ annotation: {
144
+ type: "function-reference",
145
+ name: "relativetime",
146
+ // `unit=$unitValue` as a literal, as some importers emit it
147
+ options: [
148
+ {
149
+ name: "unit",
150
+ value: { type: "literal", value: "$unitValue" },
151
+ },
152
+ ],
153
+ },
154
+ },
155
+ ],
156
+ },
157
+ ],
158
+ });
159
+ expect(code).toContain("const digitsValue = i?.digits;");
160
+ expect(code).toContain("const unitValue = i?.unit;");
161
+ expect(message({ amount: 1, digits: 2, unit: "day", value: 1 })).toBe("1.00 / in 1 day");
162
+ });
163
+ test("options of unknown annotations are not emitted, so their locals are not declared", () => {
164
+ const code = compile({
165
+ declarations: [
166
+ input("value"),
167
+ input("style"),
168
+ local("styleValue", "style"),
169
+ ],
170
+ variants: [
171
+ {
172
+ pattern: [
173
+ {
174
+ type: "expression",
175
+ arg: { type: "variable-reference", name: "value" },
176
+ annotation: {
177
+ type: "function-reference",
178
+ name: "customFormatter",
179
+ options: [
180
+ {
181
+ name: "style",
182
+ value: { type: "variable-reference", name: "styleValue" },
183
+ },
184
+ ],
185
+ },
186
+ },
187
+ ],
188
+ },
189
+ ],
190
+ });
191
+ expect(code).not.toContain("styleValue");
192
+ });
193
+ test("a local read only by a markup option is declared in .parts() only", async () => {
194
+ const { code, message } = await compileAndImport({
195
+ declarations: [input("url"), local("href", "url")],
196
+ variants: [
197
+ {
198
+ pattern: [
199
+ {
200
+ type: "markup-start",
201
+ name: "link",
202
+ options: [
203
+ {
204
+ name: "to",
205
+ value: { type: "variable-reference", name: "href" },
206
+ },
207
+ ],
208
+ },
209
+ text("Docs"),
210
+ { type: "markup-end", name: "link" },
211
+ ],
212
+ },
213
+ ],
214
+ });
215
+ expect(code.match(/const href = i\?\.url;/g)).toHaveLength(1);
216
+ // the string function reads no input
217
+ expect(code).toContain("LocalizedString} */ (() => {");
218
+ expect(message({ url: "/docs" })).toBe("Docs");
219
+ expect(message.parts?.({ url: "/docs" })).toEqual([
220
+ {
221
+ type: "markup-start",
222
+ name: "link",
223
+ options: { to: "/docs" },
224
+ attributes: {},
225
+ },
226
+ { type: "text", value: "Docs" },
227
+ { type: "markup-end", name: "link", options: {}, attributes: {} },
228
+ ]);
229
+ });
230
+ test("a message that reads no input does not declare the input parameter", async () => {
231
+ const { code, message } = await compileAndImport({
232
+ declarations: [input("name"), local("nameValue", "name")],
233
+ variants: [{ pattern: [text("Bonjour")] }],
234
+ });
235
+ expect(code).toContain("() => {");
236
+ expect(code).not.toContain("nameValue");
237
+ expect(message({ name: "Ada" })).toBe("Bonjour");
238
+ });
239
+ });
240
+ describe("declaration order", () => {
241
+ test("a local declared before the local it reads is emitted after it", async () => {
242
+ const { code, message } = await compileAndImport({
243
+ declarations: [
244
+ input("count"),
245
+ // reads countValue, which is declared below
246
+ local("countPlural", "countValue", plural()),
247
+ local("countValue", "countAlias"),
248
+ local("countAlias", "count"),
249
+ ],
250
+ selectors: ["countPlural"],
251
+ variants: [
252
+ { matches: [literal("countPlural", "one")], pattern: [text("one")] },
253
+ { matches: [catchall("countPlural")], pattern: [text("other")] },
254
+ ],
255
+ });
256
+ const position = (name) => code.indexOf(`const ${name} =`);
257
+ expect(position("countAlias")).toBeGreaterThan(-1);
258
+ expect(position("countAlias")).toBeLessThan(position("countValue"));
259
+ expect(position("countValue")).toBeLessThan(position("countPlural"));
260
+ expect(message({ count: 1 })).toBe("one");
261
+ expect(message({ count: 2 })).toBe("other");
262
+ });
263
+ test("locals in a valid order keep their declaration order", () => {
264
+ const code = compile({
265
+ declarations: [
266
+ input("count"),
267
+ local("b", "count"),
268
+ local("a", "count"),
269
+ local("c", "a"),
270
+ ],
271
+ variants: [{ pattern: [ref("a"), ref("b"), ref("c")] }],
272
+ });
273
+ expect(code).toContain("const b = i?.count;\n\tconst a = i?.count;\n\tconst c = a;");
274
+ });
275
+ test("locals that reference each other in a cycle fail compilation", () => {
276
+ expect(() => compile({
277
+ declarations: [input("count"), local("a", "b"), local("b", "a")],
278
+ variants: [{ pattern: [ref("a")] }],
279
+ })).toThrow('The message "locals_message" (locale "en") has local variables that reference each other in a cycle: a -> b -> a.');
280
+ });
281
+ test("a local that references itself fails compilation", () => {
282
+ expect(() => compile({
283
+ declarations: [local("a", "a")],
284
+ variants: [{ pattern: [ref("a")] }],
285
+ })).toThrow("in a cycle: a -> a.");
286
+ });
287
+ test("a cycle among locals the message does not read is ignored", async () => {
288
+ const { message } = await compileAndImport({
289
+ declarations: [input("name"), local("a", "b"), local("b", "a")],
290
+ variants: [{ pattern: [text("Hi "), ref("name")] }],
291
+ });
292
+ expect(message({ name: "Ada" })).toBe("Hi Ada");
293
+ });
294
+ });
295
+ describe("undeclared variables", () => {
296
+ test("an alias of an undeclared variable fails compilation", () => {
297
+ // previously compiled to `const e = i?.count` without an `i` parameter,
298
+ // which threw `ReferenceError: i is not defined` when called
299
+ expect(() => compile({
300
+ declarations: [local("e", "count")],
301
+ selectors: ["e"],
302
+ variants: [
303
+ { matches: [literal("e", "0")], pattern: [text("zero")] },
304
+ { matches: [catchall("e")], pattern: [text("other")] },
305
+ ],
306
+ })).toThrow('The message "locals_message" (locale "en") references the variable "count" in the local variable "e", but "count" is not declared. Declare it as an input variable or a local variable.');
307
+ });
308
+ test("an alias of an undeclared variable fails compilation when other inputs exist", () => {
309
+ expect(() => compile({
310
+ declarations: [input("name"), local("e", "count")],
311
+ variants: [{ pattern: [ref("name"), ref("e")] }],
312
+ })).toThrow('references the variable "count" in the local variable "e"');
313
+ });
314
+ test("an undeclared variable in a pattern fails compilation with the bundle and locale", () => {
315
+ expect(() => compile({
316
+ locale: "de",
317
+ declarations: [input("name")],
318
+ variants: [{ pattern: [ref("nmae")] }],
319
+ })).toThrow('The message "locals_message" (locale "de") references the variable "nmae", but "nmae" is not declared.');
320
+ });
321
+ test("an undeclared variable in an annotation option fails compilation", () => {
322
+ expect(() => compile({
323
+ declarations: [input("amount")],
324
+ variants: [
325
+ {
326
+ pattern: [
327
+ {
328
+ type: "expression",
329
+ arg: { type: "variable-reference", name: "amount" },
330
+ annotation: {
331
+ type: "function-reference",
332
+ name: "number",
333
+ options: [
334
+ {
335
+ name: "minimumFractionDigits",
336
+ value: { type: "variable-reference", name: "digits" },
337
+ },
338
+ ],
339
+ },
340
+ },
341
+ ],
342
+ },
343
+ ],
344
+ })).toThrow('references the variable "digits", but "digits" is not declared');
345
+ });
346
+ test("a local the message does not read may reference an undeclared variable", async () => {
347
+ const { code, message } = await compileAndImport({
348
+ declarations: [input("name"), local("e", "count")],
349
+ variants: [{ pattern: [text("Hi "), ref("name")] }],
350
+ });
351
+ expect(code).not.toContain("count");
352
+ expect(message({ name: "Ada" })).toBe("Hi Ada");
353
+ });
354
+ });
355
+ describe("unknown annotations on locals", () => {
356
+ test("interpolate the raw value like unknown pattern annotations", async () => {
357
+ const warn = vi
358
+ .spyOn(Logger.prototype, "warn")
359
+ .mockImplementation(function () {
360
+ return this;
361
+ });
362
+ try {
363
+ const { code, message } = await compileAndImport({
364
+ declarations: [
365
+ input("amount"),
366
+ input("style"),
367
+ local("styleValue", "style"),
368
+ local("formatted", "amount", {
369
+ type: "function-reference",
370
+ name: "customLocalFormatter",
371
+ options: [
372
+ {
373
+ name: "style",
374
+ value: { type: "variable-reference", name: "styleValue" },
375
+ },
376
+ ],
377
+ }),
378
+ ],
379
+ variants: [{ pattern: [text("Total: "), ref("formatted")] }],
380
+ });
381
+ expect(code).toContain("const formatted = i?.amount;");
382
+ expect(code).not.toContain("registry.");
383
+ // the option of the ignored annotation is not read
384
+ expect(code).not.toContain("styleValue");
385
+ expect(message({ amount: 1234, style: "x" })).toBe("Total: 1234");
386
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('"customLocalFormatter" is unknown'));
387
+ }
388
+ finally {
389
+ warn.mockRestore();
390
+ }
391
+ });
392
+ });
393
+ describe("registryFunctions metadata", () => {
394
+ const registryFunctions = (args) => {
395
+ const message = {
396
+ id: "message-id",
397
+ bundleId: "locals_message",
398
+ locale: "en",
399
+ selectors: (args.selectors ?? []).map((name) => ({
400
+ type: "variable-reference",
401
+ name,
402
+ })),
403
+ };
404
+ return compileMessage(args.declarations, message, args.variants.map((variant, index) => ({
405
+ id: String(index),
406
+ messageId: message.id,
407
+ matches: variant.matches ?? [],
408
+ pattern: variant.pattern,
409
+ }))).registryFunctions;
410
+ };
411
+ test("message text that mentions the registry does not count", () => {
412
+ expect(registryFunctions({
413
+ declarations: [],
414
+ variants: [{ pattern: [text("Open the registry. Now.")] }],
415
+ })).toEqual([]);
416
+ });
417
+ test("an unread annotated local does not count", () => {
418
+ expect(registryFunctions({
419
+ declarations: [input("count"), local("countPlural", "count", plural())],
420
+ variants: [{ pattern: [ref("count")] }],
421
+ })).toEqual([]);
422
+ });
423
+ test("unknown local annotations do not count", () => {
424
+ expect(registryFunctions({
425
+ declarations: [
426
+ input("value"),
427
+ local("custom", "value", {
428
+ type: "function-reference",
429
+ name: "customFormatter",
430
+ options: [],
431
+ }),
432
+ ],
433
+ variants: [{ pattern: [ref("custom")] }],
434
+ })).toEqual([]);
435
+ });
436
+ test("unknown pattern annotations do not count", () => {
437
+ expect(registryFunctions({
438
+ declarations: [input("value")],
439
+ variants: [
440
+ {
441
+ pattern: [
442
+ {
443
+ type: "expression",
444
+ arg: { type: "variable-reference", name: "value" },
445
+ annotation: {
446
+ type: "function-reference",
447
+ name: "customFormatter",
448
+ options: [],
449
+ },
450
+ },
451
+ ],
452
+ },
453
+ ],
454
+ })).toEqual([]);
455
+ });
456
+ test("read locals and pattern annotations count, in both variant paths", () => {
457
+ expect(registryFunctions({
458
+ declarations: [input("count"), local("countPlural", "count", plural())],
459
+ selectors: ["countPlural"],
460
+ variants: [
461
+ { matches: [literal("countPlural", "one")], pattern: [text("one")] },
462
+ {
463
+ matches: [catchall("countPlural")],
464
+ pattern: [
465
+ {
466
+ type: "expression",
467
+ arg: { type: "variable-reference", name: "count" },
468
+ annotation: {
469
+ type: "function-reference",
470
+ name: "icu:pound",
471
+ options: [],
472
+ },
473
+ },
474
+ ],
475
+ },
476
+ ],
477
+ }).sort()).toEqual(["icuPound", "plural"]);
478
+ expect(registryFunctions({
479
+ declarations: [input("amount")],
480
+ variants: [
481
+ {
482
+ pattern: [
483
+ {
484
+ type: "expression",
485
+ arg: { type: "variable-reference", name: "amount" },
486
+ annotation: {
487
+ type: "function-reference",
488
+ name: "number",
489
+ options: [],
490
+ },
491
+ },
492
+ ],
493
+ },
494
+ ],
495
+ })).toEqual(["number"]);
496
+ });
497
+ });
498
+ //# sourceMappingURL=compile-message.locals.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-message.locals.test.js","sourceRoot":"","sources":["../../src/compiler/compile-message.locals.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAUpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD;;;GAGG;AACH,KAAK,UAAU,gBAAgB,CAAC,IAK/B;IACA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,MAAM,GACX,cAAc,EAAE;QAChB,kCAAkC;QAClC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,MAAM,CAC1B,8BAA8B,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACvE,CAAC;IACF,OAAO;QACN,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,cAIf;KACD,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,IAKhB;IACA,MAAM,OAAO,GAAY;QACxB,EAAE,EAAE,YAAY;QAChB,QAAQ,EAAE,gBAAgB;QAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI;QAC3B,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC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C,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;QAClC,MAAM,CACL,iBAAiB,CAAC;YACjB,YAAY,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC/B,QAAQ,EAAE;gBACT;oBACC,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,YAAY;4BAClB,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE;4BACnD,UAAU,EAAE;gCACX,IAAI,EAAE,oBAAoB;gCAC1B,IAAI,EAAE,QAAQ;gCACd,OAAO,EAAE,EAAE;6BACX;yBACD;qBACD;iBACD;aACD;SACD,CAAC,CACF,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, test, vi } from \"vitest\";\nimport type {\n\tDeclaration,\n\tExpression,\n\tLocalVariable,\n\tMatch,\n\tMessage,\n\tPattern,\n\tVariant,\n} from \"@inlang/sdk\";\nimport { compileMessage } from \"./compile-message.js\";\nimport { createRegistry } from \"./registry.js\";\nimport { Logger } from \"../services/logger/index.js\";\n\n/**\n * Compiles a message and imports it together with an inlined registry so the\n * generated code can be executed.\n */\nasync function compileAndImport(args: {\n\tdeclarations: Declaration[];\n\tselectors?: string[];\n\tlocale?: string;\n\tvariants: Array<{ matches?: Match[]; pattern: Pattern }>;\n}) {\n\tconst code = compile(args);\n\tconst source =\n\t\tcreateRegistry() +\n\t\t\"\\nexport const locals_message = \" +\n\t\tcode.replaceAll(\"registry.\", \"\");\n\tconst module = await import(\n\t\t\"data:text/javascript;base64,\" + Buffer.from(source).toString(\"base64\")\n\t);\n\treturn {\n\t\tcode,\n\t\tmessage: module.locals_message as ((\n\t\t\tinputs?: Record<string, unknown>\n\t\t) => string) & {\n\t\t\tparts?: (inputs?: Record<string, unknown>) => unknown[];\n\t\t},\n\t};\n}\n\nfunction compile(args: {\n\tdeclarations: Declaration[];\n\tselectors?: string[];\n\tlocale?: string;\n\tvariants: Array<{ matches?: Match[]; pattern: Pattern }>;\n}): string {\n\tconst message: Message = {\n\t\tid: \"message-id\",\n\t\tbundleId: \"locals_message\",\n\t\tlocale: args.locale ?? \"en\",\n\t\tselectors: (args.selectors ?? []).map((name) => ({\n\t\t\ttype: \"variable-reference\",\n\t\t\tname,\n\t\t})),\n\t};\n\tconst variants: Variant[] = args.variants.map((variant, index) => ({\n\t\tid: String(index),\n\t\tmessageId: message.id,\n\t\tmatches: variant.matches ?? [],\n\t\tpattern: variant.pattern,\n\t}));\n\treturn compileMessage(args.declarations, message, variants).code;\n}\n\nconst input = (name: string): Declaration => ({\n\ttype: \"input-variable\",\n\tname,\n});\nconst local = (\n\tname: string,\n\targ: string,\n\tannotation?: Expression[\"annotation\"]\n): LocalVariable => ({\n\ttype: \"local-variable\",\n\tname,\n\tvalue: {\n\t\ttype: \"expression\",\n\t\targ: { type: \"variable-reference\", name: arg },\n\t\t...(annotation ? { annotation } : {}),\n\t},\n});\nconst plural = (): Expression[\"annotation\"] => ({\n\ttype: \"function-reference\",\n\tname: \"plural\",\n\toptions: [],\n});\nconst ref = (name: string): Pattern[number] => ({\n\ttype: \"expression\",\n\targ: { type: \"variable-reference\", name },\n});\nconst literal = (key: string, value: string): Match => ({\n\ttype: \"literal-match\",\n\tkey,\n\tvalue,\n});\nconst catchall = (key: string): Match => ({ type: \"catchall-match\", key });\nconst text = (value: string): Pattern[number] => ({ type: \"text\", value });\n\ndescribe(\"emits only the locals a message reads\", () => {\n\ttest(\"a locale that does not read a bundle local does not declare it\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [input(\"status\"), local(\"statusExact\", \"status\")],\n\t\t\tselectors: [\"status\"],\n\t\t\tvariants: [\n\t\t\t\t{ matches: [literal(\"status\", \"active\")], pattern: [text(\"Active\")] },\n\t\t\t\t{ matches: [catchall(\"status\")], pattern: [text(\"Other\")] },\n\t\t\t],\n\t\t});\n\n\t\texpect(code).not.toContain(\"statusExact\");\n\t\texpect(message({ status: \"active\" })).toBe(\"Active\");\n\t\texpect(message({ status: \"inactive\" })).toBe(\"Other\");\n\t});\n\n\ttest(\"locals read through selectors, patterns and other locals are declared\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [\n\t\t\t\tinput(\"count\"),\n\t\t\t\tinput(\"name\"),\n\t\t\t\tlocal(\"countValue\", \"count\"),\n\t\t\t\tlocal(\"countPlural\", \"countValue\", plural()),\n\t\t\t\tlocal(\"unusedPlural\", \"count\", plural()),\n\t\t\t\tlocal(\"nameValue\", \"name\"),\n\t\t\t\tlocal(\"unusedName\", \"name\"),\n\t\t\t],\n\t\t\tselectors: [\"countPlural\"],\n\t\t\tvariants: [\n\t\t\t\t{\n\t\t\t\t\tmatches: [literal(\"countPlural\", \"one\")],\n\t\t\t\t\tpattern: [text(\"One for \"), ref(\"nameValue\")],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tmatches: [catchall(\"countPlural\")],\n\t\t\t\t\tpattern: [text(\"Many for \"), ref(\"nameValue\")],\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\texpect(code).toContain(\"const countValue = i?.count;\");\n\t\texpect(code).toContain(\n\t\t\t'const countPlural = registry.plural(\"en\", countValue, {});'\n\t\t);\n\t\texpect(code).toContain(\"const nameValue = i?.name;\");\n\t\texpect(code).not.toContain(\"unusedPlural\");\n\t\texpect(code).not.toContain(\"unusedName\");\n\t\texpect(message({ count: 1, name: \"Ada\" })).toBe(\"One for Ada\");\n\t\texpect(message({ count: 2, name: \"Ada\" })).toBe(\"Many for Ada\");\n\t});\n\n\ttest(\"locals read through annotation options are declared\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [\n\t\t\t\tinput(\"amount\"),\n\t\t\t\tinput(\"digits\"),\n\t\t\t\tinput(\"unit\"),\n\t\t\t\tinput(\"value\"),\n\t\t\t\tlocal(\"digitsValue\", \"digits\"),\n\t\t\t\tlocal(\"unitValue\", \"unit\"),\n\t\t\t],\n\t\t\tvariants: [\n\t\t\t\t{\n\t\t\t\t\tpattern: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"amount\" },\n\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\tname: \"number\",\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"digitsValue\" },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttext(\" / \"),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\tname: \"relativetime\",\n\t\t\t\t\t\t\t\t// `unit=$unitValue` as a literal, as some importers emit it\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: \"unit\",\n\t\t\t\t\t\t\t\t\t\tvalue: { type: \"literal\", value: \"$unitValue\" },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\texpect(code).toContain(\"const digitsValue = i?.digits;\");\n\t\texpect(code).toContain(\"const unitValue = i?.unit;\");\n\t\texpect(message({ amount: 1, digits: 2, unit: \"day\", value: 1 })).toBe(\n\t\t\t\"1.00 / in 1 day\"\n\t\t);\n\t});\n\n\ttest(\"options of unknown annotations are not emitted, so their locals are not declared\", () => {\n\t\tconst code = compile({\n\t\t\tdeclarations: [\n\t\t\t\tinput(\"value\"),\n\t\t\t\tinput(\"style\"),\n\t\t\t\tlocal(\"styleValue\", \"style\"),\n\t\t\t],\n\t\t\tvariants: [\n\t\t\t\t{\n\t\t\t\t\tpattern: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\tname: \"customFormatter\",\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: \"style\",\n\t\t\t\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"styleValue\" },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\texpect(code).not.toContain(\"styleValue\");\n\t});\n\n\ttest(\"a local read only by a markup option is declared in .parts() only\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [input(\"url\"), local(\"href\", \"url\")],\n\t\t\tvariants: [\n\t\t\t\t{\n\t\t\t\t\tpattern: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"markup-start\",\n\t\t\t\t\t\t\tname: \"link\",\n\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: \"to\",\n\t\t\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"href\" },\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttext(\"Docs\"),\n\t\t\t\t\t\t{ type: \"markup-end\", name: \"link\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\texpect(code.match(/const href = i\\?\\.url;/g)).toHaveLength(1);\n\t\t// the string function reads no input\n\t\texpect(code).toContain(\"LocalizedString} */ (() => {\");\n\t\texpect(message({ url: \"/docs\" })).toBe(\"Docs\");\n\t\texpect(message.parts?.({ url: \"/docs\" })).toEqual([\n\t\t\t{\n\t\t\t\ttype: \"markup-start\",\n\t\t\t\tname: \"link\",\n\t\t\t\toptions: { to: \"/docs\" },\n\t\t\t\tattributes: {},\n\t\t\t},\n\t\t\t{ type: \"text\", value: \"Docs\" },\n\t\t\t{ type: \"markup-end\", name: \"link\", options: {}, attributes: {} },\n\t\t]);\n\t});\n\n\ttest(\"a message that reads no input does not declare the input parameter\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [input(\"name\"), local(\"nameValue\", \"name\")],\n\t\t\tvariants: [{ pattern: [text(\"Bonjour\")] }],\n\t\t});\n\n\t\texpect(code).toContain(\"() => {\");\n\t\texpect(code).not.toContain(\"nameValue\");\n\t\texpect(message({ name: \"Ada\" })).toBe(\"Bonjour\");\n\t});\n});\n\ndescribe(\"declaration order\", () => {\n\ttest(\"a local declared before the local it reads is emitted after it\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [\n\t\t\t\tinput(\"count\"),\n\t\t\t\t// reads countValue, which is declared below\n\t\t\t\tlocal(\"countPlural\", \"countValue\", plural()),\n\t\t\t\tlocal(\"countValue\", \"countAlias\"),\n\t\t\t\tlocal(\"countAlias\", \"count\"),\n\t\t\t],\n\t\t\tselectors: [\"countPlural\"],\n\t\t\tvariants: [\n\t\t\t\t{ matches: [literal(\"countPlural\", \"one\")], pattern: [text(\"one\")] },\n\t\t\t\t{ matches: [catchall(\"countPlural\")], pattern: [text(\"other\")] },\n\t\t\t],\n\t\t});\n\n\t\tconst position = (name: string) => code.indexOf(`const ${name} =`);\n\t\texpect(position(\"countAlias\")).toBeGreaterThan(-1);\n\t\texpect(position(\"countAlias\")).toBeLessThan(position(\"countValue\"));\n\t\texpect(position(\"countValue\")).toBeLessThan(position(\"countPlural\"));\n\t\texpect(message({ count: 1 })).toBe(\"one\");\n\t\texpect(message({ count: 2 })).toBe(\"other\");\n\t});\n\n\ttest(\"locals in a valid order keep their declaration order\", () => {\n\t\tconst code = compile({\n\t\t\tdeclarations: [\n\t\t\t\tinput(\"count\"),\n\t\t\t\tlocal(\"b\", \"count\"),\n\t\t\t\tlocal(\"a\", \"count\"),\n\t\t\t\tlocal(\"c\", \"a\"),\n\t\t\t],\n\t\t\tvariants: [{ pattern: [ref(\"a\"), ref(\"b\"), ref(\"c\")] }],\n\t\t});\n\n\t\texpect(code).toContain(\n\t\t\t\"const b = i?.count;\\n\\tconst a = i?.count;\\n\\tconst c = a;\"\n\t\t);\n\t});\n\n\ttest(\"locals that reference each other in a cycle fail compilation\", () => {\n\t\texpect(() =>\n\t\t\tcompile({\n\t\t\t\tdeclarations: [input(\"count\"), local(\"a\", \"b\"), local(\"b\", \"a\")],\n\t\t\t\tvariants: [{ pattern: [ref(\"a\")] }],\n\t\t\t})\n\t\t).toThrow(\n\t\t\t'The message \"locals_message\" (locale \"en\") has local variables that reference each other in a cycle: a -> b -> a.'\n\t\t);\n\t});\n\n\ttest(\"a local that references itself fails compilation\", () => {\n\t\texpect(() =>\n\t\t\tcompile({\n\t\t\t\tdeclarations: [local(\"a\", \"a\")],\n\t\t\t\tvariants: [{ pattern: [ref(\"a\")] }],\n\t\t\t})\n\t\t).toThrow(\"in a cycle: a -> a.\");\n\t});\n\n\ttest(\"a cycle among locals the message does not read is ignored\", async () => {\n\t\tconst { message } = await compileAndImport({\n\t\t\tdeclarations: [input(\"name\"), local(\"a\", \"b\"), local(\"b\", \"a\")],\n\t\t\tvariants: [{ pattern: [text(\"Hi \"), ref(\"name\")] }],\n\t\t});\n\n\t\texpect(message({ name: \"Ada\" })).toBe(\"Hi Ada\");\n\t});\n});\n\ndescribe(\"undeclared variables\", () => {\n\ttest(\"an alias of an undeclared variable fails compilation\", () => {\n\t\t// previously compiled to `const e = i?.count` without an `i` parameter,\n\t\t// which threw `ReferenceError: i is not defined` when called\n\t\texpect(() =>\n\t\t\tcompile({\n\t\t\t\tdeclarations: [local(\"e\", \"count\")],\n\t\t\t\tselectors: [\"e\"],\n\t\t\t\tvariants: [\n\t\t\t\t\t{ matches: [literal(\"e\", \"0\")], pattern: [text(\"zero\")] },\n\t\t\t\t\t{ matches: [catchall(\"e\")], pattern: [text(\"other\")] },\n\t\t\t\t],\n\t\t\t})\n\t\t).toThrow(\n\t\t\t'The message \"locals_message\" (locale \"en\") references the variable \"count\" in the local variable \"e\", but \"count\" is not declared. Declare it as an input variable or a local variable.'\n\t\t);\n\t});\n\n\ttest(\"an alias of an undeclared variable fails compilation when other inputs exist\", () => {\n\t\texpect(() =>\n\t\t\tcompile({\n\t\t\t\tdeclarations: [input(\"name\"), local(\"e\", \"count\")],\n\t\t\t\tvariants: [{ pattern: [ref(\"name\"), ref(\"e\")] }],\n\t\t\t})\n\t\t).toThrow('references the variable \"count\" in the local variable \"e\"');\n\t});\n\n\ttest(\"an undeclared variable in a pattern fails compilation with the bundle and locale\", () => {\n\t\texpect(() =>\n\t\t\tcompile({\n\t\t\t\tlocale: \"de\",\n\t\t\t\tdeclarations: [input(\"name\")],\n\t\t\t\tvariants: [{ pattern: [ref(\"nmae\")] }],\n\t\t\t})\n\t\t).toThrow(\n\t\t\t'The message \"locals_message\" (locale \"de\") references the variable \"nmae\", but \"nmae\" is not declared.'\n\t\t);\n\t});\n\n\ttest(\"an undeclared variable in an annotation option fails compilation\", () => {\n\t\texpect(() =>\n\t\t\tcompile({\n\t\t\t\tdeclarations: [input(\"amount\")],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tpattern: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"amount\" },\n\t\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\t\tname: \"number\",\n\t\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"digits\" },\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\t\t).toThrow('references the variable \"digits\", but \"digits\" is not declared');\n\t});\n\n\ttest(\"a local the message does not read may reference an undeclared variable\", async () => {\n\t\tconst { code, message } = await compileAndImport({\n\t\t\tdeclarations: [input(\"name\"), local(\"e\", \"count\")],\n\t\t\tvariants: [{ pattern: [text(\"Hi \"), ref(\"name\")] }],\n\t\t});\n\n\t\texpect(code).not.toContain(\"count\");\n\t\texpect(message({ name: \"Ada\" })).toBe(\"Hi Ada\");\n\t});\n});\n\ndescribe(\"unknown annotations on locals\", () => {\n\ttest(\"interpolate the raw value like unknown pattern annotations\", async () => {\n\t\tconst warn = vi\n\t\t\t.spyOn(Logger.prototype, \"warn\")\n\t\t\t.mockImplementation(function (this: Logger) {\n\t\t\t\treturn this;\n\t\t\t});\n\t\ttry {\n\t\t\tconst { code, message } = await compileAndImport({\n\t\t\t\tdeclarations: [\n\t\t\t\t\tinput(\"amount\"),\n\t\t\t\t\tinput(\"style\"),\n\t\t\t\t\tlocal(\"styleValue\", \"style\"),\n\t\t\t\t\tlocal(\"formatted\", \"amount\", {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"customLocalFormatter\",\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"style\",\n\t\t\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"styleValue\" },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\tvariants: [{ pattern: [text(\"Total: \"), ref(\"formatted\")] }],\n\t\t\t});\n\n\t\t\texpect(code).toContain(\"const formatted = i?.amount;\");\n\t\t\texpect(code).not.toContain(\"registry.\");\n\t\t\t// the option of the ignored annotation is not read\n\t\t\texpect(code).not.toContain(\"styleValue\");\n\t\t\texpect(message({ amount: 1234, style: \"x\" })).toBe(\"Total: 1234\");\n\t\t\texpect(warn).toHaveBeenCalledWith(\n\t\t\t\texpect.stringContaining('\"customLocalFormatter\" is unknown')\n\t\t\t);\n\t\t} finally {\n\t\t\twarn.mockRestore();\n\t\t}\n\t});\n});\n\ndescribe(\"registryFunctions metadata\", () => {\n\tconst registryFunctions = (args: {\n\t\tdeclarations: Declaration[];\n\t\tselectors?: string[];\n\t\tvariants: Array<{ matches?: Match[]; pattern: Pattern }>;\n\t}) => {\n\t\tconst message: Message = {\n\t\t\tid: \"message-id\",\n\t\t\tbundleId: \"locals_message\",\n\t\t\tlocale: \"en\",\n\t\t\tselectors: (args.selectors ?? []).map((name) => ({\n\t\t\t\ttype: \"variable-reference\",\n\t\t\t\tname,\n\t\t\t})),\n\t\t};\n\t\treturn compileMessage(\n\t\t\targs.declarations,\n\t\t\tmessage,\n\t\t\targs.variants.map((variant, index) => ({\n\t\t\t\tid: String(index),\n\t\t\t\tmessageId: message.id,\n\t\t\t\tmatches: variant.matches ?? [],\n\t\t\t\tpattern: variant.pattern,\n\t\t\t}))\n\t\t).registryFunctions;\n\t};\n\n\ttest(\"message text that mentions the registry does not count\", () => {\n\t\texpect(\n\t\t\tregistryFunctions({\n\t\t\t\tdeclarations: [],\n\t\t\t\tvariants: [{ pattern: [text(\"Open the registry. Now.\")] }],\n\t\t\t})\n\t\t).toEqual([]);\n\t});\n\n\ttest(\"an unread annotated local does not count\", () => {\n\t\texpect(\n\t\t\tregistryFunctions({\n\t\t\t\tdeclarations: [input(\"count\"), local(\"countPlural\", \"count\", plural())],\n\t\t\t\tvariants: [{ pattern: [ref(\"count\")] }],\n\t\t\t})\n\t\t).toEqual([]);\n\t});\n\n\ttest(\"unknown local annotations do not count\", () => {\n\t\texpect(\n\t\t\tregistryFunctions({\n\t\t\t\tdeclarations: [\n\t\t\t\t\tinput(\"value\"),\n\t\t\t\t\tlocal(\"custom\", \"value\", {\n\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\tname: \"customFormatter\",\n\t\t\t\t\t\toptions: [],\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\tvariants: [{ pattern: [ref(\"custom\")] }],\n\t\t\t})\n\t\t).toEqual([]);\n\t});\n\n\ttest(\"unknown pattern annotations do not count\", () => {\n\t\texpect(\n\t\t\tregistryFunctions({\n\t\t\t\tdeclarations: [input(\"value\")],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tpattern: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"value\" },\n\t\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\t\tname: \"customFormatter\",\n\t\t\t\t\t\t\t\t\toptions: [],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\t\t).toEqual([]);\n\t});\n\n\ttest(\"read locals and pattern annotations count, in both variant paths\", () => {\n\t\texpect(\n\t\t\tregistryFunctions({\n\t\t\t\tdeclarations: [input(\"count\"), local(\"countPlural\", \"count\", plural())],\n\t\t\t\tselectors: [\"countPlural\"],\n\t\t\t\tvariants: [\n\t\t\t\t\t{ matches: [literal(\"countPlural\", \"one\")], pattern: [text(\"one\")] },\n\t\t\t\t\t{\n\t\t\t\t\t\tmatches: [catchall(\"countPlural\")],\n\t\t\t\t\t\tpattern: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\t\tname: \"icu:pound\",\n\t\t\t\t\t\t\t\t\toptions: [],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}).sort()\n\t\t).toEqual([\"icuPound\", \"plural\"]);\n\t\texpect(\n\t\t\tregistryFunctions({\n\t\t\t\tdeclarations: [input(\"amount\")],\n\t\t\t\tvariants: [\n\t\t\t\t\t{\n\t\t\t\t\t\tpattern: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\t\t\t\targ: { type: \"variable-reference\", name: \"amount\" },\n\t\t\t\t\t\t\t\tannotation: {\n\t\t\t\t\t\t\t\t\ttype: \"function-reference\",\n\t\t\t\t\t\t\t\t\tname: \"number\",\n\t\t\t\t\t\t\t\t\toptions: [],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\t\t).toEqual([\"number\"]);\n\t});\n});\n"]}