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/dist/vite-plugin.js
CHANGED
|
@@ -348,6 +348,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
348
348
|
for (const attr of el.attributes) {
|
|
349
349
|
if (t.isJSXSpreadAttribute(attr)) continue;
|
|
350
350
|
const name = getAttrName(attr);
|
|
351
|
+
if (name === "key") continue;
|
|
351
352
|
if (name.startsWith("on") || name.startsWith("bind:") || name.includes("|")) continue;
|
|
352
353
|
let domName = name;
|
|
353
354
|
if (name === "className") domName = "class";
|
|
@@ -507,6 +508,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
507
508
|
continue;
|
|
508
509
|
}
|
|
509
510
|
const attrName = getAttrName(attr);
|
|
511
|
+
if (attrName === "key") continue;
|
|
510
512
|
if (attrName === "ref") {
|
|
511
513
|
const refExpr = getAttributeValue(attr.value);
|
|
512
514
|
statements.push(
|
|
@@ -887,10 +889,12 @@ function whatBabelPlugin({ types: t }) {
|
|
|
887
889
|
const value = getAttributeValue(attr.value);
|
|
888
890
|
islandProps.push(t.objectProperty(t.identifier(attrName), value));
|
|
889
891
|
}
|
|
890
|
-
|
|
892
|
+
const islandCall = t.callExpression(
|
|
891
893
|
t.identifier("_$createComponent"),
|
|
892
894
|
[t.identifier("Island"), t.objectExpression(islandProps), t.arrayExpression([])]
|
|
893
895
|
);
|
|
896
|
+
t.addComment(islandCall, "leading", "#__PURE__");
|
|
897
|
+
return islandCall;
|
|
894
898
|
}
|
|
895
899
|
state.needsCreateComponent = true;
|
|
896
900
|
const props = [];
|
|
@@ -903,6 +907,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
903
907
|
continue;
|
|
904
908
|
}
|
|
905
909
|
const attrName = getAttrName(attr);
|
|
910
|
+
if (attrName === "key") continue;
|
|
906
911
|
if (isBindingAttribute(attrName)) {
|
|
907
912
|
const bindProp = getBindingProperty(attrName);
|
|
908
913
|
const signalExpr = attr.value.expression;
|
|
@@ -993,7 +998,9 @@ function whatBabelPlugin({ types: t }) {
|
|
|
993
998
|
propsExpr = t.nullLiteral();
|
|
994
999
|
}
|
|
995
1000
|
const childrenArray = transformedChildren.length > 0 ? t.arrayExpression(transformedChildren) : t.arrayExpression([]);
|
|
996
|
-
|
|
1001
|
+
const call = t.callExpression(t.identifier("_$createComponent"), [t.identifier(componentName), propsExpr, childrenArray]);
|
|
1002
|
+
t.addComment(call, "leading", "#__PURE__");
|
|
1003
|
+
return call;
|
|
997
1004
|
}
|
|
998
1005
|
function transformForFineGrained(path3, state) {
|
|
999
1006
|
const { node } = path3;
|
|
@@ -1082,11 +1089,19 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1082
1089
|
state._varCounter = 0;
|
|
1083
1090
|
state._pendingSetup = [];
|
|
1084
1091
|
state.nextVarId = () => `_el$${state._varCounter++}`;
|
|
1092
|
+
state.runtimePackage = "what-framework";
|
|
1093
|
+
state._sawFrameworkImport = false;
|
|
1085
1094
|
state.signalNames = /* @__PURE__ */ new Set();
|
|
1086
1095
|
state.importedIdentifiers = /* @__PURE__ */ new Set();
|
|
1087
1096
|
for (const node of path3.node.body) {
|
|
1088
1097
|
if (t.isImportDeclaration(node)) {
|
|
1089
1098
|
const source = node.source.value;
|
|
1099
|
+
if (source === "what-framework" || source.startsWith("what-framework/")) {
|
|
1100
|
+
state.runtimePackage = "what-framework";
|
|
1101
|
+
state._sawFrameworkImport = true;
|
|
1102
|
+
} else if (!state._sawFrameworkImport && (source === "what-core" || source.startsWith("what-core/"))) {
|
|
1103
|
+
state.runtimePackage = "what-core";
|
|
1104
|
+
}
|
|
1090
1105
|
const isReactiveSource = source === "what-framework" || source.startsWith("what-framework/") || source === "what-core" || source.startsWith("what-core/") || source.startsWith("./") || source.startsWith("../");
|
|
1091
1106
|
for (const spec of node.specifiers) {
|
|
1092
1107
|
let localName = null;
|
|
@@ -1137,12 +1152,14 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1137
1152
|
},
|
|
1138
1153
|
exit(path3, state) {
|
|
1139
1154
|
for (const tmpl of state.templates.reverse()) {
|
|
1155
|
+
const templateCall = t.callExpression(t.identifier("_$template"), [t.stringLiteral(tmpl.html)]);
|
|
1156
|
+
t.addComment(templateCall, "leading", "#__PURE__");
|
|
1140
1157
|
path3.unshiftContainer(
|
|
1141
1158
|
"body",
|
|
1142
1159
|
t.variableDeclaration("const", [
|
|
1143
1160
|
t.variableDeclarator(
|
|
1144
1161
|
t.identifier(tmpl.id),
|
|
1145
|
-
|
|
1162
|
+
templateCall
|
|
1146
1163
|
)
|
|
1147
1164
|
])
|
|
1148
1165
|
);
|
|
@@ -1207,7 +1224,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1207
1224
|
if (fgSpecifiers.length > 0) {
|
|
1208
1225
|
let existingRenderImport = null;
|
|
1209
1226
|
for (const node of path3.node.body) {
|
|
1210
|
-
if (t.isImportDeclaration(node) && (node.source.value === "what-framework/render" || node.source.value === "what-core/render")) {
|
|
1227
|
+
if (t.isImportDeclaration(node) && (node.source.value === "what-framework/compiler" || node.source.value === "what-core/compiler" || node.source.value === "what-framework/render" || node.source.value === "what-core/render")) {
|
|
1211
1228
|
existingRenderImport = node;
|
|
1212
1229
|
break;
|
|
1213
1230
|
}
|
|
@@ -1224,12 +1241,12 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1224
1241
|
} else {
|
|
1225
1242
|
path3.unshiftContainer(
|
|
1226
1243
|
"body",
|
|
1227
|
-
t.importDeclaration(fgSpecifiers, t.stringLiteral(
|
|
1244
|
+
t.importDeclaration(fgSpecifiers, t.stringLiteral(`${state.runtimePackage}/compiler`))
|
|
1228
1245
|
);
|
|
1229
1246
|
}
|
|
1230
1247
|
}
|
|
1231
1248
|
if (coreSpecifiers.length > 0) {
|
|
1232
|
-
addCoreImports(path3, t, coreSpecifiers);
|
|
1249
|
+
addCoreImports(path3, t, coreSpecifiers, state.runtimePackage);
|
|
1233
1250
|
}
|
|
1234
1251
|
if (state.needsDelegation && state.delegatedEvents && state.delegatedEvents.size > 0) {
|
|
1235
1252
|
const eventArray = t.arrayExpression(
|
|
@@ -1280,7 +1297,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1280
1297
|
}
|
|
1281
1298
|
};
|
|
1282
1299
|
}
|
|
1283
|
-
function addCoreImports(path3, t, coreSpecifiers) {
|
|
1300
|
+
function addCoreImports(path3, t, coreSpecifiers, runtimePackage = "what-framework") {
|
|
1284
1301
|
let existingImport = null;
|
|
1285
1302
|
for (const node of path3.node.body) {
|
|
1286
1303
|
if (t.isImportDeclaration(node) && (node.source.value === "what-core" || node.source.value === "what-framework")) {
|
|
@@ -1300,7 +1317,7 @@ function addCoreImports(path3, t, coreSpecifiers) {
|
|
|
1300
1317
|
} else {
|
|
1301
1318
|
const importDecl = t.importDeclaration(
|
|
1302
1319
|
coreSpecifiers,
|
|
1303
|
-
t.stringLiteral(
|
|
1320
|
+
t.stringLiteral(runtimePackage)
|
|
1304
1321
|
);
|
|
1305
1322
|
path3.unshiftContainer("body", importDecl);
|
|
1306
1323
|
}
|