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/dist/vite-plugin.js
CHANGED
|
@@ -889,10 +889,12 @@ function whatBabelPlugin({ types: t }) {
|
|
|
889
889
|
const value = getAttributeValue(attr.value);
|
|
890
890
|
islandProps.push(t.objectProperty(t.identifier(attrName), value));
|
|
891
891
|
}
|
|
892
|
-
|
|
892
|
+
const islandCall = t.callExpression(
|
|
893
893
|
t.identifier("_$createComponent"),
|
|
894
894
|
[t.identifier("Island"), t.objectExpression(islandProps), t.arrayExpression([])]
|
|
895
895
|
);
|
|
896
|
+
t.addComment(islandCall, "leading", "#__PURE__");
|
|
897
|
+
return islandCall;
|
|
896
898
|
}
|
|
897
899
|
state.needsCreateComponent = true;
|
|
898
900
|
const props = [];
|
|
@@ -996,7 +998,9 @@ function whatBabelPlugin({ types: t }) {
|
|
|
996
998
|
propsExpr = t.nullLiteral();
|
|
997
999
|
}
|
|
998
1000
|
const childrenArray = transformedChildren.length > 0 ? t.arrayExpression(transformedChildren) : t.arrayExpression([]);
|
|
999
|
-
|
|
1001
|
+
const call = t.callExpression(t.identifier("_$createComponent"), [t.identifier(componentName), propsExpr, childrenArray]);
|
|
1002
|
+
t.addComment(call, "leading", "#__PURE__");
|
|
1003
|
+
return call;
|
|
1000
1004
|
}
|
|
1001
1005
|
function transformForFineGrained(path3, state) {
|
|
1002
1006
|
const { node } = path3;
|
|
@@ -1085,11 +1089,19 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1085
1089
|
state._varCounter = 0;
|
|
1086
1090
|
state._pendingSetup = [];
|
|
1087
1091
|
state.nextVarId = () => `_el$${state._varCounter++}`;
|
|
1092
|
+
state.runtimePackage = "what-framework";
|
|
1093
|
+
state._sawFrameworkImport = false;
|
|
1088
1094
|
state.signalNames = /* @__PURE__ */ new Set();
|
|
1089
1095
|
state.importedIdentifiers = /* @__PURE__ */ new Set();
|
|
1090
1096
|
for (const node of path3.node.body) {
|
|
1091
1097
|
if (t.isImportDeclaration(node)) {
|
|
1092
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
|
+
}
|
|
1093
1105
|
const isReactiveSource = source === "what-framework" || source.startsWith("what-framework/") || source === "what-core" || source.startsWith("what-core/") || source.startsWith("./") || source.startsWith("../");
|
|
1094
1106
|
for (const spec of node.specifiers) {
|
|
1095
1107
|
let localName = null;
|
|
@@ -1140,12 +1152,14 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1140
1152
|
},
|
|
1141
1153
|
exit(path3, state) {
|
|
1142
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__");
|
|
1143
1157
|
path3.unshiftContainer(
|
|
1144
1158
|
"body",
|
|
1145
1159
|
t.variableDeclaration("const", [
|
|
1146
1160
|
t.variableDeclarator(
|
|
1147
1161
|
t.identifier(tmpl.id),
|
|
1148
|
-
|
|
1162
|
+
templateCall
|
|
1149
1163
|
)
|
|
1150
1164
|
])
|
|
1151
1165
|
);
|
|
@@ -1210,7 +1224,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1210
1224
|
if (fgSpecifiers.length > 0) {
|
|
1211
1225
|
let existingRenderImport = null;
|
|
1212
1226
|
for (const node of path3.node.body) {
|
|
1213
|
-
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")) {
|
|
1214
1228
|
existingRenderImport = node;
|
|
1215
1229
|
break;
|
|
1216
1230
|
}
|
|
@@ -1227,12 +1241,12 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1227
1241
|
} else {
|
|
1228
1242
|
path3.unshiftContainer(
|
|
1229
1243
|
"body",
|
|
1230
|
-
t.importDeclaration(fgSpecifiers, t.stringLiteral(
|
|
1244
|
+
t.importDeclaration(fgSpecifiers, t.stringLiteral(`${state.runtimePackage}/compiler`))
|
|
1231
1245
|
);
|
|
1232
1246
|
}
|
|
1233
1247
|
}
|
|
1234
1248
|
if (coreSpecifiers.length > 0) {
|
|
1235
|
-
addCoreImports(path3, t, coreSpecifiers);
|
|
1249
|
+
addCoreImports(path3, t, coreSpecifiers, state.runtimePackage);
|
|
1236
1250
|
}
|
|
1237
1251
|
if (state.needsDelegation && state.delegatedEvents && state.delegatedEvents.size > 0) {
|
|
1238
1252
|
const eventArray = t.arrayExpression(
|
|
@@ -1283,7 +1297,7 @@ function whatBabelPlugin({ types: t }) {
|
|
|
1283
1297
|
}
|
|
1284
1298
|
};
|
|
1285
1299
|
}
|
|
1286
|
-
function addCoreImports(path3, t, coreSpecifiers) {
|
|
1300
|
+
function addCoreImports(path3, t, coreSpecifiers, runtimePackage = "what-framework") {
|
|
1287
1301
|
let existingImport = null;
|
|
1288
1302
|
for (const node of path3.node.body) {
|
|
1289
1303
|
if (t.isImportDeclaration(node) && (node.source.value === "what-core" || node.source.value === "what-framework")) {
|
|
@@ -1303,7 +1317,7 @@ function addCoreImports(path3, t, coreSpecifiers) {
|
|
|
1303
1317
|
} else {
|
|
1304
1318
|
const importDecl = t.importDeclaration(
|
|
1305
1319
|
coreSpecifiers,
|
|
1306
|
-
t.stringLiteral(
|
|
1320
|
+
t.stringLiteral(runtimePackage)
|
|
1307
1321
|
);
|
|
1308
1322
|
path3.unshiftContainer("body", importDecl);
|
|
1309
1323
|
}
|