@wuchale/svelte 0.15.0 → 0.15.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,16 +1,11 @@
1
- // $$ cd .. && npm run test
2
1
  import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
3
2
  import { SvelteTransformer } from "./transformer.js";
4
3
  import { getDependencies, loaderPathResolver } from 'wuchale/adapter-utils';
5
4
  const topLevelDeclarationsInside = ['$derived', '$derived.by'];
6
- const ignoreElements = ['style', 'path', 'code', 'pre'];
7
5
  const svelteHeuristic = (msgStr, details) => {
8
6
  if (!defaultHeuristic(msgStr, details)) {
9
7
  return false;
10
8
  }
11
- if (ignoreElements.includes(details.element)) {
12
- return false;
13
- }
14
9
  if (details.scope !== 'script') {
15
10
  return true;
16
11
  }
@@ -207,7 +207,7 @@ export class SvelteTransformer extends Transformer {
207
207
  msgs.push(...this.visitProgram(node.module.content));
208
208
  this.mstr.appendRight(
209
209
  // @ts-expect-error
210
- this.getRealBodyStart(node.module.content.body), this.initRuntime(this.filename, null, null, {}));
210
+ this.getRealBodyStart(node.module.content.body) ?? node.module.content.start, this.initRuntime(this.filename, null, null, {}));
211
211
  this.additionalState = {}; // reset
212
212
  this.currentRtVar = prevRtVar; // reset
213
213
  }
@@ -264,27 +264,28 @@ export class SvelteTransformer extends Transformer {
264
264
  const msgs = this.visitSv(ast);
265
265
  const initRuntime = this.initRuntime(this.filename, null, null, {});
266
266
  if (ast.type === 'Program') {
267
- const bodyStart = this.getRealBodyStart(ast.body);
267
+ const bodyStart = this.getRealBodyStart(ast.body) ?? 0;
268
268
  this.mstr.appendRight(bodyStart, initRuntime);
269
269
  return this.finalize(msgs, bodyStart);
270
270
  }
271
271
  let headerIndex = 0;
272
272
  if (ast.module) {
273
273
  // @ts-ignore
274
- headerIndex = this.getRealBodyStart(ast.module.content.body);
274
+ headerIndex = this.getRealBodyStart(ast.module.content.body) ?? ast.module.content.start;
275
275
  }
276
276
  if (ast.instance) {
277
+ // @ts-expect-error
278
+ const instanceBodyStart = this.getRealBodyStart(ast.instance.content.body) ?? ast.instance.content.start;
277
279
  if (!ast.module) {
278
- // @ts-expect-error
279
- headerIndex = this.getRealBodyStart(ast.instance.content.body);
280
+ headerIndex = instanceBodyStart;
280
281
  }
281
- // @ts-expect-error
282
- this.mstr.appendRight(this.getRealBodyStart(ast.instance.content.body), initRuntime);
282
+ this.mstr.appendRight(instanceBodyStart, initRuntime);
283
283
  }
284
284
  else {
285
- this.mstr.prepend('<script>');
285
+ const instanceStart = ast.module?.end ?? 0;
286
+ this.mstr.prependLeft(instanceStart, '\n<script>');
286
287
  // account index for hmr data here
287
- this.mstr.prependRight(0, `${initRuntime}\n</script>\n`);
288
+ this.mstr.prependRight(instanceStart, `${initRuntime}\n</script>\n`);
288
289
  // now hmr data can be prependRight(0, ...)
289
290
  }
290
291
  const headerAdd = `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/svelte",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Protobuf-like i18n from plain code: Svelte adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -52,7 +52,7 @@
52
52
  "license": "MIT",
53
53
  "dependencies": {
54
54
  "svelte": "^5.37.0",
55
- "wuchale": "^0.16.0"
55
+ "wuchale": "^0.16.4"
56
56
  },
57
57
  "devDependencies": {
58
58
  "acorn": "^8.15.0",