@wuchale/svelte 0.18.2 → 0.19.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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createHeuristic, deepMergeObjects, defaultGenerateLoadID, defaultHeuristicOpts } from 'wuchale';
1
+ import { createHeuristic, deepMergeObjects, defaultGenerateLoadID, defaultHeuristicOpts, pofile } from 'wuchale';
2
2
  import { loaderPathResolver } from 'wuchale/adapter-utils';
3
3
  import { pluralPattern } from 'wuchale/adapter-vanilla';
4
4
  import { SvelteTransformer } from './transformer.js';
@@ -40,7 +40,7 @@ export const svelteDefaultHeuristicDerivedReq = msg => {
40
40
  };
41
41
  export const defaultArgs = {
42
42
  files: ['src/**/*.svelte', 'src/**/*.svelte.{js,ts}'],
43
- localesDir: './src/locales',
43
+ storage: pofile(),
44
44
  patterns: [pluralPattern],
45
45
  heuristic: svelteKitDefaultHeuristic,
46
46
  granularLoad: false,
@@ -1,8 +1,10 @@
1
1
  import MagicString from 'magic-string';
2
2
  import { parse, preprocess } from 'svelte/compiler';
3
+ import { getKey } from 'wuchale';
3
4
  import { MixedVisitor, nonWhitespaceText, varNames } from 'wuchale/adapter-utils';
4
5
  import { parseScript, Transformer } from 'wuchale/adapter-vanilla';
5
6
  const nodesWithChildren = ['RegularElement', 'Component'];
7
+ const noWrapTopCalls = ['$props', '$state', '$derived', '$effect'];
6
8
  const rtComponent = 'W_tx_';
7
9
  const headerAdd = `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"`;
8
10
  const snipPrefix = '_w_snippet_';
@@ -35,8 +37,8 @@ export class SvelteTransformer extends Transformer {
35
37
  return msgs;
36
38
  }
37
39
  const needsWrapping = msgs.some(msg => {
38
- if (msg.details.topLevelCall &&
39
- ['$props', '$state', '$derived', '$derived.by'].includes(msg.details.topLevelCall)) {
40
+ const topCall = msg.details.topLevelCall ?? '';
41
+ if (noWrapTopCalls.includes(topCall) || noWrapTopCalls.some(c => topCall.startsWith(`${c}.`))) {
40
42
  return false;
41
43
  }
42
44
  if (msg.details.declaring !== 'variable') {
@@ -96,7 +98,7 @@ export class SvelteTransformer extends Transformer {
96
98
  begin += `{${this.vars().nestCtx}} n`;
97
99
  }
98
100
  else {
99
- const index = this.index.get(msgInfo.toKey());
101
+ const index = this.index.get(getKey(msgInfo.msgStr, msgInfo.context));
100
102
  begin += `{${this.vars().rtCtx}(${index})}`;
101
103
  }
102
104
  let end = ' />\n';
@@ -137,7 +139,7 @@ export class SvelteTransformer extends Transformer {
137
139
  if (!pass) {
138
140
  return [];
139
141
  }
140
- this.mstr.update(node.start + startWh, node.end - endWh, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
142
+ this.mstr.update(node.start + startWh, node.end - endWh, `{${this.vars().rtTrans}(${this.index.get(getKey(msgInfo.msgStr, msgInfo.context))})}`);
141
143
  return [msgInfo];
142
144
  };
143
145
  visitSpreadAttribute = (node) => this.visit(node.expression);
@@ -184,7 +186,7 @@ export class SvelteTransformer extends Transformer {
184
186
  if (!pass) {
185
187
  return [];
186
188
  }
187
- this.mstr.update(value.start, value.end, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
189
+ this.mstr.update(value.start, value.end, `{${this.literalRepl(msgInfo)}}`);
188
190
  if (`'"`.includes(this.content[value.start - 1])) {
189
191
  this.mstr.remove(value.start - 1, value.start);
190
192
  this.mstr.remove(value.end, value.end + 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/svelte",
3
- "version": "0.18.2",
3
+ "version": "0.19.1",
4
4
  "description": "Protobuf-like i18n from plain code: Svelte adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -52,11 +52,11 @@
52
52
  "license": "MIT",
53
53
  "dependencies": {
54
54
  "magic-string": "^0.30.21",
55
- "svelte": "^5.53.1",
56
- "wuchale": "^0.20.0"
55
+ "svelte": "^5",
56
+ "wuchale": "^0.21.2"
57
57
  },
58
58
  "devDependencies": {
59
- "acorn": "^8.15.0",
59
+ "acorn": "^8.16.0",
60
60
  "typescript": "^5.9.3"
61
61
  },
62
62
  "type": "module"
@@ -4,7 +4,7 @@ import { locales } from '${DATA}'
4
4
  let locale = $state(locales[0])
5
5
 
6
6
  /**
7
- * @param {string} newLocale
7
+ * @param {import('${DATA}').Locale} newLocale
8
8
  */
9
9
  export function setLocale(newLocale) {
10
10
  locale = newLocale