@wuchale/svelte 0.19.3 → 0.19.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Adapter, AdapterArgs, CreateHeuristicOpts, HeuristicFunc, LoaderChoice } from 'wuchale';
1
+ import type { Adapter, AdapterArgs, CreateHeuristicOpts, DeepPartial, HeuristicFunc, LoaderChoice } from 'wuchale';
2
2
  import { type RuntimeCtxSv } from './transformer.js';
3
3
  export type { RuntimeCtxSv };
4
4
  export declare function createSvelteHeuristic(opts: CreateHeuristicOpts): HeuristicFunc;
@@ -8,10 +8,10 @@ export declare const svelteKitDefaultHeuristic: HeuristicFunc;
8
8
  /** Default Svelte heuristic which requires `$derived` or `$derived.by` for top level variable assignments */
9
9
  export declare const svelteDefaultHeuristicDerivedReq: HeuristicFunc;
10
10
  type LoadersAvailable = 'svelte' | 'sveltekit';
11
- export type SvelteArgs = AdapterArgs<LoadersAvailable, RuntimeCtxSv>;
11
+ export type SvelteArgs = AdapterArgs<LoadersAvailable>;
12
12
  export declare const defaultArgs: SvelteArgs;
13
13
  export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailable>, bundle: boolean): string | {
14
14
  client: string;
15
15
  server: string;
16
16
  } | null;
