@vesk/vesk-cli 0.2.33 → 0.2.34

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 +150 -16
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -36287,6 +36287,23 @@ function getJSXTagName2(el) {
36287
36287
  if (name.type === "JSXNamespacedName") return name.namespace.name + ":" + name.name.name;
36288
36288
  return null;
36289
36289
  }
36290
+ function emitJSXText(g2, text, start, end) {
36291
+ if (text.indexOf("<") === -1 && text.indexOf(">") === -1 && text.indexOf("&") === -1 && text.indexOf("{") === -1 && text.indexOf("}") === -1) {
36292
+ g2.add(text, start, end);
36293
+ return;
36294
+ }
36295
+ let out = "";
36296
+ for (let i = 0; i < text.length; i++) {
36297
+ const c = text[i];
36298
+ if (c === "<") out += "&lt;";
36299
+ else if (c === ">") out += "&gt;";
36300
+ else if (c === "&") out += "&amp;";
36301
+ else if (c === "{") out += "&#123;";
36302
+ else if (c === "}") out += "&#125;";
36303
+ else out += c;
36304
+ }
36305
+ g2.add(out, start, end);
36306
+ }
36290
36307
  function collapseWithMap(value) {
36291
36308
  let out = "";
36292
36309
  const map = [];
@@ -36505,7 +36522,7 @@ function emitJSXAttr(g2, source, attr) {
36505
36522
  g2.add(source.slice(v.start, v.end), v.start, v.end);
36506
36523
  }
36507
36524
  }
