@vesk/vesk-cli 0.2.43 → 0.2.45

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 +990 -525
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -184,21 +184,36 @@ var init_errors = __esm({
184
184
  tip: isBuiltin ? `"${name}" is a Vesk built-in. Use it directly \u2014 no manual import needed.` : ""
185
185
  });
186
186
  }
187
- static vskNamespaceTag(context = {}) {
187
+ /**
188
+ * A `.vsk` namespace is resolved at the JSX-tag level: `<ns.Icon />` looks
189
+ * the component up in the registry by its exported name, exactly like
190
+ * `import { Icon }`, and no module object is ever built. The two forms that
191
+ * genuinely need a real module object are reported here.
192
+ *
193
+ * - `nested` — `<ns.Sub.Icon />`. A `.vsk` module's exports are flat
194
+ * component names, so there is no object to walk into.
195
+ * - `value` — `ns.max` read as a value. Component tags resolve; plain value
196
+ * reads do not, because nothing binds `ns` at runtime.
197
+ */
198
+ static vskNamespaceMember(context = {}) {
199
+ const nested = context.form === "nested";
188
200
  return new _VeskError(
189
- "Namespace imports are not supported for `.vsk` modules.",
201
+ nested ? "A `.vsk` namespace is flat, so `<ns.Sub.Icon />` cannot be resolved." : "A `.vsk` namespace resolves component tags only, so `ns.value` is not available.",
190
202
  {
191
203
  ...context,
192
204
  code: context.code || "V0410",
193
- suggestions: [
194
- "Import the component by name: import { MyIcon } from './icons.vsk'",
195
- "Rename on import: import { MyIcon as Icon } from './icons.vsk'"
205
+ suggestions: nested ? [
206
+ "Import the component by name: import { Icon } from './icons.vsk'",
207
+ "Import from the module that owns Sub: import * as Sub from './sub.vsk'"
208
+ ] : [
209
+ "Import the value by name: import { MAX } from './constants.vsk'",
210
+ "Move the value into a .ts module and import it from there \u2014 those are real ES modules with live bindings."
196
211
  ],
197
212
  nextSteps: [
198
- "A `.vsk` component is a registry entry keyed by its name, not a module namespace object, so `<ns.Icon />` cannot be resolved.",
199
- "If you need a namespace object, import from a `.ts`/`.js` module instead \u2014 those are real ES modules."
213
+ "A `.vsk` tag resolves by component name in the global registry, not by module exports, so `import * as ns` + `<ns.Icon />` needs no module object.",
214
+ nested ? "Re-export with a flat name (`export { Icon }`) or import the component directly." : "Re-export the value under a flat name and import it directly, or keep the value in a .ts module."
200
215
  ],
201
- tip: "A `.vsk` module exposes its components as named exports; use a named or renamed import rather than `import * as ns`."
216
+ tip: "`<ns.Icon />` works; only nested paths and value reads need a real module namespace."
202
217
  }
203
218
  );
204
219
  }
@@ -1644,11 +1659,11 @@ var init_context = __esm({
1644
1659
 
1645
1660
  // ../runtime/src/server-events.ts
1646
1661
  function getStore() {
1647
- const g2 = globalThis;
1648
- if (!g2.__vesk_server_ctx || typeof g2.__vesk_server_ctx !== "object") {
1649
- g2.__vesk_server_ctx = {};
1662
+ const g4 = globalThis;
1663
+ if (!g4.__vesk_server_ctx || typeof g4.__vesk_server_ctx !== "object") {
1664
+ g4.__vesk_server_ctx = {};
1650
1665
  }
1651
- return g2.__vesk_server_ctx;
1666
+ return g4.__vesk_server_ctx;
1652
1667
  }
1653
1668
  function server_locals() {
1654
1669
  return getStore();
@@ -2638,9 +2653,9 @@ function createHydrateWalker(container, markerList) {
2638
2653
  }
2639
2654
  function bumpNavEpoch() {
2640
2655
  try {
2641
- const g2 = globalThis;
2642
- const next = (g2.__vesk_nav_epoch || 0) + 1;
2643
- g2.__vesk_nav_epoch = next;
2656
+ const g4 = globalThis;
2657
+ const next = (g4.__vesk_nav_epoch || 0) + 1;
2658
+ g4.__vesk_nav_epoch = next;
2644
2659
  return next;
2645
2660
  } catch {
2646
2661
  return 0;
@@ -5320,8 +5335,8 @@ function createRouter(routes, options = {}) {
5320
5335
  },
5321
5336
  _runGuards(to) {
5322
5337
  const from = get(_state.path) || window.location.pathname;
5323
- for (const g2 of this._beforeGuards ?? []) {
5324
- const d = g2(to, from);
5338
+ for (const g4 of this._beforeGuards ?? []) {
5339
+ const d = g4(to, from);
5325
5340
  if (d instanceof Promise) {
5326
5341
  return d.then((r) => {
5327
5342
  if (r === false || typeof r === "string") return r;
@@ -5647,8 +5662,8 @@ function createFileRouter(routeTree, options = {}) {
5647
5662
  },
5648
5663
  _runGuards(to) {
5649
5664
  const from = get(_state.path) || window.location.pathname;
5650
- for (const g2 of this._beforeGuards ?? []) {
5651
- const d = g2(to, from);
5665
+ for (const g4 of this._beforeGuards ?? []) {
5666
+ const d = g4(to, from);
5652
5667
  if (d instanceof Promise) {
5653
5668
  return d.then((r) => {
5654
5669
  if (r === false || typeof r === "string") return r;
@@ -20181,17 +20196,125 @@ function jsxTagRootName(nameNode) {
20181
20196
  while (node && node.type === "JSXMemberExpression") node = node.object;
20182
20197
  return node && node.type === "JSXIdentifier" ? node.name : "";
20183
20198
  }
20199
+ function jsxTagMemberName(nameNode) {
20200
+ let node = nameNode;
20201
+ while (node && node.type === "JSXMemberExpression") {
20202
+ node = node.property;
20203
+ if (node && node.type === "JSXIdentifier") return node.name;
20204
+ }
20205
+ return "";
20206
+ }
20207
+ function jsxTagDepth(nameNode) {
20208
+ let depth = 0;
20209
+ let node = nameNode;
20210
+ while (node && node.type === "JSXMemberExpression") {
20211
+ depth++;
20212
+ node = node.object;
20213
+ }
20214
+ return depth;
20215
+ }
20184
20216
  function collectVskNamespaceLocals(ast) {
20185
- const out = /* @__PURE__ */ new Set();
20217
+ const namespaceLocals = /* @__PURE__ */ new Map();
20186
20218
  for (const node of ast.body || []) {
20187
20219
  if (node.type !== "ImportDeclaration") continue;
20188
20220
  if (typeof node.source?.value !== "string" || !node.source.value.endsWith(".vsk")) continue;
20189
20221
  for (const spec of node.specifiers || []) {
20190
- if (spec.type === "ImportNamespaceSpecifier" && spec.local?.name) out.add(spec.local.name);
20222
+ if (spec.type === "ImportNamespaceSpecifier" && spec.local?.name) {
20223
+ namespaceLocals.set(spec.local.name, { path: node.source.value, shadowed: false });
20224
+ }
20225
+ }
20226
+ }
20227
+ if (namespaceLocals.size === 0) return /* @__PURE__ */ new Set();
20228
+ markShadowedBindings(ast, namespaceLocals);
20229
+ return new Set([...namespaceLocals].filter(([, v]) => !v.shadowed).map(([k]) => k));
20230
+ }
20231
+ function markShadowedBindings(node, namespaceLocals) {
20232
+ if (!node || typeof node !== "object") return;
20233
+ if (Array.isArray(node)) {
20234
+ for (const child of node) markShadowedBindings(child, namespaceLocals);
20235
+ return;
20236
+ }
20237
+ if (typeof node.type === "string") {
20238
+ if (node.type === "ImportNamespaceSpecifier") return;
20239
+ for (const name of declaredBindingNames(node)) {
20240
+ const entry = namespaceLocals.get(name);
20241
+ if (entry) entry.shadowed = true;
20191
20242
  }
20192
20243
  }
20244
+ for (const key of Object.keys(node)) {
20245
+ if (key === "loc" || key === "range" || key === "start" || key === "end") continue;
20246
+ markShadowedBindings(node[key], namespaceLocals);
20247
+ }
20248
+ }
20249
+ function declaredBindingNames(node) {
20250
+ const out = [];
20251
+ const pushPattern = (id) => {
20252
+ if (!id) return;
20253
+ if (id.type === "Identifier") {
20254
+ out.push(id.name);
20255
+ return;
20256
+ }
20257
+ if (id.type === "ObjectPattern") {
20258
+ for (const prop of id.properties || []) {
20259
+ if (prop.type === "RestElement") pushPattern(prop.argument);
20260
+ else pushPattern(prop.value);
20261
+ }
20262
+ return;
20263
+ }
20264
+ if (id.type === "ArrayPattern") {
20265
+ for (const el of id.elements || []) if (el) pushPattern(el.type === "RestElement" ? el.argument : el);
20266
+ return;
20267
+ }
20268
+ if (id.type === "AssignmentPattern") pushPattern(id.left);
20269
+ if (id.type === "RestElement") pushPattern(id.argument);
20270
+ };
20271
+ switch (node.type) {
20272
+ case "VariableDeclarator":
20273
+ pushPattern(node.id);
20274
+ break;
20275
+ case "FunctionDeclaration":
20276
+ case "FunctionExpression":
20277
+ case "ArrowFunctionExpression":
20278
+ if (node.id) pushPattern(node.id);
20279
+ for (const param of node.params || []) pushPattern(param);
20280
+ break;
20281
+ case "ClassDeclaration":
20282
+ case "ClassExpression":
20283
+ if (node.id) pushPattern(node.id);
20284
+ break;
20285
+ case "CatchClause":
20286
+ pushPattern(node.param);
20287
+ break;
20288
+ default:
20289
+ break;
20290
+ }
20193
20291
  return out;
20194
20292
  }
20293
+ function assertNoVskNamespaceValue(source, expr) {
20294
+ if (!currentVskNamespaceLocals || currentVskNamespaceLocals.size === 0) return;
20295
+ const hit = findNamespaceValueUse(expr, currentVskNamespaceLocals);
20296
+ if (!hit) return;
20297
+ const { line, column } = offsetToLineCol2(source, hit.start ?? 0);
20298
+ throw VeskError.vskNamespaceMember({ file: currentSourceFile, line, column, code: codeFrame(source, line, column), form: "value" });
20299
+ }
20300
+ function findNamespaceValueUse(node, locals2) {
20301
+ if (!node || typeof node !== "object") return null;
20302
+ if (Array.isArray(node)) {
20303
+ for (const child of node) {
20304
+ const hit = findNamespaceValueUse(child, locals2);
20305
+ if (hit) return hit;
20306
+ }
20307
+ return null;
20308
+ }
20309
+ if (typeof node.type !== "string") return null;
20310
+ if (node.type === "MemberExpression" && node.object?.type === "Identifier" && locals2.has(node.object.name)) return node;
20311
+ for (const key of Object.keys(node)) {
20312
+ if (key === "loc" || key === "range" || key === "start" || key === "end") continue;
20313
+ const hit = findNamespaceValueUse(node[key], locals2);
20314
+ if (hit) return hit;
20315
+ }
20316
+ return null;
20317
+ }
20195
20318
  function isHTMLTag(name) {
20196
20319
  return name.length > 0 && name[0] === name[0].toLowerCase();
20197
20320
  }
@@ -20199,6 +20322,7 @@ function isMapCall(expr) {
20199
20322
  return expr.type === "CallExpression" && expr.callee.type === "MemberExpression" && expr.callee.property.name === "map" && expr.arguments.length === 1 && expr.arguments[0].type === "ArrowFunctionExpression";
20200
20323
  }
20201
20324
  function toExpression(source, expr) {
20325
+ assertNoVskNamespaceValue(source, expr);
20202
20326
  return new Expression(getSource(source, expr), [], expr, source);
20203
20327
  }
20204
20328
  function processAttribute(source, attr) {
@@ -20561,12 +20685,16 @@ function processJSXElement(source, element) {
20561
20685
  }
20562
20686
  if (nameNode && nameNode.type === "JSXMemberExpression") {
20563
20687
  const root3 = jsxTagRootName(nameNode);
20564
- if (currentVskNamespaceLocals && currentVskNamespaceLocals.has(root3)) {
20688
+ const isVskNamespace = !!currentVskNamespaceLocals && currentVskNamespaceLocals.has(root3);
20689
+ if (isVskNamespace && jsxTagDepth(nameNode) > 1) {
20565
20690
  const { line, column } = offsetToLineCol2(source, nameNode.start ?? 0);
20566
- throw VeskError.vskNamespaceTag({ file: currentSourceFile, line, column, code: codeFrame(source, line, column) });
20691
+ throw VeskError.vskNamespaceMember({ file: currentSourceFile, line, column, code: codeFrame(source, line, column), form: "nested" });
20567
20692
  }
20568
20693
  const { props, spreadProps, slots } = extractProps(source, element);
20569
20694
  const children2 = selfClosing ? [] : processJSXChildren(source, element.children || []);
20695
+ if (isVskNamespace) {
20696
+ return [new ComponentCall(jsxTagMemberName(nameNode), props, [...children2, ...slots.map((s) => new PropSlot(s.name, s.nodes))], spreadProps, element.start)];
20697
+ }
20570
20698
  return [new ComponentCall(tagName, props, [...children2, ...slots.map((s) => new PropSlot(s.name, s.nodes))], spreadProps, element.start, getSource(source, nameNode))];
20571
20699
  }
20572
20700
  if (!isHTMLTag(tagName) && selfClosing) {
@@ -21621,16 +21749,16 @@ function sha256Bytes(msg) {
21621
21749
  const s1 = rr(w[j - 2], 17) ^ rr(w[j - 2], 19) ^ w[j - 2] >>> 10;
21622
21750
  w[j] = w[j - 16] + s0 + w[j - 7] + s1 >>> 0;
21623
21751
  }
21624
- let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g2 = h6, h = h7;
21752
+ let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g4 = h6, h = h7;
21625
21753
  for (let j = 0; j < 64; j++) {
21626
21754
  const S1 = rr(e, 6) ^ rr(e, 11) ^ rr(e, 25);
21627
- const ch = e & f ^ ~e & g2;
21755
+ const ch = e & f ^ ~e & g4;
21628
21756
  const t1 = h + S1 + ch + SHA_K[j] + w[j] >>> 0;
21629
21757
  const S0 = rr(a, 2) ^ rr(a, 13) ^ rr(a, 22);
21630
21758
  const maj = a & b ^ a & c ^ b & c;
21631
21759
  const t2 = S0 + maj >>> 0;
21632
- h = g2;
21633
- g2 = f;
21760
+ h = g4;
21761
+ g4 = f;
21634
21762
  f = e;
21635
21763
  e = d + t1 >>> 0;
21636
21764
  d = c;
@@ -21644,7 +21772,7 @@ function sha256Bytes(msg) {
21644
21772
  h3 = h3 + d >>> 0;
21645
21773
  h4 = h4 + e >>> 0;
21646
21774
  h5 = h5 + f >>> 0;
21647
- h6 = h6 + g2 >>> 0;
21775
+ h6 = h6 + g4 >>> 0;
21648
21776
  h7 = h7 + h >>> 0;
21649
21777
  }
21650
21778
  const out = new Uint8Array(32);
@@ -22695,23 +22823,23 @@ async function _getImpl() {
22695
22823
  return _signImpl;
22696
22824
  }
22697
22825
  async function signCookie2(name, value, host) {
22698
- const impl = await _getImpl();
22699
- if (impl.signCookie) return impl.signCookie(name, value, host);
22826
+ const impl3 = await _getImpl();
22827
+ if (impl3.signCookie) return impl3.signCookie(name, value, host);
22700
22828
  throw new Error("signCookie: @vesk/compiler not available");
22701
22829
  }
22702
22830
  async function unsignCookie2(name, signedValue, host) {
22703
- const impl = await _getImpl();
22704
- if (impl.unsignCookie) return impl.unsignCookie(name, signedValue, host);
22831
+ const impl3 = await _getImpl();
22832
+ if (impl3.unsignCookie) return impl3.unsignCookie(name, signedValue, host);
22705
22833
  throw new Error("unsignCookie: @vesk/compiler not available");
22706
22834
  }
22707
22835
  async function setSignedCookie2(name, value, options = {}, host) {
22708
- const impl = await _getImpl();
22709
- if (impl.setSignedCookie) return impl.setSignedCookie(name, value, options, host);
22836
+ const impl3 = await _getImpl();
22837
+ if (impl3.setSignedCookie) return impl3.setSignedCookie(name, value, options, host);
22710
22838
  throw new Error("setSignedCookie: @vesk/compiler not available");
22711
22839
  }
22712
22840
  async function readSignedCookie2(name, cookieString, host) {
22713
- const impl = await _getImpl();
22714
- if (impl.readSignedCookie) return impl.readSignedCookie(name, cookieString, host);
22841
+ const impl3 = await _getImpl();
22842
+ if (impl3.readSignedCookie) return impl3.readSignedCookie(name, cookieString, host);
22715
22843
  throw new Error("readSignedCookie: @vesk/compiler not available");
22716
22844
  }
22717
22845
  var ServerRequest, ServerResponse, DEFAULT_MAX_BODY_BYTES2, PayloadTooLargeError, VeskRequest, _VeskResponse, VeskResponse, _signImpl;
@@ -26227,9 +26355,9 @@ var init_primitive = __esm({
26227
26355
 
26228
26356
  // ../runtime/src/action.ts
26229
26357
  function getActionRegistry() {
26230
- const g2 = globalThis;
26231
- if (!g2[registryKey]) g2[registryKey] = {};
26232
- return g2[registryKey];
26358
+ const g4 = globalThis;
26359
+ if (!g4[registryKey]) g4[registryKey] = {};
26360
+ return g4[registryKey];
26233
26361
  }
26234
26362
  function hashString(str3) {
26235
26363
  let h1 = 2166136261;
@@ -26267,8 +26395,8 @@ function getAction(id) {
26267
26395
  return getActionRegistry()[id] || null;
26268
26396
  }
26269
26397
  function clearActions() {
26270
- const g2 = globalThis;
26271
- g2[registryKey] = {};
26398
+ const g4 = globalThis;
26399
+ g4[registryKey] = {};
26272
26400
  }
26273
26401
  function isFormAction(action) {
26274
26402
  return typeof action === "object" && action !== null && (action.__veskAction === true || typeof action.id === "string" && typeof action.url === "string");
@@ -30999,15 +31127,23 @@ function compileClientBoth(source, _componentName, sourcePath2, opts) {
30999
31127
  const comp = emitClientFromIR(ir, { forceClient: true, nameAllocator: alloc });
31000
31128
  const aliases = vskRegistryAliases(ir.imports, ir.exportAliases);
31001
31129
  const reexportPaths = sourcePath2 ? collectVskReexportPaths(ir.reexportSources, sourcePath2) : [];
31002
- if (opts?.skipHyd) return { comp, hyd: "", name, aliases, reexportPaths };
31130
+ if (opts?.skipHyd) return { comp, hyd: "", name, aliases, reexportPaths, componentNames: ir.components.map((c) => c.name) };
31003
31131
  return {
31004
31132
  comp,
31005
31133
  hyd: emitClientFromIR(irHyd, { forceClient: true, hydrate: true, includeTopLevel: false, nameAllocator: alloc, markerless: opts?.markerless !== false }),
31006
31134
  name,
31007
31135
  aliases,
31008
- reexportPaths
31136
+ reexportPaths,
31137
+ // Every component NAME this file registers, not just the resolved one —
31138
+ // the bundle needs the full list to spot same-name declarations across
31139
+ // files (see findVskComponentCollisions).
31140
+ componentNames: ir.components.map((c) => c.name)
31009
31141
  };
31010
31142
  }
31143
+ function vskComponentNames(source, sourcePath2) {
31144
+ const ast = parse4(source, sourcePath2 ? { filename: sourcePath2 } : {});
31145
+ return generateIR(ast, source, sourcePath2).components.map((c) => c.name);
31146
+ }
31011
31147
  var BINDING_REF_CALLS, NON_BUBBLING_EVENTS, Ctx, PROPERTY_ATTRS;
31012
31148
  var init_client_codegen = __esm({
31013
31149
  "../compiler/src/client-codegen.ts"() {
@@ -31608,35 +31744,159 @@ var init_server_jsgen = __esm({
31608
31744
 
31609
31745
  // ../compiler/src/ssr-store.ts
31610
31746
  import { AsyncLocalStorage } from "node:async_hooks";
31747
+ function newSsrToken() {
31748
+ return Math.random().toString(36).slice(2);
31749
+ }
31750
+ function createSsrStore() {
31751
+ return { token: newSsrToken(), data: {} };
31752
+ }
31753
+ function adoptSsrStore() {
31754
+ return storage.getStore() ?? createSsrStore();
31755
+ }
31756
+ function isThenable(value) {
31757
+ return typeof value?.then === "function";
31758
+ }
31611
31759
  function withSsrStore(fn) {
31612
31760
  const existing = storage.getStore();
31613
31761
  if (existing) return fn();
31614
- return storage.run({}, fn);
31762
+ const store = createSsrStore();
31763
+ keepSsrSlot(store.token);
31764
+ let result;
31765
+ try {
31766
+ result = storage.run(store, fn);
31767
+ } catch (err) {
31768
+ dropSsrSlot(store.token);
31769
+ throw err;
31770
+ }
31771
+ if (isThenable(result)) {
31772
+ return result.then(
31773
+ (value) => {
31774
+ dropSsrSlot(store.token);
31775
+ return value;
31776
+ },
31777
+ (err) => {
31778
+ dropSsrSlot(store.token);
31779
+ throw err;
31780
+ }
31781
+ );
31782
+ }
31783
+ dropSsrSlot(store.token);
31784
+ return result;
31615
31785
  }
31616
- var storage, ssrSink2;
31786
+ function withSsrStoreOf(store, fn) {
31787
+ return storage.run(store, fn);
31788
+ }
31789
+ function keepSsrSlot(token) {
31790
+ if (!token) return;
31791
+ liveSlots.set(token, (liveSlots.get(token) ?? 0) + 1);
31792
+ }
31793
+ function dropSsrSlot(token) {
31794
+ if (!token) return;
31795
+ const count = liveSlots.get(token);
31796
+ if (count === void 0) return;
31797
+ if (count <= 1) liveSlots.delete(token);
31798
+ else liveSlots.set(token, count - 1);
31799
+ }
31800
+ function isSsrSlotLive(token) {
31801
+ return liveSlots.has(token);
31802
+ }
31803
+ var TOKEN_KEY, IMPL_KEY, g2, impl, storage, liveSlots, ssrSink2;
31617
31804
  var init_ssr_store = __esm({
31618
31805
  "../compiler/src/ssr-store.ts"() {
31619
31806
  "use strict";
31620
31807
  init_index_server();
31621
- storage = new AsyncLocalStorage();
31808
+ TOKEN_KEY = "__vsk_ssr_token";
31809
+ IMPL_KEY = "__vsk_ssr_store_impl";
31810
+ g2 = globalThis;
31811
+ impl = g2[IMPL_KEY] ?? (g2[IMPL_KEY] = {
31812
+ storage: new AsyncLocalStorage(),
31813
+ liveSlots: /* @__PURE__ */ new Map(),
31814
+ // Only the copy that created the implementation installs the token
31815
+ // accessor; a later copy must not redefine it over the shared storage.
31816
+ ownsAccessor: true
31817
+ });
31818
+ storage = impl.storage;
31819
+ liveSlots = impl.liveSlots;
31622
31820
  ssrSink2 = {
31623
31821
  set: (key, value) => {
31624
31822
  const store = storage.getStore();
31625
- if (store) store[key] = value;
31823
+ if (store) store.data[key] = value;
31626
31824
  },
31627
31825
  get: (key) => {
31628
31826
  const store = storage.getStore();
31629
- return store ? store[key] : void 0;
31827
+ return store ? store.data[key] : void 0;
31630
31828
  },
31631
- snapshot: () => ({ ...storage.getStore() ?? {} }),
31829
+ snapshot: () => ({ ...storage.getStore()?.data ?? {} }),
31632
31830
  clear: () => {
31633
31831
  const store = storage.getStore();
31634
31832
  if (store) {
31635
- for (const key of Object.keys(store)) delete store[key];
31833
+ for (const key of Object.keys(store.data)) delete store.data[key];
31636
31834
  }
31637
31835
  }
31638
31836
  };
31639
31837
  setSsrSink(ssrSink2);
31838
+ if (impl.ownsAccessor) {
31839
+ Object.defineProperty(globalThis, TOKEN_KEY, {
31840
+ configurable: true,
31841
+ get() {
31842
+ return storage.getStore()?.token;
31843
+ },
31844
+ set(value) {
31845
+ const store = storage.getStore();
31846
+ if (store) store.token = value;
31847
+ }
31848
+ });
31849
+ }
31850
+ }
31851
+ });
31852
+
31853
+ // ../compiler/src/vsk-collision.ts
31854
+ var VskComponentOwners, reportedCollisions;
31855
+ var init_vsk_collision = __esm({
31856
+ "../compiler/src/vsk-collision.ts"() {
31857
+ "use strict";
31858
+ VskComponentOwners = class {
31859
+ owners = /* @__PURE__ */ new Map();
31860
+ /** Records that `file` declares a component called `name`. */
31861
+ claim(name, file) {
31862
+ let set2 = this.owners.get(name);
31863
+ if (!set2) {
31864
+ set2 = /* @__PURE__ */ new Set();
31865
+ this.owners.set(name, set2);
31866
+ }
31867
+ set2.add(file);
31868
+ }
31869
+ /** Names declared by more than one file, each with its declaring files. */
31870
+ collisions() {
31871
+ const out = [];
31872
+ for (const [name, files] of this.owners) {
31873
+ if (files.size > 1) out.push({ name, files: [...files] });
31874
+ }
31875
+ return out.sort((a, b) => a.name.localeCompare(b.name));
31876
+ }
31877
+ /**
31878
+ * Warns once per colliding name. Returns the message per collision so a
31879
+ * caller (or a test) can assert on the text without capturing stderr.
31880
+ *
31881
+ * Deduped by name for the life of the process: the SSR path compiles one
31882
+ * file graph per `compileFile` call, so without this a single build would
31883
+ * repeat the same warning once per entry page.
31884
+ */
31885
+ report(context) {
31886
+ const collisions = this.collisions();
31887
+ const fresh = [];
31888
+ for (const { name, files } of collisions) {
31889
+ if (reportedCollisions.has(name)) continue;
31890
+ reportedCollisions.add(name);
31891
+ fresh.push(`${name}: ${files.join(", ")}`);
31892
+ console.warn(
31893
+ `[vesk] ${context}: component "${name}" is declared in ${files.length} files and resolves to only one of them \u2014 ${files.join(", ")}. Which one wins depends on compile order, and the client and server registries pick differently, so this can render a different component in the browser than in the SSR HTML. Rename one of them.`
31894
+ );
31895
+ }
31896
+ return fresh;
31897
+ }
31898
+ };
31899
+ reportedCollisions = /* @__PURE__ */ new Set();
31640
31900
  }
31641
31901
  });
31642
31902
 
@@ -31660,9 +31920,12 @@ function scopedVesk(fn, fallback) {
31660
31920
  return fn.__veskScope || fallback;
31661
31921
  }
31662
31922
  function compileFile(source, options) {
31663
- return compileFileInternal(source, options?.sourcePath, /* @__PURE__ */ new Set());
31923
+ const owners = new VskComponentOwners();
31924
+ const result = compileFileInternal(source, options?.sourcePath, /* @__PURE__ */ new Set(), owners);
31925
+ owners.report("SSR");
31926
+ return result;
31664
31927
  }
31665
- function compileFileInternal(source, sourcePath2, seenImportFiles) {
31928
+ function compileFileInternal(source, sourcePath2, seenImportFiles, owners) {
31666
31929
  if (sourcePath2) {
31667
31930
  const dir = dirname7(sourcePath2);
31668
31931
  source = inlineMdImportsFrom(source, sourcePath2, guessProjectRoots(dir));
@@ -31671,6 +31934,7 @@ function compileFileInternal(source, sourcePath2, seenImportFiles) {
31671
31934
  const ir = generateIR(ast, source, sourcePath2);
31672
31935
  const componentMap = buildComponentMap2(ir, true);
31673
31936
  const ownComponentNames = ir.components.map((c) => c.name);
31937
+ if (sourcePath2 && owners) for (const n of ownComponentNames) owners.claim(n, sourcePath2);
31674
31938
  const __vesk = loadRuntimeImports(ir.imports);
31675
31939
  applyLocalModuleImports(__vesk, ir.imports, sourcePath2);
31676
31940
  if (sourcePath2) {
@@ -31687,7 +31951,7 @@ function compileFileInternal(source, sourcePath2, seenImportFiles) {
31687
31951
  } catch {
31688
31952
  continue;
31689
31953
  }
31690
- const sub = compileFileInternal(importedSrc, importPath, seenImportFiles);
31954
+ const sub = compileFileInternal(importedSrc, importPath, seenImportFiles, owners);
31691
31955
  for (const [name, fn] of sub.componentMap) {
31692
31956
  if (!componentMap.has(name)) componentMap.set(name, fn);
31693
31957
  }
@@ -31716,29 +31980,32 @@ function render2(source, componentName, props = {}, registry = /* @__PURE__ */ n
31716
31980
  const targetComp = compiled.ir.components.find((c) => c.name === componentName);
31717
31981
  const isAsyncComp = !!(targetComp && (targetComp.isAsync || targetComp.ssrAwait));
31718
31982
  globalThis.__vsk_ssr = true;
31719
- if (!globalThis.__vsk_ssr_token) globalThis.__vsk_ssr_token = Math.random().toString(36).slice(2);
31720
- const renderToken = globalThis.__vsk_ssr_token;
31721
- if (isAsyncComp) {
31722
- return withSsrStore(() => (async () => {
31723
- let bodyHtml2;
31724
- try {
31725
- bodyHtml2 = await renderFn(props, fullRegistry, scopedVesk(renderFn, __vesk));
31726
- } finally {
31727
- delete globalThis.__vsk_ssr;
31728
- await settleSsrPromises(renderToken);
31729
- clearSsrCells(renderToken);
31730
- }
31731
- return bodyHtml2;
31732
- })());
31733
- }
31734
- let bodyHtml;
31735
- try {
31736
- bodyHtml = withSsrStore(() => renderFn(props, fullRegistry, scopedVesk(renderFn, __vesk)));
31737
- } finally {
31738
- delete globalThis.__vsk_ssr;
31739
- clearSsrCells(renderToken);
31740
- }
31741
- return bodyHtml;
31983
+ return withSsrStore(() => {
31984
+ if (!globalThis.__vsk_ssr_token) globalThis.__vsk_ssr_token = Math.random().toString(36).slice(2);
31985
+ const renderToken = globalThis.__vsk_ssr_token;
31986
+ keepSsrSlot(renderToken);
31987
+ if (isAsyncComp) {
31988
+ return (async () => {
31989
+ let bodyHtml2;
31990
+ try {
31991
+ bodyHtml2 = await renderFn(props, fullRegistry, scopedVesk(renderFn, __vesk));
31992
+ } finally {
31993
+ delete globalThis.__vsk_ssr;
31994
+ await settleSsrPromises(renderToken);
31995
+ clearSsrCells(renderToken);
31996
+ }
31997
+ return bodyHtml2;
31998
+ })();
31999
+ }
32000
+ let bodyHtml;
32001
+ try {
32002
+ bodyHtml = renderFn(props, fullRegistry, scopedVesk(renderFn, __vesk));
32003
+ } finally {
32004
+ delete globalThis.__vsk_ssr;
32005
+ clearSsrCells(renderToken);
32006
+ }
32007
+ return bodyHtml;
32008
+ });
31742
32009
  }
31743
32010
  function renderPage(source, componentName, props = {}, registry = /* @__PURE__ */ new Map(), options = {}) {
31744
32011
  resetVskState(!!options.hydrate, options.markerless !== false);
@@ -31762,9 +32029,10 @@ function renderPage(source, componentName, props = {}, registry = /* @__PURE__ *
31762
32029
  globalThis.__vsk_ssr = true;
31763
32030
  if (!globalThis.__vsk_ssr_token) globalThis.__vsk_ssr_token = Math.random().toString(36).slice(2);
31764
32031
  const renderToken = globalThis.__vsk_ssr_token;
32032
+ keepSsrSlot(renderToken);
31765
32033
  pruneSsrDataSlots();
31766
32034
  if (targetComp && (targetComp.isAsync || targetComp.ssrAwait)) {
31767
- return withSsrStore(() => (async () => {
32035
+ return (async () => {
31768
32036
  let bodyHtml2;
31769
32037
  try {
31770
32038
  bodyHtml2 = await renderFn(ssrProps, fullRegistry, scopedVesk(renderFn, __vesk));
@@ -31778,22 +32046,22 @@ function renderPage(source, componentName, props = {}, registry = /* @__PURE__ *
31778
32046
  head: renderHeadHtml(targetComp, ssrProps),
31779
32047
  props: ssrProps
31780
32048
  };
31781
- })());
32049
+ })();
31782
32050
  }
31783
32051
  let bodyHtml;
31784
32052
  try {
31785
- bodyHtml = withSsrStore(() => renderFn(ssrProps, fullRegistry, scopedVesk(renderFn, __vesk)));
32053
+ bodyHtml = renderFn(ssrProps, fullRegistry, scopedVesk(renderFn, __vesk));
31786
32054
  } finally {
31787
32055
  delete globalThis.__vsk_ssr;
31788
32056
  }
31789
32057
  const headHtml = targetComp ? renderHeadHtml(targetComp, ssrProps) : "";
31790
32058
  const pending = globalThis[`__vsk_ssr_promises_${renderToken}`];
31791
32059
  if (pending && pending.length > 0) {
31792
- return withSsrStore(() => (async () => {
32060
+ return (async () => {
31793
32061
  await settleSsrPromises(renderToken);
31794
32062
  clearSsrCells(renderToken);
31795
32063
  return { body: bodyHtml, head: headHtml, props: ssrProps };
31796
- })());
32064
+ })();
31797
32065
  }
31798
32066
  clearSsrCells(renderToken);
31799
32067
  return { body: bodyHtml, head: headHtml, props: ssrProps };
@@ -31817,6 +32085,7 @@ function clearSsrCells(token) {
31817
32085
  if (!token) return;
31818
32086
  delete globalThis[`__vsk_ssr_promises_${token}`];
31819
32087
  delete globalThis[`__vsk_ssr_failures_${token}`];
32088
+ dropSsrSlot(token);
31820
32089
  const cells = globalThis.__vsk_ssr_cells;
31821
32090
  if (!cells || !(cells instanceof Map)) return;
31822
32091
  for (const k of cells.keys()) {
@@ -31825,16 +32094,28 @@ function clearSsrCells(token) {
31825
32094
  }
31826
32095
  async function settleSsrPromises(token) {
31827
32096
  if (!token) return;
31828
- const pending = globalThis[`__vsk_ssr_promises_${token}`];
31829
- if (!pending || pending.length === 0) return;
31830
- await Promise.allSettled(pending);
32097
+ const key = `__vsk_ssr_promises_${token}`;
32098
+ for (let round = 0; round < 10; round++) {
32099
+ const pending = globalThis[key];
32100
+ if (!pending || pending.length === 0) return;
32101
+ const before = pending.length;
32102
+ await Promise.allSettled(pending.slice());
32103
+ const after = globalThis[key];
32104
+ if (!after || after.length <= before) return;
32105
+ }
31831
32106
  }
31832
32107
  function pruneSsrDataSlots() {
31833
- const g2 = globalThis;
31834
- const keys = Object.keys(g2).filter((k) => typeof k === "string" && k.startsWith("__vsk_ssr_data_"));
31835
- if (keys.length <= 40) return;
31836
- keys.sort().slice(0, keys.length - 40).forEach((k) => {
31837
- delete g2[k];
32108
+ const g4 = globalThis;
32109
+ const prefix = "__vsk_ssr_data_";
32110
+ const stale = [];
32111
+ for (const k of Object.keys(g4)) {
32112
+ if (typeof k !== "string" || !k.startsWith(prefix)) continue;
32113
+ if (isSsrSlotLive(k.slice(prefix.length))) continue;
32114
+ stale.push(k);
32115
+ }
32116
+ if (stale.length <= 40) return;
32117
+ stale.sort().slice(0, stale.length - 40).forEach((k) => {
32118
+ delete g4[k];
31838
32119
  });
31839
32120
  }
31840
32121
  async function applyHeadPlugins(headHtml, plugins, ctx2) {
@@ -31964,6 +32245,7 @@ async function renderFullPage(source, componentName, props = {}, registry = /* @
31964
32245
  globalThis.__vsk_ssr = true;
31965
32246
  if (!globalThis.__vsk_ssr_token) globalThis.__vsk_ssr_token = Math.random().toString(36).slice(2);
31966
32247
  const renderToken = globalThis.__vsk_ssr_token;
32248
+ keepSsrSlot(renderToken);
31967
32249
  pruneSsrDataSlots();
31968
32250
  globalThis.__vsk_ssr_data = {};
31969
32251
  try {
@@ -32040,12 +32322,15 @@ ${dataScriptBlock}${clientScript}</body>
32040
32322
  } finally {
32041
32323
  delete globalThis.__vsk_ssr;
32042
32324
  delete globalThis[`__vsk_ssr_data_${renderToken}`];
32043
- delete globalThis.__vsk_ssr_token;
32325
+ dropSsrSlot(renderToken);
32044
32326
  pruneSsrDataSlots();
32045
32327
  }
32046
32328
  });
32047
32329
  }
32048
32330
  function renderPageStream(source, componentName, props = {}, registry = /* @__PURE__ */ new Map(), options = {}) {
32331
+ const streamStore = adoptSsrStore();
32332
+ keepSsrSlot(streamStore.token);
32333
+ const streamToken = streamStore.token;
32049
32334
  async function* raw2() {
32050
32335
  const cached = options.cached || void 0;
32051
32336
  const ir = cached ? cached.ir : generateIR(parse4(source, options.sourcePath ? { filename: options.sourcePath } : {}), source, options.sourcePath);
@@ -32114,8 +32399,7 @@ function renderPageStream(source, componentName, props = {}, registry = /* @__PU
32114
32399
  yield '</head>\n<body>\n<div id="root">\n';
32115
32400
  globalThis.__vsk_ssr = true;
32116
32401
  globalThis.__vsk_ssr_data = {};
32117
- if (!globalThis.__vsk_ssr_token) globalThis.__vsk_ssr_token = Math.random().toString(36).slice(2);
32118
- const renderToken = globalThis.__vsk_ssr_token;
32402
+ const renderToken = streamToken;
32119
32403
  pruneSsrDataSlots();
32120
32404
  let bodyHtml;
32121
32405
  try {
@@ -32135,7 +32419,7 @@ function renderPageStream(source, componentName, props = {}, registry = /* @__PU
32135
32419
  console.error(`[render-trace] renderPageStream comp=${componentName} keys=${Object.keys(ssrData).join(",") || "\u2205"} slot=${Object.keys(slot).join(",") || "\u2205"} sink=${Object.keys(ssrSink2.snapshot()).join(",") || "\u2205"}`);
32136
32420
  }
32137
32421
  delete globalThis[`__vsk_ssr_data_${renderToken}`];
32138
- delete globalThis.__vsk_ssr_token;
32422
+ dropSsrSlot(renderToken);
32139
32423
  pruneSsrDataSlots();
32140
32424
  const dataScripts = buildDataScripts(ssrProps, ssrData, options.externalDataScript);
32141
32425
  const dataScriptBlock = dataScripts.length > 0 ? "\n" + dataScripts.join("\n") : "";
@@ -32148,11 +32432,20 @@ function renderPageStream(source, componentName, props = {}, registry = /* @__PU
32148
32432
  }
32149
32433
  const gen = raw2();
32150
32434
  async function* scoped() {
32151
- let result;
32152
- do {
32153
- result = await withSsrStore(() => gen.next());
32154
- if (!result.done) yield result.value;
32155
- } while (!result.done);
32435
+ try {
32436
+ let result;
32437
+ do {
32438
+ result = await withSsrStoreOf(streamStore, () => gen.next());
32439
+ if (!result.done) yield result.value;
32440
+ } while (!result.done);
32441
+ } finally {
32442
+ dropSsrSlot(streamToken);
32443
+ delete globalThis[`__vsk_ssr_data_${streamToken}`];
32444
+ delete globalThis[`__vsk_ssr_promises_${streamToken}`];
32445
+ delete globalThis[`__vsk_ssr_failures_${streamToken}`];
32446
+ delete globalThis.__vsk_ssr_data;
32447
+ pruneSsrDataSlots();
32448
+ }
32156
32449
  }
32157
32450
  return scoped();
32158
32451
  }
@@ -32171,6 +32464,7 @@ var init_server_render = __esm({
32171
32464
  init_md_inline();
32172
32465
  init_ssr_store();
32173
32466
  init_module_imports();
32467
+ init_vsk_collision();
32174
32468
  }
32175
32469
  });
32176
32470
 
@@ -33769,7 +34063,7 @@ ${serverStoreLine}
33769
34063
  // SSR already resolved. Entry is consumed on read (bound store).
33770
34064
  if (pathname === '/ssr-data.js') {
33771
34065
  const dataToken = url.searchParams.get('t') || '';
33772
- const dataStore = (globalThis.__vsk_ssr_data_store || {});
34066
+ const dataStore = (globalThis.__vsk_ssr_payload_store || {});
33773
34067
  const payload = dataStore[dataToken];
33774
34068
  if (payload) delete dataStore[dataToken];
33775
34069
  const dataLines = [];
@@ -37334,19 +37628,34 @@ var init_errors2 = __esm({
37334
37628
  tip: isBuiltin ? `"${name}" is a Vesk built-in. Use it directly \u2014 no manual import needed.` : ""
37335
37629
  });
37336
37630
  }
37337
- static vskNamespaceTag(context = {}) {
37338
- return new _VeskError("Namespace imports are not supported for `.vsk` modules.", {
37631
+ /**
37632
+ * A `.vsk` namespace is resolved at the JSX-tag level: `<ns.Icon />` looks
37633
+ * the component up in the registry by its exported name, exactly like
37634
+ * `import { Icon }`, and no module object is ever built. The two forms that
37635
+ * genuinely need a real module object are reported here.
37636
+ *
37637
+ * - `nested` — `<ns.Sub.Icon />`. A `.vsk` module's exports are flat
37638
+ * component names, so there is no object to walk into.
37639
+ * - `value` — `ns.max` read as a value. Component tags resolve; plain value
37640
+ * reads do not, because nothing binds `ns` at runtime.
37641
+ */
37642
+ static vskNamespaceMember(context = {}) {
37643
+ const nested = context.form === "nested";
37644
+ return new _VeskError(nested ? "A `.vsk` namespace is flat, so `<ns.Sub.Icon />` cannot be resolved." : "A `.vsk` namespace resolves component tags only, so `ns.value` is not available.", {
37339
37645
  ...context,
37340
37646
  code: context.code || "V0410",
37341
- suggestions: [
37342
- "Import the component by name: import { MyIcon } from './icons.vsk'",
37343
- "Rename on import: import { MyIcon as Icon } from './icons.vsk'"
37647
+ suggestions: nested ? [
37648
+ "Import the component by name: import { Icon } from './icons.vsk'",
37649
+ "Import from the module that owns Sub: import * as Sub from './sub.vsk'"
37650
+ ] : [
37651
+ "Import the value by name: import { MAX } from './constants.vsk'",
37652
+ "Move the value into a .ts module and import it from there \u2014 those are real ES modules with live bindings."
37344
37653
  ],
37345
37654
  nextSteps: [
37346
- "A `.vsk` component is a registry entry keyed by its name, not a module namespace object, so `<ns.Icon />` cannot be resolved.",
37347
- "If you need a namespace object, import from a `.ts`/`.js` module instead \u2014 those are real ES modules."
37655
+ "A `.vsk` tag resolves by component name in the global registry, not by module exports, so `import * as ns` + `<ns.Icon />` needs no module object.",
37656
+ nested ? "Re-export with a flat name (`export { Icon }`) or import the component directly." : "Re-export the value under a flat name and import it directly, or keep the value in a .ts module."
37348
37657
  ],
37349
- tip: "A `.vsk` module exposes its components as named exports; use a named or renamed import rather than `import * as ns`."
37658
+ tip: "`<ns.Icon />` works; only nested paths and value reads need a real module namespace."
37350
37659
  });
37351
37660
  }
37352
37661
  static classDecl(context = {}) {
@@ -37538,9 +37847,9 @@ function getJSXTagName2(el) {
37538
37847
  if (name.type === "JSXNamespacedName") return name.namespace.name + ":" + name.name.name;
37539
37848
  return null;
37540
37849
  }
37541
- function emitJSXText(g2, text, start, end) {
37850
+ function emitJSXText(g4, text, start, end) {
37542
37851
  if (text.indexOf("<") === -1 && text.indexOf(">") === -1 && text.indexOf("&") === -1 && text.indexOf("{") === -1 && text.indexOf("}") === -1) {
37543
- g2.add(text, start, end);
37852
+ g4.add(text, start, end);
37544
37853
  return;
37545
37854
  }
37546
37855
  let out = "";
@@ -37553,7 +37862,7 @@ function emitJSXText(g2, text, start, end) {
37553
37862
  else if (c === "}") out += "&#125;";
37554
37863
  else out += c;
37555
37864
  }
37556
- g2.add(out, start, end);
37865
+ g4.add(out, start, end);
37557
37866
  }
37558
37867
  function collapseWithMap(value) {
37559
37868
  let out = "";
@@ -37710,31 +38019,31 @@ function stripCallTypeArgs(text) {
37710
38019
  }
37711
38020
  return text;
37712
38021
  }
37713
- function emitTrackDeclStatement(g2, source, stmt, indent4, isLast, opts) {
38022
+ function emitTrackDeclStatement(g4, source, stmt, indent4, isLast, opts) {
37714
38023
  const fullText = stripTrailingSemicolons(source.slice(stmt.start, stmt.end).trimEnd());
37715
38024
  const text = fullText + (!fullText.endsWith("}") && !isLast ? ";" : "");
37716
38025
  const decls = stmt.declarations || [];
37717
- g2.add(indent4);
38026
+ g4.add(indent4);
37718
38027
  let prevEnd = stmt.start;
37719
38028
  for (let di = 0; di < decls.length; di++) {
37720
38029
  const decl = decls[di];
37721
38030
  const id = decl.id;
37722
38031
  const isLazy = id && id.type === "ArrayPattern" && id.lazy === true && decl.init;
37723
38032
  if (!isLazy) {
37724
- g2.addRaw(source.slice(prevEnd, decl.start));
37725
- g2.add(source.slice(decl.start, decl.end), decl.start, decl.end);
38033
+ g4.addRaw(source.slice(prevEnd, decl.start));
38034
+ g4.add(source.slice(decl.start, decl.end), decl.start, decl.end);
37726
38035
  prevEnd = decl.end;
37727
38036
  continue;
37728
38037
  }
37729
- if (di > 0) g2.addRaw(source.slice(prevEnd, decl.start));
38038
+ if (di > 0) g4.addRaw(source.slice(prevEnd, decl.start));
37730
38039
  const ch = text[decl.end - stmt.start] ?? " ";
37731
38040
  const elements = id.elements || [];
37732
38041
  const names = elements.map((el) => el ? el.name : null).filter((n) => typeof n === "string");
37733
38042
  const initText = source.slice(decl.init.start, decl.init.end);
37734
38043
  if (names.length === 0) {
37735
- g2.add("let _ = ");
37736
- g2.add(initText, decl.init.start, decl.init.end);
37737
- if (ch !== ";") g2.addRaw(";");
38044
+ g4.add("let _ = ");
38045
+ g4.add(initText, decl.init.start, decl.init.end);
38046
+ if (ch !== ";") g4.addRaw(";");
37738
38047
  prevEnd = decl.end;
37739
38048
  continue;
37740
38049
  }
@@ -37745,133 +38054,133 @@ function emitTrackDeclStatement(g2, source, stmt, indent4, isLast, opts) {
37745
38054
  const firstRange = [elements[0].start, elements[0].end];
37746
38055
  const dropLastSemi = ch === ";";
37747
38056
  if (opts.typedCells) {
37748
- const cellName = g2.cellCount === 0 ? "__cell" : `__cell${g2.cellCount}`;
37749
- g2.cellCount++;
38057
+ const cellName = g4.cellCount === 0 ? "__cell" : `__cell${g4.cellCount}`;
38058
+ g4.cellCount++;
37750
38059
  if (annotation) {
37751
- g2.add(`const ${cellName}: Tracked<`);
37752
- g2.add(annotation, annStart, annEnd);
37753
- g2.add("> = ");
38060
+ g4.add(`const ${cellName}: Tracked<`);
38061
+ g4.add(annotation, annStart, annEnd);
38062
+ g4.add("> = ");
37754
38063
  } else {
37755
- g2.add(`const ${cellName} = `);
38064
+ g4.add(`const ${cellName} = `);
37756
38065
  }
37757
38066
  const cellInit = annotation ? stripCallTypeArgs(initText) : initText;
37758
- g2.add(cellInit, decl.init.start, decl.init.end);
37759
- g2.add(";");
37760
- g2.add(" let ");
37761
- g2.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
38067
+ g4.add(cellInit, decl.init.start, decl.init.end);
38068
+ g4.add(";");
38069
+ g4.add(" let ");
38070
+ g4.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
37762
38071
  if (annotation) {
37763
- g2.add(": ");
37764
- g2.add(annotation, annStart, annEnd);
38072
+ g4.add(": ");
38073
+ g4.add(annotation, annStart, annEnd);
37765
38074
  }
37766
- g2.add(` = ${cellName}.get();`);
38075
+ g4.add(` = ${cellName}.get();`);
37767
38076
  for (let n = 1; n < names.length; n++) {
37768
- g2.add(" let ");
37769
- g2.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
37770
- g2.add(` = ${cellName};`);
38077
+ g4.add(" let ");
38078
+ g4.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
38079
+ g4.add(` = ${cellName};`);
37771
38080
  }
37772
- if (dropLastSemi) g2.code = g2.code.slice(0, -1);
38081
+ if (dropLastSemi) g4.code = g4.code.slice(0, -1);
37773
38082
  } else {
37774
38083
  if (annotation) {
37775
- g2.add("let ");
37776
- g2.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
37777
- g2.add(": ");
37778
- g2.add(annotation, annStart, annEnd);
37779
- g2.add(" = (");
37780
- g2.add(stripCallTypeArgs(initText), decl.init.start, decl.init.end);
37781
- g2.add(" as unknown as ");
37782
- g2.add(annotation, annStart, annEnd);
37783
- g2.add(");");
38084
+ g4.add("let ");
38085
+ g4.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
38086
+ g4.add(": ");
38087
+ g4.add(annotation, annStart, annEnd);
38088
+ g4.add(" = (");
38089
+ g4.add(stripCallTypeArgs(initText), decl.init.start, decl.init.end);
38090
+ g4.add(" as unknown as ");
38091
+ g4.add(annotation, annStart, annEnd);
38092
+ g4.add(");");
37784
38093
  } else {
37785
- const cellName = g2.cellCount === 0 ? "__cell" : `__cell${g2.cellCount}`;
37786
- g2.cellCount++;
37787
- g2.add(`const ${cellName} = `);
37788
- g2.add(initText, decl.init.start, decl.init.end);
37789
- g2.add("; let ");
37790
- g2.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
37791
- g2.add(` = ${cellName}.get();`);
38094
+ const cellName = g4.cellCount === 0 ? "__cell" : `__cell${g4.cellCount}`;
38095
+ g4.cellCount++;
38096
+ g4.add(`const ${cellName} = `);
38097
+ g4.add(initText, decl.init.start, decl.init.end);
38098
+ g4.add("; let ");
38099
+ g4.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
38100
+ g4.add(` = ${cellName}.get();`);
37792
38101
  }
37793
38102
  for (let n = 1; n < names.length; n++) {
37794
- g2.add(" let ");
37795
- g2.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
37796
- g2.add(": any = ");
37797
- g2.add(first, firstRange[0], firstRange[1]);
37798
- g2.add(";");
37799
- if (n === names.length - 1 && dropLastSemi) g2.code = g2.code.slice(0, -1);
38103
+ g4.add(" let ");
38104
+ g4.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
38105
+ g4.add(": any = ");
38106
+ g4.add(first, firstRange[0], firstRange[1]);
38107
+ g4.add(";");
38108
+ if (n === names.length - 1 && dropLastSemi) g4.code = g4.code.slice(0, -1);
37800
38109
  }
37801
- if (names.length === 1 && dropLastSemi) g2.code = g2.code.slice(0, -1);
38110
+ if (names.length === 1 && dropLastSemi) g4.code = g4.code.slice(0, -1);
37802
38111
  }
37803
38112
  prevEnd = decl.end;
37804
38113
  }
37805
- if (!isLast) g2.addRaw(";");
38114
+ if (!isLast) g4.addRaw(";");
37806
38115
  }
37807
- function emitBlock(g2, source, body, indent4, opts) {
38116
+ function emitBlock(g4, source, body, indent4, opts) {
37808
38117
  const stmts = body && body.type === "BlockStatement" ? body.body : body ? Array.isArray(body) ? body : [body] : [];
37809
- g2.addRaw("{\n");
37810
- emitBody(g2, source, stmts, indent4 + " ", opts);
37811
- g2.addRaw("\n");
37812
- g2.add(indent4);
37813
- g2.addRaw("}");
38118
+ g4.addRaw("{\n");
38119
+ emitBody(g4, source, stmts, indent4 + " ", opts);
38120
+ g4.addRaw("\n");
38121
+ g4.add(indent4);
38122
+ g4.addRaw("}");
37814
38123
  }
37815
- function emitJSXAttr(g2, source, attr) {
38124
+ function emitJSXAttr(g4, source, attr) {
37816
38125
  if (attr.type === "JSXSpreadAttribute") {
37817
- g2.add(source.slice(attr.start, attr.end), attr.start, attr.end);
38126
+ g4.add(source.slice(attr.start, attr.end), attr.start, attr.end);
37818
38127
  return;
37819
38128
  }
37820
38129
  const name = attr.name;
37821
- g2.add(source.slice(name.start, name.end), name.start, name.end);
38130
+ g4.add(source.slice(name.start, name.end), name.start, name.end);
37822
38131
  const v = attr.value;
37823
38132
  if (!v) return;
37824
- g2.add(source.slice(name.end, v.start), name.end, v.start);
38133
+ g4.add(source.slice(name.end, v.start), name.end, v.start);
37825
38134
  if (v.type === "JSXExpressionContainer") {
37826
- g2.add(source.slice(v.start, v.expression.start), v.start, v.expression.start);
37827
- g2.add(source.slice(v.expression.start, v.expression.end), v.expression.start, v.expression.end);
37828
- g2.add(source.slice(v.expression.end, v.end), v.expression.end, v.end);
38135
+ g4.add(source.slice(v.start, v.expression.start), v.start, v.expression.start);
38136
+ g4.add(source.slice(v.expression.start, v.expression.end), v.expression.start, v.expression.end);
38137
+ g4.add(source.slice(v.expression.end, v.end), v.expression.end, v.end);
37829
38138
  } else {
37830
- g2.add(source.slice(v.start, v.end), v.start, v.end);
38139
+ g4.add(source.slice(v.start, v.end), v.start, v.end);
37831
38140
  }
37832
38141
  }
37833
- function emitJSXElement(g2, source, el, opts, hoist) {
38142
+ function emitJSXElement(g4, source, el, opts, hoist) {
37834
38143
  const op = el.openingElement;
37835
38144
  const name = op.name;
37836
38145
  let prev;
37837
38146
  if (name) {
37838
- g2.add(source.slice(op.start, name.start), op.start, name.start);
37839
- g2.add(source.slice(name.start, name.end), name.start, name.end);
38147
+ g4.add(source.slice(op.start, name.start), op.start, name.start);
38148
+ g4.add(source.slice(name.start, name.end), name.start, name.end);
37840
38149
  prev = name.end;
37841
38150
  } else {
37842
38151
  prev = op.start + 1;
37843
38152
  }
37844
38153
  for (const attr of op.attributes ?? []) {
37845
- g2.add(source.slice(prev, attr.start), prev, attr.start);
37846
- emitJSXAttr(g2, source, attr);
38154
+ g4.add(source.slice(prev, attr.start), prev, attr.start);
38155
+ emitJSXAttr(g4, source, attr);
37847
38156
  prev = attr.end;
37848
38157
  }
37849
38158
  const tail = source.slice(prev, op.end);
37850
38159
  if (op.selfClosing && !tail.includes("/")) {
37851
38160
  const gt = tail.lastIndexOf(">");
37852
38161
  const head = gt === -1 ? tail : tail.slice(0, gt);
37853
- if (head) g2.add(head, prev, prev + head.length);
37854
- g2.addRaw("/>");
38162
+ if (head) g4.add(head, prev, prev + head.length);
38163
+ g4.addRaw("/>");
37855
38164
  } else {
37856
- g2.add(tail, prev, op.end);
38165
+ g4.add(tail, prev, op.end);
37857
38166
  }
37858
38167
  if (op.selfClosing) return;
37859
- emitJSXChildren(g2, source, el.children ?? [], opts, hoist);
38168
+ emitJSXChildren(g4, source, el.children ?? [], opts, hoist);
37860
38169
  if (el.closingElement) {
37861
- g2.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
38170
+ g4.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
37862
38171
  }
37863
38172
  }
37864
- function emitJSXExprBody(g2, source, expr, opts) {
37865
- if (expr.type === "JSXElement") return emitJSXElement(g2, source, expr, opts);
37866
- if (expr.type === "JSXFragment") return emitJSXFragment(g2, source, expr, opts);
37867
- g2.add(source.slice(expr.start, expr.end), expr.start, expr.end);
38173
+ function emitJSXExprBody(g4, source, expr, opts) {
38174
+ if (expr.type === "JSXElement") return emitJSXElement(g4, source, expr, opts);
38175
+ if (expr.type === "JSXFragment") return emitJSXFragment(g4, source, expr, opts);
38176
+ g4.add(source.slice(expr.start, expr.end), expr.start, expr.end);
37868
38177
  }
37869
- function emitJSXFragment(g2, source, frag, opts, hoist) {
37870
- g2.addRaw("<>");
37871
- emitJSXChildren(g2, source, frag.children ?? [], opts, hoist);
37872
- g2.addRaw("</>");
38178
+ function emitJSXFragment(g4, source, frag, opts, hoist) {
38179
+ g4.addRaw("<>");
38180
+ emitJSXChildren(g4, source, frag.children ?? [], opts, hoist);
38181
+ g4.addRaw("</>");
37873
38182
  }
37874
- function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
38183
+ function emitForClauseMap(g4, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
37875
38184
  const clauseEnd = findBalancedEnd(text, clauseStart - 1);
37876
38185
  const clause = text.slice(clauseStart, clauseEnd);
37877
38186
  const ofIdx = findTopLevelSep(clause, "of");
@@ -37888,38 +38197,38 @@ function emitForClauseMap(g2, source, child, text, map, clauseStart, bodyEmit, e
37888
38197
  const itemVar = stripDeclKeyword(lhs).trim();
37889
38198
  if (ofIdx !== -1) {
37890
38199
  if (emptyEmit) {
37891
- g2.addRaw("{ (() => { const _v = ");
37892
- g2.add(arrExpr, arrStart, arrEnd);
37893
- g2.addRaw("; return _v.length === 0 ? (");
38200
+ g4.addRaw("{ (() => { const _v = ");
38201
+ g4.add(arrExpr, arrStart, arrEnd);
38202
+ g4.addRaw("; return _v.length === 0 ? (");
37894
38203
  emptyEmit();
37895
- g2.addRaw(") : _v.map((");
37896
- g2.addRaw(itemVar);
37897
- g2.addRaw(": (typeof _v)[number]) => (");
38204
+ g4.addRaw(") : _v.map((");
38205
+ g4.addRaw(itemVar);
38206
+ g4.addRaw(": (typeof _v)[number]) => (");
37898
38207
  bodyEmit();
37899
- g2.addRaw(")); })() }");
38208
+ g4.addRaw(")); })() }");
37900
38209
  } else {
37901
- g2.addRaw("{ ");
37902
- g2.add(arrExpr, arrStart, arrEnd);
37903
- g2.addRaw(".map((");
37904
- g2.addRaw(itemVar);
37905
- g2.addRaw(": (typeof ");
37906
- g2.add(arrExpr, arrStart, arrEnd);
37907
- g2.addRaw(")[number]) => (");
38210
+ g4.addRaw("{ ");
38211
+ g4.add(arrExpr, arrStart, arrEnd);
38212
+ g4.addRaw(".map((");
38213
+ g4.addRaw(itemVar);
38214
+ g4.addRaw(": (typeof ");
38215
+ g4.add(arrExpr, arrStart, arrEnd);
38216
+ g4.addRaw(")[number]) => (");
37908
38217
  bodyEmit();
37909
- g2.addRaw(")) }");
38218
+ g4.addRaw(")) }");
37910
38219
  }
37911
38220
  } else {
37912
- g2.addRaw("{ Object.keys(");
37913
- g2.add(arrExpr, arrStart, arrEnd);
37914
- g2.addRaw(").map((");
37915
- g2.addRaw(itemVar);
37916
- g2.addRaw(") => (");
38221
+ g4.addRaw("{ Object.keys(");
38222
+ g4.add(arrExpr, arrStart, arrEnd);
38223
+ g4.addRaw(").map((");
38224
+ g4.addRaw(itemVar);
38225
+ g4.addRaw(") => (");
37917
38226
  bodyEmit();
37918
- g2.addRaw(")) }");
38227
+ g4.addRaw(")) }");
37919
38228
  }
37920
38229
  return true;
37921
38230
  }
37922
- function emitJSXChildren(g2, source, children, opts, hoist) {
38231
+ function emitJSXChildren(g4, source, children, opts, hoist) {
37923
38232
  let i = 0;
37924
38233
  let forPending = false;
37925
38234
  while (i < children.length) {
@@ -37945,46 +38254,46 @@ function emitJSXChildren(g2, source, children, opts, hoist) {
37945
38254
  const emptyContainer = children[i + 3];
37946
38255
  if (emptyTextNode && emptyTextNode.type === "JSXText" && ["#empty", "empty"].includes(emptyTextNode.value.trim()) && emptyContainer && emptyContainer.type === "JSXExpressionContainer" && emptyContainer.expression.type !== "JSXEmptyExpression") {
37947
38256
  consumed = 4;
37948
- emptyEmit = () => emitJSXExprBody(g2, source, emptyContainer.expression, opts);
38257
+ emptyEmit = () => emitJSXExprBody(g4, source, emptyContainer.expression, opts);
37949
38258
  }
37950
38259
  let matched = false;
37951
38260
  if (nextChild.type === "JSXExpressionContainer") {
37952
38261
  const exprNode = nextChild.expression;
37953
38262
  if (exprNode.type === "JSXEmptyExpression") {
37954
- g2.add(text, child.start, child.end);
38263
+ g4.add(text, child.start, child.end);
37955
38264
  i++;
37956
38265
  continue;
37957
38266
  }
37958
38267
  matched = emitForClauseMap(
37959
- g2,
38268
+ g4,
37960
38269
  source,
37961
38270
  child,
37962
38271
  text,
37963
38272
  map,
37964
38273
  clauseStartCollapsed,
37965
- () => emitJSXExprBody(g2, source, exprNode, opts),
38274
+ () => emitJSXExprBody(g4, source, exprNode, opts),
37966
38275
  emptyEmit
37967
38276
  );
37968
38277
  } else if (nextChild.type === "JSXFragment") {
37969
38278
  matched = emitForClauseMap(
37970
- g2,
38279
+ g4,
37971
38280
  source,
37972
38281
  child,
37973
38282
  text,
37974
38283
  map,
37975
38284
  clauseStartCollapsed,
37976
- () => emitJSXFragment(g2, source, nextChild, opts),
38285
+ () => emitJSXFragment(g4, source, nextChild, opts),
37977
38286
  emptyEmit
37978
38287
  );
37979
38288
  } else {
37980
38289
  matched = emitForClauseMap(
37981
- g2,
38290
+ g4,
37982
38291
  source,
37983
38292
  child,
37984
38293
  text,
37985
38294
  map,
37986
38295
  clauseStartCollapsed,
37987
- () => emitJSXElement(g2, source, nextChild, opts),
38296
+ () => emitJSXElement(g4, source, nextChild, opts),
37988
38297
  emptyEmit
37989
38298
  );
37990
38299
  }
@@ -38001,184 +38310,184 @@ function emitJSXChildren(g2, source, children, opts, hoist) {
38001
38310
  continue;
38002
38311
  }
38003
38312
  forPending = false;
38004
- emitJSXText(g2, text, child.start, child.end);
38313
+ emitJSXText(g4, text, child.start, child.end);
38005
38314
  i++;
38006
38315
  } else if (child.type === "JSXExpressionContainer") {
38007
38316
  if (child.expression.type === "JSXEmptyExpression") {
38008
38317
  i++;
38009
38318
  continue;
38010
38319
  }
38011
- g2.addRaw("{");
38012
- g2.add(source.slice(child.expression.start, child.expression.end), child.expression.start, child.expression.end);
38013
- g2.addRaw("}");
38320
+ g4.addRaw("{");
38321
+ g4.add(source.slice(child.expression.start, child.expression.end), child.expression.start, child.expression.end);
38322
+ g4.addRaw("}");
38014
38323
  i++;
38015
38324
  } else if (child.type === "JSXElement") {
38016
38325
  if (getJSXTagName2(child) === "style") {
38017
38326
  const openEnd = child.openingElement?.end ?? child.start;
38018
38327
  const closeStart = child.closingElement?.start ?? child.end;
38019
- g2.recordStyle(child.start, child.end, source.slice(openEnd, closeStart));
38328
+ g4.recordStyle(child.start, child.end, source.slice(openEnd, closeStart));
38020
38329
  i++;
38021
38330
  continue;
38022
38331
  }
38023
- emitJSXElement(g2, source, child, opts, hoist);
38332
+ emitJSXElement(g4, source, child, opts, hoist);
38024
38333
  i++;
38025
38334
  } else if (child.type === "JSXFragment") {
38026
- emitJSXFragment(g2, source, child, opts, hoist);
38335
+ emitJSXFragment(g4, source, child, opts, hoist);
38027
38336
  i++;
38028
38337
  } 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") {
38029
38338
  if (hoist && hoist.set.has(child)) {
38030
38339
  i++;
38031
38340
  continue;
38032
38341
  }
38033
- g2.addRaw("{(() => { ");
38034
- emitBody(g2, source, [child], "", opts);
38035
- g2.addRaw(" })()}");
38342
+ g4.addRaw("{(() => { ");
38343
+ emitBody(g4, source, [child], "", opts);
38344
+ g4.addRaw(" })()}");
38036
38345
  i++;
38037
38346
  } else {
38038
38347
  i++;
38039
38348
  }
38040
38349
  }
38041
38350
  }
38042
- function emitIf(g2, source, stmt, indent4, opts) {
38043
- g2.add(indent4);
38044
- g2.addRaw("if (");
38045
- g2.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38046
- g2.addRaw(") ");
38047
- emitBlock(g2, source, stmt.consequent, indent4, opts);
38351
+ function emitIf(g4, source, stmt, indent4, opts) {
38352
+ g4.add(indent4);
38353
+ g4.addRaw("if (");
38354
+ g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38355
+ g4.addRaw(") ");
38356
+ emitBlock(g4, source, stmt.consequent, indent4, opts);
38048
38357
  if (stmt.alternate) {
38049
- g2.addRaw(" else ");
38050
- emitBlock(g2, source, stmt.alternate, indent4, opts);
38358
+ g4.addRaw(" else ");
38359
+ emitBlock(g4, source, stmt.alternate, indent4, opts);
38051
38360
  }
38052
38361
  }
38053
- function emitLoopVariable(g2, source, left) {
38362
+ function emitLoopVariable(g4, source, left) {
38054
38363
  if (left && left.type === "Identifier") {
38055
- g2.addRaw("const ");
38056
- g2.add(source.slice(left.start, left.end), left.start, left.end);
38364
+ g4.addRaw("const ");
38365
+ g4.add(source.slice(left.start, left.end), left.start, left.end);
38057
38366
  return;
38058
38367
  }
38059
- g2.add(source.slice(left.start, left.end), left.start, left.end);
38060
- }
38061
- function emitForOf(g2, source, stmt, indent4, opts) {
38062
- g2.add(indent4);
38063
- g2.addRaw("for (");
38064
- emitLoopVariable(g2, source, stmt.left);
38065
- g2.addRaw(" of ");
38066
- g2.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
38067
- g2.addRaw(") ");
38068
- emitBlock(g2, source, stmt.body, indent4, opts);
38069
- }
38070
- function emitForIn(g2, source, stmt, indent4, opts) {
38071
- g2.add(indent4);
38072
- g2.addRaw("for (");
38073
- emitLoopVariable(g2, source, stmt.left);
38074
- g2.addRaw(" in ");
38075
- g2.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
38076
- g2.addRaw(") ");
38077
- emitBlock(g2, source, stmt.body, indent4, opts);
38078
- }
38079
- function emitFor(g2, source, stmt, indent4, opts) {
38080
- g2.add(indent4);
38081
- g2.addRaw("for (");
38082
- if (stmt.init) g2.add(source.slice(stmt.init.start, stmt.init.end), stmt.init.start, stmt.init.end);
38083
- g2.addRaw("; ");
38084
- if (stmt.test) g2.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38085
- g2.addRaw("; ");
38086
- if (stmt.update) g2.add(source.slice(stmt.update.start, stmt.update.end), stmt.update.start, stmt.update.end);
38087
- g2.addRaw(") ");
38088
- emitBlock(g2, source, stmt.body, indent4, opts);
38089
- }
38090
- function emitWhile(g2, source, stmt, indent4, opts) {
38091
- g2.add(indent4);
38092
- g2.addRaw("while (");
38093
- g2.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38094
- g2.addRaw(") ");
38095
- emitBlock(g2, source, stmt.body, indent4, opts);
38096
- }
38097
- function emitDoWhile(g2, source, stmt, indent4, opts) {
38098
- g2.add(indent4);
38099
- g2.addRaw("do ");
38100
- emitBlock(g2, source, stmt.body, indent4, opts);
38101
- g2.addRaw(" while (");
38102
- g2.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38103
- g2.addRaw(");");
38104
- }
38105
- function emitSwitch(g2, source, stmt, indent4, opts) {
38106
- g2.add(indent4);
38107
- g2.addRaw("switch (");
38108
- g2.add(source.slice(stmt.discriminant.start, stmt.discriminant.end), stmt.discriminant.start, stmt.discriminant.end);
38109
- g2.addRaw(") {");
38368
+ g4.add(source.slice(left.start, left.end), left.start, left.end);
38369
+ }
38370
+ function emitForOf(g4, source, stmt, indent4, opts) {
38371
+ g4.add(indent4);
38372
+ g4.addRaw("for (");
38373
+ emitLoopVariable(g4, source, stmt.left);
38374
+ g4.addRaw(" of ");
38375
+ g4.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
38376
+ g4.addRaw(") ");
38377
+ emitBlock(g4, source, stmt.body, indent4, opts);
38378
+ }
38379
+ function emitForIn(g4, source, stmt, indent4, opts) {
38380
+ g4.add(indent4);
38381
+ g4.addRaw("for (");
38382
+ emitLoopVariable(g4, source, stmt.left);
38383
+ g4.addRaw(" in ");
38384
+ g4.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
38385
+ g4.addRaw(") ");
38386
+ emitBlock(g4, source, stmt.body, indent4, opts);
38387
+ }
38388
+ function emitFor(g4, source, stmt, indent4, opts) {
38389
+ g4.add(indent4);
38390
+ g4.addRaw("for (");
38391
+ if (stmt.init) g4.add(source.slice(stmt.init.start, stmt.init.end), stmt.init.start, stmt.init.end);
38392
+ g4.addRaw("; ");
38393
+ if (stmt.test) g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38394
+ g4.addRaw("; ");
38395
+ if (stmt.update) g4.add(source.slice(stmt.update.start, stmt.update.end), stmt.update.start, stmt.update.end);
38396
+ g4.addRaw(") ");
38397
+ emitBlock(g4, source, stmt.body, indent4, opts);
38398
+ }
38399
+ function emitWhile(g4, source, stmt, indent4, opts) {
38400
+ g4.add(indent4);
38401
+ g4.addRaw("while (");
38402
+ g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38403
+ g4.addRaw(") ");
38404
+ emitBlock(g4, source, stmt.body, indent4, opts);
38405
+ }
38406
+ function emitDoWhile(g4, source, stmt, indent4, opts) {
38407
+ g4.add(indent4);
38408
+ g4.addRaw("do ");
38409
+ emitBlock(g4, source, stmt.body, indent4, opts);
38410
+ g4.addRaw(" while (");
38411
+ g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
38412
+ g4.addRaw(");");
38413
+ }
38414
+ function emitSwitch(g4, source, stmt, indent4, opts) {
38415
+ g4.add(indent4);
38416
+ g4.addRaw("switch (");
38417
+ g4.add(source.slice(stmt.discriminant.start, stmt.discriminant.end), stmt.discriminant.start, stmt.discriminant.end);
38418
+ g4.addRaw(") {");
38110
38419
  let firstCase = true;
38111
38420
  for (const c of stmt.cases ?? []) {
38112
- g2.addRaw(firstCase ? "\n" : "\n");
38421
+ g4.addRaw(firstCase ? "\n" : "\n");
38113
38422
  firstCase = false;
38114
- g2.add(indent4);
38115
- g2.addRaw(" ");
38423
+ g4.add(indent4);
38424
+ g4.addRaw(" ");
38116
38425
  if (c.test) {
38117
- g2.addRaw("case ");
38118
- g2.add(source.slice(c.test.start, c.test.end), c.test.start, c.test.end);
38119
- g2.addRaw(":");
38426
+ g4.addRaw("case ");
38427
+ g4.add(source.slice(c.test.start, c.test.end), c.test.start, c.test.end);
38428
+ g4.addRaw(":");
38120
38429
  } else {
38121
- g2.addRaw("default:");
38430
+ g4.addRaw("default:");
38122
38431
  }
38123
- const before = g2.code.length;
38124
- emitBody(g2, source, c.consequent, indent4 + " ", opts);
38125
- if (g2.code.length > before) g2.addRaw("\n");
38432
+ const before = g4.code.length;
38433
+ emitBody(g4, source, c.consequent, indent4 + " ", opts);
38434
+ if (g4.code.length > before) g4.addRaw("\n");
38126
38435
  }
38127
- g2.addRaw("\n");
38128
- g2.add(indent4);
38129
- g2.addRaw("}");
38436
+ g4.addRaw("\n");
38437
+ g4.add(indent4);
38438
+ g4.addRaw("}");
38130
38439
  }
38131
- function emitTry(g2, source, stmt, indent4, opts) {
38132
- g2.add(indent4);
38133
- g2.addRaw("try ");
38134
- emitBlock(g2, source, stmt.block, indent4, opts);
38440
+ function emitTry(g4, source, stmt, indent4, opts) {
38441
+ g4.add(indent4);
38442
+ g4.addRaw("try ");
38443
+ emitBlock(g4, source, stmt.block, indent4, opts);
38135
38444
  if (stmt.handler) {
38136
- g2.addRaw(" catch");
38445
+ g4.addRaw(" catch");
38137
38446
  if (stmt.handler.param) {
38138
- g2.addRaw(" (");
38139
- g2.add(source.slice(stmt.handler.param.start, stmt.handler.param.end), stmt.handler.param.start, stmt.handler.param.end);
38140
- g2.addRaw(")");
38447
+ g4.addRaw(" (");
38448
+ g4.add(source.slice(stmt.handler.param.start, stmt.handler.param.end), stmt.handler.param.start, stmt.handler.param.end);
38449
+ g4.addRaw(")");
38141
38450
  }
38142
- g2.addRaw(" ");
38143
- emitBlock(g2, source, stmt.handler.body, indent4, opts);
38451
+ g4.addRaw(" ");
38452
+ emitBlock(g4, source, stmt.handler.body, indent4, opts);
38144
38453
  }
38145
38454
  if (stmt.finalizer) {
38146
- g2.addRaw(" finally ");
38147
- emitBlock(g2, source, stmt.finalizer, indent4, opts);
38455
+ g4.addRaw(" finally ");
38456
+ emitBlock(g4, source, stmt.finalizer, indent4, opts);
38148
38457
  }
38149
38458
  }
38150
- function emitPlainStatement(g2, source, stmt, indent4, isLast) {
38459
+ function emitPlainStatement(g4, source, stmt, indent4, isLast) {
38151
38460
  let text = stripTrailingSemicolons(source.slice(stmt.start, stmt.end).trimEnd());
38152
38461
  if (text === "") return;
38153
- g2.add(indent4);
38154
- g2.add(text, stmt.start, stmt.end);
38155
- if (!text.endsWith("}") && !isLast) g2.addRaw(";");
38462
+ g4.add(indent4);
38463
+ g4.add(text, stmt.start, stmt.end);
38464
+ if (!text.endsWith("}") && !isLast) g4.addRaw(";");
38156
38465
  }
38157
- function emitStatement(g2, source, stmt, indent4, isLast, opts, hoist) {
38466
+ function emitStatement(g4, source, stmt, indent4, isLast, opts, hoist) {
38158
38467
  switch (stmt.type) {
38159
38468
  case "JSXElement":
38160
38469
  if (getJSXTagName2(stmt) === "style") {
38161
38470
  const openEnd = stmt.openingElement?.end ?? stmt.start;
38162
38471
  const closeStart = stmt.closingElement?.start ?? stmt.end;
38163
- g2.recordStyle(stmt.start, stmt.end, source.slice(openEnd, closeStart));
38472
+ g4.recordStyle(stmt.start, stmt.end, source.slice(openEnd, closeStart));
38164
38473
  return;
38165
38474
  }
38166
- g2.add(indent4);
38167
- emitJSXElement(g2, source, stmt, opts, hoist);
38168
- if (!isLast) g2.addRaw(";");
38475
+ g4.add(indent4);
38476
+ emitJSXElement(g4, source, stmt, opts, hoist);
38477
+ if (!isLast) g4.addRaw(";");
38169
38478
  return;
38170
38479
  case "JSXFragment":
38171
- g2.add(indent4);
38172
- emitJSXFragment(g2, source, stmt, opts, hoist);
38173
- if (!isLast) g2.addRaw(";");
38480
+ g4.add(indent4);
38481
+ emitJSXFragment(g4, source, stmt, opts, hoist);
38482
+ if (!isLast) g4.addRaw(";");
38174
38483
  return;
38175
38484
  case "JSXExpressionContainer": {
38176
38485
  if (stmt.expression.type === "JSXEmptyExpression") return;
38177
- g2.add(indent4);
38178
- g2.addRaw("{");
38179
- g2.add(source.slice(stmt.expression.start, stmt.expression.end), stmt.expression.start, stmt.expression.end);
38180
- g2.addRaw("}");
38181
- if (!isLast) g2.addRaw(";");
38486
+ g4.add(indent4);
38487
+ g4.addRaw("{");
38488
+ g4.add(source.slice(stmt.expression.start, stmt.expression.end), stmt.expression.start, stmt.expression.end);
38489
+ g4.addRaw("}");
38490
+ if (!isLast) g4.addRaw(";");
38182
38491
  return;
38183
38492
  }
38184
38493
  case "VeskBlock": {
@@ -38186,10 +38495,10 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts, hoist) {
38186
38495
  const innerStmts = stmt.body ?? [];
38187
38496
  let firstLine = true;
38188
38497
  for (let i = 0; i < innerStmts.length; i++) {
38189
- const before = g2.code.length;
38190
- emitStatement(g2, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts, hoist);
38191
- if (g2.code.length > before) {
38192
- if (!firstLine) g2.addRaw("\n");
38498
+ const before = g4.code.length;
38499
+ emitStatement(g4, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts, hoist);
38500
+ if (g4.code.length > before) {
38501
+ if (!firstLine) g4.addRaw("\n");
38193
38502
  firstLine = false;
38194
38503
  }
38195
38504
  }
@@ -38197,38 +38506,38 @@ function emitStatement(g2, source, stmt, indent4, isLast, opts, hoist) {
38197
38506
  }
38198
38507
  case "VariableDeclaration":
38199
38508
  if (isTrackDeclStatement(stmt)) {
38200
- emitTrackDeclStatement(g2, source, stmt, indent4, isLast, opts);
38509
+ emitTrackDeclStatement(g4, source, stmt, indent4, isLast, opts);
38201
38510
  return;
38202
38511
  }
38203
- return emitPlainStatement(g2, source, stmt, indent4, isLast);
38512
+ return emitPlainStatement(g4, source, stmt, indent4, isLast);
38204
38513
  case "IfStatement":
38205
- return emitIf(g2, source, stmt, indent4, opts);
38514
+ return emitIf(g4, source, stmt, indent4, opts);
38206
38515
  case "ForOfStatement":
38207
- return emitForOf(g2, source, stmt, indent4, opts);
38516
+ return emitForOf(g4, source, stmt, indent4, opts);
38208
38517
  case "ForInStatement":
38209
- return emitForIn(g2, source, stmt, indent4, opts);
38518
+ return emitForIn(g4, source, stmt, indent4, opts);
38210
38519
  case "ForStatement":
38211
- return emitFor(g2, source, stmt, indent4, opts);
38520
+ return emitFor(g4, source, stmt, indent4, opts);
38212
38521
  case "WhileStatement":
38213
- return emitWhile(g2, source, stmt, indent4, opts);
38522
+ return emitWhile(g4, source, stmt, indent4, opts);
38214
38523
  case "DoWhileStatement":
38215
- return emitDoWhile(g2, source, stmt, indent4, opts);
38524
+ return emitDoWhile(g4, source, stmt, indent4, opts);
38216
38525
  case "SwitchStatement":
38217
- return emitSwitch(g2, source, stmt, indent4, opts);
38526
+ return emitSwitch(g4, source, stmt, indent4, opts);
38218
38527
  case "TryStatement":
38219
- return emitTry(g2, source, stmt, indent4, opts);
38528
+ return emitTry(g4, source, stmt, indent4, opts);
38220
38529
  case "LabeledStatement": {
38221
- g2.add(indent4);
38222
- g2.add(stmt.label.name, stmt.label.start, stmt.label.end);
38223
- g2.addRaw(":\n");
38224
- emitStatement(g2, source, stmt.body, indent4, isLast, opts);
38530
+ g4.add(indent4);
38531
+ g4.add(stmt.label.name, stmt.label.start, stmt.label.end);
38532
+ g4.addRaw(":\n");
38533
+ emitStatement(g4, source, stmt.body, indent4, isLast, opts);
38225
38534
  return;
38226
38535
  }
38227
38536
  default:
38228
- return emitPlainStatement(g2, source, stmt, indent4, isLast);
38537
+ return emitPlainStatement(g4, source, stmt, indent4, isLast);
38229
38538
  }
38230
38539
  }
38231
- function emitBody(g2, source, stmts, indent4, opts, hoist) {
38540
+ function emitBody(g4, source, stmts, indent4, opts, hoist) {
38232
38541
  let firstLine = true;
38233
38542
  let i = 0;
38234
38543
  while (i < stmts.length) {
@@ -38236,34 +38545,34 @@ function emitBody(g2, source, stmts, indent4, opts, hoist) {
38236
38545
  const isLast = i === stmts.length - 1;
38237
38546
  if (stmt.type === "ForOfStatement" && stmts[i + 1] && stmts[i + 1].type === "VeskBlock" && stmts[i + 1].tag === "empty") {
38238
38547
  const empty2 = stmts[i + 1];
38239
- if (!firstLine) g2.addRaw("\n");
38548
+ if (!firstLine) g4.addRaw("\n");
38240
38549
  firstLine = false;
38241
- emitForOf(g2, source, stmt, indent4, opts);
38550
+ emitForOf(g4, source, stmt, indent4, opts);
38242
38551
  const inner = empty2.body ?? [];
38243
38552
  if (inner.length > 0) {
38244
- g2.addRaw("\n");
38245
- g2.add(indent4);
38246
- g2.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
38247
- g2.addRaw(".length === 0 && (() => {");
38248
- g2.addRaw("\n");
38249
- emitBody(g2, source, inner, indent4 + " ", opts);
38250
- g2.addRaw("\n");
38251
- g2.add(indent4);
38252
- g2.addRaw("})();");
38553
+ g4.addRaw("\n");
38554
+ g4.add(indent4);
38555
+ g4.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
38556
+ g4.addRaw(".length === 0 && (() => {");
38557
+ g4.addRaw("\n");
38558
+ emitBody(g4, source, inner, indent4 + " ", opts);
38559
+ g4.addRaw("\n");
38560
+ g4.add(indent4);
38561
+ g4.addRaw("})();");
38253
38562
  }
38254
38563
  i += 2;
38255
38564
  continue;
38256
38565
  }
38257
- const before = g2.code.length;
38258
- emitStatement(g2, source, stmt, indent4, isLast, opts, hoist);
38259
- if (g2.code.length > before) {
38260
- if (!firstLine) g2.addRaw("\n");
38566
+ const before = g4.code.length;
38567
+ emitStatement(g4, source, stmt, indent4, isLast, opts, hoist);
38568
+ if (g4.code.length > before) {
38569
+ if (!firstLine) g4.addRaw("\n");
38261
38570
  firstLine = false;
38262
38571
  }
38263
38572
  i++;
38264
38573
  }
38265
38574
  }
38266
- function emitChunkMapped(g2, source, start, end) {
38575
+ function emitChunkMapped(g4, source, start, end) {
38267
38576
  if (end <= start) return;
38268
38577
  let pos = start;
38269
38578
  let i = start;
@@ -38275,8 +38584,8 @@ function emitChunkMapped(g2, source, start, end) {
38275
38584
  if (openEnd !== -1 && openEnd <= end) {
38276
38585
  const closeIdx = source.indexOf("</style>", openEnd);
38277
38586
  if (closeIdx !== -1 && closeIdx + 8 <= end) {
38278
- g2.add(source.slice(pos, i), pos, i);
38279
- g2.recordStyle(i, closeIdx + 8, source.slice(openEnd, closeIdx));
38587
+ g4.add(source.slice(pos, i), pos, i);
38588
+ g4.recordStyle(i, closeIdx + 8, source.slice(openEnd, closeIdx));
38280
38589
  pos = closeIdx + 8;
38281
38590
  i = closeIdx + 8;
38282
38591
  continue;
@@ -38286,20 +38595,20 @@ function emitChunkMapped(g2, source, start, end) {
38286
38595
  }
38287
38596
  i++;
38288
38597
  }
38289
- g2.add(source.slice(pos, end), pos, end);
38598
+ g4.add(source.slice(pos, end), pos, end);
38290
38599
  }
38291
- function emitReturn(g2, source, stmt, opts) {
38292
- g2.add(source.slice(stmt.start, stmt.start + 6), stmt.start, stmt.start + 6);
38600
+ function emitReturn(g4, source, stmt, opts) {
38601
+ g4.add(source.slice(stmt.start, stmt.start + 6), stmt.start, stmt.start + 6);
38293
38602
  const arg = stmt.argument;
38294
38603
  if (!arg) {
38295
- emitChunkMapped(g2, source, stmt.start + 6, stmt.end);
38604
+ emitChunkMapped(g4, source, stmt.start + 6, stmt.end);
38296
38605
  return;
38297
38606
  }
38298
- emitChunkMapped(g2, source, stmt.start + 6, arg.start);
38299
- if (arg.type === "JSXElement") emitJSXElement(g2, source, arg, opts);
38300
- else if (arg.type === "JSXFragment") emitJSXFragment(g2, source, arg, opts);
38301
- else emitChunkMapped(g2, source, arg.start, arg.end);
38302
- emitChunkMapped(g2, source, arg.end, stmt.end);
38607
+ emitChunkMapped(g4, source, stmt.start + 6, arg.start);
38608
+ if (arg.type === "JSXElement") emitJSXElement(g4, source, arg, opts);
38609
+ else if (arg.type === "JSXFragment") emitJSXFragment(g4, source, arg, opts);
38610
+ else emitChunkMapped(g4, source, arg.start, arg.end);
38611
+ emitChunkMapped(g4, source, arg.end, stmt.end);
38303
38612
  }
38304
38613
  function collectHoistEligible(children, set2, list) {
38305
38614
  for (const child of children ?? []) {
@@ -38319,7 +38628,7 @@ function collectHoistEligible(children, set2, list) {
38319
38628
  }
38320
38629
  }
38321
38630
  }
38322
- function emitBodyCore(g2, source, stmts, opts) {
38631
+ function emitBodyCore(g4, source, stmts, opts) {
38323
38632
  const hoistSet = /* @__PURE__ */ new Set();
38324
38633
  const byRoot = /* @__PURE__ */ new Map();
38325
38634
  const collectRoot = (root3) => {
@@ -38370,107 +38679,107 @@ function emitBodyCore(g2, source, stmts, opts) {
38370
38679
  byRoot.delete(u.node);
38371
38680
  const n = list.length;
38372
38681
  for (let k = 0; k < n; k++) {
38373
- const before2 = g2.code.length;
38374
- emitStatement(g2, source, list[k], "", false, opts, ctx2);
38375
- if (g2.code.length > before2) g2.addRaw("\n");
38682
+ const before2 = g4.code.length;
38683
+ emitStatement(g4, source, list[k], "", false, opts, ctx2);
38684
+ if (g4.code.length > before2) g4.addRaw("\n");
38376
38685
  }
38377
38686
  }
38378
38687
  }
38379
38688
  if (u.empty !== void 0) {
38380
- emitForOf(g2, source, u.node, "", opts);
38689
+ emitForOf(g4, source, u.node, "", opts);
38381
38690
  const inner = u.empty.body ?? [];
38382
38691
  if (inner.length > 0) {
38383
- g2.addRaw("\n");
38384
- g2.add("");
38385
- g2.add(
38692
+ g4.addRaw("\n");
38693
+ g4.add("");
38694
+ g4.add(
38386
38695
  source.slice(u.node.right.start, u.node.right.end),
38387
38696
  u.node.right.start,
38388
38697
  u.node.right.end
38389
38698
  );
38390
- g2.addRaw(".length === 0 && (() => {");
38391
- g2.addRaw("\n");
38392
- emitBody(g2, source, inner, " ", opts);
38393
- g2.addRaw("\n");
38394
- g2.add("");
38395
- g2.addRaw("})();");
38699
+ g4.addRaw(".length === 0 && (() => {");
38700
+ g4.addRaw("\n");
38701
+ emitBody(g4, source, inner, " ", opts);
38702
+ g4.addRaw("\n");
38703
+ g4.add("");
38704
+ g4.addRaw("})();");
38396
38705
  }
38397
38706
  return;
38398
38707
  }
38399
- const before = g2.code.length;
38400
- emitStatement(g2, source, u.node, "", isLast, opts, ctx2);
38401
- if (g2.code.length > before && !isLast) g2.addRaw("\n");
38708
+ const before = g4.code.length;
38709
+ emitStatement(g4, source, u.node, "", isLast, opts, ctx2);
38710
+ if (g4.code.length > before && !isLast) g4.addRaw("\n");
38402
38711
  };
38403
38712
  for (let i = 0; i < units.length; i++) {
38404
38713
  emitUnit(units[i], i === units.length - 1);
38405
38714
  }
38406
38715
  }
38407
- function emitExpressionBody(g2, source, coreStart, coreEnd, stmts, opts) {
38716
+ function emitExpressionBody(g4, source, coreStart, coreEnd, stmts, opts) {
38408
38717
  let pos = coreStart;
38409
38718
  for (const stmt of stmts) {
38410
38719
  if (!stmt) continue;
38411
- emitChunkMapped(g2, source, pos, stmt.start);
38720
+ emitChunkMapped(g4, source, pos, stmt.start);
38412
38721
  pos = stmt.start;
38413
38722
  if (isTrackDeclStatement(stmt)) {
38414
- emitTrackDeclStatement(g2, source, stmt, "", true, opts);
38723
+ emitTrackDeclStatement(g4, source, stmt, "", true, opts);
38415
38724
  } else if (stmt.type === "ReturnStatement") {
38416
- emitReturn(g2, source, stmt, opts);
38725
+ emitReturn(g4, source, stmt, opts);
38417
38726
  } else {
38418
- emitChunkMapped(g2, source, stmt.start, stmt.end);
38727
+ emitChunkMapped(g4, source, stmt.start, stmt.end);
38419
38728
  }
38420
38729
  pos = stmt.end;
38421
38730
  }
38422
- emitChunkMapped(g2, source, pos, coreEnd);
38731
+ emitChunkMapped(g4, source, pos, coreEnd);
38423
38732
  }
38424
- function emitRestMapped(g2, text, base, end) {
38733
+ function emitRestMapped(g4, text, base, end) {
38425
38734
  let i = 0;
38426
38735
  while (i < text.length && !isIdentStart(text[i])) i++;
38427
38736
  if (i >= text.length) {
38428
- g2.add(text, base, end);
38737
+ g4.add(text, base, end);
38429
38738
  return;
38430
38739
  }
38431
38740
  let j = i + 1;
38432
38741
  while (j < text.length && isIdentChar(text[j])) j++;
38433
- g2.add(text.slice(0, i), base, base + i);
38434
- g2.add(text.slice(i, j), base + i, base + j);
38435
- g2.add(text.slice(j), base + j, end);
38742
+ g4.add(text.slice(0, i), base, base + i);
38743
+ g4.add(text.slice(i, j), base + i, base + j);
38744
+ g4.add(text.slice(j), base + j, end);
38436
38745
  }
38437
- function emitComponentHeader(g2, source, start, bodyStart) {
38746
+ function emitComponentHeader(g4, source, start, bodyStart) {
38438
38747
  const h = source.slice(start, bodyStart);
38439
38748
  const k = findFirstKeyword(h, "component");
38440
38749
  if (k === -1) {
38441
38750
  const { text, end: end2 } = stripTrailingClientRange(h);
38442
38751
  if (!text.includes("(")) {
38443
38752
  const trimmed = text.trimEnd();
38444
- g2.add(trimmed, start, start + end2 - (text.length - trimmed.length));
38445
- g2.addRaw("() ");
38753
+ g4.add(trimmed, start, start + end2 - (text.length - trimmed.length));
38754
+ g4.addRaw("() ");
38446
38755
  } else {
38447
- g2.add(text, start, start + end2);
38756
+ g4.add(text, start, start + end2);
38448
38757
  }
38449
38758
  return;
38450
38759
  }
38451
- g2.add(h.slice(0, k), start, start + k);
38452
- g2.add("function", start + k, start + k + "component".length);
38760
+ g4.add(h.slice(0, k), start, start + k);
38761
+ g4.add("function", start + k, start + k + "component".length);
38453
38762
  const restBase = start + k + "component".length;
38454
38763
  const { text: rest, end } = stripTrailingClientRange(h.slice(k + "component".length));
38455
38764
  const transformed = h.slice(0, k) + "function" + rest;
38456
38765
  if (!transformed.includes("(")) {
38457
38766
  const trimmed = rest.trimEnd();
38458
- emitRestMapped(g2, trimmed, restBase, restBase + end - (rest.length - trimmed.length));
38459
- g2.addRaw("() ");
38767
+ emitRestMapped(g4, trimmed, restBase, restBase + end - (rest.length - trimmed.length));
38768
+ g4.addRaw("() ");
38460
38769
  } else {
38461
- emitRestMapped(g2, rest, restBase, restBase + end);
38770
+ emitRestMapped(g4, rest, restBase, restBase + end);
38462
38771
  }
38463
38772
  }
38464
- function emitComponent(g2, source, node, start, opts) {
38773
+ function emitComponent(g4, source, node, start, opts) {
38465
38774
  const body = node.body;
38466
38775
  if (!body || body.start == null || body.end == null) return;
38467
- emitComponentHeader(g2, source, start, body.start);
38776
+ emitComponentHeader(g4, source, start, body.start);
38468
38777
  const statementMode = isStatementMode2(node);
38469
38778
  const stmts = body.body ?? [];
38470
38779
  if (statementMode) {
38471
- g2.addRaw("{ ");
38472
- emitBodyCore(g2, source, stmts, opts);
38473
- g2.addRaw(" }");
38780
+ g4.addRaw("{ ");
38781
+ emitBodyCore(g4, source, stmts, opts);
38782
+ g4.addRaw(" }");
38474
38783
  } else {
38475
38784
  const raw2 = source.slice(body.start, body.end);
38476
38785
  const rawLen = raw2.length;
@@ -38490,9 +38799,9 @@ function emitComponent(g2, source, node, start, opts) {
38490
38799
  }
38491
38800
  while (coreStart < coreEnd && isWhitespaceChar(source[coreStart])) coreStart++;
38492
38801
  while (coreEnd > coreStart && isWhitespaceChar(source[coreEnd - 1])) coreEnd--;
38493
- if (hasBraces) g2.addRaw("{ ");
38494
- emitExpressionBody(g2, source, coreStart, coreEnd, stmts, opts);
38495
- if (hasBraces) g2.addRaw(" }");
38802
+ if (hasBraces) g4.addRaw("{ ");
38803
+ emitExpressionBody(g4, source, coreStart, coreEnd, stmts, opts);
38804
+ if (hasBraces) g4.addRaw(" }");
38496
38805
  }
38497
38806
  }
38498
38807
  function isModuleAst(ast) {
@@ -38522,26 +38831,26 @@ function compileVskCodegen(source, opts = {}) {
38522
38831
  };
38523
38832
  }
38524
38833
  const clean = blankForClauses(source, ast);
38525
- const g2 = new VskGen();
38834
+ const g4 = new VskGen();
38526
38835
  const components = getComponents(ast).sort((a, b) => a.start - b.start);
38527
38836
  let pos = 0;
38528
38837
  for (const { node, start } of components) {
38529
38838
  const body = node.body;
38530
38839
  if (!body || body.start == null || body.end == null) continue;
38531
- g2.add(clean.slice(pos, start), pos, start);
38532
- emitComponent(g2, clean, node, start, opts);
38840
+ g4.add(clean.slice(pos, start), pos, start);
38841
+ emitComponent(g4, clean, node, start, opts);
38533
38842
  pos = body.end;
38534
38843
  }
38535
- g2.add(clean.slice(pos), pos, source.length);
38536
- let code = g2.code;
38844
+ g4.add(clean.slice(pos), pos, source.length);
38845
+ let code = g4.code;
38537
38846
  if (isModuleAst(ast) && containsIdentifier(code, "Head") && !isIdentifierImported(code, "Head")) {
38538
- g2.prepend("declare const Head: (props: { children?: Component }) => Component;\n");
38539
- code = g2.code;
38847
+ g4.prepend("declare const Head: (props: { children?: Component }) => Component;\n");
38848
+ code = g4.code;
38540
38849
  }
38541
38850
  if (!isModuleAst(ast)) {
38542
38851
  code += "\nexport {};\n";
38543
38852
  }
38544
- return { code, mappings: g2.mappings, styleRegions: g2.styleRegions, errors: [] };
38853
+ return { code, mappings: g4.mappings, styleRegions: g4.styleRegions, errors: [] };
38545
38854
  }
38546
38855
  function isTypeDecl(stmt) {
38547
38856
  return stmt.type === "TSInterfaceDeclaration" || stmt.type === "TSTypeAliasDeclaration" || stmt.type === "ExportNamedDeclaration" && (stmt.declaration?.type === "TSInterfaceDeclaration" || stmt.declaration?.type === "TSTypeAliasDeclaration");
@@ -40154,7 +40463,7 @@ async function bundleRuntime(appDir, outDir) {
40154
40463
  const runtimeRoot = findRuntimeSrc(appDir);
40155
40464
  const entryFile = resolve3(outDir, "server", `.runtime-entry-${buildId++}.mjs`);
40156
40465
  const entryContent = [
40157
- `import { renderPage, renderFullPage, renderPageStream, compileFile, setRuntimeModule, setVskHydrate, hydratePrecompile, assertSameOrigin } from ${JSON.stringify(resolve3(compilerRoot, "server-codegen.js"))};`,
40466
+ `import { renderPage, renderFullPage, renderPageStream, compileFile, setRuntimeModule, setVskHydrate, hydratePrecompile, assertSameOrigin, withSsrStore } from ${JSON.stringify(resolve3(compilerRoot, "server-codegen.js"))};`,
40158
40467
  `import { parseCookies } from ${JSON.stringify(resolve3(compilerRoot, "server-cookies.js"))};`,
40159
40468
  `import * as __veskRuntime from ${JSON.stringify(resolve3(runtimeRoot, "index-server.js"))};`,
40160
40469
  "",
@@ -40193,7 +40502,7 @@ async function bundleRuntime(appDir, outDir) {
40193
40502
  "}",
40194
40503
  "",
40195
40504
  "export { renderPage, renderFullPage, renderPageStream, compileFile, setVskHydrate, hydratePrecompile, parseCookies, assertSameOrigin };",
40196
- 'export { withSsrStore } from "@vesk/compiler/src/ssr-store";',
40505
+ "export { withSsrStore };",
40197
40506
  "",
40198
40507
  "// Deliver hydration data as an origin-served script so strict CSP (no unsafe-inline)",
40199
40508
  "// does not block it. The prod server serves /ssr-data.js from the global store.",
@@ -40205,7 +40514,11 @@ async function bundleRuntime(appDir, outDir) {
40205
40514
  " let tk = '';",
40206
40515
  " for (const b of bytes) tk += b.toString(16).padStart(2, '0');",
40207
40516
  " const token = tk;",
40208
- " const store = (globalThis.__vsk_ssr_data_store ||= {});",
40517
+ " // Named __vsk_ssr_payload_store, NOT __vsk_ssr_data_*: the compiler keys",
40518
+ " // per-request slots `__vsk_ssr_data_<token>` and pruneSsrDataSlots()",
40519
+ " // reaps that prefix. Sharing it let the reaper wipe every pending",
40520
+ " // /ssr-data.js payload, so a served page's hydration script 404'd.",
40521
+ " const store = (globalThis.__vsk_ssr_payload_store ||= {});",
40209
40522
  " store[token] = payload;",
40210
40523
  " // Bound the store: if the browser never fetches /ssr-data.js the entry",
40211
40524
  " // would otherwise linger forever. Evict the oldest entry past 100.",
@@ -40429,6 +40742,7 @@ function precompileFileInternal(source, sourcePath2, seenImportFiles) {
40429
40742
 
40430
40743
  // ../compiler/src/server-codegen.ts
40431
40744
  init_server_render();
40745
+ init_ssr_store();
40432
40746
 
40433
40747
  // ../adapter/src/css.ts
40434
40748
  import { readFileSync as readFileSync6, existsSync as existsSync7 } from "node:fs";
@@ -40688,54 +41002,67 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
40688
41002
  let dataCode;
40689
41003
  const exposeErr = "process.env.NODE_ENV !== 'production'";
40690
41004
  const dataNavCleanup = [
40691
- " } finally {",
40692
- " const __dnToken = globalThis.__vsk_ssr_token;",
40693
- " delete globalThis.__vsk_ssr;",
40694
- " if (__dnToken) delete globalThis[`__vsk_ssr_data_${__dnToken}`];",
40695
- " delete globalThis.__vsk_ssr_token;",
40696
- " delete globalThis.__vsk_ssr_data;",
40697
- " }"
41005
+ " } finally {",
41006
+ " const __dnToken = globalThis.__vsk_ssr_token;",
41007
+ " delete globalThis.__vsk_ssr;",
41008
+ " if (__dnToken) delete globalThis[`__vsk_ssr_data_${__dnToken}`];",
41009
+ // NOT `delete globalThis.__vsk_ssr_token`: that global is a
41010
+ // configurable AsyncLocalStorage accessor (ssr-store.ts), so `delete`
41011
+ // removes the property definition and the process silently reverts to a
41012
+ // process-global token — the cross-request data-slot race, for good. The
41013
+ // token dies with the withSsrStore scope wrapped around this block instead.
41014
+ " delete globalThis.__vsk_ssr_data;",
41015
+ " }"
41016
+ ];
41017
+ const dataNavWrap = (body) => [
41018
+ " return withSsrStore(async () => {",
41019
+ ...body.map((l) => l ? " " + l : l),
41020
+ " });"
40698
41021
  ];
40699
41022
  if (layoutDecls.length > 0) {
40700
41023
  dataCode = [
40701
41024
  " if (request.headers.get('x-vesk-data') === '1') {",
40702
- " try {",
40703
- " let dataPage;",
40704
- " try {",
40705
- " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
40706
- " } catch (err) {",
40707
- " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
40708
- " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
40709
- ` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
40710
- " }",
40711
- " let _dataHead = dataPage.head || '';",
40712
- " for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {",
40713
- " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
40714
- " _dataHead = (_dl.head || '') + _dataHead;",
40715
- " }",
40716
- " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
40717
- " headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
40718
- " });",
40719
- ...dataNavCleanup,
41025
+ ...dataNavWrap([
41026
+ " try {",
41027
+ " let dataPage;",
41028
+ " try {",
41029
+ " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
41030
+ " } catch (err) {",
41031
+ " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
41032
+ " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
41033
+ ` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
41034
+ " }",
41035
+ " let _dataHead = dataPage.head || '';",
41036
+ " for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {",
41037
+ " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
41038
+ " _dataHead = (_dl.head || '') + _dataHead;",
41039
+ " }",
41040
+ " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
41041
+ " headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
41042
+ " });",
41043
+ ...dataNavCleanup
41044
+ ]),
40720
41045
  " }",
40721
41046
  " return __renderHtml(params, url.href);"
40722
41047
  ].join("\n");
40723
41048
  } else {
40724
41049
  dataCode = [
40725
41050
  " if (request.headers.get('x-vesk-data') === '1') {",
40726
- " try {",
40727
- " let dataPage;",
40728
- " try {",
40729
- " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
40730
- " } catch (err) {",
40731
- " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
40732
- " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
40733
- ` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
40734
- " }",
40735
- " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: dataPage.head || '' }), {",
40736
- " headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
40737
- " });",
40738
- ...dataNavCleanup,
41051
+ ...dataNavWrap([
41052
+ " try {",
41053
+ " let dataPage;",
41054
+ " try {",
41055
+ " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
41056
+ " } catch (err) {",
41057
+ " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
41058
+ " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
41059
+ ` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
41060
+ " }",
41061
+ " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: dataPage.head || '' }), {",
41062
+ " headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
41063
+ " });",
41064
+ ...dataNavCleanup
41065
+ ]),
40739
41066
  " }",
40740
41067
  " return __renderHtml(params, url.href);"
40741
41068
  ].join("\n");
@@ -41425,6 +41752,7 @@ init_esbuild_fallback();
41425
41752
  init_strip_ts();
41426
41753
  init_parser();
41427
41754
  init_client_codegen();
41755
+ init_vsk_collision();
41428
41756
  import { readFileSync as readFileSync11, existsSync as existsSync11, writeFileSync as writeFileSync4, unlinkSync as unlinkSync3, statSync as statSync3, rmSync, mkdtempSync, mkdirSync as mkdirSync3 } from "node:fs";
41429
41757
  import { resolve as resolve10, join as join7, dirname as dirname8, relative as relative2, sep } from "node:path";
41430
41758
  import { fileURLToPath as fileURLToPath2 } from "node:url";
@@ -41697,11 +42025,11 @@ var ChunkImports = class {
41697
42025
  const lines = [];
41698
42026
  const sources = [...this.bySource.keys()].sort();
41699
42027
  for (const src2 of sources) {
41700
- const g2 = this.bySource.get(src2);
42028
+ const g4 = this.bySource.get(src2);
41701
42029
  const parts = [];
41702
- if (g2.default) parts.push(`import ${g2.default.local} from ${JSON.stringify(src2)}`);
41703
- if (g2.namespace) parts.push(`import * as ${g2.namespace.local} from ${JSON.stringify(src2)}`);
41704
- const named = [...g2.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
42030
+ if (g4.default) parts.push(`import ${g4.default.local} from ${JSON.stringify(src2)}`);
42031
+ if (g4.namespace) parts.push(`import * as ${g4.namespace.local} from ${JSON.stringify(src2)}`);
42032
+ const named = [...g4.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
41705
42033
  if (named.length > 0) {
41706
42034
  const specs = named.map((sp) => sp.imported === sp.local ? sp.local : `${sp.imported} as ${sp.local}`).join(", ");
41707
42035
  parts.push(`import { ${specs} } from ${JSON.stringify(src2)}`);
@@ -41900,7 +42228,8 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
41900
42228
  }
41901
42229
  const namesBefore = cache2 ? new Set(runtimeImportNames) : null;
41902
42230
  const importedPaths = resolveVskImports(filePath, (p, n) => compileFile2(p, n, output, imports));
41903
- const { comp: rawComp, hyd: rawHyd, name: actualName, aliases, reexportPaths } = compileClientBoth(src2, null, filePath);
42231
+ const { comp: rawComp, hyd: rawHyd, name: actualName, aliases, reexportPaths, componentNames } = compileClientBoth(src2, null, filePath);
42232
+ for (const cn of componentNames || []) componentOwners.claim(cn, filePath);
41904
42233
  const compWithImports = rawComp ? stripExports(stripVskImports(stripRuntimeImport(rawComp))) : "";
41905
42234
  const hydWithImports = rawHyd ? stripExports(stripVskImports(stripRuntimeImport(rawHyd))) : "";
41906
42235
  const compSpecs = [];
@@ -41950,6 +42279,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
41950
42279
  }
41951
42280
  const codeSplit = !!options?.codeSplit;
41952
42281
  const transformPlugins = options?.plugins || [];
42282
+ const componentOwners = new VskComponentOwners();
41953
42283
  async function applyTransformPlugins(code, filePath) {
41954
42284
  if (transformPlugins.length === 0) return code;
41955
42285
  let out = code;
@@ -42088,6 +42418,7 @@ ${entry.code}
42088
42418
  for (const chunk of chunks) {
42089
42419
  transformedChunks.push({ ...chunk, code: await applyTransformPlugins(chunk.code, chunk.name) });
42090
42420
  }
42421
+ componentOwners.report("client bundle");
42091
42422
  return { main: await applyTransformPlugins(main, "client.js"), chunks: transformedChunks, cachedFileHits, compiledFiles, mainFromCache, editedSources, editedNames };
42092
42423
  } else {
42093
42424
  let compileFileMono2 = function(filePath, resolvedName) {
@@ -42095,6 +42426,7 @@ ${entry.code}
42095
42426
  seen.add(filePath);
42096
42427
  const src2 = readFileSync11(filePath, "utf-8");
42097
42428
  resolveVskImports(filePath, (p, n) => compileFileMono2(p, n || ""));
42429
+ for (const cn of vskComponentNames(src2, filePath)) componentOwners.claim(cn, filePath);
42098
42430
  const monoAlloc = nameAllocFor(filePath);
42099
42431
  const compCode = compileClient(src2, null, { forceClient: true, sourcePath: filePath, nameAllocator: monoAlloc });
42100
42432
  const hydCode = compileClient(src2, null, { hydrate: true, forceClient: true, includeTopLevel: false, sourcePath: filePath, nameAllocator: monoAlloc });
@@ -42144,6 +42476,7 @@ ${entry.code}
42144
42476
  aliasLines,
42145
42477
  hydratorAliasLines
42146
42478
  }, !!options?.hmr, !!options?.importRuntime, runtimeImportNames, options?.routeDataCache);
42479
+ componentOwners.report("client bundle");
42147
42480
  return { main: await applyTransformPlugins(main, "client.js"), chunks: [] };
42148
42481
  }
42149
42482
  }
@@ -42743,7 +43076,7 @@ async function startProdServer(outDir, options) {
42743
43076
  }
42744
43077
  if (url.pathname === "/ssr-data.js") {
42745
43078
  const token = url.searchParams.get("t") || "";
42746
- const store = globalThis.__vsk_ssr_data_store;
43079
+ const store = globalThis.__vsk_ssr_payload_store;
42747
43080
  const payload = store?.[token];
42748
43081
  if (payload) delete store[token];
42749
43082
  const lines = [];
@@ -43558,37 +43891,120 @@ init_server_utils();
43558
43891
  init_server_head();
43559
43892
  init_server_jsgen();
43560
43893
  init_server_render();
43894
+ init_ssr_store();
43561
43895
 
43562
43896
  // ../compiler/dist/ssr-store.js
43563
43897
  init_index_server();
43564
43898
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
43565
- var storage2 = new AsyncLocalStorage2();
43899
+ var TOKEN_KEY2 = "__vsk_ssr_token";
43900
+ var IMPL_KEY2 = "__vsk_ssr_store_impl";
43901
+ var g3 = globalThis;
43902
+ var impl2 = g3[IMPL_KEY2] ?? (g3[IMPL_KEY2] = {
43903
+ storage: new AsyncLocalStorage2(),
43904
+ liveSlots: /* @__PURE__ */ new Map(),
43905
+ // Only the copy that created the implementation installs the token
43906
+ // accessor; a later copy must not redefine it over the shared storage.
43907
+ ownsAccessor: true
43908
+ });
43909
+ var storage2 = impl2.storage;
43910
+ var liveSlots2 = impl2.liveSlots;
43911
+ function newSsrToken2() {
43912
+ return Math.random().toString(36).slice(2);
43913
+ }
43914
+ function createSsrStore3() {
43915
+ return { token: newSsrToken2(), data: {} };
43916
+ }
43917
+ function isThenable2(value) {
43918
+ return typeof value?.then === "function";
43919
+ }
43566
43920
  function withSsrStore2(fn) {
43567
43921
  const existing = storage2.getStore();
43568
43922
  if (existing)
43569
43923
  return fn();
43570
- return storage2.run({}, fn);
43924
+ const store = createSsrStore3();
43925
+ keepSsrSlot2(store.token);
43926
+ let result;
43927
+ try {
43928
+ result = storage2.run(store, fn);
43929
+ } catch (err) {
43930
+ dropSsrSlot2(store.token);
43931
+ throw err;
43932
+ }
43933
+ if (isThenable2(result)) {
43934
+ return result.then((value) => {
43935
+ dropSsrSlot2(store.token);
43936
+ return value;
43937
+ }, (err) => {
43938
+ dropSsrSlot2(store.token);
43939
+ throw err;
43940
+ });
43941
+ }
43942
+ dropSsrSlot2(store.token);
43943
+ return result;
43944
+ }
43945
+ function withSsrStoreOf2(store, fn) {
43946
+ return storage2.run(store, fn);
43947
+ }
43948
+ function resetSsrToken2() {
43949
+ const store = storage2.getStore();
43950
+ const token = newSsrToken2();
43951
+ if (store) {
43952
+ if (store.token)
43953
+ liveSlots2.delete(store.token);
43954
+ store.token = token;
43955
+ }
43956
+ liveSlots2.set(token, 1);
43957
+ return token;
43958
+ }
43959
+ function keepSsrSlot2(token) {
43960
+ if (!token)
43961
+ return;
43962
+ liveSlots2.set(token, (liveSlots2.get(token) ?? 0) + 1);
43963
+ }
43964
+ function dropSsrSlot2(token) {
43965
+ if (!token)
43966
+ return;
43967
+ const count = liveSlots2.get(token);
43968
+ if (count === void 0)
43969
+ return;
43970
+ if (count <= 1)
43971
+ liveSlots2.delete(token);
43972
+ else
43973
+ liveSlots2.set(token, count - 1);
43571
43974
  }
43572
43975
  var ssrSink3 = {
43573
43976
  set: (key, value) => {
43574
43977
  const store = storage2.getStore();
43575
43978
  if (store)
43576
- store[key] = value;
43979
+ store.data[key] = value;
43577
43980
  },
43578
43981
  get: (key) => {
43579
43982
  const store = storage2.getStore();
43580
- return store ? store[key] : void 0;
43983
+ return store ? store.data[key] : void 0;
43581
43984
  },
43582
- snapshot: () => ({ ...storage2.getStore() ?? {} }),
43985
+ snapshot: () => ({ ...storage2.getStore()?.data ?? {} }),
43583
43986
  clear: () => {
43584
43987
  const store = storage2.getStore();
43585
43988
  if (store) {
43586
- for (const key of Object.keys(store))
43587
- delete store[key];
43989
+ for (const key of Object.keys(store.data))
43990
+ delete store.data[key];
43588
43991
  }
43589
43992
  }
43590
43993
  };
43591
43994
  setSsrSink(ssrSink3);
43995
+ if (impl2.ownsAccessor) {
43996
+ Object.defineProperty(globalThis, TOKEN_KEY2, {
43997
+ configurable: true,
43998
+ get() {
43999
+ return storage2.getStore()?.token;
44000
+ },
44001
+ set(value) {
44002
+ const store = storage2.getStore();
44003
+ if (store)
44004
+ store.token = value;
44005
+ }
44006
+ });
44007
+ }
43592
44008
 
43593
44009
  // ../compiler/dist/client-codegen.js
43594
44010
  init_ir();
@@ -45890,13 +46306,17 @@ function compileClientBoth2(source, _componentName, sourcePath2, opts) {
45890
46306
  const aliases = vskRegistryAliases(ir.imports, ir.exportAliases);
45891
46307
  const reexportPaths = sourcePath2 ? collectVskReexportPaths(ir.reexportSources, sourcePath2) : [];
45892
46308
  if (opts?.skipHyd)
45893
- return { comp, hyd: "", name, aliases, reexportPaths };
46309
+ return { comp, hyd: "", name, aliases, reexportPaths, componentNames: ir.components.map((c) => c.name) };
45894
46310
  return {
45895
46311
  comp,
45896
46312
  hyd: emitClientFromIR2(irHyd, { forceClient: true, hydrate: true, includeTopLevel: false, nameAllocator: alloc, markerless: opts?.markerless !== false }),
45897
46313
  name,
45898
46314
  aliases,
45899
- reexportPaths
46315
+ reexportPaths,
46316
+ // Every component NAME this file registers, not just the resolved one —
46317
+ // the bundle needs the full list to spot same-name declarations across
46318
+ // files (see findVskComponentCollisions).
46319
+ componentNames: ir.components.map((c) => c.name)
45900
46320
  };
45901
46321
  }
45902
46322
 
@@ -47095,6 +47515,7 @@ async function build3(options) {
47095
47515
  init_strip_ts();
47096
47516
  init_parser();
47097
47517
  init_client_codegen();
47518
+ init_vsk_collision();
47098
47519
  init_vsk_imports();
47099
47520
  init_md_inline();
47100
47521
  init_module_imports();
@@ -47390,13 +47811,13 @@ var ChunkImports2 = class {
47390
47811
  const lines = [];
47391
47812
  const sources = [...this.bySource.keys()].sort();
47392
47813
  for (const src2 of sources) {
47393
- const g2 = this.bySource.get(src2);
47814
+ const g4 = this.bySource.get(src2);
47394
47815
  const parts = [];
47395
- if (g2.default)
47396
- parts.push(`import ${g2.default.local} from ${JSON.stringify(src2)}`);
47397
- if (g2.namespace)
47398
- parts.push(`import * as ${g2.namespace.local} from ${JSON.stringify(src2)}`);
47399
- const named = [...g2.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
47816
+ if (g4.default)
47817
+ parts.push(`import ${g4.default.local} from ${JSON.stringify(src2)}`);
47818
+ if (g4.namespace)
47819
+ parts.push(`import * as ${g4.namespace.local} from ${JSON.stringify(src2)}`);
47820
+ const named = [...g4.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
47400
47821
  if (named.length > 0) {
47401
47822
  const specs = named.map((sp) => sp.imported === sp.local ? sp.local : `${sp.imported} as ${sp.local}`).join(", ");
47402
47823
  parts.push(`import { ${specs} } from ${JSON.stringify(src2)}`);
@@ -47612,7 +48033,9 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
47612
48033
  }
47613
48034
  const namesBefore = cache2 ? new Set(runtimeImportNames) : null;
47614
48035
  const importedPaths = resolveVskImports(filePath, (p, n) => compileFile2(p, n, output, imports));
47615
- const { comp: rawComp, hyd: rawHyd, name: actualName, aliases, reexportPaths } = compileClientBoth(src2, null, filePath);
48036
+ const { comp: rawComp, hyd: rawHyd, name: actualName, aliases, reexportPaths, componentNames } = compileClientBoth(src2, null, filePath);
48037
+ for (const cn of componentNames || [])
48038
+ componentOwners.claim(cn, filePath);
47616
48039
  const compWithImports = rawComp ? stripExports(stripVskImports(stripRuntimeImport(rawComp))) : "";
47617
48040
  const hydWithImports = rawHyd ? stripExports(stripVskImports(stripRuntimeImport(rawHyd))) : "";
47618
48041
  const compSpecs = [];
@@ -47666,6 +48089,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
47666
48089
  }
47667
48090
  const codeSplit = !!options?.codeSplit;
47668
48091
  const transformPlugins = options?.plugins || [];
48092
+ const componentOwners = new VskComponentOwners();
47669
48093
  async function applyTransformPlugins(code, filePath) {
47670
48094
  if (transformPlugins.length === 0)
47671
48095
  return code;
@@ -47811,6 +48235,7 @@ ${entry.code}
47811
48235
  for (const chunk of chunks) {
47812
48236
  transformedChunks.push({ ...chunk, code: await applyTransformPlugins(chunk.code, chunk.name) });
47813
48237
  }
48238
+ componentOwners.report("client bundle");
47814
48239
  return { main: await applyTransformPlugins(main, "client.js"), chunks: transformedChunks, cachedFileHits, compiledFiles, mainFromCache, editedSources, editedNames };
47815
48240
  } else {
47816
48241
  let compileFileMono2 = function(filePath, resolvedName) {
@@ -47819,6 +48244,8 @@ ${entry.code}
47819
48244
  seen.add(filePath);
47820
48245
  const src2 = readFileSync24(filePath, "utf-8");
47821
48246
  resolveVskImports(filePath, (p, n) => compileFileMono2(p, n || ""));
48247
+ for (const cn of vskComponentNames(src2, filePath))
48248
+ componentOwners.claim(cn, filePath);
47822
48249
  const monoAlloc = nameAllocFor(filePath);
47823
48250
  const compCode = compileClient(src2, null, { forceClient: true, sourcePath: filePath, nameAllocator: monoAlloc });
47824
48251
  const hydCode = compileClient(src2, null, { hydrate: true, forceClient: true, includeTopLevel: false, sourcePath: filePath, nameAllocator: monoAlloc });
@@ -47878,6 +48305,7 @@ ${entry.code}
47878
48305
  aliasLines,
47879
48306
  hydratorAliasLines
47880
48307
  }, !!options?.hmr, !!options?.importRuntime, runtimeImportNames, options?.routeDataCache);
48308
+ componentOwners.report("client bundle");
47881
48309
  return { main: await applyTransformPlugins(main, "client.js"), chunks: [] };
47882
48310
  }
47883
48311
  }
@@ -53833,10 +54261,10 @@ function parseCookies3(str3) {
53833
54261
  // ../runtime/dist/action.js
53834
54262
  var registryKey2 = "__vesk_actions";
53835
54263
  function getActionRegistry2() {
53836
- const g2 = globalThis;
53837
- if (!g2[registryKey2])
53838
- g2[registryKey2] = {};
53839
- return g2[registryKey2];
54264
+ const g4 = globalThis;
54265
+ if (!g4[registryKey2])
54266
+ g4[registryKey2] = {};
54267
+ return g4[registryKey2];
53840
54268
  }
53841
54269
  function getAction2(id) {
53842
54270
  return getActionRegistry2()[id] || null;
@@ -54412,8 +54840,41 @@ var ROUTE_STRUCTURAL_VSK = /* @__PURE__ */ new Set([
54412
54840
  "offline.vsk",
54413
54841
  "network.vsk"
54414
54842
  ]);
54415
- var HMR_SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".vesk", "tarballs", ".git"]);
54416
- var HMR_SKIP_MARKERS = ["node_modules/", ".vesk/", "tmp-vesk-chunk-"];
54843
+ var HMR_SKIP_DIRS = /* @__PURE__ */ new Set([
54844
+ "node_modules",
54845
+ ".vesk",
54846
+ "tarballs",
54847
+ ".git",
54848
+ "dist",
54849
+ "build",
54850
+ "coverage",
54851
+ "out",
54852
+ ".next",
54853
+ ".nuxt",
54854
+ ".output",
54855
+ ".svelte-kit",
54856
+ ".turbo",
54857
+ ".cache",
54858
+ ".vercel",
54859
+ ".netlify"
54860
+ ]);
54861
+ var HMR_SKIP_MARKERS = [
54862
+ "node_modules/",
54863
+ ".vesk/",
54864
+ "tmp-vesk-chunk-",
54865
+ "/dist/",
54866
+ "/build/",
54867
+ "/coverage/",
54868
+ "/out/",
54869
+ "/.next/",
54870
+ "/.nuxt/",
54871
+ "/.output/",
54872
+ "/.svelte-kit/",
54873
+ "/.turbo/",
54874
+ "/.cache/",
54875
+ "/.vercel/",
54876
+ "/.netlify/"
54877
+ ];
54417
54878
  var HMR_SCRIPT_EXTS = [".mts", ".ts", ".tsx", ".mjs", ".js", ".cjs"];
54418
54879
  var HMR_CONFIG_NAMES = /* @__PURE__ */ new Set([
54419
54880
  "vesk.config.ts",
@@ -54459,9 +54920,9 @@ function storeDataScript(payload) {
54459
54920
  return "/_vesk/ssr-data.js?t=" + token;
54460
54921
  }
54461
54922
  function currentSsrData() {
54462
- const g2 = globalThis;
54463
- const token = g2.__vsk_ssr_token;
54464
- const slot = (token ? g2[`__vsk_ssr_data_${token}`] : void 0) || {};
54923
+ const g4 = globalThis;
54924
+ const token = g4.__vsk_ssr_token;
54925
+ const slot = (token ? g4[`__vsk_ssr_data_${token}`] : void 0) || {};
54465
54926
  return { ...ssrSink3.snapshot() || {}, ...slot };
54466
54927
  }
54467
54928
  function countPages(nodes) {
@@ -54554,9 +55015,9 @@ async function startDevServer(port, projectDir, config, host) {
54554
55015
  }
54555
55016
  }
54556
55017
  function eventsStore() {
54557
- const g2 = globalThis;
54558
- if (!g2.__vesk_server_ctx) g2.__vesk_server_ctx = {};
54559
- return g2.__vesk_server_ctx;
55018
+ const g4 = globalThis;
55019
+ if (!g4.__vesk_server_ctx) g4.__vesk_server_ctx = {};
55020
+ return g4.__vesk_server_ctx;
54560
55021
  }
54561
55022
  function makeEventCtx(overrides) {
54562
55023
  const store = eventsStore();
@@ -54960,6 +55421,7 @@ async function startDevServer(port, projectDir, config, host) {
54960
55421
  const treeChanged = needsRescan && prevTree !== stripAnnots(routeTree);
54961
55422
  const isOutsideApp = !fullPath.startsWith(appDirPath + "/") && fullPath !== appDirPath;
54962
55423
  const fileDeleted = eventType === "rename" && !fileExists;
55424
+ if (isOutsideApp) ssrCompileCache.clear();
54963
55425
  const cssPromise = rebuildTailwindCss();
54964
55426
  let bundleError = null;
54965
55427
  let hotEditedSource = null;
@@ -55104,6 +55566,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
55104
55566
  const t0 = Date.now();
55105
55567
  try {
55106
55568
  bcast({ type: "compiling" });
55569
+ ssrCompileCache.clear();
55107
55570
  await fullRebuild();
55108
55571
  LOG.info(`${kind === "config" ? "config" : "script"} changed, full rebuild + reload (${filename}) \u2014 ${Date.now() - t0}ms`);
55109
55572
  } catch (e) {
@@ -55411,11 +55874,11 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
55411
55874
  const forData = req.headers["x-vesk-data"] === "1";
55412
55875
  async function renderSSR() {
55413
55876
  const ssg2 = globalThis;
55414
- const freshToken = Math.random().toString(36).slice(2);
55415
- ssg2.__vsk_ssr_token = freshToken;
55416
55877
  ssg2.__vsk_ssr_data = {};
55878
+ let freshToken;
55417
55879
  try {
55418
55880
  return await withSsrStore2(async () => {
55881
+ freshToken = resetSsrToken2();
55419
55882
  const chain = cleanChain;
55420
55883
  let body = "";
55421
55884
  let head = "";
@@ -55490,17 +55953,16 @@ ${prettifyHtml(body)}
55490
55953
  return { html, props: props || { params: matched.params }, head };
55491
55954
  });
55492
55955
  } finally {
55493
- delete ssg2[`__vsk_ssr_data_${freshToken}`];
55494
- delete ssg2[`__vsk_ssr_promises_${freshToken}`];
55495
- delete ssg2[`__vsk_ssr_failures_${freshToken}`];
55496
- if (ssg2.__vsk_ssr_token === freshToken) delete ssg2.__vsk_ssr_token;
55956
+ const token = freshToken;
55957
+ dropSsrSlot2(token);
55958
+ delete ssg2[`__vsk_ssr_data_${token}`];
55959
+ delete ssg2[`__vsk_ssr_promises_${token}`];
55960
+ delete ssg2[`__vsk_ssr_failures_${token}`];
55497
55961
  delete ssg2.__vsk_ssr_data;
55498
55962
  }
55499
55963
  }
55500
55964
  function renderSSRStream() {
55501
55965
  const sst = globalThis;
55502
- const streamToken = Math.random().toString(36).slice(2);
55503
- sst.__vsk_ssr_token = streamToken;
55504
55966
  sst.__vsk_ssr_data = {};
55505
55967
  async function* raw2() {
55506
55968
  const chain = cleanChain;
@@ -55564,18 +56026,22 @@ ${prettifyHtml(body)}
55564
56026
  yield ' <script type="module" src="/_vesk/client.js"></script>\n</body>\n</html>';
55565
56027
  }
55566
56028
  const gen = raw2();
56029
+ const streamStore = createSsrStore3();
55567
56030
  async function* scoped() {
55568
56031
  try {
55569
56032
  let result;
55570
56033
  do {
55571
- result = await withSsrStore2(() => gen.next());
56034
+ result = await withSsrStoreOf2(streamStore, () => gen.next());
55572
56035
  if (!result.done) yield result.value;
55573
56036
  } while (!result.done);
55574
56037
  } finally {
55575
- delete sst[`__vsk_ssr_data_${streamToken}`];
55576
- delete sst[`__vsk_ssr_promises_${streamToken}`];
55577
- delete sst[`__vsk_ssr_failures_${streamToken}`];
55578
- if (sst.__vsk_ssr_token === streamToken) delete sst.__vsk_ssr_token;
56038
+ const token = streamStore.token;
56039
+ dropSsrSlot2(token);
56040
+ if (token) {
56041
+ delete sst[`__vsk_ssr_data_${token}`];
56042
+ delete sst[`__vsk_ssr_promises_${token}`];
56043
+ delete sst[`__vsk_ssr_failures_${token}`];
56044
+ }
55579
56045
  delete sst.__vsk_ssr_data;
55580
56046
  }
55581
56047
  }
@@ -55794,7 +56260,6 @@ ${prettifyHtml(body)}
55794
56260
  LOG.info(`${projectDir}`);
55795
56261
  LOG.info(`${pageCount} page${pageCount === 1 ? "" : "s"}: ${routes.join(", ") || "(none)"}`);
55796
56262
  if (apiCount > 0) LOG.info(`${apiCount} api route${apiCount === 1 ? "" : "s"} (app/api)`);
55797
- LOG.info("hmr enabled \u2014 edit app/ to hot reload");
55798
56263
  });
55799
56264
  updateSourceMapping();
55800
56265
  const hmrClients = /* @__PURE__ */ new Set();