17
- export declare const adapter: (args?: Partial<SvelteArgs>) => Adapter;
17
+ export declare const adapter: (args?: DeepPartial<SvelteArgs>) => Adapter;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createHeuristic, deepMergeObjects, defaultGenerateLoadID, defaultHeuristicOpts, pofile } from 'wuchale';
1
+ import { createHeuristic, defaultGenerateLoadID, defaultHeuristicOpts, fillDefaults, 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';
@@ -20,7 +20,10 @@ export function createSvelteHeuristic(opts) {
20
20
  }
21
21
  /** Default Svelte heuristic which extracts top level variable assignments as well, leading to `$derived` being auto added when needed */
22
22
  export const svelteDefaultHeuristic = createSvelteHeuristic(defaultHeuristicOpts);
23
- export const svelteKitDefaultHeuristic = createSvelteHeuristic({ ...defaultHeuristicOpts, urlCalls: ['goto'] });
23
+ export const svelteKitDefaultHeuristic = createSvelteHeuristic({
24
+ ...defaultHeuristicOpts,
25
+ urlCalls: ['asset', 'goto', 'pushState', 'replaceState', 'resolve'],
26
+ });
24
27
  /** Default Svelte heuristic which requires `$derived` or `$derived.by` for top level variable assignments */
25
28
  export const svelteDefaultHeuristicDerivedReq = msg => {
26
29
  const defRes = svelteDefaultHeuristic(msg);
@@ -42,17 +45,17 @@ export const defaultArgs = {
42
45
  files: ['src/**/*.svelte', 'src/**/*.svelte.{js,ts}'],
43
46
  storage: pofile(),
44
47
  patterns: [pluralPattern],
45
- heuristic: svelteKitDefaultHeuristic,
48
+ heuristic: svelteDefaultHeuristic,
46
49
  granularLoad: false,
47
50
  bundleLoad: false,
48
51
  generateLoadID: defaultGenerateLoadID,
49
52
  loader: 'svelte',
50
53
  runtime: {
51
- initReactive: ({ file, funcName, module }) => {
54
+ initReactive: ({ file, funcName, ctx: { module } }) => {
52
55
  const inTopLevel = funcName == null;
53
56
  return file.endsWith('.svelte.js') || module ? inTopLevel : inTopLevel ? true : null;
54
57
  },
55
- useReactive: ({ file, funcName, module }) => {
58
+ useReactive: ({ file, funcName, ctx: { module } }) => {
56
59
  const inTopLevel = funcName == null;
57
60
  return file.endsWith('.svelte.js') || module ? inTopLevel : true;
58
61
  },
@@ -83,7 +86,10 @@ export function getDefaultLoaderPath(loader, bundle) {
83
86
  return resolveLoaderPath(loader);
84
87
  }
85
88
  export const adapter = (args = defaultArgs) => {
86
- const { heuristic, patterns, runtime, loader, ...rest } = deepMergeObjects(args, defaultArgs);
89
+ if (args.loader === 'sveltekit' && args.heuristic == null) {
90
+ args.heuristic = svelteKitDefaultHeuristic;
91
+ }
92
+ const { heuristic, patterns, runtime, loader, ...rest } = fillDefaults(args, defaultArgs);
87
93
  return {
88
94
  transform: ({ content, filename, index, expr, matchUrl }) => {
89
95
  return new SvelteTransformer(content, filename, index, heuristic, patterns, expr, runtime, matchUrl).transformSv();
@@ -4,19 +4,20 @@ import type { CatalogExpr, CodePattern, HeuristicFunc, IndexTracker, Message, Ru
4
4
  import { MixedVisitor } from 'wuchale/adapter-utils';
5
5
  import { Transformer } from 'wuchale/adapter-vanilla';
6
6
  type MixedNodesTypes = AST.Text | AST.Tag | AST.ElementLike | AST.Block | AST.Comment;
7
+ type MixedVisitorSvelte = MixedVisitor<MixedNodesTypes, AST.Text, AST.Comment, AST.ExpressionTag>;
7
8
  export type RuntimeCtxSv = {
8
9
  module: boolean;
9
10
  };
10
- export declare class SvelteTransformer extends Transformer<RuntimeCtxSv> {
11
- currentElement?: string;
11
+ export declare class SvelteTransformer extends Transformer {
12
+ currentElement?: string | undefined;
12
13
  inCompoundText: boolean;
13
14
  currentSnippet: number;
14
15
  moduleExportExprs: AnyNode[];
15
- mixedVisitor: MixedVisitor<MixedNodesTypes>;
16
- constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf<RuntimeCtxSv>, matchUrl: UrlMatcher);
16
+ mixedVisitor: MixedVisitorSvelte;
17
+ constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf, matchUrl: UrlMatcher);
17
18
  visitExpressionTag: (node: AST.ExpressionTag) => Message[];
18
19
  visitVariableDeclarator: (node: VariableDeclarator) => Message[];
19
- initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
20
+ initMixedVisitor: () => MixedVisitorSvelte;
20
21
  visitFragment: (node: AST.Fragment) => Message[];
21
22
  visitRegularElement: (node: AST.ElementLike) => Message[];
22
23
  visitComponent: (node: AST.ElementLike) => Message[];
@@ -1,4 +1,3 @@
1
- import MagicString from 'magic-string';
2
1
  import { parse, preprocess } from 'svelte/compiler';
3
2
  import { getKey } from 'wuchale';
4
3
  import { MixedVisitor, nonWhitespaceText, varNames } from 'wuchale/adapter-utils';
@@ -8,7 +7,7 @@ const noWrapTopCalls = ['$props', '$state', '$derived', '$effect'];
8
7
  const rtComponent = 'W_tx_';
9
8
  const headerAdd = `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"`;
10
9
  const snipPrefix = '_w_snippet_';
11
- const rtModuleVar = varNames.rt + 'mod_';
10
+ const rtModuleVar = `${varNames.rt}mod_`;
12
11
  // for use before actually parsing the code,
13
12
  // to remove the contents of e.g. <style lang="scss"> which can cause parse errors
14
13
  // without messing up indices for magic-string
@@ -25,6 +24,7 @@ export class SvelteTransformer extends Transformer {
25
24
  constructor(content, filename, index, heuristic, patterns, catalogExpr, rtConf, matchUrl) {
26
25
  super(content, filename, index, heuristic, patterns, catalogExpr, rtConf, matchUrl, [varNames.rt, rtModuleVar]);
27
26
  this.heuristciDetails.insideProgram = false;
27
+ this.mixedVisitor = this.initMixedVisitor();
28
28
  }
29
29
  visitExpressionTag = (node) => this.visit(node.expression);
30
30
  visitVariableDeclarator = (node) => {
@@ -67,9 +67,9 @@ export class SvelteTransformer extends Transformer {
67
67
  isComment: node => node.type === 'Comment',
68
68
  leaveInPlace: node => ['ConstTag', 'SnippetBlock'].includes(node.type),
69
69
  isExpression: node => node.type === 'ExpressionTag',
70
- getTextContent: (node) => node.data,
71
- getCommentData: (node) => node.data.trim(),
72
- canHaveChildren: (node) => nodesWithChildren.includes(node.type),
70
+ getTextContent: node => node.data,
71
+ getCommentData: node => node.data.trim(),
72
+ canHaveChildren: node => nodesWithChildren.includes(node.type),
73
73
  visitFunc: (child, inCompoundText) => {
74
74
  const inCompoundTextPrev = this.inCompoundText;
75
75
  this.inCompoundText = inCompoundText;
@@ -107,7 +107,7 @@ export class SvelteTransformer extends Transformer {
107
107
  let end = ' />\n';
108
108
  if (hasExprs) {
109
109
  begin += ' a={[';
110
- end = ']}' + end;
110
+ end = `]}${end}`;
111
111
  }
112
112
  this.mstr.appendLeft(lastChildEnd, begin);
113
113
  this.mstr.appendRight(lastChildEnd, end);
@@ -334,8 +334,6 @@ export class SvelteTransformer extends Transformer {
334
334
  ;
335
335
  [ast, this.comments] = parseScript(this.content);
336
336
  }
337
- this.mstr = new MagicString(this.content);
338
- this.mixedVisitor = this.initMixedVisitor();
339
337
  if (ast.type === 'Root' && ast.module) {
340
338
  this.collectModuleExportExprs(ast.module);
341
339
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/svelte",
3
- "version": "0.19.3",
3
+ "version": "0.19.4",
4
4
  "description": "Protobuf-like i18n from plain code: Svelte adapter",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -53,11 +53,12 @@
53
53
  "dependencies": {
54
54
  "magic-string": "^0.30.21",
55
55
  "svelte": "^5",
56
- "wuchale": "^0.22.1"
56
+ "wuchale": "^0.23.0"
57
57
  },
58
58
  "devDependencies": {
59
+ "@types/node": "~24.12.2",
59
60
  "acorn": "^8.16.0",
60
- "typescript": "^5.9.3"
61
+ "typescript": "^6.0.3"
61
62
  },
62
63
  "type": "module"
63
64
  }
@@ -3,7 +3,7 @@ import { loadCatalog, loadIDs } from '${PROXY_SYNC}'
3
3
 
4
4
  const key = '${KEY}'
5
5
 
6
- export { loadCatalog, loadIDs, key } // for hooks.server.{js,ts}
6
+ export { key, loadCatalog, loadIDs } // for hooks.server.{js,ts}
7
7
 
8
8
  // for non-reactive
9
9
  export const getRuntime = (/** @type {string} */ loadID) => currentRuntime(key, loadID)