@wuchale/svelte 0.17.7 → 0.17.8
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 +2 -2
- package/dist/transformer.d.ts +2 -2
- package/dist/transformer.js +23 -15
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export type SvelteArgs = AdapterArgs<LoadersAvailable>;
|
|
|
10
10
|
export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailable>, bundle: boolean): string | {
|
|
11
11
|
client: string;
|
|
12
12
|
server: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const adapter: (args?: SvelteArgs) => Adapter;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare const adapter: (args?: Partial<SvelteArgs>) => Adapter;
|
|
15
15
|
export {};
|
package/dist/transformer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AnyNode, VariableDeclarator } 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, CatalogExpr, RuntimeConf, CodePattern } from 'wuchale';
|
|
5
|
+
import type { IndexTracker, HeuristicFunc, TransformOutput, CatalogExpr, RuntimeConf, CodePattern, UrlMatcher } from 'wuchale';
|
|
6
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 {
|
|
@@ -13,7 +13,7 @@ export declare class SvelteTransformer extends Transformer {
|
|
|
13
13
|
currentSnippet: number;
|
|
14
14
|
moduleExportRanges: [number, number][];
|
|
15
15
|
mixedVisitor: MixedVisitor<MixedNodesTypes>;
|
|
16
|
-
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf, matchUrl:
|
|
16
|
+
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf, matchUrl: UrlMatcher);
|
|
17
17
|
visitExpressionTag: (node: AST.ExpressionTag) => Message[];
|
|
18
18
|
visitVariableDeclarator: (node: VariableDeclarator) => Message[];
|
|
19
19
|
initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
|
package/dist/transformer.js
CHANGED
|
@@ -32,11 +32,12 @@ export class SvelteTransformer extends Transformer {
|
|
|
32
32
|
visitExpressionTag = (node) => this.visit(node.expression);
|
|
33
33
|
visitVariableDeclarator = (node) => {
|
|
34
34
|
const msgs = this.defaultVisitVariableDeclarator(node);
|
|
35
|
-
|
|
35
|
+
const init = node.init;
|
|
36
|
+
if (!msgs.length || this.declaring != null || init == null || ['ArrowFunctionExpression', 'FunctionExpression'].includes(init.type)) {
|
|
36
37
|
return msgs;
|
|
37
38
|
}
|
|
38
39
|
const needsWrapping = msgs.some(msg => {
|
|
39
|
-
if (['$props', '$state', '$derived', '$derived.by'].includes(msg.details.topLevelCall)) {
|
|
40
|
+
if (msg.details.topLevelCall && ['$props', '$state', '$derived', '$derived.by'].includes(msg.details.topLevelCall)) {
|
|
40
41
|
return false;
|
|
41
42
|
}
|
|
42
43
|
if (msg.details.declaring !== 'variable') {
|
|
@@ -47,10 +48,10 @@ export class SvelteTransformer extends Transformer {
|
|
|
47
48
|
if (!needsWrapping) {
|
|
48
49
|
return msgs;
|
|
49
50
|
}
|
|
50
|
-
const isExported = this.moduleExportRanges.some(([start, end]) =>
|
|
51
|
+
const isExported = this.moduleExportRanges.some(([start, end]) => init.start >= start && init.end <= end);
|
|
51
52
|
if (!isExported) {
|
|
52
|
-
this.mstr.appendLeft(
|
|
53
|
-
this.mstr.appendRight(
|
|
53
|
+
this.mstr.appendLeft(init.start, '$derived(');
|
|
54
|
+
this.mstr.appendRight(init.end, ')');
|
|
54
55
|
}
|
|
55
56
|
return msgs;
|
|
56
57
|
};
|
|
@@ -238,10 +239,10 @@ export class SvelteTransformer extends Transformer {
|
|
|
238
239
|
];
|
|
239
240
|
};
|
|
240
241
|
visitAwaitBlock = (node) => {
|
|
241
|
-
const msgs =
|
|
242
|
-
|
|
243
|
-
...this.visitFragment(node.then)
|
|
244
|
-
|
|
242
|
+
const msgs = this.visit(node.expression);
|
|
243
|
+
if (node.then) {
|
|
244
|
+
msgs.push(...this.visitFragment(node.then));
|
|
245
|
+
}
|
|
245
246
|
if (node.pending) {
|
|
246
247
|
msgs.push(...this.visitFragment(node.pending));
|
|
247
248
|
}
|
|
@@ -269,9 +270,12 @@ export class SvelteTransformer extends Transformer {
|
|
|
269
270
|
this.commentDirectives = {}; // reset
|
|
270
271
|
// @ts-expect-error
|
|
271
272
|
msgs.push(...this.visitProgram(node.module.content));
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
const runtimeInit = this.initRuntime(this.filename);
|
|
274
|
+
if (runtimeInit) {
|
|
275
|
+
this.mstr.appendRight(
|
|
276
|
+
// @ts-expect-error
|
|
277
|
+
this.getRealBodyStart(node.module.content.body) ?? node.module.content.start, runtimeInit);
|
|
278
|
+
}
|
|
275
279
|
this.additionalState = {}; // reset
|
|
276
280
|
this.currentRtVar = prevRtVar; // reset
|
|
277
281
|
}
|
|
@@ -358,10 +362,12 @@ export class SvelteTransformer extends Transformer {
|
|
|
358
362
|
this.collectModuleExportRanges(ast.module);
|
|
359
363
|
}
|
|
360
364
|
const msgs = this.visitSv(ast);
|
|
361
|
-
const initRuntime = this.initRuntime(this.filename
|
|
365
|
+
const initRuntime = this.initRuntime(this.filename);
|
|
362
366
|
if (ast.type === 'Program') {
|
|
363
367
|
const bodyStart = this.getRealBodyStart(ast.body) ?? 0;
|
|
364
|
-
|
|
368
|
+
if (initRuntime) {
|
|
369
|
+
this.mstr.appendRight(bodyStart, initRuntime);
|
|
370
|
+
}
|
|
365
371
|
return this.finalize(msgs, bodyStart);
|
|
366
372
|
}
|
|
367
373
|
let headerIndex = 0;
|
|
@@ -375,7 +381,9 @@ export class SvelteTransformer extends Transformer {
|
|
|
375
381
|
if (!ast.module) {
|
|
376
382
|
headerIndex = instanceBodyStart;
|
|
377
383
|
}
|
|
378
|
-
|
|
384
|
+
if (initRuntime) {
|
|
385
|
+
this.mstr.appendRight(instanceBodyStart, initRuntime);
|
|
386
|
+
}
|
|
379
387
|
}
|
|
380
388
|
else {
|
|
381
389
|
const instanceStart = ast.module?.end ?? 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/svelte",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.8",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: Svelte adapter",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"svelte": "^5.37.0",
|
|
55
|
-
"
|
|
55
|
+
"magic-string": "^0.30.21",
|
|
56
|
+
"wuchale": "^0.18.8"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"acorn": "^8.15.0",
|