@wuchale/svelte 0.18.1 → 0.18.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/README.md +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -7
- package/dist/transformer.js +11 -15
- package/package.json +4 -4
- package/src/loaders/bundle.svelte.js +1 -1
package/README.md
CHANGED
|
@@ -10,5 +10,5 @@ automatically extracts and replaces translatable strings at build time.
|
|
|
10
10
|
|
|
11
11
|
- Main documentation: [wuchale.dev](https://wuchale.dev)
|
|
12
12
|
- Setup instructions: [Getting started](https://wuchale.dev/intro/start/)
|
|
13
|
-
- Adapter docs: [
|
|
13
|
+
- Adapter docs: [Svelte](https://wuchale.dev/adapters/svelte)
|
|
14
14
|
- Repository: [wuchalejs/wuchale](https://github.com/wuchalejs/wuchale)
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const svelteKitDefaultHeuristic: HeuristicFunc;
|
|
|
9
9
|
export declare const svelteDefaultHeuristicDerivedReq: HeuristicFunc;
|
|
10
10
|
type LoadersAvailable = 'svelte' | 'sveltekit';
|
|
11
11
|
export type SvelteArgs = AdapterArgs<LoadersAvailable, RuntimeCtxSv>;
|
|
12
|
+
export declare const defaultArgs: SvelteArgs;
|
|
12
13
|
export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailable>, bundle: boolean): string | {
|
|
13
14
|
client: string;
|
|
14
15
|
server: string;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { pluralPattern } from 'wuchale/adapter-vanilla';
|
|
|
4
4
|
import { SvelteTransformer } from './transformer.js';
|
|
5
5
|
export function createSvelteHeuristic(opts) {
|
|
6
6
|
const defaultHeuristic = createHeuristic(opts);
|
|
7
|
-
return
|
|
7
|
+
return msg => {
|
|
8
8
|
const defRes = defaultHeuristic(msg);
|
|
9
9
|
if (!defRes) {
|
|
10
10
|
return false;
|
|
@@ -22,7 +22,7 @@ export function createSvelteHeuristic(opts) {
|
|
|
22
22
|
export const svelteDefaultHeuristic = createSvelteHeuristic(defaultHeuristicOpts);
|
|
23
23
|
export const svelteKitDefaultHeuristic = createSvelteHeuristic({ ...defaultHeuristicOpts, urlCalls: ['goto'] });
|
|
24
24
|
/** Default Svelte heuristic which requires `$derived` or `$derived.by` for top level variable assignments */
|
|
25
|
-
export const svelteDefaultHeuristicDerivedReq =
|
|
25
|
+
export const svelteDefaultHeuristicDerivedReq = msg => {
|
|
26
26
|
const defRes = svelteDefaultHeuristic(msg);
|
|
27
27
|
if (!defRes) {
|
|
28
28
|
return false;
|
|
@@ -38,7 +38,7 @@ export const svelteDefaultHeuristicDerivedReq = (msg) => {
|
|
|
38
38
|
}
|
|
39
39
|
return false;
|
|
40
40
|
};
|
|
41
|
-
const defaultArgs = {
|
|
41
|
+
export const defaultArgs = {
|
|
42
42
|
files: ['src/**/*.svelte', 'src/**/*.svelte.{js,ts}'],
|
|
43
43
|
localesDir: './src/locales',
|
|
44
44
|
patterns: [pluralPattern],
|
|
@@ -57,12 +57,12 @@ const defaultArgs = {
|
|
|
57
57
|
return file.endsWith('.svelte.js') || module ? inTopLevel : true;
|
|
58
58
|
},
|
|
59
59
|
reactive: {
|
|
60
|
-
wrapInit:
|
|
61
|
-
wrapUse:
|
|
60
|
+
wrapInit: expr => `$derived(${expr})`,
|
|
61
|
+
wrapUse: expr => expr,
|
|
62
62
|
},
|
|
63
63
|
plain: {
|
|
64
|
-
wrapInit:
|
|
65
|
-
wrapUse:
|
|
64
|
+
wrapInit: expr => expr,
|
|
65
|
+
wrapUse: expr => expr,
|
|
66
66
|
},
|
|
67
67
|
},
|
|
68
68
|
};
|
package/dist/transformer.js
CHANGED
|
@@ -8,15 +8,11 @@ const headerAdd = `\nimport ${rtComponent} from "@wuchale/svelte/runtime.svelte"
|
|
|
8
8
|
const snipPrefix = '_w_snippet_';
|
|
9
9
|
const rtModuleVar = varNames.rt + 'mod_';
|
|
10
10
|
// for use before actually parsing the code,
|
|
11
|
-
// to remove the contents of e.g. <style lang="scss">
|
|
11
|
+
// to remove the contents of e.g. <style lang="scss"> which can cause parse errors
|
|
12
12
|
// without messing up indices for magic-string
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
code: ' '.repeat(content.length),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
};
|
|
13
|
+
const removeCSS = ({ content }) => ({
|
|
14
|
+
code: ' '.repeat(content.length),
|
|
15
|
+
});
|
|
20
16
|
export class SvelteTransformer extends Transformer {
|
|
21
17
|
// state
|
|
22
18
|
currentElement;
|
|
@@ -38,7 +34,7 @@ export class SvelteTransformer extends Transformer {
|
|
|
38
34
|
['ArrowFunctionExpression', 'FunctionExpression'].includes(init.type)) {
|
|
39
35
|
return msgs;
|
|
40
36
|
}
|
|
41
|
-
const needsWrapping = msgs.some(
|
|
37
|
+
const needsWrapping = msgs.some(msg => {
|
|
42
38
|
if (msg.details.topLevelCall &&
|
|
43
39
|
['$props', '$state', '$derived', '$derived.by'].includes(msg.details.topLevelCall)) {
|
|
44
40
|
return false;
|
|
@@ -61,11 +57,11 @@ export class SvelteTransformer extends Transformer {
|
|
|
61
57
|
initMixedVisitor = () => new MixedVisitor({
|
|
62
58
|
mstr: this.mstr,
|
|
63
59
|
vars: this.vars,
|
|
64
|
-
getRange:
|
|
65
|
-
isText:
|
|
66
|
-
isComment:
|
|
67
|
-
leaveInPlace:
|
|
68
|
-
isExpression:
|
|
60
|
+
getRange: node => ({ start: node.start, end: node.end }),
|
|
61
|
+
isText: node => node.type === 'Text',
|
|
62
|
+
isComment: node => node.type === 'Comment',
|
|
63
|
+
leaveInPlace: node => ['ConstTag', 'SnippetBlock'].includes(node.type),
|
|
64
|
+
isExpression: node => node.type === 'ExpressionTag',
|
|
69
65
|
getTextContent: (node) => node.data,
|
|
70
66
|
getCommentData: (node) => node.data.trim(),
|
|
71
67
|
canHaveChildren: (node) => nodesWithChildren.includes(node.type),
|
|
@@ -316,7 +312,7 @@ export class SvelteTransformer extends Transformer {
|
|
|
316
312
|
const isComponent = this.heuristciDetails.file.endsWith('.svelte');
|
|
317
313
|
let ast;
|
|
318
314
|
if (isComponent) {
|
|
319
|
-
const prepd = await preprocess(this.content, { style:
|
|
315
|
+
const prepd = await preprocess(this.content, { style: removeCSS });
|
|
320
316
|
ast = parse(prepd.code, { modern: true });
|
|
321
317
|
}
|
|
322
318
|
else {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/svelte",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: Svelte adapter",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"test": "node
|
|
8
|
+
"test": "node --import ../wuchale/testing/resolve.ts --test"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"i18n",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"author": "K1DV5",
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"svelte": "^5.37.0",
|
|
55
54
|
"magic-string": "^0.30.21",
|
|
56
|
-
"
|
|
55
|
+
"svelte": "^5.53.1",
|
|
56
|
+
"wuchale": "^0.20.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"acorn": "^8.15.0",
|
|
@@ -14,7 +14,7 @@ export function setLocale(newLocale) {
|
|
|
14
14
|
/**
|
|
15
15
|
* @param {{ [locale: string]: import("wuchale/runtime").CatalogModule }} catalogs
|
|
16
16
|
*/
|
|
17
|
-
export const getRuntime =
|
|
17
|
+
export const getRuntime = catalogs => toRuntime(catalogs[locale], locale)
|
|
18
18
|
|
|
19
19
|
// same function, only will be inside $derived when used
|
|
20
20
|
export const getRuntimeRx = getRuntime
|