@vesk/vesk-cli 0.2.33 → 0.2.35

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.
Files changed (2) hide show
  1. package/dist/cli.js +180 -21
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -2762,6 +2762,12 @@ var init_hydrate = __esm({
2762
2762
  }
2763
2763
  const el = tm.comment.nextElementSibling;
2764
2764
  if (this.isAlreadyAdopted(tm, el)) continue;
2765
+ if (el === null && tm.identity !== null && tm.identity.charAt(0) === "c") {
2766
+ tm.state = "claimed";
2767
+ tm.comment.remove();
2768
+ this.idx++;
2769
+ continue;
2770
+ }
2765
2771
  if (tag && el && el.tagName.toLowerCase() !== tag) {
2766
2772
  reportMiss(
2767
2773
  "tag-mismatch",
@@ -2778,6 +2784,7 @@ var init_hydrate = __esm({
2778
2784
  }
2779
2785
  this.recordAdopted(adopted);
2780
2786
  this.retireAliases(adopted);
2787
+ this.retireAliasesOf(adopted);
2781
2788
  tm.state = "claimed";
2782
2789
  return adopted;
2783
2790
  }
@@ -2807,6 +2814,12 @@ ${String(this.root.outerHTML).slice(0, 800)}` : ""),
2807
2814
  }
2808
2815
  const el = tm.comment.nextElementSibling;
2809
2816
  if (this.isAlreadyAdopted(tm, el)) continue;
2817
+ if (el === null && tm.identity !== null && tm.identity.charAt(0) === "c") {
2818
+ tm.state = "claimed";
2819
+ tm.comment.remove();
2820
+ this.idx++;
2821
+ continue;
2822
+ }
2810
2823
  if (tag && el && el.tagName.toLowerCase() !== tag) {
2811
2824
  reportMiss(
2812
2825
  "tag-mismatch",
@@ -2823,6 +2836,7 @@ ${String(this.root.outerHTML).slice(0, 800)}` : ""),
2823
2836
  }
2824
2837
  this.recordAdopted(adopted);
2825
2838
  this.retireAliases(adopted);
2839
+ this.retireAliasesOf(adopted);
2826
2840
  tm.state = "claimed";
2827
2841
  return adopted;
2828
2842
  }
@@ -19976,6 +19990,13 @@ function getReturnArgument(node) {
19976
19990
  }
19977
19991
  return null;
19978
19992
  }
