what-compiler 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/babel-plugin.js +25 -8
- package/dist/babel-plugin.js.map +2 -2
- package/dist/babel-plugin.min.js +1 -1
- package/dist/babel-plugin.min.js.map +3 -3
- package/dist/index.js +25 -8
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +3 -3
- package/dist/vite-plugin.js +25 -8
- package/dist/vite-plugin.js.map +2 -2
- package/dist/vite-plugin.min.js +6 -6
- package/dist/vite-plugin.min.js.map +3 -3
- package/package.json +2 -2
- package/src/babel-plugin.js +35 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-compiler",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "JSX compiler for What Framework - transforms JSX to optimized DOM operations",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@babel/core": "^7.0.0",
|
|
41
|
-
"what-core": "^0.6.
|
|
41
|
+
"what-core": "^0.6.3"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src",
|
package/src/babel-plugin.js
CHANGED
|
@@ -436,6 +436,7 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
436
436
|
for (const attr of el.attributes) {
|
|
437
437
|
if (t.isJSXSpreadAttribute(attr)) continue;
|
|
438
438
|
const name = getAttrName(attr);
|
|
439
|
+
if (name === 'key') continue;
|
|
439
440
|
if (name.startsWith('on') || name.startsWith('bind:') || name.includes('|')) continue;
|
|
440
441
|
|
|
441
442
|
let domName = name;
|
|
@@ -642,6 +643,9 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
642
643
|
|
|
643
644
|
const attrName = getAttrName(attr);
|
|
644
645
|
|
|
646
|
+
// Strip key prop — WhatFW has no virtual DOM, so key is meaningless (issue #6)
|
|
647
|
+
if (attrName === 'key') continue;
|
|
648
|
+
|
|
645
649
|
// Ref handling — assign element to ref object/callback
|
|
646
650
|
if (attrName === 'ref') {
|
|
647
651
|
const refExpr = getAttributeValue(attr.value);
|
|
@@ -1076,10 +1080,12 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1076
1080
|
islandProps.push(t.objectProperty(t.identifier(attrName), value));
|
|
1077
1081
|
}
|
|
1078
1082
|
|
|
1079
|
-
|
|
1083
|
+
const islandCall = t.callExpression(
|
|
1080
1084
|
t.identifier('_$createComponent'),
|
|
1081
1085
|
[t.identifier('Island'), t.objectExpression(islandProps), t.arrayExpression([])]
|
|
1082
1086
|
);
|
|
1087
|
+
t.addComment(islandCall, 'leading', '#__PURE__');
|
|
1088
|
+
return islandCall;
|
|
1083
1089
|
}
|
|
1084
1090
|
|
|
1085
1091
|
// Regular component — use _$createComponent to instantiate, component runs once
|
|
@@ -1098,6 +1104,9 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1098
1104
|
|
|
1099
1105
|
const attrName = getAttrName(attr);
|
|
1100
1106
|
|
|
1107
|
+
// Strip key prop — WhatFW has no virtual DOM, so key is meaningless (issue #6)
|
|
1108
|
+
if (attrName === 'key') continue;
|
|
1109
|
+
|
|
1101
1110
|
// Handle bind: attributes for components
|
|
1102
1111
|
if (isBindingAttribute(attrName)) {
|
|
1103
1112
|
const bindProp = getBindingProperty(attrName);
|
|
@@ -1203,7 +1212,11 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1203
1212
|
? t.arrayExpression(transformedChildren)
|
|
1204
1213
|
: t.arrayExpression([]);
|
|
1205
1214
|
|
|
1206
|
-
|
|
1215
|
+
const call = t.callExpression(t.identifier('_$createComponent'), [t.identifier(componentName), propsExpr, childrenArray]);
|
|
1216
|
+
// Mark component creation as pure for tree-shaking: if the result is unused,
|
|
1217
|
+
// bundlers can safely eliminate the call.
|
|
1218
|
+
t.addComment(call, 'leading', '#__PURE__');
|
|
1219
|
+
return call;
|
|
1207
1220
|
}
|
|
1208
1221
|
|
|
1209
1222
|
function transformForFineGrained(path, state) {
|
|
@@ -1315,6 +1328,8 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1315
1328
|
state._varCounter = 0;
|
|
1316
1329
|
state._pendingSetup = [];
|
|
1317
1330
|
state.nextVarId = () => `_el$${state._varCounter++}`;
|
|
1331
|
+
state.runtimePackage = 'what-framework';
|
|
1332
|
+
state._sawFrameworkImport = false;
|
|
1318
1333
|
|
|
1319
1334
|
// Collect signal names for smart reactivity detection
|
|
1320
1335
|
state.signalNames = new Set();
|
|
@@ -1328,6 +1343,13 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1328
1343
|
for (const node of path.node.body) {
|
|
1329
1344
|
if (t.isImportDeclaration(node)) {
|
|
1330
1345
|
const source = node.source.value;
|
|
1346
|
+
if (source === 'what-framework' || source.startsWith('what-framework/')) {
|
|
1347
|
+
state.runtimePackage = 'what-framework';
|
|
1348
|
+
state._sawFrameworkImport = true;
|
|
1349
|
+
} else if (!state._sawFrameworkImport && (source === 'what-core' || source.startsWith('what-core/'))) {
|
|
1350
|
+
state.runtimePackage = 'what-core';
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1331
1353
|
const isReactiveSource =
|
|
1332
1354
|
source === 'what-framework' ||
|
|
1333
1355
|
source.startsWith('what-framework/') ||
|
|
@@ -1393,11 +1415,15 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1393
1415
|
exit(path, state) {
|
|
1394
1416
|
// Insert template declarations at top of program (hoisted to module scope)
|
|
1395
1417
|
for (const tmpl of state.templates.reverse()) {
|
|
1418
|
+
const templateCall = t.callExpression(t.identifier('_$template'), [t.stringLiteral(tmpl.html)]);
|
|
1419
|
+
// Mark template creation as pure for tree-shaking: if the template
|
|
1420
|
+
// variable is never referenced, bundlers can eliminate this call.
|
|
1421
|
+
t.addComment(templateCall, 'leading', '#__PURE__');
|
|
1396
1422
|
path.unshiftContainer('body',
|
|
1397
1423
|
t.variableDeclaration('const', [
|
|
1398
1424
|
t.variableDeclarator(
|
|
1399
1425
|
t.identifier(tmpl.id),
|
|
1400
|
-
|
|
1426
|
+
templateCall
|
|
1401
1427
|
)
|
|
1402
1428
|
])
|
|
1403
1429
|
);
|
|
@@ -1468,6 +1494,8 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1468
1494
|
let existingRenderImport = null;
|
|
1469
1495
|
for (const node of path.node.body) {
|
|
1470
1496
|
if (t.isImportDeclaration(node) && (
|
|
1497
|
+
node.source.value === 'what-framework/compiler' ||
|
|
1498
|
+
node.source.value === 'what-core/compiler' ||
|
|
1471
1499
|
node.source.value === 'what-framework/render' ||
|
|
1472
1500
|
node.source.value === 'what-core/render'
|
|
1473
1501
|
)) {
|
|
@@ -1489,13 +1517,13 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1489
1517
|
}
|
|
1490
1518
|
} else {
|
|
1491
1519
|
path.unshiftContainer('body',
|
|
1492
|
-
t.importDeclaration(fgSpecifiers, t.stringLiteral(
|
|
1520
|
+
t.importDeclaration(fgSpecifiers, t.stringLiteral(`${state.runtimePackage}/compiler`))
|
|
1493
1521
|
);
|
|
1494
1522
|
}
|
|
1495
1523
|
}
|
|
1496
1524
|
|
|
1497
1525
|
if (coreSpecifiers.length > 0) {
|
|
1498
|
-
addCoreImports(path, t, coreSpecifiers);
|
|
1526
|
+
addCoreImports(path, t, coreSpecifiers, state.runtimePackage);
|
|
1499
1527
|
}
|
|
1500
1528
|
|
|
1501
1529
|
// Emit event delegation setup call if any delegated events were used
|
|
@@ -1555,7 +1583,7 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1555
1583
|
};
|
|
1556
1584
|
}
|
|
1557
1585
|
|
|
1558
|
-
function addCoreImports(path, t, coreSpecifiers) {
|
|
1586
|
+
function addCoreImports(path, t, coreSpecifiers, runtimePackage = 'what-framework') {
|
|
1559
1587
|
let existingImport = null;
|
|
1560
1588
|
for (const node of path.node.body) {
|
|
1561
1589
|
if (t.isImportDeclaration(node) && (
|
|
@@ -1580,7 +1608,7 @@ function addCoreImports(path, t, coreSpecifiers) {
|
|
|
1580
1608
|
} else {
|
|
1581
1609
|
const importDecl = t.importDeclaration(
|
|
1582
1610
|
coreSpecifiers,
|
|
1583
|
-
t.stringLiteral(
|
|
1611
|
+
t.stringLiteral(runtimePackage)
|
|
1584
1612
|
);
|
|
1585
1613
|
path.unshiftContainer('body', importDecl);
|
|
1586
1614
|
}
|