@wuchale/svelte 0.14.1 → 0.14.2
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/transformer.d.ts +1 -0
- package/dist/transformer.js +26 -16
- package/package.json +2 -2
package/dist/transformer.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class SvelteTransformer extends Transformer {
|
|
|
31
31
|
visitSvelteElement: (node: AST.SvelteElement) => Message[];
|
|
32
32
|
visitSvelteBoundary: (node: AST.SvelteBoundary) => Message[];
|
|
33
33
|
visitSvelteHead: (node: AST.SvelteHead) => Message[];
|
|
34
|
+
visitTitleElement: (node: AST.TitleElement) => Message[];
|
|
34
35
|
visitSvelteWindow: (node: AST.SvelteWindow) => Message[];
|
|
35
36
|
visitRoot: (node: AST.Root) => Message[];
|
|
36
37
|
visitSv: (node: AST.SvelteNode | AnyNode) => Message[];
|
package/dist/transformer.js
CHANGED
|
@@ -2,10 +2,11 @@ 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 } from "wuchale/adapter-utils";
|
|
5
|
+
import { MixedVisitor, nonWhitespaceText, varNames } from "wuchale/adapter-utils";
|
|
6
6
|
const nodesWithChildren = ['RegularElement', 'Component'];
|
|
7
7
|
const rtComponent = 'W_tx_';
|
|
8
8
|
const snipPrefix = '_w_snippet_';
|
|
9
|
+
const rtModuleVar = varNames.rt + 'mod_';
|
|
9
10
|
export class SvelteTransformer extends Transformer {
|
|
10
11
|
// state
|
|
11
12
|
currentElement;
|
|
@@ -15,7 +16,7 @@ export class SvelteTransformer extends Transformer {
|
|
|
15
16
|
currentSnippet = 0;
|
|
16
17
|
mixedVisitor;
|
|
17
18
|
constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
|
|
18
|
-
super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf);
|
|
19
|
+
super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf, [varNames.rt, rtModuleVar]);
|
|
19
20
|
}
|
|
20
21
|
visitExpressionTag = (node) => this.visit(node.expression);
|
|
21
22
|
initMixedVisitor = () => new MixedVisitor({
|
|
@@ -191,16 +192,23 @@ export class SvelteTransformer extends Transformer {
|
|
|
191
192
|
...this.visitSv(node.fragment),
|
|
192
193
|
];
|
|
193
194
|
visitSvelteHead = (node) => this.visitSv(node.fragment);
|
|
195
|
+
visitTitleElement = (node) => this.visitSv(node.fragment);
|
|
194
196
|
visitSvelteWindow = (node) => node.attributes.map(this.visitSv).flat();
|
|
195
197
|
visitRoot = (node) => {
|
|
196
198
|
const msgs = [];
|
|
197
199
|
// @ts-ignore: module is a reserved keyword, not sure how to specify the type
|
|
198
200
|
if (node.module) {
|
|
201
|
+
const prevRtVar = this.currentRtVar;
|
|
202
|
+
this.currentRtVar = rtModuleVar;
|
|
199
203
|
this.additionalState = { module: true };
|
|
200
204
|
this.commentDirectives = {}; // reset
|
|
201
|
-
// @ts-
|
|
205
|
+
// @ts-expect-error
|
|
202
206
|
msgs.push(...this.visitProgram(node.module.content));
|
|
207
|
+
this.mstr.appendRight(
|
|
208
|
+
// @ts-expect-error
|
|
209
|
+
this.getRealBodyStart(node.module.content.body), this.initRuntime(this.filename, null, null, {}));
|
|
203
210
|
this.additionalState = {}; // reset
|
|
211
|
+
this.currentRtVar = prevRtVar; // reset
|
|
204
212
|
}
|
|
205
213
|
if (node.instance) {
|
|
206
214
|
this.commentDirectives = {}; // reset
|
|
@@ -250,30 +258,32 @@ export class SvelteTransformer extends Transformer {
|
|
|
250
258
|
this.mstr = new MagicString(this.content);
|
|
251
259
|
this.mixedVisitor = this.initMixedVisitor();
|
|
252
260
|
const msgs = this.visitSv(ast);
|
|
253
|
-
const
|
|
254
|
-
isComponent ? `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"` : '',
|
|
255
|
-
this.initRuntime(this.filename, null, null, {}),
|
|
256
|
-
];
|
|
257
|
-
const headerFin = headerLines.join('\n');
|
|
261
|
+
const initRuntime = this.initRuntime(this.filename, null, null, {});
|
|
258
262
|
if (ast.type === 'Program') {
|
|
259
263
|
const bodyStart = this.getRealBodyStart(ast.body);
|
|
260
|
-
|
|
264
|
+
this.mstr.appendRight(bodyStart, initRuntime);
|
|
265
|
+
return this.finalize(msgs, bodyStart);
|
|
261
266
|
}
|
|
262
|
-
let
|
|
267
|
+
let headerIndex = 0;
|
|
263
268
|
if (ast.module) {
|
|
264
269
|
// @ts-ignore
|
|
265
|
-
|
|
270
|
+
headerIndex = this.getRealBodyStart(ast.module.content.body);
|
|
266
271
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
272
|
+
if (ast.instance) {
|
|
273
|
+
if (!ast.module) {
|
|
274
|
+
// @ts-expect-error
|
|
275
|
+
headerIndex = this.getRealBodyStart(ast.instance.content.body);
|
|
276
|
+
}
|
|
277
|
+
// @ts-expect-error
|
|
278
|
+
this.mstr.appendRight(this.getRealBodyStart(ast.instance.content.body), initRuntime);
|
|
270
279
|
}
|
|
271
280
|
else {
|
|
272
281
|
this.mstr.prepend('<script>');
|
|
273
282
|
// account index for hmr data here
|
|
274
|
-
this.mstr.prependRight(0,
|
|
283
|
+
this.mstr.prependRight(0, `${initRuntime}\n</script>\n`);
|
|
275
284
|
// now hmr data can be prependRight(0, ...)
|
|
276
285
|
}
|
|
277
|
-
|
|
286
|
+
const headerAdd = `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"`;
|
|
287
|
+
return this.finalize(msgs, headerIndex, headerAdd);
|
|
278
288
|
};
|
|
279
289
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/svelte",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
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.6"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"acorn": "^8.15.0",
|