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/index.js CHANGED
@@ -344,6 +344,7 @@ function whatBabelPlugin({ types: t }) {
344
344
  for (const attr of el.attributes) {
345
345
  if (t.isJSXSpreadAttribute(attr)) continue;
346
346
  const name = getAttrName(attr);
347
+ if (name === "key") continue;
347
348
  if (name.startsWith("on") || name.startsWith("bind:") || name.includes("|")) continue;
348
349
  let domName = name;
349
350
  if (name === "className") domName = "class";
@@ -503,6 +504,7 @@ function whatBabelPlugin({ types: t }) {
503
504
  continue;
504
505
  }
505
506
  const attrName = getAttrName(attr);
507
+ if (attrName === "key") continue;
506
508
  if (attrName === "ref") {
507
509
  const refExpr = getAttributeValue(attr.value);
508
510
  statements.push(
@@ -883,10 +885,12 @@ function whatBabelPlugin({ types: t }) {
883
885
  const value = getAttributeValue(attr.value);
884
886
  islandProps.push(t.objectProperty(t.identifier(attrName), value));
885
887
  }
886
- return t.callExpression(
888
+ const islandCall = t.callExpression(
887
889
  t.identifier("_$createComponent"),
888
890
  [t.identifier("Island"), t.objectExpression(islandProps), t.arrayExpression([])]
889
891
  );
892
+ t.addComment(islandCall, "leading", "#__PURE__");
893
+ return islandCall;
890
894
  }
891
895
  state.needsCreateComponent = true;
892
896
  const props = [];
@@ -899,6 +903,7 @@ function whatBabelPlugin({ types: t }) {
899
903
  continue;
900
904
  }
901
905
  const attrName = getAttrName(attr);
906
+ if (attrName === "key") continue;
902
907
  if (isBindingAttribute(attrName)) {
903
908
  const bindProp = getBindingProperty(attrName);
904
909
  const signalExpr = attr.value.expression;
@@ -989,7 +994,9 @@ function whatBabelPlugin({ types: t }) {
989
994
  propsExpr = t.nullLiteral();
990
995
  }
991
996
  const childrenArray = transformedChildren.length > 0 ? t.arrayExpression(transformedChildren) : t.arrayExpression([]);
992
- return t.callExpression(t.identifier("_$createComponent"), [t.identifier(componentName), propsExpr, childrenArray]);
997
+ const call = t.callExpression(t.identifier("_$createComponent"), [t.identifier(componentName), propsExpr, childrenArray]);
998
+ t.addComment(call, "leading", "#__PURE__");
999
+ return call;
993
1000
  }
994
1001
  function transformForFineGrained(path3, state) {
995
1002
  const { node } = path3;
@@ -1078,11 +1085,19 @@ function whatBabelPlugin({ types: t }) {
1078
1085
  state._varCounter = 0;
1079
1086
  state._pendingSetup = [];
1080
1087
  state.nextVarId = () => `_el$${state._varCounter++}`;
1088
+ state.runtimePackage = "what-framework";
1089
+ state._sawFrameworkImport = false;
1081
1090
  state.signalNames = /* @__PURE__ */ new Set();
1082
1091
  state.importedIdentifiers = /* @__PURE__ */ new Set();
1083
1092
  for (const node of path3.node.body) {
1084
1093
  if (t.isImportDeclaration(node)) {
1085
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
+ }
1086
1101
  const isReactiveSource = source === "what-framework" || source.startsWith("what-framework/") || source === "what-core" || source.startsWith("what-core/") || source.startsWith("./") || source.startsWith("../");
1087
1102
  for (const spec of node.specifiers) {
1088
1103
  let localName = null;
@@ -1133,12 +1148,14 @@ function whatBabelPlugin({ types: t }) {
1133
1148
  },
1134
1149
  exit(path3, state) {
1135
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__");
1136
1153
  path3.unshiftContainer(
1137
1154
  "body",
1138
1155
  t.variableDeclaration("const", [
1139
1156
  t.variableDeclarator(
1140
1157
  t.identifier(tmpl.id),
1141
- t.callExpression(t.identifier("_$template"), [t.stringLiteral(tmpl.html)])
1158
+ templateCall
1142
1159
  )
1143
1160
  ])
1144
1161
  );
@@ -1203,7 +1220,7 @@ function whatBabelPlugin({ types: t }) {
1203
1220
  if (fgSpecifiers.length > 0) {
1204
1221
  let existingRenderImport = null;
1205
1222
  for (const node of path3.node.body) {
1206
- 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")) {
1207
1224
  existingRenderImport = node;
1208
1225
  break;
1209
1226
  }
@@ -1220,12 +1237,12 @@ function whatBabelPlugin({ types: t }) {
1220
1237
  } else {
1221
1238
  path3.unshiftContainer(
1222
1239
  "body",
1223
- t.importDeclaration(fgSpecifiers, t.stringLiteral("what-framework/render"))
1240
+ t.importDeclaration(fgSpecifiers, t.stringLiteral(`${state.runtimePackage}/compiler`))
1224
1241
  );
1225
1242
  }
1226
1243
  }
1227
1244
  if (coreSpecifiers.length > 0) {
1228
- addCoreImports(path3, t, coreSpecifiers);
1245
+ addCoreImports(path3, t, coreSpecifiers, state.runtimePackage);
1229
1246
  }
1230
1247
  if (state.needsDelegation && state.delegatedEvents && state.delegatedEvents.size > 0) {
1231
1248
  const eventArray = t.arrayExpression(
@@ -1276,7 +1293,7 @@ function whatBabelPlugin({ types: t }) {
1276
1293
  }
1277
1294
  };
1278
1295
  }
1279
- function addCoreImports(path3, t, coreSpecifiers) {
1296
+ function addCoreImports(path3, t, coreSpecifiers, runtimePackage = "what-framework") {
1280
1297
  let existingImport = null;
1281
1298
  for (const node of path3.node.body) {
1282
1299
  if (t.isImportDeclaration(node) && (node.source.value === "what-core" || node.source.value === "what-framework")) {
@@ -1296,7 +1313,7 @@ function addCoreImports(path3, t, coreSpecifiers) {
1296
1313
  } else {
1297
1314
  const importDecl = t.importDeclaration(
1298
1315
  coreSpecifiers,
1299
- t.stringLiteral("what-framework")
1316
+ t.stringLiteral(runtimePackage)
1300
1317
  );
1301
1318
  path3.unshiftContainer("body", importDecl);
1302
1319
  }