@wuchale/jsx 0.6.1 → 0.6.3
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 +5 -4
- package/dist/runtime.d.ts +5 -5
- package/dist/runtime.jsx +9 -9
- package/dist/runtime.solid.jsx +2 -2
- package/dist/transformer.d.ts +2 -2
- package/dist/transformer.js +22 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defaultGenerateLoadID, defaultHeuristic, deepMergeObjects } from 'wuchale';
|
|
2
2
|
import { adapter as vanillaAdapter } from 'wuchale/adapter-vanilla';
|
|
3
3
|
import { JSXTransformer } from "./transformer.js";
|
|
4
|
-
import { getDependencies } from 'wuchale/adapter-utils';
|
|
4
|
+
import { getDependencies, loaderPathResolver } from 'wuchale/adapter-utils';
|
|
5
5
|
const ignoreElements = ['style', 'path'];
|
|
6
6
|
const jsxHeuristic = (msgStr, details) => {
|
|
7
7
|
if (!defaultHeuristic(msgStr, details)) {
|
|
@@ -65,14 +65,15 @@ const defaultArgs = {
|
|
|
65
65
|
runtime: defaultRuntime,
|
|
66
66
|
variant: 'default',
|
|
67
67
|
};
|
|
68
|
+
const resolveLoaderPath = loaderPathResolver(import.meta.url, '../src/loaders', 'js');
|
|
68
69
|
export const adapter = (args = defaultArgs) => {
|
|
69
70
|
let { heuristic, pluralsFunc, variant, runtime, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
70
71
|
if (variant === 'solidjs' && args.runtime == null) {
|
|
71
72
|
runtime = defaultRuntimeSolid;
|
|
72
73
|
}
|
|
73
74
|
return {
|
|
74
|
-
transform: ({ content, filename, index,
|
|
75
|
-
return new JSXTransformer(content, filename, index, heuristic, pluralsFunc,
|
|
75
|
+
transform: ({ content, filename, index, expr }) => {
|
|
76
|
+
return new JSXTransformer(content, filename, index, heuristic, pluralsFunc, expr, runtime).transformJx(variant);
|
|
76
77
|
},
|
|
77
78
|
loaderExts: ['.js', '.ts'],
|
|
78
79
|
defaultLoaders: async () => {
|
|
@@ -93,7 +94,7 @@ export const adapter = (args = defaultArgs) => {
|
|
|
93
94
|
if (rest.bundleLoad) {
|
|
94
95
|
loader += '.bundle';
|
|
95
96
|
}
|
|
96
|
-
return
|
|
97
|
+
return resolveLoaderPath(loader);
|
|
97
98
|
},
|
|
98
99
|
runtime,
|
|
99
100
|
...rest,
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Composite, Mixed } from 'wuchale';
|
|
2
2
|
export type WuchaleComponentProps = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
n?: boolean;
|
|
4
|
+
x: Composite;
|
|
5
|
+
t: Function;
|
|
6
|
+
a: any[];
|
|
7
7
|
};
|
|
8
|
-
export declare function selectFragment({
|
|
8
|
+
export declare function selectFragment({ n, x, t, a }: WuchaleComponentProps, i: number): string | Mixed | Composite;
|
|
9
9
|
declare const _default: (props: WuchaleComponentProps) => (string | Composite | Mixed)[];
|
|
10
10
|
export default _default;
|
package/dist/runtime.jsx
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export function selectFragment({
|
|
2
|
-
if (typeof
|
|
3
|
-
return
|
|
1
|
+
export function selectFragment({ n, x, t, a }, i) {
|
|
2
|
+
if (typeof x === 'string') {
|
|
3
|
+
return x;
|
|
4
4
|
}
|
|
5
|
-
if (typeof
|
|
6
|
-
if (!
|
|
7
|
-
return
|
|
5
|
+
if (typeof x === 'number') {
|
|
6
|
+
if (!n || i > 0) {
|
|
7
|
+
return a[x];
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
const tag =
|
|
11
|
+
const tag = t[x[0]];
|
|
12
12
|
if (tag == null) {
|
|
13
13
|
return 'i18n-404:tag';
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
return tag(
|
|
16
|
+
return tag(x);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
export default (props) => {
|
|
21
|
-
return props.
|
|
21
|
+
return props.x.map((fragment, i) => selectFragment({ ...props, x: fragment }, i));
|
|
22
22
|
};
|
package/dist/runtime.solid.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { selectFragment } from './runtime.jsx';
|
|
2
2
|
import { For } from 'solid-js';
|
|
3
3
|
export default (props) => {
|
|
4
|
-
return <For each={props.
|
|
5
|
-
{(fragment, i) => <>{selectFragment({ ...props,
|
|
4
|
+
return <For each={props.x}>
|
|
5
|
+
{(fragment, i) => <>{selectFragment({ ...props, x: fragment }, i())}</>}
|
|
6
6
|
</For>;
|
|
7
7
|
};
|
package/dist/transformer.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class JSXTransformer extends Transformer {
|
|
|
12
12
|
inCompoundText: boolean;
|
|
13
13
|
commentDirectivesStack: CommentDirectives[];
|
|
14
14
|
lastVisitIsComment: boolean;
|
|
15
|
-
|
|
15
|
+
currentJsxKey: number;
|
|
16
16
|
mixedVisitor: MixedVisitor<MixedNodesTypes>;
|
|
17
17
|
constructor(content: string, filename: string, index: IndexTracker, heuristic: HeuristicFunc, pluralsFunc: string, catalogExpr: CatalogExpr, rtConf: RuntimeConf);
|
|
18
18
|
initMixedVisitor: () => MixedVisitor<MixedNodesTypes>;
|
|
@@ -30,6 +30,6 @@ export declare class JSXTransformer extends Transformer {
|
|
|
30
30
|
visitJSXSpreadAttribute: (node: JX.JSXSpreadAttribute) => Message[];
|
|
31
31
|
visitJSXEmptyExpression: (node: JX.JSXEmptyExpression) => Message[];
|
|
32
32
|
visitJx: (node: JX.Node | JX.JSXSpreadChild | Estree.Program) => Message[];
|
|
33
|
-
transformJx: (
|
|
33
|
+
transformJx: (lib: JSXLib) => TransformOutput;
|
|
34
34
|
}
|
|
35
35
|
export {};
|
package/dist/transformer.js
CHANGED
|
@@ -11,14 +11,14 @@ export function parseScript(content) {
|
|
|
11
11
|
return [JsxParser.parse(content, opts), comments];
|
|
12
12
|
}
|
|
13
13
|
const nodesWithChildren = ['JSXElement'];
|
|
14
|
-
const rtComponent = '
|
|
14
|
+
const rtComponent = 'W_tx_';
|
|
15
15
|
export class JSXTransformer extends Transformer {
|
|
16
16
|
// state
|
|
17
17
|
currentElement;
|
|
18
18
|
inCompoundText = false;
|
|
19
19
|
commentDirectivesStack = [];
|
|
20
20
|
lastVisitIsComment = false;
|
|
21
|
-
|
|
21
|
+
currentJsxKey = 0;
|
|
22
22
|
mixedVisitor;
|
|
23
23
|
constructor(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf) {
|
|
24
24
|
super(content, filename, index, heuristic, pluralsFunc, catalogExpr, rtConf);
|
|
@@ -52,19 +52,23 @@ export class JSXTransformer extends Transformer {
|
|
|
52
52
|
checkHeuristic: this.checkHeuristicBool,
|
|
53
53
|
index: this.index,
|
|
54
54
|
wrapNested: (msgInfo, hasExprs, nestedRanges, lastChildEnd) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
toAppend
|
|
55
|
+
let begin = `<${rtComponent}`;
|
|
56
|
+
if (nestedRanges.length > 0) {
|
|
57
|
+
for (const [i, [childStart, _, haveCtx]] of nestedRanges.entries()) {
|
|
58
|
+
let toAppend;
|
|
59
|
+
if (i === 0) {
|
|
60
|
+
toAppend = `${begin} t={[`;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
toAppend = ', ';
|
|
64
|
+
}
|
|
65
|
+
this.mstr.appendRight(childStart, `${toAppend}${haveCtx ? this.vars().nestCtx : '()'} => `);
|
|
59
66
|
}
|
|
60
|
-
|
|
61
|
-
toAppend = ', ';
|
|
62
|
-
}
|
|
63
|
-
this.mstr.appendRight(childStart, `${toAppend}${haveCtx ? this.vars().nestCtx : '()'} => `);
|
|
67
|
+
begin = `]}`;
|
|
64
68
|
}
|
|
65
|
-
|
|
69
|
+
begin += ' x=';
|
|
66
70
|
if (this.inCompoundText) {
|
|
67
|
-
begin += `{${this.vars().nestCtx}}
|
|
71
|
+
begin += `{${this.vars().nestCtx}} n`;
|
|
68
72
|
}
|
|
69
73
|
else {
|
|
70
74
|
const index = this.index.get(msgInfo.toKey());
|
|
@@ -72,7 +76,7 @@ export class JSXTransformer extends Transformer {
|
|
|
72
76
|
}
|
|
73
77
|
let end = ' />';
|
|
74
78
|
if (hasExprs) {
|
|
75
|
-
begin += '
|
|
79
|
+
begin += ' a={[';
|
|
76
80
|
end = ']}' + end;
|
|
77
81
|
}
|
|
78
82
|
this.mstr.appendLeft(lastChildEnd, begin);
|
|
@@ -106,7 +110,8 @@ export class JSXTransformer extends Transformer {
|
|
|
106
110
|
if (this.inCompoundText) {
|
|
107
111
|
this.mstr.appendLeft(
|
|
108
112
|
// @ts-expect-error
|
|
109
|
-
node.openingElement.name.end, ` key="_${this.
|
|
113
|
+
node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
|
|
114
|
+
this.currentJsxKey++;
|
|
110
115
|
}
|
|
111
116
|
this.currentElement = currentElement;
|
|
112
117
|
return msgs;
|
|
@@ -207,22 +212,17 @@ export class JSXTransformer extends Transformer {
|
|
|
207
212
|
this.commentDirectives = commentDirectivesPrev;
|
|
208
213
|
return msgs;
|
|
209
214
|
};
|
|
210
|
-
transformJx = (
|
|
215
|
+
transformJx = (lib) => {
|
|
211
216
|
const [ast, comments] = parseScript(this.content);
|
|
212
217
|
this.comments = comments;
|
|
213
218
|
this.mstr = new MagicString(this.content);
|
|
214
219
|
this.mixedVisitor = this.initMixedVisitor();
|
|
215
220
|
const msgs = this.visitJx(ast);
|
|
216
|
-
|
|
217
|
-
return this.finalize(msgs, 0);
|
|
218
|
-
}
|
|
219
|
-
const headerFin = [
|
|
221
|
+
const header = [
|
|
220
222
|
`import ${rtComponent} from "@wuchale/jsx/runtime${lib === 'solidjs' ? '.solid' : ''}.jsx"`,
|
|
221
|
-
headerHead,
|
|
222
223
|
this.initRuntime(this.filename, null, null, {}),
|
|
223
224
|
].join('\n');
|
|
224
225
|
const bodyStart = this.getRealBodyStart(ast.body);
|
|
225
|
-
this.
|
|
226
|
-
return this.finalize(msgs, bodyStart);
|
|
226
|
+
return this.finalize(msgs, bodyStart, header);
|
|
227
227
|
};
|
|
228
228
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/jsx",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: JSX adapter",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@sveltejs/acorn-typescript": "^1.0.5",
|
|
73
73
|
"acorn": "^8.15.0",
|
|
74
74
|
"acorn-jsx": "^5.3.2",
|
|
75
|
-
"wuchale": "^0.15.
|
|
75
|
+
"wuchale": "^0.15.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/estree-jsx": "^1.0.5",
|