@wuchale/svelte 0.14.0 → 0.14.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 +3 -2
- package/dist/transformer.d.ts +1 -1
- package/dist/transformer.js +13 -16
- package/package.json +2 -2
- package/src/runtime.svelte +5 -5
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// $$ cd .. && npm run test
|
|
1
2
|
import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
|
|
2
3
|
import { SvelteTransformer } from "./transformer.js";
|
|
3
4
|
import { getDependencies } from 'wuchale/adapter-utils';
|
|
@@ -54,8 +55,8 @@ const defaultArgs = {
|
|
|
54
55
|
export const adapter = (args = defaultArgs) => {
|
|
55
56
|
const { heuristic, pluralsFunc, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
56
57
|
return {
|
|
57
|
-
transform: ({ content, filename, index,
|
|
58
|
-
return new SvelteTransformer(content, filename, index, heuristic, pluralsFunc,
|
|
58
|
+
transform: ({ content, filename, index, expr }) => {
|
|
59
|
+
return new SvelteTransformer(content, filename, index, heuristic, pluralsFunc, expr, runtime).transformSv();
|
|
59
60
|
},
|
|
60
61
|
loaderExts: ['.svelte.js', '.svelte.ts', '.js', '.ts'],
|
|
61
62
|
defaultLoaders: async () => {
|
package/dist/transformer.d.ts
CHANGED
|
@@ -34,6 +34,6 @@ export declare class SvelteTransformer extends Transformer {
|
|
|
34
34
|
visitSvelteWindow: (node: AST.SvelteWindow) => Message[];
|
|
35
35
|
visitRoot: (node: AST.Root) => Message[];
|
|
36
36
|
visitSv: (node: AST.SvelteNode | AnyNode) => Message[];
|
|
37
|
-
transformSv: (
|
|
37
|
+
transformSv: () => TransformOutput;
|
|
38
38
|
}
|
|
39
39
|
export {};
|
package/dist/transformer.js
CHANGED
|
@@ -4,8 +4,8 @@ import { Message } from 'wuchale';
|
|
|
4
4
|
import { Transformer, parseScript } from 'wuchale/adapter-vanilla';
|
|
5
5
|
import { MixedVisitor, nonWhitespaceText } from "wuchale/adapter-utils";
|
|
6
6
|
const nodesWithChildren = ['RegularElement', 'Component'];
|
|
7
|
-
const rtComponent = '
|
|
8
|
-
const snipPrefix = '
|
|
7
|
+
const rtComponent = 'W_tx_';
|
|
8
|
+
const snipPrefix = '_w_snippet_';
|
|
9
9
|
export class SvelteTransformer extends Transformer {
|
|
10
10
|
// state
|
|
11
11
|
currentElement;
|
|
@@ -49,9 +49,13 @@ export class SvelteTransformer extends Transformer {
|
|
|
49
49
|
this.mstr.appendRight(childStart, snippetBegin);
|
|
50
50
|
this.mstr.prependLeft(childEnd, '\n{/snippet}');
|
|
51
51
|
}
|
|
52
|
-
let begin = `\n<${rtComponent}
|
|
52
|
+
let begin = `\n<${rtComponent}`;
|
|
53
|
+
if (snippets.length) {
|
|
54
|
+
begin += ` t={[${snippets.join(', ')}]}`;
|
|
55
|
+
}
|
|
56
|
+
begin += ' x=';
|
|
53
57
|
if (this.inCompoundText) {
|
|
54
|
-
begin += `{${this.vars().nestCtx}}
|
|
58
|
+
begin += `{${this.vars().nestCtx}} n`;
|
|
55
59
|
}
|
|
56
60
|
else {
|
|
57
61
|
const index = this.index.get(msgInfo.toKey());
|
|
@@ -59,7 +63,7 @@ export class SvelteTransformer extends Transformer {
|
|
|
59
63
|
}
|
|
60
64
|
let end = ' />\n';
|
|
61
65
|
if (hasExprs) {
|
|
62
|
-
begin += '
|
|
66
|
+
begin += ' a={[';
|
|
63
67
|
end = ']}' + end;
|
|
64
68
|
}
|
|
65
69
|
this.mstr.appendLeft(lastChildEnd, begin);
|
|
@@ -232,7 +236,7 @@ export class SvelteTransformer extends Transformer {
|
|
|
232
236
|
this.commentDirectives = commentDirectivesPrev;
|
|
233
237
|
return msgs;
|
|
234
238
|
};
|
|
235
|
-
transformSv = (
|
|
239
|
+
transformSv = () => {
|
|
236
240
|
const isComponent = this.filename.endsWith('.svelte');
|
|
237
241
|
let ast;
|
|
238
242
|
if (isComponent) {
|
|
@@ -246,37 +250,30 @@ export class SvelteTransformer extends Transformer {
|
|
|
246
250
|
this.mstr = new MagicString(this.content);
|
|
247
251
|
this.mixedVisitor = this.initMixedVisitor();
|
|
248
252
|
const msgs = this.visitSv(ast);
|
|
249
|
-
if (!msgs.length) {
|
|
250
|
-
return this.finalize(msgs, 0);
|
|
251
|
-
}
|
|
252
253
|
const headerLines = [
|
|
253
254
|
isComponent ? `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"` : '',
|
|
254
|
-
headerHead,
|
|
255
255
|
this.initRuntime(this.filename, null, null, {}),
|
|
256
256
|
];
|
|
257
257
|
const headerFin = headerLines.join('\n');
|
|
258
258
|
if (ast.type === 'Program') {
|
|
259
259
|
const bodyStart = this.getRealBodyStart(ast.body);
|
|
260
|
-
this.
|
|
261
|
-
return this.finalize(msgs, bodyStart);
|
|
260
|
+
return this.finalize(msgs, bodyStart, headerFin);
|
|
262
261
|
}
|
|
263
262
|
let hmrHeaderIndex = 0;
|
|
264
263
|
if (ast.module) {
|
|
265
264
|
// @ts-ignore
|
|
266
265
|
hmrHeaderIndex = this.getRealBodyStart(ast.module.content.body);
|
|
267
|
-
this.mstr.appendRight(hmrHeaderIndex, headerFin);
|
|
268
266
|
}
|
|
269
267
|
else if (ast.instance) {
|
|
270
268
|
// @ts-ignore
|
|
271
269
|
hmrHeaderIndex = this.getRealBodyStart(ast.instance.content.body);
|
|
272
|
-
this.mstr.appendRight(hmrHeaderIndex, headerFin);
|
|
273
270
|
}
|
|
274
271
|
else {
|
|
275
272
|
this.mstr.prepend('<script>');
|
|
276
273
|
// account index for hmr data here
|
|
277
|
-
this.mstr.prependRight(0,
|
|
274
|
+
this.mstr.prependRight(0, `</script>\n`);
|
|
278
275
|
// now hmr data can be prependRight(0, ...)
|
|
279
276
|
}
|
|
280
|
-
return this.finalize(msgs, hmrHeaderIndex);
|
|
277
|
+
return this.finalize(msgs, hmrHeaderIndex, headerFin);
|
|
281
278
|
};
|
|
282
279
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/svelte",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.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.15.
|
|
55
|
+
"wuchale": "^0.15.4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"acorn": "^8.15.0",
|
package/src/runtime.svelte
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
const {
|
|
2
|
+
const {n = false, x, t, a} = $props()
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
|
-
{#each
|
|
5
|
+
{#each x as fragment, i}
|
|
6
6
|
{#if typeof fragment === 'string'}
|
|
7
7
|
{fragment}
|
|
8
8
|
{:else if typeof fragment === 'number'}
|
|
9
|
-
{#if !
|
|
10
|
-
{
|
|
9
|
+
{#if !n || i > 0}
|
|
10
|
+
{a[fragment]}
|
|
11
11
|
{/if}
|
|
12
12
|
{:else}
|
|
13
|
-
{@const tag =
|
|
13
|
+
{@const tag = t[fragment[0]]}
|
|
14
14
|
{#if tag == null}
|
|
15
15
|
[i18n-404:tag]
|
|
16
16
|
{:else}
|