@inlang/paraglide-js 2.0.2 → 2.0.4

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.
@@ -95,3 +95,54 @@ test("compiles bundles with arbitrary module identifiers", async () => {
95
95
  });
96
96
  expect(result.bundle.code).includes(`export { ${toSafeModuleId("$p@44🍌")} as "$p@44🍌" }`);
97
97
  });
98
+ test("handles message pattern with duplicate variable references", async () => {
99
+ const mockBundle = {
100
+ id: "date_last_days",
101
+ declarations: [
102
+ { type: "input-variable", name: "days" },
103
+ { type: "input-variable", name: "days" },
104
+ ],
105
+ messages: [
106
+ {
107
+ id: "date_last_days",
108
+ bundleId: "date_last_days",
109
+ locale: "en",
110
+ selectors: [],
111
+ variants: [
112
+ {
113
+ id: "1",
114
+ messageId: "date_last_days",
115
+ matches: [],
116
+ pattern: [
117
+ { type: "text", value: "Last " },
118
+ {
119
+ type: "expression",
120
+ arg: { type: "variable-reference", name: "days" },
121
+ },
122
+ { type: "text", value: " days, showing " },
123
+ {
124
+ type: "expression",
125
+ arg: { type: "variable-reference", name: "days" },
126
+ },
127
+ { type: "text", value: " items" },
128
+ ],
129
+ },
130
+ ],
131
+ },
132
+ ],
133
+ };
134
+ const result = compileBundle({
135
+ fallbackMap: {
136
+ en: "en",
137
+ },
138
+ bundle: mockBundle,
139
+ messageReferenceExpression: (locale) => `${toSafeModuleId(locale)}.date_last_days`,
140
+ });
141
+ // The JSDoc should not have duplicate parameters
142
+ expect(result.bundle.code).toContain("@param {{ days: NonNullable<unknown> }} inputs");
143
+ expect(result.bundle.code).not.toContain("days: NonNullable<unknown>, days: NonNullable<unknown>");
144
+ // Check that the pattern is compiled correctly
145
+ const enMessage = result.messages?.en;
146
+ expect(enMessage).toBeDefined();
147
+ expect(enMessage?.code).toContain("Last ${i.days} days, showing ${i.days} items");
148
+ });
@@ -69,7 +69,7 @@ test("compiles a message with variants", async () => {
69
69
  ];
70
70
  const compiled = compileMessage(declarations, message, variants);
71
71
  const { some_message } = await import("data:text/javascript;base64," +
72
- btoa("export const some_message =" + compiled.code));
72
+ btoa("export const some_message = " + compiled.code));
73
73
  expect(some_message({ fistInput: 1, secondInput: 2 })).toBe("The inputs are 1 and 2");
74
74
  expect(some_message({ fistInput: 3, secondInput: 4 })).toBe("Catch all");
75
75
  expect(some_message({ fistInput: 1, secondInput: 5 })).toBe("Catch all");
