what-compiler 0.6.2 → 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 +22 -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 +22 -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 +22 -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 +28 -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
|
@@ -1080,10 +1080,12 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1080
1080
|
islandProps.push(t.objectProperty(t.identifier(attrName), value));
|
|
1081
1081
|
}
|
|
1082
1082
|
|
|
1083
|
-
|
|
1083
|
+
const islandCall = t.callExpression(
|
|
1084
1084
|
t.identifier('_$createComponent'),
|
|
1085
1085
|
[t.identifier('Island'), t.objectExpression(islandProps), t.arrayExpression([])]
|
|
1086
1086
|
);
|
|
1087
|
+
t.addComment(islandCall, 'leading', '#__PURE__');
|
|
1088
|
+
return islandCall;
|
|
1087
1089
|
}
|
|
1088
1090
|
|
|
1089
1091
|
// Regular component — use _$createComponent to instantiate, component runs once
|
|
@@ -1210,7 +1212,11 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1210
1212
|
? t.arrayExpression(transformedChildren)
|
|
1211
1213
|
: t.arrayExpression([]);
|
|
1212
1214
|
|
|
1213
|
-
|
|
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;
|
|
1214
1220
|
}
|
|
1215
1221
|
|
|
1216
1222
|
function transformForFineGrained(path, state) {
|
|
@@ -1322,6 +1328,8 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1322
1328
|
state._varCounter = 0;
|
|
1323
1329
|
state._pendingSetup = [];
|
|
1324
1330
|
state.nextVarId = () => `_el$${state._varCounter++}`;
|
|
1331
|
+
state.runtimePackage = 'what-framework';
|
|
1332
|
+
state._sawFrameworkImport = false;
|
|
1325
1333
|
|
|
1326
1334
|
// Collect signal names for smart reactivity detection
|
|
1327
1335
|
state.signalNames = new Set();
|
|
@@ -1335,6 +1343,13 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1335
1343
|
for (const node of path.node.body) {
|
|
1336
1344
|
if (t.isImportDeclaration(node)) {
|
|
1337
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
|
+
|
|
1338
1353
|
const isReactiveSource =
|
|
1339
1354
|
source === 'what-framework' ||
|
|
1340
1355
|
source.startsWith('what-framework/') ||
|
|
@@ -1400,11 +1415,15 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1400
1415
|
exit(path, state) {
|
|
1401
1416
|
// Insert template declarations at top of program (hoisted to module scope)
|
|
1402
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__');
|
|
1403
1422
|
path.unshiftContainer('body',
|
|
1404
1423
|
t.variableDeclaration('const', [
|
|
1405
1424
|
t.variableDeclarator(
|
|
1406
1425
|
t.identifier(tmpl.id),
|
|
1407
|
-
|
|
1426
|
+
templateCall
|
|
1408
1427
|
)
|
|
1409
1428
|
])
|
|
1410
1429
|
);
|
|
@@ -1475,6 +1494,8 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1475
1494
|
let existingRenderImport = null;
|
|
1476
1495
|
for (const node of path.node.body) {
|
|
1477
1496
|
if (t.isImportDeclaration(node) && (
|
|
1497
|
+
node.source.value === 'what-framework/compiler' ||
|
|
1498
|
+
node.source.value === 'what-core/compiler' ||
|
|
1478
1499
|
node.source.value === 'what-framework/render' ||
|
|
1479
1500
|
node.source.value === 'what-core/render'
|
|
1480
1501
|
)) {
|
|
@@ -1496,13 +1517,13 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1496
1517
|
}
|
|
1497
1518
|
} else {
|
|
1498
1519
|
path.unshiftContainer('body',
|
|
1499
|
-
t.importDeclaration(fgSpecifiers, t.stringLiteral(
|
|
1520
|
+
t.importDeclaration(fgSpecifiers, t.stringLiteral(`${state.runtimePackage}/compiler`))
|
|
1500
1521
|
);
|
|
1501
1522
|
}
|
|
1502
1523
|
}
|
|
1503
1524
|
|
|
1504
1525
|
if (coreSpecifiers.length > 0) {
|
|
1505
|
-
addCoreImports(path, t, coreSpecifiers);
|
|
1526
|
+
addCoreImports(path, t, coreSpecifiers, state.runtimePackage);
|
|
1506
1527
|
}
|
|
1507
1528
|
|
|
1508
1529
|
// Emit event delegation setup call if any delegated events were used
|
|
@@ -1562,7 +1583,7 @@ export default function whatBabelPlugin({ types: t }) {
|
|
|
1562
1583
|
};
|
|
1563
1584
|
}
|
|
1564
1585
|
|
|
1565
|
-
function addCoreImports(path, t, coreSpecifiers) {
|
|
1586
|
+
function addCoreImports(path, t, coreSpecifiers, runtimePackage = 'what-framework') {
|
|
1566
1587
|
let existingImport = null;
|
|
1567
1588
|
for (const node of path.node.body) {
|
|
1568
1589
|
if (t.isImportDeclaration(node) && (
|
|
@@ -1587,7 +1608,7 @@ function addCoreImports(path, t, coreSpecifiers) {
|
|
|
1587
1608
|
} else {
|
|
1588
1609
|
const importDecl = t.importDeclaration(
|
|
1589
1610
|
coreSpecifiers,
|
|
1590
|
-
t.stringLiteral(
|
|
1611
|
+
t.stringLiteral(runtimePackage)
|
|
1591
1612
|
);
|
|
1592
1613
|
path.unshiftContainer('body', importDecl);
|
|
1593
1614
|
}
|