@wuchale/jsx 0.9.5 → 0.9.7
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.d.ts +4 -4
- package/dist/runtime.jsx +6 -7
- package/dist/transformer.js +4 -18
- package/package.json +7 -17
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { type JSXLib } from "./transformer.js";
|
|
|
3
3
|
export declare function createJsxHeuristic(opts: CreateHeuristicOpts): HeuristicFunc;
|
|
4
4
|
export declare const jsxDefaultHeuristic: HeuristicFunc;
|
|
5
5
|
type LoadersAvailable = 'default' | 'react' | 'solidjs';
|
|
6
|
-
type JSXArgs = AdapterArgs<LoadersAvailable> & {
|
|
7
|
-
variant
|
|
6
|
+
export type JSXArgs = AdapterArgs<LoadersAvailable> & {
|
|
7
|
+
variant: JSXLib;
|
|
8
8
|
};
|
|
9
9
|
export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailable>, bundle: boolean): string | {
|
|
10
10
|
client: string;
|
|
11
11
|
server: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const adapter: (args?: JSXArgs) => Adapter;
|
|
12
|
+
} | null;
|
|
13
|
+
export declare const adapter: (args?: Partial<JSXArgs>) => Adapter;
|
|
14
14
|
export {};
|
package/dist/runtime.jsx
CHANGED
|
@@ -6,15 +6,14 @@ export function selectFragment({ n, x, t, a }, i) {
|
|
|
6
6
|
if (!n || i > 0) {
|
|
7
7
|
return a[x];
|
|
8
8
|
}
|
|
9
|
+
return `i18n-400:${x}`;
|
|
10
|
+
}
|
|
11
|
+
const tag = t[x[0]];
|
|
12
|
+
if (tag == null) {
|
|
13
|
+
return 'i18n-404:tag';
|
|
9
14
|
}
|
|
10
15
|
else {
|
|
11
|
-
|
|
12
|
-
if (tag == null) {
|
|
13
|
-
return 'i18n-404:tag';
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return tag(x);
|
|
17
|
-
}
|
|
16
|
+
return tag(x);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
export default (props) => {
|
package/dist/transformer.js
CHANGED
|
@@ -26,14 +26,11 @@ export class JSXTransformer extends Transformer {
|
|
|
26
26
|
mstr: this.mstr,
|
|
27
27
|
vars: this.vars,
|
|
28
28
|
getRange: node => ({
|
|
29
|
-
// @ts-expect-error
|
|
30
29
|
start: node.start,
|
|
31
|
-
// @ts-expect-error
|
|
32
30
|
end: node.end
|
|
33
31
|
}),
|
|
34
32
|
isComment: node => node.type === 'JSXExpressionContainer'
|
|
35
33
|
&& node.expression.type === 'JSXEmptyExpression'
|
|
36
|
-
// @ts-expect-error
|
|
37
34
|
&& node.expression.end > node.expression.start,
|
|
38
35
|
isText: node => node.type === 'JSXText',
|
|
39
36
|
leaveInPlace: () => false,
|
|
@@ -111,9 +108,7 @@ export class JSXTransformer extends Transformer {
|
|
|
111
108
|
if (this.inCompoundText && this.currentJsxKey != null) {
|
|
112
109
|
const key = node.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'key');
|
|
113
110
|
if (!key) {
|
|
114
|
-
this.mstr.appendLeft(
|
|
115
|
-
// @ts-expect-error
|
|
116
|
-
node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
|
|
111
|
+
this.mstr.appendLeft(node.openingElement.name.end, ` key="_${this.currentJsxKey}"`);
|
|
117
112
|
this.currentJsxKey++;
|
|
118
113
|
}
|
|
119
114
|
}
|
|
@@ -129,16 +124,11 @@ export class JSXTransformer extends Transformer {
|
|
|
129
124
|
if (!pass) {
|
|
130
125
|
return [];
|
|
131
126
|
}
|
|
132
|
-
this.mstr.update(
|
|
133
|
-
// @ts-expect-error
|
|
134
|
-
node.start + startWh,
|
|
135
|
-
// @ts-expect-error
|
|
136
|
-
node.end - endWh, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
|
|
127
|
+
this.mstr.update(node.start + startWh, node.end - endWh, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
|
|
137
128
|
return [msgInfo];
|
|
138
129
|
};
|
|
139
130
|
visitJSXFragment = (node) => this.visitChildrenJ(node);
|
|
140
131
|
getMarkupCommentBody = (node) => {
|
|
141
|
-
// @ts-expect-error
|
|
142
132
|
const comment = this.content.slice(node.start, node.end).trim();
|
|
143
133
|
if (!comment) {
|
|
144
134
|
return '';
|
|
@@ -185,11 +175,7 @@ export class JSXTransformer extends Transformer {
|
|
|
185
175
|
if (!pass) {
|
|
186
176
|
return [];
|
|
187
177
|
}
|
|
188
|
-
this.mstr.update(
|
|
189
|
-
// @ts-expect-error
|
|
190
|
-
value.start,
|
|
191
|
-
// @ts-expect-error
|
|
192
|
-
value.end, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
|
|
178
|
+
this.mstr.update(value.start, value.end, `{${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})}`);
|
|
193
179
|
return [msgInfo];
|
|
194
180
|
};
|
|
195
181
|
visitJSXSpreadAttribute = (node) => this.visit(node.argument);
|
|
@@ -242,7 +228,7 @@ export class JSXTransformer extends Transformer {
|
|
|
242
228
|
const msgs = this.visitJx(ast);
|
|
243
229
|
const header = [
|
|
244
230
|
`import ${rtComponent} from "@wuchale/jsx/runtime${lib === 'solidjs' ? '.solid' : ''}.jsx"`,
|
|
245
|
-
this.initRuntime(this.filename
|
|
231
|
+
this.initRuntime(this.filename),
|
|
246
232
|
].join('\n');
|
|
247
233
|
const bodyStart = this.getRealBodyStart(ast.body);
|
|
248
234
|
return this.finalize(msgs, bodyStart, header);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/jsx",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: JSX adapter",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"test": "node tests"
|
|
8
|
+
"test": "node tests/index.ts"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"i18n",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"gettext",
|
|
15
15
|
"jsx",
|
|
16
16
|
"react",
|
|
17
|
-
"
|
|
17
|
+
"preact",
|
|
18
|
+
"solidjs",
|
|
18
19
|
"vite",
|
|
19
20
|
"po",
|
|
20
21
|
"react-i18n",
|
|
@@ -56,22 +57,11 @@
|
|
|
56
57
|
"bugs": "https://github.com/wuchalejs/wuchale/issues",
|
|
57
58
|
"author": "K1DV5",
|
|
58
59
|
"license": "MIT",
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"react": "^19.1.1",
|
|
61
|
-
"solid-js": "^1.9.9"
|
|
62
|
-
},
|
|
63
|
-
"peerDependenciesMeta": {
|
|
64
|
-
"solid-js": {
|
|
65
|
-
"optional": true
|
|
66
|
-
},
|
|
67
|
-
"react": {
|
|
68
|
-
"optional": true
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
60
|
"dependencies": {
|
|
72
|
-
"@sveltejs/acorn-typescript": "^1.0.
|
|
61
|
+
"@sveltejs/acorn-typescript": "^1.0.8",
|
|
73
62
|
"acorn": "^8.15.0",
|
|
74
|
-
"
|
|
63
|
+
"magic-string": "^0.30.21",
|
|
64
|
+
"wuchale": "^0.18.8"
|
|
75
65
|
},
|
|
76
66
|
"devDependencies": {
|
|
77
67
|
"@types/estree-jsx": "^1.0.5",
|