@vesk/compiler 0.2.23 → 0.2.24

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.
@@ -1 +1 @@
1
- {"version":3,"file":"client-codegen.d.ts","sourceRoot":"","sources":["../src/client-codegen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAGL,cAAc,EAQd,gBAAgB,EAOjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAwCxD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC;CAC1B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI1D;AAiDD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,gBAAgB,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAwGlI;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAU5E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAY5F;AAw1CD,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAe3C;AA2HD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAqED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAA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AG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAY5F;AAw2CD,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAe3C;AA2HD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C;AAqED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAAG,MAAM,CAOnN;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAqBxJ;AAED,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -828,7 +828,11 @@ function emitOpaque(ctx, node, tracked, effTarget, parentVar) {
828
828
  const cl = ctx.n();
829
829
  ctx.push(indent(`const ${cl} = [];`));
830
830
  for (const n of chain[i].nodes) {
831
+ const savedClaim = ctx.claimStatic;
832
+ if (hyd)
833
+ ctx.claimStatic = true;
831
834
  const v = emitNode(ctx, n, tracked, effectsVar, parentVar);
835
+ ctx.claimStatic = savedClaim;
832
836
  if (v)
833
837
  ctx.push(indent(`${cl}.push(${v});`));
834
838
  }
@@ -842,7 +846,11 @@ function emitOpaque(ctx, node, tracked, effTarget, parentVar) {
842
846
  const cl2 = ctx.n();
843
847
  ctx.push(indent(`const ${cl2} = [];`));
844
848
  for (const n of finalElse) {
849
+ const savedClaim = ctx.claimStatic;
850
+ if (hyd)
851
+ ctx.claimStatic = true;
845
852
  const v = emitNode(ctx, n, tracked, effectsVar, parentVar);
853
+ ctx.claimStatic = savedClaim;
846
854
  if (v)
847
855
  ctx.push(indent(`${cl2}.push(${v});`));
848
856
  }
@@ -855,22 +863,22 @@ function emitOpaque(ctx, node, tracked, effTarget, parentVar) {
855
863
  if (finalRender)
856
864
  init += ` else { ${asyncKw}${finalRender}(); }`;
857
865
  ctx.push(init);
858
- let branchInit;
859
- if (chain.length === 1 && finalRender)
860
- branchInit = `(${chain[0].cond} ? 0 : 1)`;
861
- else if (chain.length === 2 && finalRender)
862
- branchInit = `(${chain[0].cond} ? 0 : (${chain[1].cond} ? 1 : 2))`;
863
- else if (chain.length === 2 && !finalRender)
864
- branchInit = `(${chain[0].cond} ? 0 : (${chain[1].cond} ? 1 : -1))`;
865
- else
866
- branchInit = `(${chain[0].cond} ? 0 : -1)`;
866
+ // Resolve which branch index the chain is in, for any chain depth. The last
867
+ // fallback is `chain.length` when a final `else` exists, otherwise -1 (no
868
+ // branch renders). Build the nested ternary from the innermost condition
869
+ // outwards so every else-if participates.
870
+ let branchInitFallback = finalRender ? `${chain.length}` : '-1';
871
+ for (let i = chain.length - 1; i >= 0; i--) {
872
+ branchInitFallback = `(${chain[i].cond} ? ${i} : ${branchInitFallback})`;
873
+ }
874
+ const branchInit = `(${branchInitFallback})`;
867
875
  let effInner = `if (__new === 0) { ${asyncKw}${renderNames[0]}(); }`;
868
876
  for (let i = 1; i < chain.length; i++)
869
877
  effInner += ` else if (__new === ${i}) { ${asyncKw}${renderNames[i]}(); }`;
870
878
  if (finalRender)
871
879
  effInner += ` else { ${asyncKw}${finalRender}(); }`;
872
880
  const effBody = `effect(${ctx.isAsyncScope ? 'async () => {' : '() => {'}
873
- if (__first) { __first = false; return; }
881
+ if (__first) { __first = false; __iv = ${branchInit}; return; }
874
882
  const __new = ${branchInit};
875
883
  if (__new !== __iv) {
876
884
  for (const e of ${effectsVar}) destroy_block(e);
@@ -918,7 +926,11 @@ function emitOpaque(ctx, node, tracked, effTarget, parentVar) {
918
926
  if (hyd)
919
927
  ctx.push(indent(`const __cl = [];`));
920
928
  for (const n of node.consequentNodes) {
929
+ const savedClaim = ctx.claimStatic;
930
+ if (hyd)
931
+ ctx.claimStatic = true;
921
932
  const v = emitNode(ctx, n, tracked, effectsVar, hyd ? parentVar : conFrag);
933
+ ctx.claimStatic = savedClaim;
922
934
  if (v) {
923
935
  if (hyd)
924
936
  ctx.push(indent(`__cl.push(${v});`));
@@ -943,7 +955,11 @@ function emitOpaque(ctx, node, tracked, effTarget, parentVar) {
943
955
  if (hyd)
944
956
  ctx.push(indent(`const __cl = [];`));
945
957
  for (const n of node.alternateNodes) {
958
+ const savedAltClaim = ctx.claimStatic;
959
+ if (hyd)
960
+ ctx.claimStatic = true;
946
961
  const v = emitNode(ctx, n, tracked, effectsVar, hyd ? parentVar : altFrag);
962
+ ctx.claimStatic = savedAltClaim;
947
963
  if (v) {
948
964
  if (hyd)
949
965
  ctx.push(indent(`__cl.push(${v});`));
@@ -1 +1 @@
1
- {"version":3,"file":"server-jsgen.d.ts","sourceRoot":"","sources":["../src/server-jsgen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAOzE,OAAO,EAAkG,KAAK,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAoCrK,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,GAAE,OAAe,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAmDjJ;AA6VD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,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-209,18 +209,27 @@ function opaqueRegionToJS(node, isAsync = false, tracked) {
209
209
  const lines = [];
210
210
  const cond = exprJSX(node.condition, tracked);
211
211
  lines.push(`if (${cond}) {`);
212
+ // Static branch content still needs server claim markers: the client
213
+ // re-branches an if/else-if region on every tracked change (OpaqueDynamicRegion
214
+ // claimStatic codegen), so opposed to plain component bodies it must be able
215
+ // to adopt the SSR nodes in place — not leave them orphaned next to the
216
+ // region's anchors. Mirrors mapRegionToJS' alternate handling below.
217
+ setVskForceClaim(true);
212
218
  for (const n of node.consequentNodes) {
213
219
  const code = irNodeToJS(n, null, isAsync, tracked);
214
220
  if (code)
215
221
  lines.push(indent(code));
216
222
  }
223
+ setVskForceClaim(false);
217
224
  if (node.alternateNodes.length > 0) {
218
225
  lines.push(`} else {`);
226
+ setVskForceClaim(true);
219
227
  for (const n of node.alternateNodes) {
220
228
  const code = irNodeToJS(n, null, isAsync, tracked);
221
229
  if (code)
222
230
  lines.push(indent(code));
223
231
  }
232
+ setVskForceClaim(false);
224
233
  }
225
234
  lines.push(`}`);
226
235
  return lines.join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/compiler",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
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.23",
23
+ "@vesk/types": "^0.2.24",
24
24
  "acorn": "^8.15.0",
25
25
  "esrap": "^2.3.0",
26
26
  "is-reference": "^3.0.0",