@vesk/compiler 0.2.44 → 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.
@@ -4,4 +4,5 @@ export { irNodeToJS, generateFunctionBody, buildComponentMap, buildComponentEntr
4
4
  export { irToJSON, irFromJSON, hydratePrecompile, } from '@vesk/compiler/src/precompile-runtime';
5
5
  export { precompileFile, } from '@vesk/compiler/src/precompile';
6
6
  export { compileFile, render, renderPage, ssg, renderFullPage, renderPageStream, buildDataScripts, applyHeadPlugins, applyHeadInjects, applyHtmlPlugins, } from '@vesk/compiler/src/server-render';
7
+ export { withSsrStore, withSsrStoreOf, createSsrStore, adoptSsrStore, currentSsrToken, resetSsrToken, keepSsrSlot, dropSsrSlot, isSsrSlotLive, ssrSink, } from '@vesk/compiler/src/ssr-store';
7
8
  //# sourceMappingURL=server-codegen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-codegen.d.ts","sourceRoot":"","sources":["../src/server-codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EACtB,GAAG,EACH,MAAM,EACN,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,OAAO,EACP,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,aAAa,EACb,SAAS,EACT,eAAe,EACf,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,QAAQ,EACR,UAAU,EACV,iBAAiB,GAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EACL,cAAc,GACf,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,MAAM,EACN,UAAU,EACV,GAAG,EACH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,kCAAkC,CAAC"}
1
+ {"version":3,"file":"server-codegen.d.ts","sourceRoot":"","sources":["../src/server-codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EACtB,GAAG,EACH,MAAM,EACN,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,OAAO,EACP,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,WAAW,EACX,aAAa,EACb,SAAS,EACT,eAAe,EACf,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,QAAQ,EACR,UAAU,EACV,iBAAiB,GAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EACL,cAAc,GACf,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,MAAM,EACN,UAAU,EACV,GAAG,EACH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,kCAAkC,CAAC;AAO1C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,OAAO,GACR,MAAM,8BAA8B,CAAC"}
@@ -4,3 +4,9 @@ export { irNodeToJS, generateFunctionBody, buildComponentMap, buildComponentEntr
4
4
  export { irToJSON, irFromJSON, hydratePrecompile, } from '@vesk/compiler/src/precompile-runtime';
5
5
  export { precompileFile, } from '@vesk/compiler/src/precompile';
6
6
  export { compileFile, render, renderPage, ssg, renderFullPage, renderPageStream, buildDataScripts, applyHeadPlugins, applyHeadInjects, applyHtmlPlugins, } from '@vesk/compiler/src/server-render';
7
+ // Re-exported so bundlers reach the request-scope store through THIS module
8
+ // rather than a second specifier for the same file. A bundle that resolved
9
+ // `@vesk/compiler/src/ssr-store` on its own (as the server-runtime entry used
10
+ // to) could end up with two copies of the module — two AsyncLocalStorages and
11
+ // two liveness maps — and the scope one copy opens is invisible to the other.
12
+ export { withSsrStore, withSsrStoreOf, createSsrStore, adoptSsrStore, currentSsrToken, resetSsrToken, keepSsrSlot, dropSsrSlot, isSsrSlotLive, ssrSink, } from '@vesk/compiler/src/ssr-store';
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-store.d.ts","sourceRoot":"","sources":["../src/ssr-store.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,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;CAC/B;AA8CD;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,QAAQ,CAExC;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAuB9C;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEjE;AAED,wEAAwE;AACxE,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAYtC;AAED,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAG3D;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAM3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,eAAO,MAAM,OAAO,EAAE,WAgBrB,CAAC"}
package/dist/ssr-store.js CHANGED
@@ -4,7 +4,16 @@ import { AsyncLocalStorage } from 'node:async_hooks';
4
4
  // resolving types through the barrel then fails.
5
5
  import { setSsrSink } from '@vesk/runtime/src/index-server';
6
6
  const TOKEN_KEY = '__vsk_ssr_token';
7
- const storage = new AsyncLocalStorage();
7
+ const IMPL_KEY = '__vsk_ssr_store_impl';
8
+ const g = globalThis;
9
+ const impl = g[IMPL_KEY] ?? (g[IMPL_KEY] = {
10
+ storage: new AsyncLocalStorage(),
11
+ liveSlots: new Map(),
12
+ // Only the copy that created the implementation installs the token
13
+ // accessor; a later copy must not redefine it over the shared storage.
14
+ ownsAccessor: true,
15
+ });
16
+ const storage = impl.storage;
8
17
  /**
9
18
  * Tokens whose `__vsk_ssr_data_<token>` slot a live render still owns, with a
10
19
  * refcount. A request runs `renderPage` (page) -> `renderPage` (each nested
@@ -13,7 +22,7 @@ const storage = new AsyncLocalStorage();
13
22
  * first inner release revoke the claim the document render still depends on,
14
23
  * so the reaper could reap a live request's handoff. Counts balance instead.
15
24
  */
16
- const liveSlots = new Map();
25
+ const liveSlots = impl.liveSlots;
17
26
  function newSsrToken() {
18
27
  return Math.random().toString(36).slice(2);
19
28
  }
@@ -151,6 +160,9 @@ export const ssrSink = {
151
160
  }
152
161
  },
153
162
  };
163
+ // `setSsrSink` is safe to call from every copy: each copy's sink reads and
164
+ // writes the same shared store, so whichever one the runtime ends up holding
165
+ // behaves identically.
154
166
  setSsrSink(ssrSink);
155
167
  // The generated server code reads `globalThis.__vsk_ssr_token` synchronously
156
168
  // at the top of every component render, and the runtime's promise tracker and
@@ -170,14 +182,16 @@ setSsrSink(ssrSink);
170
182
  // process-global token, reintroducing the race for every later request. Clear
171
183
  // a token by assigning through `globalThis` inside a scope, or with
172
184
  // `resetSsrToken`.
173
- Object.defineProperty(globalThis, TOKEN_KEY, {
174
- configurable: true,
175
- get() {
176
- return storage.getStore()?.token;
177
- },
178
- set(value) {
179
- const store = storage.getStore();
180
- if (store)
181
- store.token = value;
182
- },
183
- });
185
+ if (impl.ownsAccessor) {
186
+ Object.defineProperty(globalThis, TOKEN_KEY, {
187
+ configurable: true,
188
+ get() {
189
+ return storage.getStore()?.token;
190
+ },
191
+ set(value) {
192
+ const store = storage.getStore();
193
+ if (store)
194
+ store.token = value;
195
+ },
196
+ });
197
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/compiler",
3
- "version": "0.2.44",
3
+ "version": "0.2.45",
4
4
  "type": "module",
5
5
  "description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@sveltejs/acorn-typescript": "^1.0.0",
23
- "@vesk/types": "^0.2.44",
23
+ "@vesk/types": "^0.2.45",
24
24
  "acorn": "^8.15.0",
25
25
  "esrap": "^2.3.0",
26
26
  "is-reference": "^3.0.0",