what-compiler 0.6.2 → 0.6.5
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/dist/index.js
CHANGED
|
@@ -885,10 +885,12 @@ function whatBabelPlugin({ types: t }) {
|
|
|
885
885
|
const value = getAttributeValue(attr.value);
|
|
886
886
|
islandProps.push(t.objectProperty(t.identifier(attrName), value));
|
|
887
887
|
}
|
|
888
|
-
|
|
888
|
+
const islandCall = t.callExpression(
|
|
889
889
|
t.identifier("_$createComponent"),
|
|
890
890
|
[t.identifier("Island"), t.objectExpression(islandProps), t.arrayExpression([])]
|
|
891
891
|
);
|
|
892
|
+
t.addComment(islandCall, "leading", "#__PURE__");
|
|
893
|
+
return islandCall;
|
|
892
894
|
}
|
|
893
895
|
state.needsCreateComponent = true;
|
|
894
896
|
const props = [];
|
|
@@ -992,7 +994,9 @@ function whatBabelPlugin({ types: t }) {
|
|
|
992
994
|
propsExpr = t.nullLiteral();
|
|
993
995
|
}
|
|
994
996
|
const childrenArray = transformedChildren.length > 0 ? t.arrayExpression(transformedChildren) : t.arrayExpression([]);
|
|
995
|
-
|
|
997
|
+
const call = t.callExpression(t.identifier("_$createComponent"), [t.identifier(componentName), propsExpr, childrenArray]);
|
|
998
|
+
t.addComment(call, "leading", "#__PURE__");
|
|
999
|
+
return call;
|
|
996
1000
|
}
|
|
997
1001
|
function transformForFineGrained(path3, state) {
|
|
998
1002
|
const { node } = path3;
|
|
@@ -1081,11 +1085,19 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1081
1085
|
state._varCounter = 0;
|
|
1082
1086
|
state._pendingSetup = [];
|
|
1083
1087
|
state.nextVarId = () => `_el$${state._varCounter++}`;
|
|
1088
|
+
state.runtimePackage = "what-framework";
|
|
1089
|
+
state._sawFrameworkImport = false;
|
|
1084
1090
|
state.signalNames = /* @__PURE__ */ new Set();
|
|
1085
1091
|
state.importedIdentifiers = /* @__PURE__ */ new Set();
|
|
1086
1092
|
for (const node of path3.node.body) {
|
|
1087
1093
|
if (t.isImportDeclaration(node)) {
|
|
1088
1094
|
const source = node.source.value;
|
|
1095
|
+
if (source === "what-framework" || source.startsWith("what-framework/")) {
|
|
1096
|
+
state.runtimePackage = "what-framework";
|
|
1097
|
+
state._sawFrameworkImport = true;
|
|
1098
|
+
} else if (!state._sawFrameworkImport && (source === "what-core" || source.startsWith("what-core/"))) {
|
|
1099
|
+
state.runtimePackage = "what-core";
|
|
1100
|
+
}
|
|
1089
1101
|
const isReactiveSource = source === "what-framework" || source.startsWith("what-framework/") || source === "what-core" || source.startsWith("what-core/") || source.startsWith("./") || source.startsWith("../");
|
|
1090
1102
|
for (const spec of node.specifiers) {
|
|
1091
1103
|
let localName = null;
|
|
@@ -1136,12 +1148,14 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1136
1148
|
},
|
|
1137
1149
|
exit(path3, state) {
|
|
1138
1150
|
for (const tmpl of state.templates.reverse()) {
|
|
1151
|
+
const templateCall = t.callExpression(t.identifier("_$template"), [t.stringLiteral(tmpl.html)]);
|
|
1152
|
+
t.addComment(templateCall, "leading", "#__PURE__");
|
|
1139
1153
|
path3.unshiftContainer(
|
|
1140
1154
|
"body",
|
|
1141
1155
|
t.variableDeclaration("const", [
|
|
1142
1156
|
t.variableDeclarator(
|
|
1143
1157
|
t.identifier(tmpl.id),
|
|
1144
|
-
|
|
1158
|
+
templateCall
|
|
1145
1159
|
)
|
|
1146
1160
|
])
|
|
1147
1161
|
);
|
|
@@ -1206,7 +1220,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1206
1220
|
if (fgSpecifiers.length > 0) {
|
|
1207
1221
|
let existingRenderImport = null;
|
|
1208
1222
|
for (const node of path3.node.body) {
|
|
1209
|
-
if (t.isImportDeclaration(node) && (node.source.value === "what-framework/render" || node.source.value === "what-core/render")) {
|
|
1223
|
+
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")) {
|
|
1210
1224
|
existingRenderImport = node;
|
|
1211
1225
|
break;
|
|
1212
1226
|
}
|
|
@@ -1223,12 +1237,12 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1223
1237
|
} else {
|
|
1224
1238
|
path3.unshiftContainer(
|
|
1225
1239
|
"body",
|
|
1226
|
-
t.importDeclaration(fgSpecifiers, t.stringLiteral(
|
|
1240
|
+
t.importDeclaration(fgSpecifiers, t.stringLiteral(`${state.runtimePackage}/compiler`))
|
|
1227
1241
|
);
|
|
1228
1242
|
}
|
|
1229
1243
|
}
|
|
1230
1244
|
if (coreSpecifiers.length > 0) {
|
|
1231
|
-
addCoreImports(path3, t, coreSpecifiers);
|
|
1245
|
+
addCoreImports(path3, t, coreSpecifiers, state.runtimePackage);
|
|
1232
1246
|
}
|
|
1233
1247
|
if (state.needsDelegation && state.delegatedEvents && state.delegatedEvents.size > 0) {
|
|
1234
1248
|
const eventArray = t.arrayExpression(
|
|
@@ -1279,7 +1293,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1279
1293
|
}
|
|
1280
1294
|
};
|
|
1281
1295
|
}
|
|
1282
|
-
function addCoreImports(path3, t, coreSpecifiers) {
|
|
1296
|
+
function addCoreImports(path3, t, coreSpecifiers, runtimePackage = "what-framework") {
|
|
1283
1297
|
let existingImport = null;
|
|
1284
1298
|
for (const node of path3.node.body) {
|
|
1285
1299
|
if (t.isImportDeclaration(node) && (node.source.value === "what-core" || node.source.value === "what-framework")) {
|
|
@@ -1299,7 +1313,7 @@ function addCoreImports(path3, t, coreSpecifiers) {
|
|
|
1299
1313
|
} else {
|
|
1300
1314
|
const importDecl = t.importDeclaration(
|
|
1301
1315
|
coreSpecifiers,
|
|
1302
|
-
t.stringLiteral(
|
|
1316
|
+
t.stringLiteral(runtimePackage)
|
|
1303
1317
|
);
|
|
1304
1318
|
path3.unshiftContainer("body", importDecl);
|
|
1305
1319
|
}
|