36508
- function emitJSXElement(g2, source, el, opts) {
36525
+ function emitJSXElement(g2, source, el, opts, hoist) {
36509
36526
  const op = el.openingElement;
36510
36527
  const name = op.name;
36511
36528
  let prev;
@@ -36531,7 +36548,7 @@ function emitJSXElement(g2, source, el, opts) {
36531
36548
  g2.add(tail, prev, op.end);
36532
36549
  }
36533
36550
  if (op.selfClosing) return;
36534
- emitJSXChildren(g2, source, el.children ?? [], opts);
36551
+ emitJSXChildren(g2, source, el.children ?? [], opts, hoist);
36535
36552
  if (el.closingElement) {
36536
36553
  g2.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
36537
36554
  }
@@ -36541,9 +36558,9 @@ function emitJSXExprBody(g2, source, expr, opts) {
36541
36558
  if (expr.type === "JSXFragment") return emitJSXFragment(g2, source, expr, opts);
36542
36559
  g2.add(source.slice(expr.start, expr.end), expr.start, expr.end);
36543
36560
  }
36544
- function emitJSXFragment(g2, source, frag, opts) {
36561
+ function emitJSXFragment(g2, source, frag, opts, hoist) {
36545
36562
  g2.addRaw("<>");
36546
- emitJSXChildren(g2, source, frag.children ?? [], opts);
36563
+ emitJSXChildren(g2, source, frag.children ?? [], opts, hoist);
36547
36564
  g2.addRaw("</>");
36548
36565
  }
36549
36566
  function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
@@ -36594,7 +36611,7 @@ function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, e
36594
36611
  }
36595
36612
  return true;
36596
36613
  }
36597
- function emitJSXChildren(g2, source, children, opts) {
36614
+ function emitJSXChildren(g2, source, children, opts, hoist) {
36598
36615
  let i = 0;
36599
36616
  let forPending = false;
36600
36617
  while (i < children.length) {
@@ -36676,7 +36693,7 @@ function emitJSXChildren(g2, source, children, opts) {
36676
36693
  continue;
36677
36694
  }
36678
36695
  forPending = false;
36679
- g2.add(text, child.start, child.end);
36696
+ emitJSXText(g2, text, child.start, child.end);
36680
36697
  i++;
36681
36698
  } else if (child.type === "JSXExpressionContainer") {
36682
36699
  if (child.expression.type === "JSXEmptyExpression") {
@@ -36695,12 +36712,16 @@ function emitJSXChildren(g2, source, children, opts) {
36695
36712
  i++;
36696
36713
  continue;
36697
36714
  }
36698
- emitJSXElement(g2, source, child, opts);
36715
+ emitJSXElement(g2, source, child, opts, hoist);
36699
36716
  i++;
36700
36717
  } else if (child.type === "JSXFragment") {
36701
- emitJSXFragment(g2, source, child, opts);
36718
+ emitJSXFragment(g2, source, child, opts, hoist);
36702
36719
  i++;
36703
36720
  } 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") {
36721
+ if (hoist && hoist.set.has(child)) {
36722
+ i++;
36723
+ continue;
36724
+ }
36704
36725
  g2.addRaw("{(() => { ");
36705
36726
  emitBody(g2, source, [child], "", opts);
36706
36727
  g2.addRaw(" })()}");
@@ -36817,7 +36838,7 @@ function emitPlainStatement(g2, source, stmt, indent4, isLast) {
36817
36838
  g2.add(text, stmt.start, stmt.end);
36818
36839
  if (!text.endsWith("}") && !isLast) g2.addRaw(";");
36819
36840
  }
36820
- function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36841
+ function emitStatement(g2, source, stmt, indent4, isLast, opts, hoist) {
36821
36842
  switch (stmt.type) {
36822
36843
  case "JSXElement":
36823
36844
  if (getJSXTagName2(stmt) === "style") {
@@ -36827,12 +36848,12 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36827
36848
  return;
36828
36849
  }
36829
36850
  g2.add(indent4);
36830
- emitJSXElement(g2, source, stmt, opts);
36851
+ emitJSXElement(g2, source, stmt, opts, hoist);
36831
36852
  if (!isLast) g2.addRaw(";");
36832
36853
  return;
36833
36854
  case "JSXFragment":
36834
36855
  g2.add(indent4);
36835
- emitJSXFragment(g2, source, stmt, opts);
36856
+ emitJSXFragment(g2, source, stmt, opts, hoist);
36836
36857
  if (!isLast) g2.addRaw(";");
36837
36858
  return;
36838
36859
  case "JSXExpressionContainer": {
@@ -36850,7 +36871,7 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36850
36871
  let firstLine = true;
36851
36872
  for (let i = 0; i < innerStmts.length; i++) {
36852
36873
  const before = g2.code.length;
36853
- emitStatement(g2, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts);
36874
+ emitStatement(g2, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts, hoist);
36854
36875
  if (g2.code.length > before) {
36855
36876
  if (!firstLine) g2.addRaw("\n");
36856
36877
  firstLine = false;
@@ -36891,7 +36912,7 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36891
36912
  return emitPlainStatement(g2, source, stmt, indent4, isLast);
36892
36913
  }
36893
36914
  }
36894
- function emitBody(g2, source, stmts, indent4, opts) {
36915
+ function emitBody(g2, source, stmts, indent4, opts, hoist) {
36895
36916
  let firstLine = true;
36896
36917
  let i = 0;
36897
36918
  while (i < stmts.length) {
@@ -36918,7 +36939,7 @@ function emitBody(g2, source, stmts, indent4, opts) {
36918
36939
  continue;
36919
36940
  }
36920
36941
  const before = g2.code.length;
36921
- emitStatement(g2, source, stmt, indent4, isLast, opts);
36942
+ emitStatement(g2, source, stmt, indent4, isLast, opts, hoist);
36922
36943
  if (g2.code.length > before) {
36923
36944
  if (!firstLine) g2.addRaw("\n");
36924
36945
  firstLine = false;
@@ -36964,8 +36985,108 @@ function emitReturn(g2, source, stmt, opts) {
36964
36985
  else emitChunkMapped(g2, source, arg.start, arg.end);
36965
36986
  emitChunkMapped(g2, source, arg.end, stmt.end);
36966
36987
  }
36988
+ function collectHoistEligible(children, set2, list) {
36989
+ for (const child of children ?? []) {
36990
+ if (child.type === "JSXElement") {
36991
+ if (getJSXTagName2(child) === "style") continue;
36992
+ collectHoistEligible(child.children ?? [], set2, list);
36993
+ continue;
36994
+ }
36995
+ if (child.type === "JSXFragment") {
36996
+ collectHoistEligible(child.children ?? [], set2, list);
36997
+ continue;
36998
+ }
36999
+ if (child.type === "VariableDeclaration" || child.type === "ExpressionStatement") {
37000
+ set2.add(child);
37001
+ if (list) list.push(child);
37002
+ continue;
37003
+ }
37004
+ }
37005
+ }
36967
37006
  function emitBodyCore(g2, source, stmts, opts) {
36968
- emitBody(g2, source, stmts, "", opts);
37007
+ const hoistSet = /* @__PURE__ */ new Set();
37008
+ const byRoot = /* @__PURE__ */ new Map();
37009
+ const collectRoot = (root3) => {
37010
+ const list = [];
37011
+ collectHoistEligible(root3.children ?? [], hoistSet, list);
37012
+ if (list.length > 0) byRoot.set(root3, list);
37013
+ };
37014
+ const scanRoots = (list) => {
37015
+ for (const s of list) {
37016
+ if (!s) continue;
37017
+ if (s.type === "JSXElement" && getJSXTagName2(s) !== "style") {
37018
+ collectRoot(s);
37019
+ } else if (s.type === "JSXFragment") {
37020
+ collectRoot(s);
37021
+ } else if (s.type === "VeskBlock") {
37022
+ scanRoots(s.body ?? []);
37023
+ }
37024
+ }
37025
+ };
37026
+ scanRoots(stmts);
37027
+ const ctx2 = { set: hoistSet };
37028
+ const isRoot = (st) => st.type === "JSXElement" && getJSXTagName2(st) !== "style" || st.type === "JSXFragment";
37029
+ const units = [];
37030
+ const pushStmts = (list) => {
37031
+ for (let i = 0; i < list.length; i++) {
37032
+ const s = list[i];
37033
+ if (!s) continue;
37034
+ if (s.type === "ForOfStatement" && list[i + 1] && list[i + 1].type === "VeskBlock" && list[i + 1].tag === "empty") {
37035
+ units.push({ node: s, isHoisted: false, empty: list[i + 1] });
37036
+ i++;
37037
+ continue;
37038
+ }
37039
+ units.push({ node: s, isHoisted: isRoot(s) });
37040
+ }
37041
+ };
37042
+ for (const s of stmts) {
37043
+ if (!s) continue;
37044
+ if (s.type === "VeskBlock") {
37045
+ pushStmts(s.body ?? []);
37046
+ continue;
37047
+ }
37048
+ pushStmts([s]);
37049
+ }
37050
+ const emitUnit = (u, isLast) => {
37051
+ if (u.isHoisted) {
37052
+ const list = byRoot.get(u.node);
37053
+ if (list) {
37054
+ byRoot.delete(u.node);
37055
+ const n = list.length;
37056
+ for (let k = 0; k < n; k++) {
37057
+ const before2 = g2.code.length;
37058
+ emitStatement(g2, source, list[k], "", false, opts, ctx2);
37059
+ if (g2.code.length > before2) g2.addRaw("\n");
37060
+ }
37061
+ }
37062
+ }
37063
+ if (u.empty !== void 0) {
37064
+ emitForOf(g2, source, u.node, "", opts);
37065
+ const inner = u.empty.body ?? [];
37066
+ if (inner.length > 0) {
37067
+ g2.addRaw("\n");
37068
+ g2.add("");
37069
+ g2.add(
37070
+ source.slice(u.node.right.start, u.node.right.end),
37071
+ u.node.right.start,
37072
+ u.node.right.end
37073
+ );
37074
+ g2.addRaw(".length === 0 && (() => {");
37075
+ g2.addRaw("\n");
37076
+ emitBody(g2, source, inner, " ", opts);
37077
+ g2.addRaw("\n");
37078
+ g2.add("");
37079
+ g2.addRaw("})();");
37080
+ }
37081
+ return;
37082
+ }
37083
+ const before = g2.code.length;
37084
+ emitStatement(g2, source, u.node, "", isLast, opts, ctx2);
37085
+ if (g2.code.length > before && !isLast) g2.addRaw("\n");
37086
+ };
37087
+ for (let i = 0; i < units.length; i++) {
37088
+ emitUnit(units[i], i === units.length - 1);
37089
+ }
36969
37090
  }
36970
37091
  function emitExpressionBody(g2, source, coreStart, coreEnd, stmts, opts) {
36971
37092
  let pos = coreStart;
@@ -37769,7 +37890,16 @@ declare namespace JSX {
37769
37890
  noscript?: VeskGlobalAttributes;
37770
37891
  template?: VeskGlobalAttributes;
37771
37892
  slot?: VeskGlobalAttributes & { name?: string };
37772
- meta?: VeskGlobalAttributes & { name?: string; content?: string; charSet?: string; httpEquiv?: string };
37893
+ meta?: VeskGlobalAttributes & {
37894
+ name?: string;
37895
+ content?: string;
37896
+ charSet?: string;
37897
+ httpEquiv?: string;
37898
+ // Lowercase aliases \u2014 HTML attribute names are case-insensitive and
37899
+ // real code (and SSR output) writes charset. Keep in sync with the
37900
+ // camelCase members.
37901
+ charset?: string;
37902
+ };
37773
37903
  title?: VeskGlobalAttributes;
37774
37904
  base?: VeskGlobalAttributes & { href?: string; target?: string };
37775
37905
  link?: VeskGlobalAttributes & {
@@ -37781,6 +37911,8 @@ declare namespace JSX {
37781
37911
  crossOrigin?: string;
37782
37912
  integrity?: string;
37783
37913
  type?: string;
37914
+ // Lowercase alias \u2014 see the meta note above.
37915
+ crossorigin?: string | boolean;
37784
37916
  };
37785
37917
  style?: VeskGlobalAttributes & { media?: string };
37786
37918
  script?: VeskGlobalAttributes & {
@@ -37792,6 +37924,8 @@ declare namespace JSX {
37792
37924
  integrity?: string;
37793
37925
  nonce?: string;
37794
37926
  noModule?: boolean | string;
37927
+ // Lowercase aliases \u2014 see the meta note above.
37928
+ crossorigin?: boolean | string;
37795
37929
  };
37796
37930
  svg?: VeskGlobalAttributes & {
37797
37931
  viewBox?: string;
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.34",
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.34",
12
+ "@vesk/compiler": "^0.2.34",
13
+ "@vesk/plugin-tailwind": "^0.2.34",
14
+ "@vesk/runtime": "^0.2.34",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",