@wuchale/jsx 0.6.1 → 0.6.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/index.js +2 -2
- 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 +1 -1
- package/dist/transformer.js +19 -20
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -71,8 +71,8 @@ export const adapter = (args = defaultArgs) => {
|
|
|
71
71
|
runtime = defaultRuntimeSolid;
|
|
72
72
|
}
|
|
73
73
|
return {
|
|
74
|
-
transform: ({ content, filename, index,
|
|
75
|
-
return new JSXTransformer(content, filename, index, heuristic, pluralsFunc,
|
|
74
|
+
transform: ({ content, filename, index, expr }) => {
|
|
75
|
+
return new JSXTransformer(content, filename, index, heuristic, pluralsFunc, expr, runtime).transformJx(variant);
|
|
76
76
|
},
|
|
77
77
|
loaderExts: ['.js', '.ts'],
|
|
78
78
|
defaultLoaders: async () => {
|
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
|
@@ -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,7 +11,7 @@ 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;
|
|
@@ -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);
|
|
@@ -207,22 +211,17 @@ export class JSXTransformer extends Transformer {
|
|
|
207
211
|
this.commentDirectives = commentDirectivesPrev;
|
|
208
212
|
return msgs;
|
|
209
213
|
};
|
|
210
|
-
transformJx = (
|
|
214
|
+
transformJx = (lib) => {
|
|
211
215
|
const [ast, comments] = parseScript(this.content);
|
|
212
216
|
this.comments = comments;
|
|
213
217
|
this.mstr = new MagicString(this.content);
|
|
214
218
|
this.mixedVisitor = this.initMixedVisitor();
|
|
215
219
|
const msgs = this.visitJx(ast);
|
|
216
|
-
|
|
217
|
-
return this.finalize(msgs, 0);
|
|
218
|
-
}
|
|
219
|
-
const headerFin = [
|
|
220
|
+
const header = [
|
|
220
221
|
`import ${rtComponent} from "@wuchale/jsx/runtime${lib === 'solidjs' ? '.solid' : ''}.jsx"`,
|
|
221
|
-
headerHead,
|
|
222
222
|
this.initRuntime(this.filename, null, null, {}),
|
|
223
223
|
].join('\n');
|
|
224
224
|
const bodyStart = this.getRealBodyStart(ast.body);
|
|
225
|
-
this.
|
|
226
|
-
return this.finalize(msgs, bodyStart);
|
|
225
|
+
return this.finalize(msgs, bodyStart, header);
|
|
227
226
|
};
|
|
228
227
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/jsx",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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.4"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/estree-jsx": "^1.0.5",
|