@torpor/view 1.2.1 → 1.2.3

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.
package/dist/compile.cjs CHANGED
@@ -392,6 +392,16 @@ function addPushDevBoundary(type, name, status, b) {
392
392
  const HYDRATION_START_COMMENT = "<![>";
393
393
  const HYDRATION_END_COMMENT = "<!]>";
394
394
  const HYDRATION_BREAK_COMMENT = "<!^>";
395
+ /**
396
+ * The branch-break comment for a control statement's branch, with the branch
397
+ * index baked in (`<!^2>`). The server renderer knows which branch it
398
+ * rendered; hydration reads the index back from the marker to detect a
399
+ * branch the client picks differently (see render/hydrationMarkers and
400
+ * render/branchIndex).
401
+ */
402
+ function hydrationBranchComment(index) {
403
+ return `<!^${index}>`;
404
+ }
395
405
  //#endregion
396
406
  //#region src/compile/utils/isControlNode.ts
397
407
  function isControlNode(node) {
@@ -1084,9 +1094,22 @@ function declareControlFragmentVars(fragment, node, path, status, b, parentName,
1084
1094
  case "@html group":
1085
1095
  declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, node.operation.substring(1).replace(" group", ""), declare);
1086
1096
  break;
1087
- default: for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
1097
+ default:
1098
+ if (SCRIPT_OPERATIONS.has(node.operation)) {
1099
+ buildNode(node, status, b, parentName, anchorName);
1100
+ node.handled = true;
1101
+ break;
1102
+ }
1103
+ for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
1088
1104
  }
1089
1105
  }
1106
+ const SCRIPT_OPERATIONS = /* @__PURE__ */ new Set([
1107
+ "@const",
1108
+ "@console",
1109
+ "@debugger",
1110
+ "@function",
1111
+ "@async function"
1112
+ ]);
1090
1113
  function declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
1091
1114
  declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, "comp", declare);
1092
1115
  }
@@ -3216,13 +3239,14 @@ function buildServerHtmlNode(node, status) {
3216
3239
  function buildServerIfNode(node, status, b) {
3217
3240
  status.output += HYDRATION_START_COMMENT;
3218
3241
  flushOutput(status, b);
3219
- for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b);
3242
+ let index = 0;
3243
+ for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b, index++);
3220
3244
  status.output += HYDRATION_END_COMMENT;
3221
3245
  status.output += "<!>";
3222
3246
  }
3223
- function buildServerIfBranch(node, status, b) {
3247
+ function buildServerIfBranch(node, status, b, index) {
3224
3248
  b.append(`${node.statement} {`);
3225
- status.output += HYDRATION_BREAK_COMMENT;
3249
+ status.output += hydrationBranchComment(index);
3226
3250
  for (let child of node.children) buildServerNode(child, status, b);
3227
3251
  flushOutput(status, b);
3228
3252
  b.append("}");
@@ -3256,14 +3280,15 @@ function buildServerSwitchNode(node, status, b) {
3256
3280
  status.output += HYDRATION_START_COMMENT;
3257
3281
  flushOutput(status, b);
3258
3282
  b.append(`${node.statement} {`);
3259
- for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b);
3283
+ let index = 0;
3284
+ for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b, index++);
3260
3285
  b.append("}");
3261
3286
  status.output += HYDRATION_END_COMMENT;
3262
3287
  status.output += "<!>";
3263
3288
  }
