@wuchale/svelte 0.14.2 → 0.15.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.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // $$ cd .. && npm run test
2
2
  import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
3
3
  import { SvelteTransformer } from "./transformer.js";
4
- import { getDependencies } from 'wuchale/adapter-utils';
4
+ import { getDependencies, loaderPathResolver } from 'wuchale/adapter-utils';
5
5
  const topLevelDeclarationsInside = ['$derived', '$derived.by'];
6
- const ignoreElements = ['style', 'path'];
6
+ const ignoreElements = ['style', 'path', 'code', 'pre'];
7
7
  const svelteHeuristic = (msgStr, details) => {
8
8
  if (!defaultHeuristic(msgStr, details)) {
9
9
  return false;
@@ -52,6 +52,7 @@ const defaultArgs = {
52
52
  },
53
53
  },
54
54
  };
55
+ const resolveLoaderPath = loaderPathResolver(import.meta.url, '../src/loaders', 'svelte.js');
55
56
  export const adapter = (args = defaultArgs) => {
56
57
  const { heuristic, pluralsFunc, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
57
58
  return {
@@ -73,11 +74,11 @@ export const adapter = (args = defaultArgs) => {
73
74
  defaultLoaderPath: loader => {
74
75
  if (loader === 'sveltekit') {
75
76
  return {
76
- client: new URL(`../src/loaders/svelte.svelte.js`, import.meta.url).pathname,
77
- ssr: new URL(`../src/loaders/sveltekit.ssr.svelte.js`, import.meta.url).pathname
77
+ client: resolveLoaderPath('svelte'),
78
+ ssr: resolveLoaderPath('sveltekit.ssr'),
78
79
  };
79
80
  }
80
- return new URL(`../src/loaders/${loader}.svelte.js`, import.meta.url).pathname;
81
+ return resolveLoaderPath(loader);
81
82
  },
82
83
  runtime,
83
84
  ...rest,
@@ -2,8 +2,8 @@ import type { AnyNode } from "acorn";
2
2
  import { type AST } from "svelte/compiler";
3
3
  import { Message } from 'wuchale';
4
4
  import { Transformer } from 'wuchale/adapter-vanilla';
5
- import type { IndexTracker, HeuristicFunc, TransformOutput, CommentDirectives, CatalogExpr, RuntimeConf } from 'wuchale';
6
- import { MixedVisitor } from "wuchale/adapter-utils";
5
+ import type { IndexTracker, HeuristicFunc, TransformOutput, CatalogExpr, RuntimeConf } from 'wuchale';
6
+ import { MixedVisitor, type CommentDirectives } from "wuchale/adapter-utils";
7
7
  type MixedNodesTypes = AST.Text | AST.Tag | AST.ElementLike | AST.Block | AST.Comment;
8
8
  export declare class SvelteTransformer extends Transformer {
9
9
  currentElement?: string;
@@ -2,7 +2,7 @@ import MagicString from "magic-string";
2
2
  import { parse } from "svelte/compiler";
3
3
  import { Message } from 'wuchale';
4
4
  import { Transformer, parseScript } from 'wuchale/adapter-vanilla';
5
- import { MixedVisitor, nonWhitespaceText, varNames } from "wuchale/adapter-utils";
5
+ import { MixedVisitor, nonWhitespaceText, processCommentDirectives, varNames } from "wuchale/adapter-utils";
6
6
  const nodesWithChildren = ['RegularElement', 'Component'];
7
7
  const rtComponent = 'W_tx_';
8
8
  const snipPrefix = '_w_snippet_';
@@ -77,6 +77,7 @@ export class SvelteTransformer extends Transformer {
77
77
  inCompoundText: this.inCompoundText,
78
78
  scope: 'markup',
79
79
  element: this.currentElement,
80
+ useComponent: this.currentElement !== 'title'
80
81
  });
81
82
  visitRegularElement = (node) => {
82
83
  const currentElement = this.currentElement;
@@ -192,7 +193,7 @@ export class SvelteTransformer extends Transformer {
192
193
  ...this.visitSv(node.fragment),
193
194
  ];
194
195
  visitSvelteHead = (node) => this.visitSv(node.fragment);
195
- visitTitleElement = (node) => this.visitSv(node.fragment);
196
+ visitTitleElement = (node) => this.visitRegularElement(node);
196
197
  visitSvelteWindow = (node) => node.attributes.map(this.visitSv).flat();
197
198
  visitRoot = (node) => {
198
199
  const msgs = [];
@@ -219,12 +220,12 @@ export class SvelteTransformer extends Transformer {
219
220
  };
220
221
  visitSv = (node) => {
221
222
  if (node.type === 'Comment') {
222
- const directives = this.processCommentDirectives(node.data.trim());
223
+ this.commentDirectives = processCommentDirectives(node.data.trim(), this.commentDirectives);
223
224
  if (this.lastVisitIsComment) {
224
- this.commentDirectivesStack[this.commentDirectivesStack.length - 1] = directives;
225
+ this.commentDirectivesStack[this.commentDirectivesStack.length - 1] = this.commentDirectives;
225
226
  }
226
227
  else {
227
- this.commentDirectivesStack.push(directives);
228
+ this.commentDirectivesStack.push(this.commentDirectives);
228
229
  }
229
230
  this.lastVisitIsComment = true;
230
231
  return [];
@@ -238,6 +239,9 @@ export class SvelteTransformer extends Transformer {
238
239
  this.commentDirectives = this.commentDirectivesStack.pop();
239
240
  this.lastVisitIsComment = false;
240
241
  }
242
+ if (this.commentDirectives.ignoreFile) {
243
+ return [];
244
+ }
241
245
  if (this.commentDirectives.forceInclude !== false) {
242
246
  msgs = this.visit(node);
243
247
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/svelte",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
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.15.6"
55
+ "wuchale": "^0.16.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "acorn": "^8.15.0",