19993
+ function getReturnStatement(node) {
19994
+ if (node.type === "ReturnStatement") return node;
19995
+ if (node.type === "BlockStatement" && node.body.length === 1 && node.body[0].type === "ReturnStatement") {
19996
+ return node.body[0];
19997
+ }
19998
+ return null;
19999
+ }
19979
20000
  function isStatementMode(bodyStmts) {
19980
20001
  if (bodyStmts.some((s) => s.type === "JSXElement" || s.type === "JSXExpressionContainer" || s.type === "JSXFragment")) return true;
19981
20002
  for (const stmt of bodyStmts) {
@@ -20105,9 +20126,9 @@ function processStatementModeBody(source, bodyStmts, filename) {
20105
20126
  const refName = getComponentRefName(stmt);
20106
20127
  if (refName) nodes.push(new ComponentRef(refName));
20107
20128
  } else if (stmt.type === "IfStatement") {
20108
- const guardArg = !stmt.alternate ? getReturnArgument(stmt.consequent) : null;
20109
- if (guardArg) {
20110
- const consequent = exprToIR(source, guardArg);
20129
+ const guardReturn = !stmt.alternate ? getReturnStatement(stmt.consequent) : null;
20130
+ if (guardReturn) {
20131
+ const consequent = guardReturn.argument ? exprToIR(source, guardReturn.argument) : [];
20111
20132
  const alternate = processStatementModeBody(source, bodyStmts.slice(i + 1), filename);
20112
20133
  nodes.push(new OpaqueDynamicRegion(toExpression(source, stmt.test), consequent, alternate));
20113
20134
  break;
@@ -28719,7 +28740,9 @@ function emitComponentCall(ctx2, node, tracked2, effectsVar, parentVar, compPref
28719
28740
  ctx2.push(`return $f; })();`);
28720
28741
  propsEntries.push(`children: ${frag}`);
28721
28742
  }
28722
- ctx2.push(`const ${v} = ${awaitKw}${access}(${callArgs()}, __registry, ${walkerArg});`);
28743
+ ctx2.push(`let ${v} = undefined;`);
28744
+ ctx2.push(`if (__hydrate) __hydrate.childFrame = (__hydrate.childFrame || 0) + 1;`);
28745
+ ctx2.push(`try { ${v} = ${awaitKw}${access}(${callArgs()}, __registry, ${walkerArg}); } finally { if (__hydrate) __hydrate.childFrame--; }`);
28723
28746
  maybeReplace(v);
28724
28747
  maybeRetire();
28725
28748
  return v;
@@ -36287,6 +36310,23 @@ function getJSXTagName2(el) {
36287
36310
  if (name.type === "JSXNamespacedName") return name.namespace.name + ":" + name.name.name;
36288
36311
  return null;
36289
36312
  }
36313
+ function emitJSXText(g2, text, start, end) {
36314
+ if (text.indexOf("<") === -1 && text.indexOf(">") === -1 && text.indexOf("&") === -1 && text.indexOf("{") === -1 && text.indexOf("}") === -1) {
36315
+ g2.add(text, start, end);
36316
+ return;
36317
+ }
36318
+ let out = "";
36319
+ for (let i = 0; i < text.length; i++) {
36320
+ const c = text[i];
36321
+ if (c === "<") out += "&lt;";
36322
+ else if (c === ">") out += "&gt;";
36323
+ else if (c === "&") out += "&amp;";
36324
+ else if (c === "{") out += "&#123;";
36325
+ else if (c === "}") out += "&#125;";
36326
+ else out += c;
36327
+ }
36328
+ g2.add(out, start, end);
36329
+ }
36290
36330
  function collapseWithMap(value) {
36291
36331
  let out = "";
36292
36332
  const map = [];
@@ -36505,7 +36545,7 @@ function emitJSXAttr(g2, source, attr) {
36505
36545
  g2.add(source.slice(v.start, v.end), v.start, v.end);
36506
36546
  }
36507
36547
  }
36508
- function emitJSXElement(g2, source, el, opts) {
36548
+ function emitJSXElement(g2, source, el, opts, hoist) {
36509
36549
  const op = el.openingElement;
36510
36550
  const name = op.name;
36511
36551
  let prev;
@@ -36531,7 +36571,7 @@ function emitJSXElement(g2, source, el, opts) {
36531
36571
  g2.add(tail, prev, op.end);
36532
36572
  }
36533
36573
  if (op.selfClosing) return;
36534
- emitJSXChildren(g2, source, el.children ?? [], opts);
36574
+ emitJSXChildren(g2, source, el.children ?? [], opts, hoist);
36535
36575
  if (el.closingElement) {
36536
36576
  g2.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
36537
36577
  }
@@ -36541,9 +36581,9 @@ function emitJSXExprBody(g2, source, expr, opts) {
36541
36581
  if (expr.type === "JSXFragment") return emitJSXFragment(g2, source, expr, opts);
36542
36582
  g2.add(source.slice(expr.start, expr.end), expr.start, expr.end);
36543
36583
  }
36544
- function emitJSXFragment(g2, source, frag, opts) {
36584
+ function emitJSXFragment(g2, source, frag, opts, hoist) {
36545
36585
  g2.addRaw("<>");
36546
- emitJSXChildren(g2, source, frag.children ?? [], opts);
36586
+ emitJSXChildren(g2, source, frag.children ?? [], opts, hoist);
36547
36587
  g2.addRaw("</>");
36548
36588
  }
36549
36589
  function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
@@ -36594,7 +36634,7 @@ function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, e
36594
36634
  }
36595
36635
  return true;
36596
36636
  }
36597
- function emitJSXChildren(g2, source, children, opts) {
36637
+ function emitJSXChildren(g2, source, children, opts, hoist) {
36598
36638
  let i = 0;
36599
36639
  let forPending = false;
36600
36640
  while (i < children.length) {
@@ -36676,7 +36716,7 @@ function emitJSXChildren(g2, source, children, opts) {
36676
36716
  continue;
36677
36717
  }
36678
36718
  forPending = false;
36679
- g2.add(text, child.start, child.end);
36719
+ emitJSXText(g2, text, child.start, child.end);
36680
36720
  i++;
36681
36721
  } else if (child.type === "JSXExpressionContainer") {
36682
36722
  if (child.expression.type === "JSXEmptyExpression") {
@@ -36695,12 +36735,16 @@ function emitJSXChildren(g2, source, children, opts) {
36695
36735
  i++;
36696
36736
  continue;
36697
36737
  }
36698
- emitJSXElement(g2, source, child, opts);
36738
+ emitJSXElement(g2, source, child, opts, hoist);
36699
36739
  i++;
36700
36740
  } else if (child.type === "JSXFragment") {
36701
- emitJSXFragment(g2, source, child, opts);
36741
+ emitJSXFragment(g2, source, child, opts, hoist);
36702
36742
  i++;
36703
36743
  } else if (child.type === "IfStatement" || child.type === "ForOfStatement" || child.type === "ForStatement" || child.type === "ForInStatement" || child.type === "WhileStatement" || child.type === "DoWhileStatement" || child.type === "SwitchStatement" || child.type === "TryStatement" || child.type === "VariableDeclaration" || child.type === "ExpressionStatement") {
36744
+ if (hoist && hoist.set.has(child)) {
36745
+ i++;
36746
+ continue;
36747
+ }
36704
36748
  g2.addRaw("{(() => { ");
36705
36749
  emitBody(g2, source, [child], "", opts);
36706
36750
  g2.addRaw(" })()}");
@@ -36817,7 +36861,7 @@ function emitPlainStatement(g2, source, stmt, indent4, isLast) {
36817
36861
  g2.add(text, stmt.start, stmt.end);
36818
36862
  if (!text.endsWith("}") && !isLast) g2.addRaw(";");
36819
36863
  }
36820
- function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36864
+ function emitStatement(g2, source, stmt, indent4, isLast, opts, hoist) {
36821
36865
  switch (stmt.type) {
36822
36866
  case "JSXElement":
36823
36867
  if (getJSXTagName2(stmt) === "style") {
@@ -36827,12 +36871,12 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36827
36871
  return;
36828
36872
  }
36829
36873
  g2.add(indent4);
36830
- emitJSXElement(g2, source, stmt, opts);
36874
+ emitJSXElement(g2, source, stmt, opts, hoist);
36831
36875
  if (!isLast) g2.addRaw(";");
36832
36876
  return;
36833
36877
  case "JSXFragment":
36834
36878
  g2.add(indent4);
36835
- emitJSXFragment(g2, source, stmt, opts);
36879
+ emitJSXFragment(g2, source, stmt, opts, hoist);
36836
36880
  if (!isLast) g2.addRaw(";");
36837
36881
  return;
36838
36882
  case "JSXExpressionContainer": {
@@ -36850,7 +36894,7 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36850
36894
  let firstLine = true;
36851
36895
  for (let i = 0; i < innerStmts.length; i++) {
36852
36896
  const before = g2.code.length;
36853
- emitStatement(g2, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts);
36897
+ emitStatement(g2, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts, hoist);
36854
36898
  if (g2.code.length > before) {
36855
36899
  if (!firstLine) g2.addRaw("\n");
36856
36900
  firstLine = false;
@@ -36891,7 +36935,7 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36891
36935
  return emitPlainStatement(g2, source, stmt, indent4, isLast);
36892
36936
  }
36893
36937
  }
36894
- function emitBody(g2, source, stmts, indent4, opts) {
36938
+ function emitBody(g2, source, stmts, indent4, opts, hoist) {
36895
36939
  let firstLine = true;
36896
36940
  let i = 0;
36897
36941
  while (i < stmts.length) {
@@ -36918,7 +36962,7 @@ function emitBody(g2, source, stmts, indent4, opts) {
36918
36962
  continue;
36919
36963
  }
36920
36964
  const before = g2.code.length;
36921
- emitStatement(g2, source, stmt, indent4, isLast, opts);
36965
+ emitStatement(g2, source, stmt, indent4, isLast, opts, hoist);
36922
36966
  if (g2.code.length > before) {
36923
36967
  if (!firstLine) g2.addRaw("\n");
36924
36968
  firstLine = false;
@@ -36964,8 +37008,108 @@ function emitReturn(g2, source, stmt, opts) {
36964
37008
  else emitChunkMapped(g2, source, arg.start, arg.end);
36965
37009
  emitChunkMapped(g2, source, arg.end, stmt.end);
36966
37010
  }
37011
+ function collectHoistEligible(children, set2, list) {
37012
+ for (const child of children ?? []) {
37013
+ if (child.type === "JSXElement") {
37014
+ if (getJSXTagName2(child) === "style") continue;
37015
+ collectHoistEligible(child.children ?? [], set2, list);
37016
+ continue;
37017
+ }
37018
+ if (child.type === "JSXFragment") {
37019
+ collectHoistEligible(child.children ?? [], set2, list);
37020
+ continue;
37021
+ }
37022
+ if (child.type === "VariableDeclaration" || child.type === "ExpressionStatement") {
37023
+ set2.add(child);
37024
+ if (list) list.push(child);
37025
+ continue;
37026
+ }
37027
+ }
37028
+ }
36967
37029
  function emitBodyCore(g2, source, stmts, opts) {
36968
- emitBody(g2, source, stmts, "", opts);
37030
+ const hoistSet = /* @__PURE__ */ new Set();
37031
+ const byRoot = /* @__PURE__ */ new Map();
37032
+ const collectRoot = (root3) => {
37033
+ const list = [];
37034
+ collectHoistEligible(root3.children ?? [], hoistSet, list);
37035
+ if (list.length > 0) byRoot.set(root3, list);
37036
+ };
37037
+ const scanRoots = (list) => {
37038
+ for (const s of list) {
37039
+ if (!s) continue;
37040
+ if (s.type === "JSXElement" && getJSXTagName2(s) !== "style") {
37041
+ collectRoot(s);
37042
+ } else if (s.type === "JSXFragment") {
37043
+ collectRoot(s);
37044
+ } else if (s.type === "VeskBlock") {
37045
+ scanRoots(s.body ?? []);
37046
+ }
37047
+ }
37048
+ };
37049
+ scanRoots(stmts);
37050
+ const ctx2 = { set: hoistSet };
37051
+ const isRoot = (st) => st.type === "JSXElement" && getJSXTagName2(st) !== "style" || st.type === "JSXFragment";
37052
+ const units = [];
37053
+ const pushStmts = (list) => {
37054
+ for (let i = 0; i < list.length; i++) {
37055
+ const s = list[i];
37056
+ if (!s) continue;
37057
+ if (s.type === "ForOfStatement" && list[i + 1] && list[i + 1].type === "VeskBlock" && list[i + 1].tag === "empty") {
37058
+ units.push({ node: s, isHoisted: false, empty: list[i + 1] });
37059
+ i++;
37060
+ continue;
37061
+ }
37062
+ units.push({ node: s, isHoisted: isRoot(s) });
37063
+ }
37064
+ };
37065
+ for (const s of stmts) {
37066
+ if (!s) continue;
37067
+ if (s.type === "VeskBlock") {
37068
+ pushStmts(s.body ?? []);
37069
+ continue;
37070
+ }
37071
+ pushStmts([s]);
37072
+ }
37073
+ const emitUnit = (u, isLast) => {
37074
+ if (u.isHoisted) {
37075
+ const list = byRoot.get(u.node);
37076
+ if (list) {
37077
+ byRoot.delete(u.node);
37078
+ const n = list.length;
37079
+ for (let k = 0; k < n; k++) {
37080
+ const before2 = g2.code.length;
37081
+ emitStatement(g2, source, list[k], "", false, opts, ctx2);
37082
+ if (g2.code.length > before2) g2.addRaw("\n");
37083
+ }
37084
+ }
37085
+ }
37086
+ if (u.empty !== void 0) {
37087
+ emitForOf(g2, source, u.node, "", opts);
37088
+ const inner = u.empty.body ?? [];
37089
+ if (inner.length > 0) {
37090
+ g2.addRaw("\n");
37091
+ g2.add("");
37092
+ g2.add(
37093
+ source.slice(u.node.right.start, u.node.right.end),
37094
+ u.node.right.start,
37095
+ u.node.right.end
37096
+ );
37097
+ g2.addRaw(".length === 0 && (() => {");
37098
+ g2.addRaw("\n");
37099
+ emitBody(g2, source, inner, " ", opts);
37100
+ g2.addRaw("\n");
37101
+ g2.add("");
37102
+ g2.addRaw("})();");
37103
+ }
37104
+ return;
37105
+ }
37106
+ const before = g2.code.length;
37107
+ emitStatement(g2, source, u.node, "", isLast, opts, ctx2);
37108
+ if (g2.code.length > before && !isLast) g2.addRaw("\n");
37109
+ };
37110
+ for (let i = 0; i < units.length; i++) {
37111
+ emitUnit(units[i], i === units.length - 1);
37112
+ }
36969
37113
  }
36970
37114
  function emitExpressionBody(g2, source, coreStart, coreEnd, stmts, opts) {
36971
37115
  let pos = coreStart;
@@ -37769,7 +37913,16 @@ declare namespace JSX {
37769
37913
  noscript?: VeskGlobalAttributes;
37770
37914
  template?: VeskGlobalAttributes;
37771
37915
  slot?: VeskGlobalAttributes & { name?: string };
37772
- meta?: VeskGlobalAttributes & { name?: string; content?: string; charSet?: string; httpEquiv?: string };
37916
+ meta?: VeskGlobalAttributes & {
37917
+ name?: string;
37918
+ content?: string;
37919
+ charSet?: string;
37920
+ httpEquiv?: string;
37921
+ // Lowercase aliases \u2014 HTML attribute names are case-insensitive and
37922
+ // real code (and SSR output) writes charset. Keep in sync with the
37923
+ // camelCase members.
37924
+ charset?: string;
37925
+ };
37773
37926
  title?: VeskGlobalAttributes;
37774
37927
  base?: VeskGlobalAttributes & { href?: string; target?: string };
37775
37928
  link?: VeskGlobalAttributes & {
@@ -37781,6 +37934,8 @@ declare namespace JSX {
37781
37934
  crossOrigin?: string;
37782
37935
  integrity?: string;
37783
37936
  type?: string;
37937
+ // Lowercase alias \u2014 see the meta note above.
37938
+ crossorigin?: string | boolean;
37784
37939
  };
37785
37940
  style?: VeskGlobalAttributes & { media?: string };
37786
37941
  script?: VeskGlobalAttributes & {
@@ -37792,6 +37947,8 @@ declare namespace JSX {
37792
37947
  integrity?: string;
37793
37948
  nonce?: string;
37794
37949
  noModule?: boolean | string;
37950
+ // Lowercase aliases \u2014 see the meta note above.
37951
+ crossorigin?: boolean | string;
37795
37952
  };
37796
37953
  svg?: VeskGlobalAttributes & {
37797
37954
  viewBox?: string;
@@ -42691,7 +42848,9 @@ function emitComponentCall2(ctx2, node, tracked2, effectsVar, parentVar, compPre
42691
42848
  ctx2.push(`return $f; })();`);
42692
42849
  propsEntries.push(`children: ${frag}`);
42693
42850
  }
42694
- ctx2.push(`const ${v} = ${awaitKw}${access}(${callArgs()}, __registry, ${walkerArg});`);
42851
+ ctx2.push(`let ${v} = undefined;`);
42852
+ ctx2.push(`if (__hydrate) __hydrate.childFrame = (__hydrate.childFrame || 0) + 1;`);
42853
+ ctx2.push(`try { ${v} = ${awaitKw}${access}(${callArgs()}, __registry, ${walkerArg}); } finally { if (__hydrate) __hydrate.childFrame--; }`);
42695
42854
  maybeReplace(v);
42696
42855
  maybeRetire();
42697
42856
  return v;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.33",
3
+ "version": "0.2.35",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "main": "./dist/cli.js",
10
10
  "dependencies": {
11
- "@vesk/adapter": "^0.2.33",
12
- "@vesk/compiler": "^0.2.33",
13
- "@vesk/plugin-tailwind": "^0.2.33",
14
- "@vesk/runtime": "^0.2.33",
11
+ "@vesk/adapter": "^0.2.35",
12
+ "@vesk/compiler": "^0.2.35",
13
+ "@vesk/plugin-tailwind": "^0.2.35",
14
+ "@vesk/runtime": "^0.2.35",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",