@wuchale/svelte 0.20.2 → 0.20.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.
@@ -17,7 +17,7 @@ export declare class SvelteTransformer extends Transformer {
17
17
  visitExpressionTag(node: AST.ExpressionTag): Message[];
18
18
  visitVariableDeclarator(node: VariableDeclarator): Message[];
19
19
  initMixedVisitor(): MixedVisitorSvelte;
20
- visitFragment(node: AST.Fragment): Message[];
20
+ visitFragment(node: AST.Fragment, nestable?: boolean): Message[];
21
21
  visitRegularElement(node: AST.ElementLike): Message[];
22
22
  visitComponent(node: AST.Component): Message[];
23
23
  visitSpreadAttribute(node: AST.SpreadAttribute): Message[];
@@ -2,7 +2,6 @@ import { parse, preprocess } from 'svelte/compiler';
2
2
  import { getKey } from 'wuchale';
3
3
  import { MixedVisitor, varNames } from 'wuchale/adapter-utils';
4
4
  import { parseScript, Transformer } from 'wuchale/adapter-vanilla';
5
- const nodesWithChildren = ['RegularElement', 'Component', 'SvelteElement'];
6
5
  const noWrapTopCalls = ['$props', '$state', '$derived', '$effect'];
7
6
  const rtComponent = 'W_tx_';
8
7
  const headerAdd = `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"`;
@@ -71,7 +70,6 @@ export class SvelteTransformer extends Transformer {
71
70
  isText: node => node.type === 'Text',
72
71
  isComment: node => node.type === 'Comment',
73
72
  leaveInPlace: node => ['ConstTag', 'SnippetBlock'].includes(node.type),
74
- canHaveChildren: node => nodesWithChildren.includes(node.type),
75
73
  isExpression: node => node.type === 'ExpressionTag',
76
74
  getTextContent: node => node.data,
77
75
  getCommentData: node => node.data.trim(),
@@ -112,9 +110,10 @@ export class SvelteTransformer extends Transformer {
112
110
  },
113
111
  });
114
112
  }
115
- visitFragment(node) {
113
+ visitFragment(node, nestable = false) {
116
114
  return this.mixedVisitor.visit({
117
115
  children: node.nodes,
116
+ nestable,
118
117
  commentDirectives: this.commentDirectives,
119
118
  scope: 'markup',
120
119
  element: this.currentElement,
@@ -128,7 +127,7 @@ export class SvelteTransformer extends Transformer {
128
127
  for (const attrib of node.attributes) {
129
128
  msgs.push(...this.visitSv(attrib));
130
129
  }
131
- msgs.push(...this.visitFragment(node.fragment));
130
+ msgs.push(...this.visitFragment(node.fragment, true));
132
131
  this.currentElement = currentElement;
133
132
  return msgs;
134
133
  }
@@ -152,6 +151,7 @@ export class SvelteTransformer extends Transformer {
152
151
  if (values.length > 1) {
153
152
  const msgs = this.mixedVisitor.visit({
154
153
  children: values,
154
+ nestable: false,
155
155
  commentDirectives: this.commentDirectives,
156
156
  scope: 'attribute',
157
157
  element: this.currentElement,
@@ -178,7 +178,7 @@ export class SvelteTransformer extends Transformer {
178
178
  return this.visitSv(value);
179
179
  }
180
180
  heuDetails.scope = 'attribute';
181
- const [pass, msgInfo] = this.checkHeuristic(value.data, heuDetails);
181
+ const [pass, msgInfo] = this.checkHeuristicAllowNew(value.data, heuDetails);
182
182
  if (!pass) {
183
183
  return [];
184
184
  }
@@ -228,41 +228,41 @@ export class SvelteTransformer extends Transformer {
228
228
  if (this.hasIdentifier(this.moduleExportExprs, node.expression.name)) {
229
229
  this.currentRtVar = rtModuleVar;
230
230
  }
231
- const msgs = this.visitFragment(node.body);
231
+ const msgs = this.visitFragment(node.body, false);
232
232
  this.currentRtVar = prevRtVar;
233
233
  return msgs;
234
234
  }
235
235
  visitIfBlock(node) {
236
236
  const msgs = this.visit(node.test);
237
- msgs.push(...this.visitSv(node.consequent));
237
+ msgs.push(...this.visitFragment(node.consequent, false));
238
238
  if (node.alternate) {
239
- msgs.push(...this.visitSv(node.alternate));
239
+ msgs.push(...this.visitFragment(node.alternate, false));
240
240
  }
241
241
  return msgs;
242
242
  }
243
243
  visitEachBlock(node) {
244
- const msgs = [...this.visit(node.expression), ...this.visitSv(node.body)];
244
+ const msgs = [...this.visit(node.expression), ...this.visitFragment(node.body, false)];
245
245
  if (node.key) {
246
246
  msgs.push(...this.visit(node.key));
247
247
  }
248
248
  if (node.fallback) {
249
- msgs.push(...this.visitSv(node.fallback));
249
+ msgs.push(...this.visitFragment(node.fallback, false));
250
250
  }
251
251
  return msgs;
252
252
  }
253
253
  visitKeyBlock(node) {
254
- return [...this.visit(node.expression), ...this.visitSv(node.fragment)];
254
+ return [...this.visit(node.expression), ...this.visitFragment(node.fragment, false)];
255
255
  }
256
256
  visitAwaitBlock(node) {
257
257
  const msgs = this.visit(node.expression);
258
258
  if (node.then) {
259
- msgs.push(...this.visitFragment(node.then));
259
+ msgs.push(...this.visitFragment(node.then, false));
260
260
  }
261
261
  if (node.pending) {
262
- msgs.push(...this.visitFragment(node.pending));
262
+ msgs.push(...this.visitFragment(node.pending, false));
263
263
  }
264
264
  if (node.catch) {
265
- msgs.push(...this.visitFragment(node.catch));
265
+ msgs.push(...this.visitFragment(node.catch, false));
266
266
  }
267
267
  return msgs;
268
268
  }
@@ -280,7 +280,7 @@ export class SvelteTransformer extends Transformer {
280
280
  else {
281
281
  this.currentElement = 'svelte:element';
282
282
  }
283
- const msgs = [...node.attributes.flatMap(n => this.visitSv(n)), ...this.visitFragment(node.fragment)];
283
+ const msgs = [...node.attributes.flatMap(n => this.visitSv(n)), ...this.visitFragment(node.fragment, true)];
284
284
  this.currentElement = currentElement;
285
285
  return msgs;
286
286
  }
@@ -318,7 +318,7 @@ export class SvelteTransformer extends Transformer {
318
318
  this.commentDirectives = {}; // reset
319
319
  msgs.push(...this.visitProgram(node.instance.content));
320
320
  }
321
- msgs.push(...this.visitFragment(node.fragment), ...this.mixedVisitor.applyMod());
321
+ msgs.push(...this.visitFragment(node.fragment, false));
322
322
  return msgs;
323
323
  }
324
324
  visitSv(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/svelte",
3
- "version": "0.20.2",
3
+ "version": "0.20.4",
4
4
  "description": "Protobuf-like i18n from plain code: Svelte adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -54,7 +54,7 @@
54
54
  "svelte": "^5"
55
55
  },
56
56
  "dependencies": {
57
- "wuchale": "^0.25.3"
57
+ "wuchale": "^0.25.6"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "~24.13.2",