@vesk/vesk-cli 0.2.32 → 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 +165 -19
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -2139,15 +2139,27 @@ var init_resource = __esm({
2139
2139
  isServer = () => !!g().__vsk_ssr;
2140
2140
  ssrSink = null;
2141
2141
  DEFAULT_FAILURE_TTL = 1e4;
2142
- useFetch.text = (url, options) => useFetch(() => doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {})).then((r) => r.text()), {
2142
+ useFetch.text = (url, options) => useFetch(async () => {
2143
+ const res = await doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {}));
2144
+ if (!res.ok) throw new HttpError(res.status, res.statusText);
2145
+ return res.text();
2146
+ }, {
2143
2147
  ...options,
2144
2148
  key: options?.key ?? url
2145
2149
  });
2146
- useFetch.json = (url, options) => useFetch(() => doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {})).then((r) => r.json()), {
2150
+ useFetch.json = (url, options) => useFetch(async () => {
2151
+ const res = await doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {}));
2152
+ if (!res.ok) throw new HttpError(res.status, res.statusText);
2153
+ return res.json();
2154
+ }, {
2147
2155
  ...options,
2148
2156
  key: options?.key ?? url
2149
2157
  });
2150
- useFetch.arrayBuffer = (url, options) => useFetch(() => doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {})).then((r) => r.arrayBuffer()), {
2158
+ useFetch.arrayBuffer = (url, options) => useFetch(async () => {
2159
+ const res = await doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {}));
2160
+ if (!res.ok) throw new HttpError(res.status, res.statusText);
2161
+ return res.arrayBuffer();
2162
+ }, {
2151
2163
  ...options,
2152
2164
  key: options?.key ?? url
2153
2165
  });
@@ -36275,6 +36287,23 @@ function getJSXTagName2(el) {
36275
36287
  if (name.type === "JSXNamespacedName") return name.namespace.name + ":" + name.name.name;
36276
36288
  return null;
36277
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
+ }
36278
36307
  function collapseWithMap(value) {
36279
36308
  let out = "";
36280
36309
  const map = [];
@@ -36493,7 +36522,7 @@ function emitJSXAttr(g2, source, attr) {
36493
36522
  g2.add(source.slice(v.start, v.end), v.start, v.end);
36494
36523
  }
36495
36524
  }