@@ -1 +1 @@
1
- {"version":3,"file":"jsdoc-types.d.ts","sourceRoot":"","sources":["../../src/compiler/jsdoc-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,GAAG,MAAM,CAOT;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAU1D"}
1
+ {"version":3,"file":"jsdoc-types.d.ts","sourceRoot":"","sources":["../../src/compiler/jsdoc-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,GAAG,MAAM,CAOT;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAoB1D"}
@@ -17,7 +17,13 @@ export function inputsType(inputs) {
17
17
  if (inputs.length === 0) {
18
18
  return "{}";
19
19
  }
20
- const inputParams = inputs
20
+ // Deduplicate inputs by name to avoid TypeScript errors with duplicate properties in JSDoc
21
+ const uniqueInputMap = new Map();
22
+ for (const input of inputs) {
23
+ uniqueInputMap.set(input.name, input);
24
+ }
25
+ const uniqueInputs = Array.from(uniqueInputMap.values());
26
+ const inputParams = uniqueInputs
21
27
  .map((input) => {
22
28
  return `${input.name}: NonNullable<unknown>`;
23
29
  })
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jsdoc-types.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-types.test.d.ts","sourceRoot":"","sources":["../../src/compiler/jsdoc-types.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { test, expect } from "vitest";
2
+ import { inputsType, jsDocBundleFunctionTypes } from "./jsdoc-types.js";
3
+ test("inputsType generates unique parameter types even when the same input appears multiple times", () => {
4
+ // Simulate a case where the same input appears multiple times (like in a translation with placeholders)
5
+ const inputs = [
6
+ { name: "days", type: "input-variable" },
7
+ { name: "days", type: "input-variable" }, // Duplicated input
8
+ ];
9
+ // The generated input type should only include each parameter once
10
+ const result = inputsType(inputs);
11
+ expect(result).toBe("{ days: NonNullable<unknown> }");
12
+ // It should not generate a duplicate parameter
13
+ expect(result).not.toBe("{ days: NonNullable<unknown>, days: NonNullable<unknown> }");
14
+ });
15
+ test("jsDocBundleFunctionTypes correctly handles messages with duplicate inputs", () => {
16
+ const inputs = [
17
+ { name: "days", type: "input-variable" },
18
+ { name: "days", type: "input-variable" }, // Duplicated input
19
+ ];
20
+ const locales = ["en-us", "de-de"];
21
+ const result = jsDocBundleFunctionTypes({ inputs, locales });
22
+ // The JSDoc should only include each parameter once
23
+ expect(result).toContain("@param {{ days: NonNullable<unknown> }} inputs");
24
+ // It should not contain duplicated parameters
25
+ expect(result).not.toContain("@param {{ days: NonNullable<unknown>, days: NonNullable<unknown> }} inputs");
26
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"get-locale.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/get-locale.js"],"names":[],"mappings":"AA+BA;;;;;;;;;;;GAWG;AACH,sBAFU,MAAM,MAAM,CAyDpB;AA4BF;;;;;;;;;;;;;;GAcG;AACH,iCAFU,CAAC,EAAE,EAAE,MAAM,MAAM,KAAK,IAAI,CAIlC"}
1
+ {"version":3,"file":"get-locale.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/get-locale.js"],"names":[],"mappings":"AA+BA;;;;;;;;;;;GAWG;AACH,sBAFU,MAAM,MAAM,CA8DpB;AA4BF;;;;;;;;;;;;;;GAcG;AACH,iCAFU,CAAC,EAAE,EAAE,MAAM,MAAM,KAAK,IAAI,CAIlC"}
@@ -45,7 +45,10 @@ export let getLocale = () => {
45
45
  else if (strat === "baseLocale") {
46
46
  locale = baseLocale;
47
47
  }
48
- else if (TREE_SHAKE_URL_STRATEGY_USED && strat === "url" && !isServer && typeof window !== 'undefined') {
48
+ else if (TREE_SHAKE_URL_STRATEGY_USED &&
49
+ strat === "url" &&
50
+ !isServer &&
51
+ typeof window !== "undefined") {
49
52
  locale = extractLocaleFromUrl(window.location.href);
50
53
  }
51
54
  else if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&
@@ -41,7 +41,7 @@ export let setLocale = (newLocale, options) => {
41
41
  _locale = newLocale;
42
42
  }
43
43
  else if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
44
- if (isServer || typeof document === 'undefined') {
44
+ if (isServer || typeof document === "undefined") {
45
45
  continue;
46
46
  }
47
47
  // set the cookie
@@ -1,5 +1,5 @@
1
1
  export const ENV_VARIABLES = {
2
2
  PARJS_APP_ID: "library.inlang.paraglideJs",
3
3
  PARJS_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz",
4
- PARJS_PACKAGE_VERSION: "2.0.2",
4
+ PARJS_PACKAGE_VERSION: "2.0.4",
5
5
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inlang/paraglide-js",
3
3
  "type": "module",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -20,6 +20,7 @@
20
20
  "./dist",
21
21
  "./bin"
22
22
  ],
23
+ "types": "./dist/index.d.ts",
23
24
  "exports": {
24
25
  ".": "./dist/index.js",
25
26
  "./urlpattern-polyfill": "./dist/urlpattern-polyfill/index.js"
@@ -30,8 +31,8 @@
30
31
  "json5": "2.2.3",
31
32
  "unplugin": "^2.1.2",
32
33
  "urlpattern-polyfill": "^10.0.0",
33
- "@inlang/sdk": "2.4.3",
34
- "@inlang/recommend-sherlock": "0.2.1"
34
+ "@inlang/recommend-sherlock": "0.2.1",
35
+ "@inlang/sdk": "2.4.4"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@eslint/js": "^9.18.0",
@@ -50,8 +51,8 @@
50
51
  "typescript-eslint": "^8.20.0",
51
52
  "vitest": "2.1.8",
52
53
  "@inlang/plugin-message-format": "4.0.0",
53
- "@inlang/paraglide-js": "2.0.2",
54
- "@opral/tsconfig": "1.1.0"
54
+ "@opral/tsconfig": "1.1.0",
55
+ "@inlang/paraglide-js": "2.0.4"
55
56
  },
56
57
  "keywords": [
57
58
  "inlang",