@wuchale/svelte 0.15.1 → 0.16.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 +9 -12
- package/dist/transformer.d.ts +4 -3
- package/dist/transformer.js +23 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
|
|
2
2
|
import { SvelteTransformer } from "./transformer.js";
|
|
3
3
|
import { getDependencies, loaderPathResolver } from 'wuchale/adapter-utils';
|
|
4
|
-
|
|
5
|
-
const svelteHeuristic =
|
|
6
|
-
if (!defaultHeuristic(
|
|
4
|
+
import { pluralPattern } from 'wuchale/adapter-vanilla';
|
|
5
|
+
const svelteHeuristic = msg => {
|
|
6
|
+
if (!defaultHeuristic(msg)) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
if (details.scope !== 'script') {
|
|
9
|
+
if (msg.details.scope !== 'script') {
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
|
-
if (details.
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (details.call === '$inspect') {
|
|
12
|
+
if (msg.details.call === '$inspect') {
|
|
16
13
|
return false;
|
|
17
14
|
}
|
|
18
15
|
return true;
|
|
@@ -20,7 +17,7 @@ const svelteHeuristic = (msgStr, details) => {
|
|
|
20
17
|
const defaultArgs = {
|
|
21
18
|
files: ['src/**/*.svelte', 'src/**/*.svelte.{js,ts}'],
|
|
22
19
|
catalog: './src/locales/{locale}',
|
|
23
|
-
|
|
20
|
+
patterns: [pluralPattern],
|
|
24
21
|
heuristic: svelteHeuristic,
|
|
25
22
|
granularLoad: false,
|
|
26
23
|
bundleLoad: false,
|
|
@@ -49,10 +46,10 @@ const defaultArgs = {
|
|
|
49
46
|
};
|
|
50
47
|
const resolveLoaderPath = loaderPathResolver(import.meta.url, '../src/loaders', 'svelte.js');
|
|
51
48
|
export const adapter = (args = defaultArgs) => {
|
|
52
|
-
const { heuristic,
|
|
49
|
+
const { heuristic, patterns, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
53
50
|
return {
|
|
54
51
|
transform: ({ content, filename, index, expr }) => {
|
|
55
|
-
return new SvelteTransformer(content, filename, index, heuristic,
|
|
52
|
+
return new SvelteTransformer(content, filename, index, heuristic, patterns, expr, runtime).transformSv();
|
|
56
53
|
},
|
|
57
54
|
loaderExts: ['.svelte.js', '.svelte.ts', '.js', '.ts'],
|
|
58
55
|
defaultLoaders: async () => {
|
|
@@ -70,7 +67,7 @@ export const adapter = (args = defaultArgs) => {
|
|
|
70
67
|
if (loader === 'sveltekit') {
|
|
71
68
|
return {
|
|
72
69
|
client: resolveLoaderPath('svelte'),
|
|
73
|
-
|
|
70
|
+
server: resolveLoaderPath('sveltekit.ssr'),
|
|
74
71
|
};
|
|
75
72
|
}
|
|
76
73
|
return resolveLoaderPath(loader);
|
package/dist/transformer.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AnyNode } from "acorn";
|
|
1
|
+
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 } from 'wuchale';
|
|
5
|
+
import type { IndexTracker, HeuristicFunc, TransformOutput, CatalogExpr, RuntimeConf, CodePattern } 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 {
|
|
@@ -12,8 +12,9 @@ export declare class SvelteTransformer extends Transformer {
|
|
|
12
12
|
lastVisitIsComment: boolean;
|
|
13
13
|
currentSnippet: number;
|
|
14
14
|
mixedVisitor: MixedVisitor<MixedNodesTypes>;
|
|
15
|
-
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc,
|
|
15
|
+
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, patterns: CodePattern[], catalogExpr: CatalogExpr, rtConf: RuntimeConf);
|
|
16
16
|
visitExpressionTag: (node: AST.ExpressionTag) => Message[];
|
|
17
|
+
visitVariableDeclarator: (node: VariableDeclarator) => Message[];
|
|
17
18
|
initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
|
|
18
19
|
visitFragment: (node: AST.Fragment) => Message[];
|
|
19
20
|
visitRegularElement: (node: AST.ElementLike) => Message[];
|
package/dist/transformer.js
CHANGED
|
@@ -15,10 +15,30 @@ export class SvelteTransformer extends Transformer {
|
|
|
15
15
|
lastVisitIsComment = false;
|
|
16
16
|
currentSnippet = 0;
|
|
17
17
|
mixedVisitor;
|
|
18
|
-
constructor(content, filename, index, heuristic,
|
|
19
|
-
super(content, filename, index, heuristic,
|
|
18
|
+
constructor(content, filename, index, heuristic, patterns, catalogExpr, rtConf) {
|
|
19
|
+
super(content, filename, index, heuristic, patterns, catalogExpr, rtConf, [varNames.rt, rtModuleVar]);
|
|
20
20
|
}
|
|
21
21
|
visitExpressionTag = (node) => this.visit(node.expression);
|
|
22
|
+
visitVariableDeclarator = (node) => {
|
|
23
|
+
const msgs = this.defaultVisitVariableDeclarator(node);
|
|
24
|
+
if (!msgs.length || this.declaring != null || ['ArrowFunctionExpression', 'FunctionExpression'].includes(node.init.type)) {
|
|
25
|
+
return msgs;
|
|
26
|
+
}
|
|
27
|
+
const needsWrapping = msgs.some(msg => {
|
|
28
|
+
if (['$derived', '$derived.by'].includes(msg.details.topLevelCall)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (msg.details.declaring !== 'variable') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
if (needsWrapping) {
|
|
37
|
+
this.mstr.appendLeft(node.init.start, '$derived(');
|
|
38
|
+
this.mstr.appendRight(node.init.end, ')');
|
|
39
|
+
}
|
|
40
|
+
return msgs;
|
|
41
|
+
};
|
|
22
42
|
initMixedVisitor = () => new MixedVisitor({
|
|
23
43
|
mstr: this.mstr,
|
|
24
44
|
vars: this.vars,
|
|
@@ -37,6 +57,7 @@ export class SvelteTransformer extends Transformer {
|
|
|
37
57
|
return childTxts;
|
|
38
58
|
},
|
|
39
59
|
visitExpressionTag: this.visitExpressionTag,
|
|
60
|
+
fullHeuristicDetails: this.fullHeuristicDetails,
|
|
40
61
|
checkHeuristic: this.checkHeuristicBool,
|
|
41
62
|
index: this.index,
|
|
42
63
|
wrapNested: (msgInfo, hasExprs, nestedRanges, lastChildEnd) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.
|
|
55
|
+
"wuchale": "^0.17.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"acorn": "^8.15.0",
|