what-compiler 0.1.0 → 0.1.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/package.json +5 -3
- package/src/babel-plugin.js +1 -1
- package/src/runtime.js +57 -3
- package/src/vite-plugin.js +0 -17
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-compiler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "JSX compiler for What Framework - transforms JSX to optimized DOM operations",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
9
9
|
"./babel": "./src/babel-plugin.js",
|
|
10
|
-
"./vite": "./src/vite-plugin.js"
|
|
10
|
+
"./vite": "./src/vite-plugin.js",
|
|
11
|
+
"./runtime": "./src/runtime.js"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [
|
|
13
14
|
"what",
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
"author": "",
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"peerDependencies": {
|
|
23
|
-
"@babel/core": "^7.0.0"
|
|
24
|
+
"@babel/core": "^7.0.0",
|
|
25
|
+
"what-core": "^0.1.0"
|
|
24
26
|
},
|
|
25
27
|
"files": [
|
|
26
28
|
"src"
|
package/src/babel-plugin.js
CHANGED
|
@@ -486,7 +486,7 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
486
486
|
|
|
487
487
|
const importDecl = t.importDeclaration(
|
|
488
488
|
helpers.map(h => t.importSpecifier(t.identifier(h), t.identifier(h))),
|
|
489
|
-
t.stringLiteral('what-
|
|
489
|
+
t.stringLiteral('what-compiler/runtime')
|
|
490
490
|
);
|
|
491
491
|
|
|
492
492
|
path.unshiftContainer('body', importDecl);
|
package/src/runtime.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Optimized DOM creation and updates with signal reactivity
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { effect, untrack, batch } from 'what-
|
|
6
|
+
import { effect, untrack, batch } from 'what-core';
|
|
7
7
|
|
|
8
8
|
// Check if value is a signal (callable with .set)
|
|
9
9
|
function isSignal(value) {
|
|
@@ -204,15 +204,69 @@ function appendChild(parent, child) {
|
|
|
204
204
|
for (const c of child) {
|
|
205
205
|
appendChild(parent, c);
|
|
206
206
|
}
|
|
207
|
+
} else if (child && typeof child === 'object' && child.tag != null) {
|
|
208
|
+
// VNode from h() — interop with what-core's VNode system
|
|
209
|
+
parent.appendChild(renderVNode(child));
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
|
|
213
|
+
// Convert a what-core VNode to a real DOM node (interop bridge)
|
|
214
|
+
function renderVNode(vnode) {
|
|
215
|
+
if (vnode == null || vnode === false || vnode === true) return document.createComment('');
|
|
216
|
+
if (typeof vnode === 'string' || typeof vnode === 'number') return document.createTextNode(String(vnode));
|
|
217
|
+
if (vnode instanceof Node) return vnode;
|
|
218
|
+
if (Array.isArray(vnode)) {
|
|
219
|
+
const frag = document.createDocumentFragment();
|
|
220
|
+
for (const v of vnode) frag.appendChild(renderVNode(v));
|
|
221
|
+
return frag;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const { tag, props, children } = vnode;
|
|
225
|
+
|
|
226
|
+
// Component VNode
|
|
227
|
+
if (typeof tag === 'function') {
|
|
228
|
+
const result = tag({ ...props, children });
|
|
229
|
+
return renderVNode(result);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Element VNode
|
|
233
|
+
const el = document.createElement(tag);
|
|
234
|
+
if (props) {
|
|
235
|
+
for (const [key, val] of Object.entries(props)) {
|
|
236
|
+
if (key === 'key' || key === 'ref' || key === 'children') continue;
|
|
237
|
+
if (key.startsWith('on') && typeof val === 'function') {
|
|
238
|
+
el.addEventListener(key.slice(2).toLowerCase(), val);
|
|
239
|
+
} else if (key === 'className' || key === 'class') {
|
|
240
|
+
el.className = val || '';
|
|
241
|
+
} else if (key === 'style' && typeof val === 'object') {
|
|
242
|
+
Object.assign(el.style, val);
|
|
243
|
+
} else if (val !== false && val != null) {
|
|
244
|
+
el.setAttribute(key, val === true ? '' : String(val));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (children) {
|
|
249
|
+
for (const child of children) {
|
|
250
|
+
el.appendChild(renderVNode(child));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return el;
|
|
254
|
+
}
|
|
255
|
+
|
|
210
256
|
/**
|
|
211
257
|
* Create a component instance
|
|
212
258
|
*/
|
|
213
259
|
export function _createComponent(Component, props) {
|
|
214
|
-
//
|
|
215
|
-
|
|
260
|
+
// Call the component function.
|
|
261
|
+
// Don't untrack — framework components like Router need signal tracking.
|
|
262
|
+
const result = Component(props);
|
|
263
|
+
|
|
264
|
+
// If the component returned a VNode (from h()), convert to DOM
|
|
265
|
+
if (result && typeof result === 'object' && !(result instanceof Node) && !Array.isArray(result) && result.tag != null) {
|
|
266
|
+
return renderVNode(result);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return result;
|
|
216
270
|
}
|
|
217
271
|
|
|
218
272
|
/**
|
package/src/vite-plugin.js
CHANGED
|
@@ -53,23 +53,6 @@ export default function whatVitePlugin(options = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
|
|
56
|
-
// Resolve what-framework imports
|
|
57
|
-
resolveId(id) {
|
|
58
|
-
if (id === 'what-framework/runtime') {
|
|
59
|
-
return '\0what-runtime';
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
// Load virtual modules
|
|
65
|
-
load(id) {
|
|
66
|
-
if (id === '\0what-runtime') {
|
|
67
|
-
// Return the runtime module
|
|
68
|
-
return `export * from 'what-compiler/runtime';`;
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
},
|
|
72
|
-
|
|
73
56
|
// Configure for development
|
|
74
57
|
config(config, { mode }) {
|
|
75
58
|
return {
|