3264
- function buildServerSwitchBranch(node, status, b) {
3289
+ function buildServerSwitchBranch(node, status, b, index) {
3265
3290
  b.append(`${node.statement} {`);
3266
- status.output += HYDRATION_BREAK_COMMENT;
3291
+ status.output += hydrationBranchComment(index);
3267
3292
  for (let child of node.children) buildServerNode(child, status, b);
3268
3293
  flushOutput(status, b);
3269
3294
  b.append("break;");
package/dist/compile.mjs CHANGED
@@ -391,6 +391,16 @@ function addPushDevBoundary(type, name, status, b) {
391
391
  const HYDRATION_START_COMMENT = "<![>";
392
392
  const HYDRATION_END_COMMENT = "<!]>";
393
393
  const HYDRATION_BREAK_COMMENT = "<!^>";
394
+ /**
395
+ * The branch-break comment for a control statement's branch, with the branch
396
+ * index baked in (`<!^2>`). The server renderer knows which branch it
397
+ * rendered; hydration reads the index back from the marker to detect a
398
+ * branch the client picks differently (see render/hydrationMarkers and
399
+ * render/branchIndex).
400
+ */
401
+ function hydrationBranchComment(index) {
402
+ return `<!^${index}>`;
403
+ }
394
404
  //#endregion
395
405
  //#region src/compile/utils/isControlNode.ts
396
406
  function isControlNode(node) {
@@ -1083,9 +1093,22 @@ function declareControlFragmentVars(fragment, node, path, status, b, parentName,
1083
1093
  case "@html group":
1084
1094
  declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, node.operation.substring(1).replace(" group", ""), declare);
1085
1095
  break;
1086
- default: for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
1096
+ default:
1097
+ if (SCRIPT_OPERATIONS.has(node.operation)) {
1098
+ buildNode(node, status, b, parentName, anchorName);
1099
+ node.handled = true;
1100
+ break;
1101
+ }
1102
+ for (let [i, child] of node.children.entries()) declareFragmentVars(fragment, child, path, status, b, parentName, anchorName, varPaths, i === node.children.length - 1, declare);
1087
1103
  }
1088
1104
  }
1105
+ const SCRIPT_OPERATIONS = /* @__PURE__ */ new Set([
1106
+ "@const",
1107
+ "@console",
1108
+ "@debugger",
1109
+ "@function",
1110
+ "@async function"
1111
+ ]);
1089
1112
  function declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
1090
1113
  declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, "comp", declare);
1091
1114
  }
@@ -3215,13 +3238,14 @@ function buildServerHtmlNode(node, status) {
3215
3238
  function buildServerIfNode(node, status, b) {
3216
3239
  status.output += HYDRATION_START_COMMENT;
3217
3240
  flushOutput(status, b);
3218
- for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b);
3241
+ let index = 0;
3242
+ for (let branch of node.children) if (isControlNode(branch)) buildServerIfBranch(branch, status, b, index++);
3219
3243
  status.output += HYDRATION_END_COMMENT;
3220
3244
  status.output += "<!>";
3221
3245
  }
3222
- function buildServerIfBranch(node, status, b) {
3246
+ function buildServerIfBranch(node, status, b, index) {
3223
3247
  b.append(`${node.statement} {`);
3224
- status.output += HYDRATION_BREAK_COMMENT;
3248
+ status.output += hydrationBranchComment(index);
3225
3249
  for (let child of node.children) buildServerNode(child, status, b);
3226
3250
  flushOutput(status, b);
3227
3251
  b.append("}");
@@ -3255,14 +3279,15 @@ function buildServerSwitchNode(node, status, b) {
3255
3279
  status.output += HYDRATION_START_COMMENT;
3256
3280
  flushOutput(status, b);
3257
3281
  b.append(`${node.statement} {`);
3258
- for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b);
3282
+ let index = 0;
3283
+ for (let branch of node.children.filter((c) => isControlNode(c))) if (isControlNode(branch)) buildServerSwitchBranch(branch, status, b, index++);
3259
3284
  b.append("}");
3260
3285
  status.output += HYDRATION_END_COMMENT;
3261
3286
  status.output += "<!>";
3262
3287
  }
3263
- function buildServerSwitchBranch(node, status, b) {
3288
+ function buildServerSwitchBranch(node, status, b, index) {
3264
3289
  b.append(`${node.statement} {`);
3265
- status.output += HYDRATION_BREAK_COMMENT;
3290
+ status.output += hydrationBranchComment(index);
3266
3291
  for (let child of node.children) buildServerNode(child, status, b);
3267
3292
  flushOutput(status, b);
3268
3293
  b.append("break;");