36496
- function emitJSXElement(g2, source, el, opts) {
36525
+ function emitJSXElement(g2, source, el, opts, hoist) {
36497
36526
  const op = el.openingElement;
36498
36527
  const name = op.name;
36499
36528
  let prev;
@@ -36519,7 +36548,7 @@ function emitJSXElement(g2, source, el, opts) {
36519
36548
  g2.add(tail, prev, op.end);
36520
36549
  }
36521
36550
  if (op.selfClosing) return;
36522
- emitJSXChildren(g2, source, el.children ?? [], opts);
36551
+ emitJSXChildren(g2, source, el.children ?? [], opts, hoist);
36523
36552
  if (el.closingElement) {
36524
36553
  g2.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
36525
36554
  }
@@ -36529,9 +36558,9 @@ function emitJSXExprBody(g2, source, expr, opts) {
36529
36558
  if (expr.type === "JSXFragment") return emitJSXFragment(g2, source, expr, opts);
36530
36559
  g2.add(source.slice(expr.start, expr.end), expr.start, expr.end);
36531
36560
  }
36532
- function emitJSXFragment(g2, source, frag, opts) {
36561
+ function emitJSXFragment(g2, source, frag, opts, hoist) {
36533
36562
  g2.addRaw("<>");
36534
- emitJSXChildren(g2, source, frag.children ?? [], opts);
36563
+ emitJSXChildren(g2, source, frag.children ?? [], opts, hoist);
36535
36564
  g2.addRaw("</>");
36536
36565
  }
36537
36566
  function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
@@ -36582,7 +36611,7 @@ function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, e
36582
36611
  }
36583
36612
  return true;
36584
36613
  }
36585
- function emitJSXChildren(g2, source, children, opts) {
36614
+ function emitJSXChildren(g2, source, children, opts, hoist) {
36586
36615
  let i = 0;
36587
36616
  let forPending = false;
36588
36617
  while (i < children.length) {
@@ -36664,7 +36693,7 @@ function emitJSXChildren(g2, source, children, opts) {
36664
36693
  continue;
36665
36694
  }
36666
36695
  forPending = false;
36667
- g2.add(text, child.start, child.end);
36696
+ emitJSXText(g2, text, child.start, child.end);
36668
36697
  i++;
36669
36698
  } else if (child.type === "JSXExpressionContainer") {
36670
36699
  if (child.expression.type === "JSXEmptyExpression") {
@@ -36683,12 +36712,16 @@ function emitJSXChildren(g2, source, children, opts) {
36683
36712
  i++;
36684
36713
  continue;
36685
36714
  }
36686
- emitJSXElement(g2, source, child, opts);
36715
+ emitJSXElement(g2, source, child, opts, hoist);
36687
36716
  i++;
36688
36717
  } else if (child.type === "JSXFragment") {
36689
- emitJSXFragment(g2, source, child, opts);
36718
+ emitJSXFragment(g2, source, child, opts, hoist);
36690
36719
  i++;
36691
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
+ }
36692
36725
  g2.addRaw("{(() => { ");
36693
36726
  emitBody(g2, source, [child], "", opts);
36694
36727
  g2.addRaw(" })()}");
@@ -36805,7 +36838,7 @@ function emitPlainStatement(g2, source, stmt, indent4, isLast) {
36805
36838
  g2.add(text, stmt.start, stmt.end);
36806
36839
  if (!text.endsWith("}") && !isLast) g2.addRaw(";");
36807
36840
  }
36808
- function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36841
+ function emitStatement(g2, source, stmt, indent4, isLast, opts, hoist) {
36809
36842
  switch (stmt.type) {
36810
36843
  case "JSXElement":
36811
36844
  if (getJSXTagName2(stmt) === "style") {
@@ -36815,12 +36848,12 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36815
36848
  return;
36816
36849
  }
36817
36850
  g2.add(indent4);
36818
- emitJSXElement(g2, source, stmt, opts);
36851
+ emitJSXElement(g2, source, stmt, opts, hoist);
36819
36852
  if (!isLast) g2.addRaw(";");
36820
36853
  return;
36821
36854
  case "JSXFragment":
36822
36855
  g2.add(indent4);
36823
- emitJSXFragment(g2, source, stmt, opts);
36856
+ emitJSXFragment(g2, source, stmt, opts, hoist);
36824
36857
  if (!isLast) g2.addRaw(";");
36825
36858
  return;
36826
36859
  case "JSXExpressionContainer": {
@@ -36838,7 +36871,7 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36838
36871
  let firstLine = true;
36839
36872
  for (let i = 0; i < innerStmts.length; i++) {
36840
36873
  const before = g2.code.length;
36841
- 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);
36842
36875
  if (g2.code.length > before) {
36843
36876
  if (!firstLine) g2.addRaw("\n");
36844
36877
  firstLine = false;
@@ -36879,7 +36912,7 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts) {
36879
36912
  return emitPlainStatement(g2, source, stmt, indent4, isLast);
36880
36913
  }
36881
36914
  }
36882
- function emitBody(g2, source, stmts, indent4, opts) {
36915
+ function emitBody(g2, source, stmts, indent4, opts, hoist) {
36883
36916
  let firstLine = true;
36884
36917
  let i = 0;
36885
36918
  while (i < stmts.length) {
@@ -36906,7 +36939,7 @@ function emitBody(g2, source, stmts, indent4, opts) {
36906
36939
  continue;
36907
36940
  }
36908
36941
  const before = g2.code.length;
36909
- emitStatement(g2, source, stmt, indent4, isLast, opts);
36942
+ emitStatement(g2, source, stmt, indent4, isLast, opts, hoist);
36910
36943
  if (g2.code.length > before) {
36911
36944
  if (!firstLine) g2.addRaw("\n");
36912
36945
  firstLine = false;
@@ -36952,8 +36985,108 @@ function emitReturn(g2, source, stmt, opts) {
36952
36985
  else emitChunkMapped(g2, source, arg.start, arg.end);
36953
36986
  emitChunkMapped(g2, source, arg.end, stmt.end);
36954
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
+ }
36955
37006
  function emitBodyCore(g2, source, stmts, opts) {
36956
- 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
+ }
36957
37090
  }
36958
37091
  function emitExpressionBody(g2, source, coreStart, coreEnd, stmts, opts) {
36959
37092
  let pos = coreStart;
@@ -37757,7 +37890,16 @@ declare namespace JSX {
37757
37890
  noscript?: VeskGlobalAttributes;
37758
37891
  template?: VeskGlobalAttributes;
37759
37892
  slot?: VeskGlobalAttributes & { name?: string };
37760
- 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
+ };
37761
37903
  title?: VeskGlobalAttributes;
37762
37904
  base?: VeskGlobalAttributes & { href?: string; target?: string };
37763
37905
  link?: VeskGlobalAttributes & {
@@ -37769,6 +37911,8 @@ declare namespace JSX {
37769
37911
  crossOrigin?: string;
37770
37912
  integrity?: string;
37771
37913
  type?: string;
37914
+ // Lowercase alias \u2014 see the meta note above.
37915
+ crossorigin?: string | boolean;
37772
37916
  };
37773
37917
  style?: VeskGlobalAttributes & { media?: string };
37774
37918
  script?: VeskGlobalAttributes & {
@@ -37780,6 +37924,8 @@ declare namespace JSX {
37780
37924
  integrity?: string;
37781
37925
  nonce?: string;
37782
37926
  noModule?: boolean | string;
37927
+ // Lowercase aliases \u2014 see the meta note above.
37928
+ crossorigin?: boolean | string;
37783
37929
  };
37784
37930
  svg?: VeskGlobalAttributes & {
37785
37931
  viewBox?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.32",
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.32",
12
- "@vesk/compiler": "^0.2.32",
13
- "@vesk/plugin-tailwind": "^0.2.32",
14
- "@vesk/runtime": "^0.2.32",
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",