@wuchale/jsx 0.9.6 → 0.10.0
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 +3 -3
- package/dist/index.js +7 -12
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.jsx +6 -7
- package/dist/transformer.js +15 -9
- package/package.json +6 -16
- package/src/loaders/react.js +3 -2
- package/src/loaders/solidjs.js +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export declare function createJsxHeuristic(opts: CreateHeuristicOpts): Heuristic
|
|
|
4
4
|
export declare const jsxDefaultHeuristic: HeuristicFunc;
|
|
5
5
|
type LoadersAvailable = 'default' | 'react' | 'solidjs';
|
|
6
6
|
export type JSXArgs = AdapterArgs<LoadersAvailable> & {
|
|
7
|
-
variant
|
|
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/index.js
CHANGED
|
@@ -20,14 +20,14 @@ export function createJsxHeuristic(opts) {
|
|
|
20
20
|
}
|
|
21
21
|
export const jsxDefaultHeuristic = createJsxHeuristic(defaultHeuristicOpts);
|
|
22
22
|
const defaultRuntime = {
|
|
23
|
-
|
|
23
|
+
initReactive: ({ funcName, nested }) => {
|
|
24
24
|
const inTopLevel = funcName == null;
|
|
25
25
|
const insideReactive = !inTopLevel && !nested && ((funcName.startsWith('use') && funcName.length > 3) || /[A-Z]/.test(funcName[0]));
|
|
26
|
-
return
|
|
27
|
-
init: inTopLevel ? null : insideReactive,
|
|
28
|
-
use: insideReactive
|
|
29
|
-
};
|
|
26
|
+
return inTopLevel ? null : insideReactive;
|
|
30
27
|
},
|
|
28
|
+
useReactive: ({ funcName, nested }) => funcName != null
|
|
29
|
+
&& !nested
|
|
30
|
+
&& ((funcName.startsWith('use') && funcName.length > 3) || /[A-Z]/.test(funcName[0])),
|
|
31
31
|
reactive: {
|
|
32
32
|
wrapInit: expr => expr,
|
|
33
33
|
wrapUse: expr => expr,
|
|
@@ -39,13 +39,8 @@ const defaultRuntime = {
|
|
|
39
39
|
};
|
|
40
40
|
const defaultRuntimeSolid = {
|
|
41
41
|
...defaultRuntime,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
init: inTopLevel ? true : null, // init only in top level
|
|
46
|
-
use: true, // always use reactive
|
|
47
|
-
};
|
|
48
|
-
},
|
|
42
|
+
initReactive: ({ funcName }) => funcName == null ? true : null, // init only in top level
|
|
43
|
+
useReactive: true, // always reactive, because solidjs doesn't have a problem with it
|
|
49
44
|
reactive: {
|
|
50
45
|
wrapInit: expr => `() => ${expr}`,
|
|
51
46
|
wrapUse: expr => `${expr}()`
|
package/dist/runtime.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import type { Composite, Mixed } from 'wuchale';
|
|
|
2
2
|
export type WuchaleComponentProps = {
|
|
3
3
|
n?: boolean;
|
|
4
4
|
x: Composite;
|
|
5
|
-
t: Function;
|
|
5
|
+
t: Function[];
|
|
6
6
|
a: any[];
|
|
7
7
|
};
|
|
8
|
-
export declare function selectFragment({ n, x, t, a }: WuchaleComponentProps, i: number): string | Mixed | Composite;
|
|
9
|
-
declare const _default: (props: WuchaleComponentProps) => (string | Composite | Mixed)[];
|
|
8
|
+
export declare function selectFragment({ n, x, t, a }: WuchaleComponentProps, i: number): string | Mixed | Composite | undefined;
|
|
9
|
+
declare const _default: (props: WuchaleComponentProps) => (string | Composite | Mixed | undefined)[];
|
|
10
10
|
export default _default;
|
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;
|
|
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
|
@@ -81,13 +81,19 @@ export class JSXTransformer extends Transformer {
|
|
|
81
81
|
this.mstr.appendRight(lastChildEnd, end);
|
|
82
82
|
},
|
|
83
83
|
});
|
|
84
|
-
visitChildrenJ = (node) =>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
visitChildrenJ = (node) => {
|
|
85
|
+
const prevInsideProg = this.heuristciDetails.insideProgram;
|
|
86
|
+
this.heuristciDetails.insideProgram = false;
|
|
87
|
+
const msg = this.mixedVisitor.visit({
|
|
88
|
+
children: node.children,
|
|
89
|
+
commentDirectives: this.commentDirectives,
|
|
90
|
+
inCompoundText: this.inCompoundText,
|
|
91
|
+
scope: 'markup',
|
|
92
|
+
element: this.currentElement,
|
|
93
|
+
});
|
|
94
|
+
this.heuristciDetails.insideProgram = prevInsideProg; // restore
|
|
95
|
+
return msg;
|
|
96
|
+
};
|
|
91
97
|
visitNameJSXNamespacedName = (node) => {
|
|
92
98
|
return `${this.visitName(node.namespace)}:${this.visitName(node.name)}`;
|
|
93
99
|
};
|
|
@@ -218,7 +224,7 @@ export class JSXTransformer extends Transformer {
|
|
|
218
224
|
};
|
|
219
225
|
transformJx = (lib) => {
|
|
220
226
|
// jsx vs type casting is not ambiguous in all files except .ts files
|
|
221
|
-
const [ast, comments] = (this.
|
|
227
|
+
const [ast, comments] = (this.heuristciDetails.file.endsWith('.ts') ? parseScript : parseScriptJSX)(this.content);
|
|
222
228
|
this.comments = comments;
|
|
223
229
|
this.mstr = new MagicString(this.content);
|
|
224
230
|
this.mixedVisitor = this.initMixedVisitor();
|
|
@@ -228,7 +234,7 @@ export class JSXTransformer extends Transformer {
|
|
|
228
234
|
const msgs = this.visitJx(ast);
|
|
229
235
|
const header = [
|
|
230
236
|
`import ${rtComponent} from "@wuchale/jsx/runtime${lib === 'solidjs' ? '.solid' : ''}.jsx"`,
|
|
231
|
-
this.initRuntime(
|
|
237
|
+
this.initRuntime(),
|
|
232
238
|
].join('\n');
|
|
233
239
|
const bodyStart = this.getRealBodyStart(ast.body);
|
|
234
240
|
return this.finalize(msgs, bodyStart, header);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/jsx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: JSX adapter",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -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.19.0"
|
|
75
65
|
},
|
|
76
66
|
"devDependencies": {
|
|
77
67
|
"@types/estree-jsx": "^1.0.5",
|
package/src/loaders/react.js
CHANGED
|
@@ -21,9 +21,10 @@ const collection = {
|
|
|
21
21
|
registerLoaders(key, loadCatalog, loadIDs, collection)
|
|
22
22
|
|
|
23
23
|
export const getRuntimeRx = (/** @type {string} */ loadID) => {
|
|
24
|
-
|
|
24
|
+
// function to useState because runtime is a function too
|
|
25
|
+
const [runtime, setRuntime] = useState(() => getRuntime(loadID))
|
|
25
26
|
useEffect(() => {
|
|
26
|
-
const cb = (/** @type {import('wuchale/runtime').Runtime} */ runtime) => setRuntime(runtime)
|
|
27
|
+
const cb = (/** @type {import('wuchale/runtime').Runtime} */ runtime) => setRuntime(() => runtime)
|
|
27
28
|
callbacks[loadID] ??= new Set()
|
|
28
29
|
callbacks[loadID].add(cb)
|
|
29
30
|
return () => callbacks[loadID].delete(cb)
|
package/src/loaders/solidjs.js
CHANGED
|
@@ -9,6 +9,6 @@ const [store, setStore] = createStore({})
|
|
|
9
9
|
// two exports. can be the same because solid-js can use them anywhere unlike react
|
|
10
10
|
export const getRuntimeRx = registerLoaders(key, loadCatalog, loadIDs, {
|
|
11
11
|
get: loadID => store[loadID],
|
|
12
|
-
set: setStore,
|
|
12
|
+
set: (loadID, runtime) => setStore(loadID, () => runtime),
|
|
13
13
|
})
|
|
14
14
|
export const getRuntime = getRuntimeRx
|