@wcstack/lint 4.3.0 → 4.5.0

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/cli.cjs CHANGED
@@ -56,31 +56,6 @@ function createFileReader(htmlPath, read = (p) => (0, import_node_fs.readFileSyn
56
56
  };
57
57
  }
58
58
 
59
- // src/core/offsetToPosition.ts
60
- function createPositionMapper(text3) {
61
- const lineStarts = [0];
62
- for (let i = 0; i < text3.length; i++) {
63
- const c = text3.charCodeAt(i);
64
- if (c === 10) {
65
- lineStarts.push(i + 1);
66
- } else if (c === 13) {
67
- if (text3.charCodeAt(i + 1) === 10) i++;
68
- lineStarts.push(i + 1);
69
- }
70
- }
71
- return (offset2) => {
72
- const clamped = Math.max(0, Math.min(offset2, text3.length));
73
- let lo = 0;
74
- let hi = lineStarts.length - 1;
75
- while (lo < hi) {
76
- const mid = lo + hi + 1 >> 1;
77
- if (lineStarts[mid] <= clamped) lo = mid;
78
- else hi = mid - 1;
79
- }
80
- return { line: lo + 1, column: clamped - lineStarts[lo] + 1 };
81
- };
82
- }
83
-
84
59
  // src/core/diagnostics.ts
85
60
  var WcsDiagnosticCode = {
86
61
  // --- sidecar manifest envelope / schema subset ---
@@ -107,8 +82,12 @@ var WcsDiagnosticCode = {
107
82
  // --- path / type resolution against a stateSchema ---
108
83
  PathNonexistent: "wcs/path-nonexistent",
109
84
  PathTypeMismatch: "wcs/path-type-mismatch",
85
+ // 書き戻す束縛(`value:` / `checked:` / `radio:` / `checkbox:`、`#ro` なし)が、setter の無い getter を指す。ランタイムは
86
+ // 入力のたびに `"<path>" is a getter without a setter` を投げる(code なし — 7GUIs の評価の Temperature)。error。
110
87
  PathReadonly: "wcs/path-readonly",
111
88
  PathReservedName: "wcs/path-reserved-name",
89
+ // lint の限界の告知(作者の誤りではない): `export default { … }` のトップレベルの spread が持ち込むキーは読めないので、
90
+ // stateSchema の無い state のパスは検査しない — それを spread の上で 1 回だけ言う。info。
112
91
  PathDynamicUnknown: "wcs/path-dynamic-unknown",
113
92
  // --- existing binding-expression validators (retrofitted) ---
114
93
  FilterUnknown: "wcs/filter-unknown",
@@ -119,6 +98,17 @@ var WcsDiagnosticCode = {
119
98
  BindingTypeExpectation: "wcs/binding-type-expectation",
120
99
  TokenUndeclared: "wcs/token-undeclared",
121
100
  TokenMisconfigured: "wcs/token-misconfigured",
101
+ // 宣言したコマンドトークンを emit する(スクリプトの `.emit()`・マークアップの `on*: $command.x`)のに、どの
102
+ // `command.<method>:` 束縛にも結ばれていない。emit は誰にも届かず、ランタイムは何も言わない(7GUIs の評価)。warning
103
+ // (ページの外 — 別ファイルのルートのテンプレート — で束ねる形は見えない)。
104
+ CommandTokenUnbound: "wcs/command-token-unbound",
105
+ // state が宣言していないトップレベルのキーへの書き込み(`this.selectedID = …` と `selectedId`)。新しいキーができる
106
+ // だけで、宣言したキーの束縛は変わらない。ランタイムは何も言わない。近い名前(打ち間違い)があるときだけ、warning。
107
+ WritePathMissing: "wcs/write-path-missing",
108
+ // getter・メソッドの中で読む state のパス(`this["items.*.amout"]`・`$getAll("items.*.amout")`・`this.totl`)が宣言に無い。
109
+ // 入れ子のパスの読みは undefined になり、そこから計算した金額が黙って違う(確定申告の下書きツールの評価)。トップレベルの
110
+ // キーは読んだ時点で throw する。近い名前(打ち間違い)があるときだけ、warning。ランタイムの diagnostics も同じ code。
111
+ ReadPathMissing: "wcs/read-path-missing",
122
112
  NestedAssign: "wcs/nested-assign",
123
113
  // --- 意味論(構文・存在検査では捕まらない取り違え。service/semanticValidator.ts) ---
124
114
  // `$getAll` / `$setAll` / `$resolve` の添字の本数がパスの `*` の本数と噛み合わない。
@@ -217,6 +207,11 @@ var WcsDiagnosticCode = {
217
207
  // 未知メンバーへのバインド(プロパティ / command. / eventToken. キー)。4.0 のランタイムは #38 / #1203 /
218
208
  // #1204 で拒み、root では初期化が、行では束縛が失敗する(3.x の「黙って無視」ではない)。error。
219
209
  TagMemberUnknown: "wcs/tag-member-unknown",
210
+ // `semantics: "handle"` の出力(`<wcs-camera>` の `streamReady` = 生の MediaStream)を、値としてパスに
211
+ // 束ねた。プロトコルは「値の置き場ではなく ref / callback で受ける」と定める(protocol/wc-bindable.ts)。
212
+ // ランタイムは書くので動くが、スナップショット・DevTools・SSR に載らないオブジェクトが state に入る
213
+ // (docs/seam-apps.md、state-field-report)。warning。5.0 でランタイムが拒むかは誤りの目録の議題。
214
+ HandleBoundAsValue: "wcs/handle-bound-as-value",
220
215
  // タグのメンバー名が "on" で始まる(`once` 等)のに先頭ドット無しで束縛した: ランタイムはイベント束縛にして
221
216
  // "ce" イベントを待ち、値は届かない。明示のプロパティ形 `.once:` を提案する(@wcstack/state 3.1・要件 B5 / 3.x 計画 D36)
222
217
  OnPrefixedMember: "wcs/on-prefixed-member",
@@ -326,6 +321,31 @@ function sortDiagnostics(diagnostics) {
326
321
  return [...diagnostics].sort((a, b) => a.start - b.start || severityRank[a.severity] - severityRank[b.severity] || (a.code < b.code ? -1 : a.code > b.code ? 1 : 0));
327
322
  }
328
323
 
324
+ // src/core/offsetToPosition.ts
325
+ function createPositionMapper(text3) {
326
+ const lineStarts = [0];
327
+ for (let i = 0; i < text3.length; i++) {
328
+ const c = text3.charCodeAt(i);
329
+ if (c === 10) {
330
+ lineStarts.push(i + 1);
331
+ } else if (c === 13) {
332
+ if (text3.charCodeAt(i + 1) === 10) i++;
333
+ lineStarts.push(i + 1);
334
+ }
335
+ }
336
+ return (offset2) => {
337
+ const clamped = Math.max(0, Math.min(offset2, text3.length));
338
+ let lo = 0;
339
+ let hi = lineStarts.length - 1;
340
+ while (lo < hi) {
341
+ const mid = lo + hi + 1 >> 1;
342
+ if (lineStarts[mid] <= clamped) lo = mid;
343
+ else hi = mid - 1;
344
+ }
345
+ return { line: lo + 1, column: clamped - lineStarts[lo] + 1 };
346
+ };
347
+ }
348
+
329
349
  // ../state/dist/parser.esm.js
330
350
  var hooks = {};
331
351
  function editDistance(a, b, max) {
@@ -585,8 +605,8 @@ function checkPathLikeGetPathInfo(path) {
585
605
  function recursionUnsupported(path) {
586
606
  raise(1101, [path]);
587
607
  }
588
- function parseStatePart(statePart) {
589
- const [stateAndPath, filters] = splitFilters(statePart, "output", cacheFilterInfos);
608
+ function parseStatePart(statePart2) {
609
+ const [stateAndPath, filters] = splitFilters(statePart2, "output", cacheFilterInfos);
590
610
  if (stateAndPath.includes("@")) {
591
611
  raise(32, [stateAndPath]);
592
612
  }
@@ -595,7 +615,7 @@ function parseStatePart(statePart) {
595
615
  const body = isLoopRelative ? statePathName.slice(DELIMITER.length) : statePathName;
596
616
  const hasEmptySegment = body.length > 0 && body.split(DELIMITER).some((segment) => segment.length === 0);
597
617
  if (hasEmptySegment || !isLoopRelative && body.length === 0) {
598
- raise(119, [statePart]);
618
+ raise(119, [statePart2]);
599
619
  }
600
620
  checkPathLikeGetPathInfo(statePathName);
601
621
  return {
@@ -1157,7 +1177,7 @@ function parseBindTextsForElement(bindText) {
1157
1177
  raise(101, [bindText2]);
1158
1178
  }
1159
1179
  const propPart = bindText2.slice(0, separatorIndex).trim();
1160
- const statePart = bindText2.slice(separatorIndex + 1).trim();
1180
+ const statePart2 = bindText2.slice(separatorIndex + 1).trim();
1161
1181
  const keyword = propPart.split(MODIFIER_SEPARATOR)[0].split(FILTER_SEPARATOR)[0].trim();
1162
1182
  if (KEYWORDS_WITHOUT_MODIFIERS.has(keyword)) {
1163
1183
  if (keyword !== propPart) {
@@ -1165,20 +1185,20 @@ function parseBindTextsForElement(bindText) {
1165
1185
  }
1166
1186
  let stateResult2;
1167
1187
  if (keyword === ELSE_KEYWORD) {
1168
- if (statePart.length > 0) {
1188
+ if (statePart2.length > 0) {
1169
1189
  raise(103, [bindText2]);
1170
1190
  }
1171
1191
  stateResult2 = { statePathName: "#else", outFilters: [] };
1172
1192
  } else if (keyword === SPREAD_PROP) {
1173
- if (statePart.length === 0) {
1193
+ if (statePart2.length === 0) {
1174
1194
  raise(104, [bindText2]);
1175
1195
  }
1176
- stateResult2 = parseStatePart(statePart);
1196
+ stateResult2 = parseStatePart(statePart2);
1177
1197
  if (stateResult2.outFilters.length > 0) {
1178
1198
  raise(105, [bindText2]);
1179
1199
  }
1180
1200
  } else {
1181
- stateResult2 = parseStatePart(statePart);
1201
+ stateResult2 = parseStatePart(statePart2);
1182
1202
  if (keyword === "for" && stateResult2.outFilters.length > 0) {
1183
1203
  raise(121, [bindText2]);
1184
1204
  }
@@ -1195,7 +1215,7 @@ function parseBindTextsForElement(bindText) {
1195
1215
  if (keyword === CLASS_NAMESPACE || keyword === ATTR_NAMESPACE) {
1196
1216
  raise(122, [bindText2, keyword]);
1197
1217
  }
1198
- const stateResult = parseStatePart(statePart);
1218
+ const stateResult = parseStatePart(statePart2);
1199
1219
  const propResult = parsePropPart(propPart);
1200
1220
  const [head] = propResult.propSegments;
1201
1221
  if (head === "" && propResult.propSegments.length > 1) {
@@ -1441,6 +1461,9 @@ function parseWcsStateElements(html, stateTagName = "wcs-state") {
1441
1461
  const jsonAttr = extractAttribute(wcsMatch.tagContent, "json") ?? void 0;
1442
1462
  const stateAttr = extractAttribute(wcsMatch.tagContent, "state") ?? void 0;
1443
1463
  const srcAttr = extractAttribute(wcsMatch.tagContent, "src") ?? void 0;
1464
+ const contentAt = pos + 1 + stateTagName.length;
1465
+ const srcSpan = extractAttributeSpan(wcsMatch.tagContent, "src", contentAt);
1466
+ const jsonSpan = extractAttributeSpan(wcsMatch.tagContent, "json", contentAt);
1444
1467
  const tagStart = pos;
1445
1468
  const tagEnd = wcsMatch.end;
1446
1469
  pos = wcsMatch.end;
@@ -1484,7 +1507,18 @@ function parseWcsStateElements(html, stateTagName = "wcs-state") {
1484
1507
  wcsEnd = wcsCloseIdx === -1 ? len : wcsCloseIdx;
1485
1508
  }
1486
1509
  }
1487
- elements.push({ mountPath, bindComponent, jsonAttr, stateAttr, srcAttr, scriptBlocks, tagStart, tagEnd });
1510
+ elements.push({
1511
+ mountPath,
1512
+ bindComponent,
1513
+ jsonAttr,
1514
+ stateAttr,
1515
+ srcAttr,
1516
+ scriptBlocks,
1517
+ tagStart,
1518
+ tagEnd,
1519
+ ...srcSpan !== null ? { srcSpan } : {},
1520
+ ...jsonSpan !== null ? { jsonSpan } : {}
1521
+ });
1488
1522
  pos = wcsEnd;
1489
1523
  if (wcsCloseIdx !== -1) pos = afterCloseTag(html, wcsCloseIdx);
1490
1524
  }
@@ -1619,13 +1653,13 @@ function findCloseTag(html, startPos, tagName, lower2 = asciiLowerCase(html)) {
1619
1653
  return -1;
1620
1654
  }
1621
1655
  function parseAttributeNames(tagContent) {
1622
- const names = /* @__PURE__ */ new Set();
1656
+ const names2 = /* @__PURE__ */ new Set();
1623
1657
  const attribute = /([^\s"'<>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'<>`=]+))?/g;
1624
1658
  let match;
1625
1659
  while ((match = attribute.exec(tagContent)) !== null) {
1626
- names.add(match[1].toLowerCase());
1660
+ names2.add(match[1].toLowerCase());
1627
1661
  }
1628
- return names;
1662
+ return names2;
1629
1663
  }
1630
1664
  function extractAttribute(tagContent, attrName) {
1631
1665
  const regex = new RegExp(
@@ -1636,6 +1670,16 @@ function extractAttribute(tagContent, attrName) {
1636
1670
  if (!match) return null;
1637
1671
  return match[1] ?? match[2] ?? match[3] ?? null;
1638
1672
  }
1673
+ function extractAttributeSpan(tagContent, attrName, at2) {
1674
+ const regex = new RegExp(`(^|\\s)${attrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|(\\S+))`, "i");
1675
+ const match = regex.exec(tagContent);
1676
+ if (match === null) return null;
1677
+ const start = at2 + match.index + match[1].length;
1678
+ const end = at2 + match.index + match[0].length;
1679
+ const value = match[2] ?? match[3] ?? match[4] ?? "";
1680
+ const valueEnd = match[4] === void 0 ? end - 1 : end;
1681
+ return { start, end, valueStart: valueEnd - value.length, valueEnd };
1682
+ }
1639
1683
  var IGNORE_VOID_ELEMENTS = /* @__PURE__ */ new Set([
1640
1684
  "area",
1641
1685
  "base",
@@ -2990,17 +3034,25 @@ function hasDefaultExportObject(scriptContent) {
2990
3034
  return locateDefaultExportObject(scriptContent) !== null;
2991
3035
  }
2992
3036
  function hasTopLevelSpread(scriptContent) {
3037
+ return findTopLevelSpread(scriptContent) !== null;
3038
+ }
3039
+ function findTopLevelSpread(scriptContent) {
2993
3040
  const root = locateDefaultExportObject(scriptContent);
2994
- if (!root) return false;
3041
+ if (!root) return null;
2995
3042
  const scan = maskCommentsAndStrings(root.content);
2996
3043
  let depth = 0;
3044
+ let start = -1;
2997
3045
  for (let i = 0; i < scan.length; i++) {
2998
3046
  const ch = scan[i];
2999
3047
  if (ch === "(" || ch === "[" || ch === "{") depth++;
3000
3048
  else if (ch === ")" || ch === "]" || ch === "}") depth--;
3001
- else if (depth === 0 && ch === "." && scan.startsWith("...", i)) return true;
3049
+ else if (depth === 0 && start < 0 && ch === "." && scan.startsWith("...", i)) start = i;
3050
+ else if (depth === 0 && start >= 0 && ch === ",") return spreadRange(root.start, scan, start, i);
3002
3051
  }
3003
- return false;
3052
+ return start < 0 ? null : spreadRange(root.start, scan, start, scan.length);
3053
+ }
3054
+ function spreadRange(base, scan, start, stop) {
3055
+ return { start: base + start, end: base + start + scan.slice(start, stop).trimEnd().length };
3004
3056
  }
3005
3057
  function analyzeObjectEntries(scriptContent, key, allowEmptyKeys = false) {
3006
3058
  const root = locateDefaultExportObject(scriptContent);
@@ -3373,7 +3425,7 @@ function readBase(expr, scan, aliases, paths) {
3373
3425
  if (alias === null) return null;
3374
3426
  if (alias[1] !== "this") {
3375
3427
  const shape = aliases.get(alias[1]);
3376
- return shape === void 0 ? null : { shape, rest: alias[1].length };
3428
+ return { shape: shape ?? OPAQUE, rest: alias[1].length };
3377
3429
  }
3378
3430
  const segments = [];
3379
3431
  let i = 4;
@@ -3398,6 +3450,7 @@ function readBase(expr, scan, aliases, paths) {
3398
3450
  break;
3399
3451
  }
3400
3452
  const path = segments.join(".");
3453
+ if (path === "" && /^\s*\??\.\s*\$[$\w]*\s*\(/.test(scan.slice(4))) return { shape: OPAQUE, rest: 4 };
3401
3454
  if (path === "" || path.startsWith("$")) return null;
3402
3455
  return {
3403
3456
  shape: { isList: hasPath(paths, `${path}.*`), mirrors: [{ from: path, to: "" }], fields: [] },
@@ -3408,12 +3461,25 @@ function applyChain(expr, scan, start, initial) {
3408
3461
  let shape = initial;
3409
3462
  let i = start;
3410
3463
  while (scan.slice(i).trim() !== "") {
3464
+ if (shape.opaque && /^\s*\(/.test(scan.slice(i))) {
3465
+ const open2 = scan.indexOf("(", i);
3466
+ i = open2 + extractDelimitedContent(expr, scan, open2, "(", ")").length + 2;
3467
+ continue;
3468
+ }
3411
3469
  const call = /^\s*\??\.\s*([$\w]+)\s*\(/.exec(scan.slice(i));
3412
3470
  if (call === null) return null;
3413
3471
  const open = i + call[0].length - 1;
3414
3472
  const args = extractDelimitedContent(expr, scan, open, "(", ")");
3415
3473
  i = open + args.length + 2;
3416
3474
  const method = call[1];
3475
+ if (shape.opaque) {
3476
+ if (method === "map") {
3477
+ const mapped = mapRows(args, shape);
3478
+ if (mapped === null) return null;
3479
+ shape = mapped;
3480
+ }
3481
+ continue;
3482
+ }
3417
3483
  if (ROW_PRESERVING_METHODS.has(method)) {
3418
3484
  if (!shape.isList) return null;
3419
3485
  } else if (ROW_PICKING_METHODS.has(method)) {
@@ -3428,8 +3494,9 @@ function applyChain(expr, scan, start, initial) {
3428
3494
  return null;
3429
3495
  }
3430
3496
  }
3431
- return shape;
3497
+ return shape.opaque ? null : shape;
3432
3498
  }
3499
+ var OPAQUE = { isList: true, mirrors: [], fields: [], opaque: true };
3433
3500
  function pickRow(shape) {
3434
3501
  return {
3435
3502
  isList: false,
@@ -3440,7 +3507,7 @@ function pickRow(shape) {
3440
3507
  function mapRows(args, shape) {
3441
3508
  const [callback] = splitTopLevelElements(args);
3442
3509
  if (callback === void 0) return null;
3443
- const head = /^(?:async\s+)?(?:function\b[^(]*\(\s*([$\w]+)[^)]*\)|\(\s*([$\w]+)[^)]*\)|([$\w]+))\s*(=>)?\s*/.exec(callback);
3510
+ const head = /^(?:async\s+)?(?:function\b[^(]*\(\s*([$\w]+)?[^)]*\)|\(\s*([$\w]+)?[^)]*\)|([$\w]+))\s*(=>)?\s*/.exec(callback);
3444
3511
  if (head === null) return null;
3445
3512
  const param = head[1] ?? head[2] ?? head[3];
3446
3513
  const body = callback.slice(head[0].length);
@@ -3954,9 +4021,9 @@ function derefSchemaNodes(node, defs) {
3954
4021
  }
3955
4022
  return out;
3956
4023
  }
3957
- function schemaTypeHint(nodes) {
4024
+ function schemaTypeHint(nodes2) {
3958
4025
  const hints = /* @__PURE__ */ new Set();
3959
- for (const n of nodes) {
4026
+ for (const n of nodes2) {
3960
4027
  const types2 = typeof n.type === "string" ? [n.type] : Array.isArray(n.type) ? n.type : [];
3961
4028
  if (types2.length > 0) {
3962
4029
  for (const t of types2) {
@@ -3995,10 +4062,10 @@ function collectSchemaObjectPaths(node, prefix, paths, defs, depth) {
3995
4062
  }
3996
4063
  }
3997
4064
  function pushSchemaValuePaths(path, node, paths, defs, depth) {
3998
- const nodes = derefSchemaNodes(node, defs);
3999
- const typeHint = schemaTypeHint(nodes);
4065
+ const nodes2 = derefSchemaNodes(node, defs);
4066
+ const typeHint = schemaTypeHint(nodes2);
4000
4067
  paths.push(withHint({ path, kind: "data", fromSchema: true }, typeHint));
4001
- const items = nodes.map((n) => n.items).find((i) => i !== void 0 && i !== null && typeof i === "object");
4068
+ const items = nodes2.map((n) => n.items).find((i) => i !== void 0 && i !== null && typeof i === "object");
4002
4069
  const isArray2 = items !== void 0 || (typeHint?.split("|").includes("array") ?? false);
4003
4070
  if (isArray2) {
4004
4071
  const itemNodes = items !== void 0 ? derefSchemaNodes(items, defs) : [];
@@ -4015,7 +4082,7 @@ function pushSchemaValuePaths(path, node, paths, defs, depth) {
4015
4082
  }
4016
4083
  return;
4017
4084
  }
4018
- if (nodes.some((n) => n.properties !== void 0)) {
4085
+ if (nodes2.some((n) => n.properties !== void 0)) {
4019
4086
  collectSchemaObjectPaths(node, path, paths, defs, depth + 1);
4020
4087
  }
4021
4088
  }
@@ -4114,9 +4181,12 @@ function fromJson(text3) {
4114
4181
  const paths = analyzeJsonPaths(text3);
4115
4182
  return { paths, readable: paths.length > 0 || isJsonObject(text3) };
4116
4183
  }
4184
+ function scriptReadable(script, paths) {
4185
+ return !hasTopLevelSpread(script) && (paths.length > 0 || hasDefaultExportObject(script));
4186
+ }
4117
4187
  function fromScript(script) {
4118
4188
  const paths = analyzeStatePaths(script);
4119
- return { paths, readable: paths.length > 0 || isReadableStateScript(script) };
4189
+ return { paths, readable: scriptReadable(script, paths) };
4120
4190
  }
4121
4191
  function resolveElementPathsRaw(element2, html, fileReader) {
4122
4192
  let readable = false;
@@ -4139,19 +4209,23 @@ function resolveElementPathsRaw(element2, html, fileReader) {
4139
4209
  readable ||= resolved.readable;
4140
4210
  }
4141
4211
  if (element2.scriptBlocks.length > 0) {
4142
- const paths = element2.scriptBlocks.flatMap((block) => analyzeStatePaths(block.content));
4212
+ const blocks = element2.scriptBlocks.map((block) => ({ script: block.content, paths: analyzeStatePaths(block.content) }));
4143
4213
  return {
4144
- paths,
4145
- readable: paths.length > 0 || readable || element2.scriptBlocks.some((block) => isReadableStateScript(block.content))
4214
+ paths: blocks.flatMap((block) => block.paths),
4215
+ readable: readable || blocks.some((block) => scriptReadable(block.script, block.paths))
4146
4216
  };
4147
4217
  }
4148
4218
  return readable ? { paths: [], readable } : UNREADABLE;
4149
4219
  }
4150
4220
  function readStateScript(srcPath, fileReader) {
4151
- if (srcPath.endsWith(".js")) {
4152
- return fileReader(srcPath.replace(/\.js$/, ".ts")) || fileReader(srcPath) || void 0;
4221
+ return readStateScriptFile(srcPath, fileReader)?.text;
4222
+ }
4223
+ function readStateScriptFile(srcPath, fileReader) {
4224
+ const paths = srcPath.endsWith(".js") ? [srcPath.replace(/\.js$/, ".ts"), srcPath] : srcPath.endsWith(".ts") ? [srcPath] : [];
4225
+ for (const path of paths) {
4226
+ const text3 = fileReader(path);
4227
+ if (text3) return { path, text: text3 };
4153
4228
  }
4154
- if (srcPath.endsWith(".ts")) return fileReader(srcPath) || void 0;
4155
4229
  return void 0;
4156
4230
  }
4157
4231
  function resolveSrcAttribute(srcPath, fileReader) {
@@ -4184,10 +4258,6 @@ function isInsideForTemplate(html, offset2, bindAttrName = "data-wcs") {
4184
4258
  }
4185
4259
  return false;
4186
4260
  }
4187
- function getInnermostForPath(html, offset2, bindAttrName = "data-wcs") {
4188
- const chain = getEnclosingForPaths(html, offset2, bindAttrName);
4189
- return chain.length === 0 ? null : chain[chain.length - 1];
4190
- }
4191
4261
  var BINDING_SYNTAX_MARKER = `[${WcsDiagnosticCode.BindingSyntax}]`;
4192
4262
  function isForBindingRefused(bindText) {
4193
4263
  try {
@@ -4433,10 +4503,10 @@ function analyzeElementContexts(html, offsets, bindAttrName = "data-wcs", stateT
4433
4503
  }
4434
4504
  const match3 = bindAttr.exec(attrs);
4435
4505
  const value = match3 === null ? null : match3[1] ?? match3[2] ?? match3[3];
4436
- const names = value === null ? [] : propertyNamesOf(value);
4437
- const structural = name === "template" && names.length === 1 && STRUCTURAL_DIRECTIVES2.has(names[0]) && !value.slice(0, Math.max(0, indexOfOutsideQuotes2(value, ":"))).includes("#");
4506
+ const names2 = value === null ? [] : propertyNamesOf(value);
4507
+ const structural = name === "template" && names2.length === 1 && STRUCTURAL_DIRECTIVES2.has(names2[0]) && !value.slice(0, Math.max(0, indexOfOutsideQuotes2(value, ":"))).includes("#");
4438
4508
  const plainTemplate = name === "template" && !structural;
4439
- const blocks = plainTemplate && stack.some((e) => e.name === "template") || name !== "template" && names.some((n) => CONTENT_PROPERTIES.has(n));
4509
+ const blocks = plainTemplate && stack.some((e) => e.name === "template") || name !== "template" && names2.some((n) => CONTENT_PROPERTIES.has(n));
4440
4510
  const scope = plainTemplate ? { hasOwnState: false, id: extractAttribute(attrs, "id"), underRouter: stack.some((e) => e.name === ROUTER_TAG) } : null;
4441
4511
  stack.push({ name, structural, scope, blocks });
4442
4512
  }
@@ -5893,7 +5963,7 @@ pp$8.parseClassElement = function(constructorAllowsSuper) {
5893
5963
  }
5894
5964
  var ecmaVersion = this.options.ecmaVersion;
5895
5965
  var node = this.startNode();
5896
- var keyName = "";
5966
+ var keyName2 = "";
5897
5967
  var isGenerator = false;
5898
5968
  var isAsync = false;
5899
5969
  var kind = "method";
@@ -5906,34 +5976,34 @@ pp$8.parseClassElement = function(constructorAllowsSuper) {
5906
5976
  if (this.isClassElementNameStart() || this.type === types$1.star) {
5907
5977
  isStatic = true;
5908
5978
  } else {
5909
- keyName = "static";
5979
+ keyName2 = "static";
5910
5980
  }
5911
5981
  }
5912
5982
  node.static = isStatic;
5913
- if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
5983
+ if (!keyName2 && ecmaVersion >= 8 && this.eatContextual("async")) {
5914
5984
  if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) {
5915
5985
  isAsync = true;
5916
5986
  } else {
5917
- keyName = "async";
5987
+ keyName2 = "async";
5918
5988
  }
5919
5989
  }
5920
- if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) {
5990
+ if (!keyName2 && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) {
5921
5991
  isGenerator = true;
5922
5992
  }
5923
- if (!keyName && !isAsync && !isGenerator) {
5993
+ if (!keyName2 && !isAsync && !isGenerator) {
5924
5994
  var lastValue = this.value;
5925
5995
  if (this.eatContextual("get") || this.eatContextual("set")) {
5926
5996
  if (this.isClassElementNameStart()) {
5927
5997
  kind = lastValue;
5928
5998
  } else {
5929
- keyName = lastValue;
5999
+ keyName2 = lastValue;
5930
6000
  }
5931
6001
  }
5932
6002
  }
5933
- if (keyName) {
6003
+ if (keyName2) {
5934
6004
  node.computed = false;
5935
6005
  node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc);
5936
- node.key.name = keyName;
6006
+ node.key.name = keyName2;
5937
6007
  this.finishNode(node.key, "Identifier");
5938
6008
  } else {
5939
6009
  this.parseClassElementName(node);
@@ -6234,7 +6304,7 @@ pp$8.parseExportSpecifier = function(exports$1) {
6234
6304
  return this.finishNode(node, "ExportSpecifier");
6235
6305
  };
6236
6306
  pp$8.parseExportSpecifiers = function(exports$1) {
6237
- var nodes = [], first = true;
6307
+ var nodes2 = [], first = true;
6238
6308
  this.expect(types$1.braceL);
6239
6309
  while (!this.eat(types$1.braceR)) {
6240
6310
  if (!first) {
@@ -6245,9 +6315,9 @@ pp$8.parseExportSpecifiers = function(exports$1) {
6245
6315
  } else {
6246
6316
  first = false;
6247
6317
  }
6248
- nodes.push(this.parseExportSpecifier(exports$1));
6318
+ nodes2.push(this.parseExportSpecifier(exports$1));
6249
6319
  }
6250
- return nodes;
6320
+ return nodes2;
6251
6321
  };
6252
6322
  pp$8.parseImport = function(node) {
6253
6323
  this.next();
@@ -6292,16 +6362,16 @@ pp$8.parseImportNamespaceSpecifier = function() {
6292
6362
  return this.finishNode(node, "ImportNamespaceSpecifier");
6293
6363
  };
6294
6364
  pp$8.parseImportSpecifiers = function() {
6295
- var nodes = [], first = true;
6365
+ var nodes2 = [], first = true;
6296
6366
  if (this.type === types$1.name) {
6297
- nodes.push(this.parseImportDefaultSpecifier());
6367
+ nodes2.push(this.parseImportDefaultSpecifier());
6298
6368
  if (!this.eat(types$1.comma)) {
6299
- return nodes;
6369
+ return nodes2;
6300
6370
  }
6301
6371
  }
6302
6372
  if (this.type === types$1.star) {
6303
- nodes.push(this.parseImportNamespaceSpecifier());
6304
- return nodes;
6373
+ nodes2.push(this.parseImportNamespaceSpecifier());
6374
+ return nodes2;
6305
6375
  }
6306
6376
  this.expect(types$1.braceL);
6307
6377
  while (!this.eat(types$1.braceR)) {
@@ -6313,14 +6383,14 @@ pp$8.parseImportSpecifiers = function() {
6313
6383
  } else {
6314
6384
  first = false;
6315
6385
  }
6316
- nodes.push(this.parseImportSpecifier());
6386
+ nodes2.push(this.parseImportSpecifier());
6317
6387
  }
6318
- return nodes;
6388
+ return nodes2;
6319
6389
  };
6320
6390
  pp$8.parseWithClause = function() {
6321
- var nodes = [];
6391
+ var nodes2 = [];
6322
6392
  if (!this.eat(types$1._with)) {
6323
- return nodes;
6393
+ return nodes2;
6324
6394
  }
6325
6395
  this.expect(types$1.braceL);
6326
6396
  var attributeKeys = {};
@@ -6335,14 +6405,14 @@ pp$8.parseWithClause = function() {
6335
6405
  first = false;
6336
6406
  }
6337
6407
  var attr = this.parseImportAttribute();
6338
- var keyName = attr.key.type === "Identifier" ? attr.key.name : attr.key.value;
6339
- if (hasOwn(attributeKeys, keyName)) {
6340
- this.raiseRecoverable(attr.key.start, "Duplicate attribute key '" + keyName + "'");
6408
+ var keyName2 = attr.key.type === "Identifier" ? attr.key.name : attr.key.value;
6409
+ if (hasOwn(attributeKeys, keyName2)) {
6410
+ this.raiseRecoverable(attr.key.start, "Duplicate attribute key '" + keyName2 + "'");
6341
6411
  }
6342
- attributeKeys[keyName] = true;
6343
- nodes.push(attr);
6412
+ attributeKeys[keyName2] = true;
6413
+ nodes2.push(attr);
6344
6414
  }
6345
- return nodes;
6415
+ return nodes2;
6346
6416
  };
6347
6417
  pp$8.parseImportAttribute = function() {
6348
6418
  var node = this.startNode();
@@ -10491,7 +10561,7 @@ function visitDestructure(pattern, prefix, scope, out) {
10491
10561
  emit(out, segments, { form: "destructure", callee: false, written: false }, property.start, property.end);
10492
10562
  }
10493
10563
  }
10494
- function collectThisMemberRefs(body, names) {
10564
+ function collectThisMemberRefs(body, names2) {
10495
10565
  let program;
10496
10566
  try {
10497
10567
  program = parse3(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
@@ -10500,11 +10570,11 @@ function collectThisMemberRefs(body, names) {
10500
10570
  }
10501
10571
  const fn = unwrapWrapper(program);
10502
10572
  if (fn === null) return null;
10503
- return walkThisMembers(fn.body, names, PREFIX.length);
10573
+ return walkThisMembers(fn.body, names2, PREFIX.length);
10504
10574
  }
10505
10575
  var VALUE_PREFIX = "(async function* () {\n(";
10506
10576
  var VALUE_SUFFIX = ")\n})";
10507
- function collectThisMemberRefsInValue(value, names) {
10577
+ function collectThisMemberRefsInValue(value, names2) {
10508
10578
  let program;
10509
10579
  try {
10510
10580
  program = parse3(VALUE_PREFIX + value + VALUE_SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
@@ -10517,9 +10587,9 @@ function collectThisMemberRefsInValue(value, names) {
10517
10587
  if (statement.type !== "ExpressionStatement") return null;
10518
10588
  const expression = statement.expression;
10519
10589
  if (expression.type !== "FunctionExpression") return [];
10520
- return walkThisMembers(expression.body, names, VALUE_PREFIX.length);
10590
+ return walkThisMembers(expression.body, names2, VALUE_PREFIX.length);
10521
10591
  }
10522
- function walkThisMembers(root, names, offsetShift) {
10592
+ function walkThisMembers(root, names2, offsetShift) {
10523
10593
  const out = [];
10524
10594
  const walk = (node, thisIsState) => {
10525
10595
  if (isClassNode(node)) return;
@@ -10530,7 +10600,7 @@ function walkThisMembers(root, names, offsetShift) {
10530
10600
  }
10531
10601
  if (thisIsState && node.type === "MemberExpression" && node.object.type === "ThisExpression") {
10532
10602
  const hit = thisMemberName(node);
10533
- if (hit !== null && names.has(hit.name)) {
10603
+ if (hit !== null && names2.has(hit.name)) {
10534
10604
  out.push({ name: hit.name, start: hit.start - offsetShift, end: hit.end - offsetShift });
10535
10605
  }
10536
10606
  }
@@ -10697,13 +10767,13 @@ function findInPlaceChanges(text3, kind, root) {
10697
10767
  const collect2 = (node) => {
10698
10768
  if (isFunctionNode(node)) {
10699
10769
  if (node.type === "FunctionDeclaration" && node.id !== null) bind(node.id.name);
10700
- const names = /* @__PURE__ */ new Set();
10701
- for (const param of node.params) bindingNames(param, names);
10702
- names.forEach(bind);
10770
+ const names2 = /* @__PURE__ */ new Set();
10771
+ for (const param of node.params) bindingNames(param, names2);
10772
+ names2.forEach(bind);
10703
10773
  } else if (node.type === "VariableDeclarator") {
10704
- const names = /* @__PURE__ */ new Set();
10705
- bindingNames(node.id, names);
10706
- names.forEach(bind);
10774
+ const names2 = /* @__PURE__ */ new Set();
10775
+ bindingNames(node.id, names2);
10776
+ names2.forEach(bind);
10707
10777
  const init = node.init ? unwrapChain(node.init) : null;
10708
10778
  if (init !== null && node.id.type === "Identifier" && init.type === "MemberExpression") {
10709
10779
  const chain = memberChain(init, source);
@@ -10721,9 +10791,9 @@ function findInPlaceChanges(text3, kind, root) {
10721
10791
  }
10722
10792
  }
10723
10793
  } else if (node.type === "CatchClause" && node.param) {
10724
- const names = /* @__PURE__ */ new Set();
10725
- bindingNames(node.param, names);
10726
- names.forEach(bind);
10794
+ const names2 = /* @__PURE__ */ new Set();
10795
+ bindingNames(node.param, names2);
10796
+ names2.forEach(bind);
10727
10797
  } else if (node.type === "ClassDeclaration" && node.id !== null) {
10728
10798
  bind(node.id.name);
10729
10799
  } else if (node.type === "AssignmentExpression" && node.left.type === "Identifier") {
@@ -10785,14 +10855,14 @@ function findLocationRead(body) {
10785
10855
  }
10786
10856
  const wrapper = unwrapWrapper(program);
10787
10857
  if (wrapper === null) return null;
10788
- const names = /* @__PURE__ */ new Set();
10858
+ const names2 = /* @__PURE__ */ new Set();
10789
10859
  const scan = (node) => {
10790
- if (isFunctionNode(node)) for (const param of node.params) bindingNames(param, names);
10791
- if (node.type === "VariableDeclarator") bindingNames(node.id, names);
10860
+ if (isFunctionNode(node)) for (const param of node.params) bindingNames(param, names2);
10861
+ if (node.type === "VariableDeclarator") bindingNames(node.id, names2);
10792
10862
  forEachChild(node, scan);
10793
10863
  };
10794
10864
  scan(wrapper.body);
10795
- if (names.has("location")) return null;
10865
+ if (names2.has("location")) return null;
10796
10866
  const isLocation = (node) => {
10797
10867
  const n = unwrapChain(node);
10798
10868
  if (n.type === "Identifier") return n.name === "location";
@@ -10869,6 +10939,13 @@ var ja = {
10869
10939
  updatedCallbackUnbound: (p) => `$renderedCallback \u306F binding \u99C6\u52D5\u3067\u3059\u3002"${p}" \u306F\u3053\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u3069\u306E\u30D0\u30A4\u30F3\u30C7\u30A3\u30F3\u30B0\u306B\u3082\u73FE\u308C\u306A\u3044\u305F\u3081\u3001\u3053\u306E\u5206\u5C90\u306F\u4E00\u5EA6\u3082\u5B9F\u884C\u3055\u308C\u307E\u305B\u3093\u3002\u63CF\u753B\u306B\u4F9D\u5B58\u305B\u305A\u53CD\u5FDC\u3059\u308B\u306A\u3089 $watch \u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044`,
10870
10940
  onHandlerThis: (name) => `$on \u306E\u30CF\u30F3\u30C9\u30E9 "${name}" \u304C this \u3092\u4F7F\u3063\u3066\u3044\u307E\u3059\u3002$on \u306E\u30CF\u30F3\u30C9\u30E9\u306F state \u3092\u7B2C 1 \u5F15\u6570\u3067\u53D7\u3051\u53D6\u308A\uFF08\`${name}(state, event) { state.x = \u2026 }\`\uFF09\u3001this \u306F undefined \u306A\u306E\u3067\u3001this.\u2026 \u306F\u547C\u3070\u308C\u305F\u3068\u304D\u306B\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\u3002$watch \u3084\u30E1\u30BD\u30C3\u30C9\u3068\u9055\u3046\u70B9\u306B\u6CE8\u610F`,
10871
10941
  getterReadsLocation: (read) => `\u3053\u306E getter \u306F ${read} \u3092\u8AAD\u3093\u3067\u3044\u307E\u3059\u304C\u3001location \u306F state \u3067\u306F\u306A\u3044\u306E\u3067\u3001\u6700\u521D\u306B\u8AAD\u3093\u3060 URL \u3092\u6301\u3061\u7D9A\u3051\u307E\u3059\uFF08\u30CA\u30D3\u30B2\u30FC\u30B7\u30E7\u30F3\u3067\u518D\u8A55\u4FA1\u3055\u308C\u307E\u305B\u3093\uFF09\u3002URL \u306F state \u3092\u901A\u3057\u3066\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044 \u2014 <wcs-router> \u306E path / searchParams \u3092\u675F\u306D\u308B`,
10942
+ getterReadsClock: (read) => `\u3053\u306E getter \u306F ${read} \u3092\u8AAD\u3093\u3067\u3044\u307E\u3059\u304C\u3001\u6642\u523B\u306F state \u3067\u306F\u306A\u3044\u306E\u3067\u4F9D\u5B58\u3068\u3057\u3066\u767B\u9332\u3055\u308C\u305A\u3001getter \u306F\u30AD\u30E3\u30C3\u30B7\u30E5\u3057\u305F\u6700\u521D\u306E\u5024\u3092\u8FD4\u3057\u7D9A\u3051\u307E\u3059\uFF08\u30A4\u30D9\u30F3\u30C8\u30C8\u30FC\u30AF\u30F3\u3067\u6BCE\u30D5\u30EC\u30FC\u30E0\u300C\u63CF\u304D\u76F4\u3057\u300D\u3066\u3082\u5909\u308F\u308A\u307E\u305B\u3093\uFF09\u3002\u6642\u523B\u3092 state \u306B\u7F6E\u3044\u3066\u304F\u3060\u3055\u3044 \u2014 <wcs-raf> \u3084 <wcs-timer> \u304C\u66F8\u304F\u5024\u3092\u675F\u306D\u308B`,
10943
+ updatedCallbackUnknownPath: (p) => `"${p}" \u306F state \u306E\u30D1\u30B9\u3067\u306F\u306A\u3044\u306E\u3067 $renderedCallback \u306E paths \u306B\u73FE\u308C\u305A\u3001\u3053\u306E\u5206\u5C90\u306F\u4E00\u5EA6\u3082\u5B9F\u884C\u3055\u308C\u307E\u305B\u3093`,
10944
+ commandTokenUnbound: (t) => `\u30B3\u30DE\u30F3\u30C9\u30C8\u30FC\u30AF\u30F3 "${t}" \u3092 emit \u3057\u3066\u3044\u307E\u3059\u304C\u3001\u3053\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306B\u305D\u308C\u3092\u53D7\u3051\u308B command.<\u30E1\u30BD\u30C3\u30C9>: ${t} \u306E\u675F\u7E1B\u304C\u3042\u308A\u307E\u305B\u3093\u3002emit \u306F\u8AB0\u306B\u3082\u5C4A\u304D\u307E\u305B\u3093\u3002\u30E1\u30BD\u30C3\u30C9\u3092\u547C\u3076\u8981\u7D20\u306B\u675F\u306D\u3066\u304F\u3060\u3055\u3044\uFF08command.focus: ${t}\uFF09`,
10945
+ writePathMissing: (k) => `"${k}" \u306F state \u304C\u5BA3\u8A00\u3057\u3066\u3044\u306A\u3044\u30AD\u30FC\u3067\u3059\u3002\u66F8\u304D\u8FBC\u307F\u306F\u65B0\u3057\u3044\u30AD\u30FC\u3092\u4F5C\u308B\u3060\u3051\u3067\u3001\u5BA3\u8A00\u3057\u305F\u30AD\u30FC\u306E\u675F\u7E1B\u306B\u306F\u5C4A\u304D\u307E\u305B\u3093`,
10946
+ readPathMissing: (p, top) => top ? `"${p}" \u306F state \u304C\u5BA3\u8A00\u3057\u3066\u3044\u306A\u3044\u30AD\u30FC\u3067\u3059\u3002\u8AAD\u3093\u3060\u6642\u70B9\u3067\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\uFF08#301\uFF09` : `\u30D1\u30B9 "${p}" \u306F\u72B6\u614B\u5B9A\u7FA9\u306B\u5B58\u5728\u3057\u307E\u305B\u3093\u3002\u8AAD\u307F\u306F undefined \u306B\u306A\u308A\u3001\u305D\u3053\u304B\u3089\u8A08\u7B97\u3057\u305F\u5024\u306F\u9ED9\u3063\u3066\u9055\u3044\u307E\u3059`,
10947
+ pathDynamicUnknownSpread: (sp) => `${sp} \u304C\u6301\u3061\u8FBC\u3080\u30AD\u30FC\u306F\u9759\u7684\u306B\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u3053\u306E state \u306E\u30D1\u30B9\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u675F\u7E1B\u30FBgetter \u306E\u4E2D\u306E\u8AAD\u307F\u30FB$watch \u306E\u30AD\u30FC\uFF09\u3002\u30AD\u30FC\u3092 wcstack.manifest.json \u306E stateSchema \u306B\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059\u3002npx wcs-schema\uFF08@wcstack/typescript\uFF09\u304C state \u306E\u578B\uFF08JSDoc\u30FBTypeScript\uFF09\u304B\u3089\u4F5C\u308C\u307E\u3059`,
10948
+ pathReadonlyTwoWay: (p, prop) => `"${p}" \u306F setter \u306E\u7121\u3044 getter \u3067\u3059\u304C\u3001${prop}: \u306F\u8AAD\u8005\u306E\u5165\u529B\u3092\u66F8\u304D\u623B\u3059\u306E\u3067\u3001\u5165\u529B\u306E\u305F\u3073\u306B\u66F8\u304D\u8FBC\u307F\u304C\u5931\u6557\u3057\u307E\u3059\uFF08"${p}" is a getter without a setter\uFF09\u3002setter \u3092\u8DB3\u3059\uFF08set "${p}"(v) { \u2026 }\uFF09\u304B\u3001#ro \u3067\u4E00\u65B9\u5411\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${prop}#ro: ${p}\uFF09`,
10872
10949
  submitWithoutPrevent: (h) => `onsubmit \u306B #prevent \u304C\u7121\u304F\u3001"${h}" \u3082 preventDefault \u3092\u547C\u3073\u307E\u305B\u3093\u3002\u30D6\u30E9\u30A6\u30B6\u306F\u30D5\u30A9\u30FC\u30E0\u3082\u9001\u308B\u306E\u3067\u3001\u30DA\u30FC\u30B8\u304C\u8AAD\u307F\u76F4\u3055\u308C\u308B\u304B\u3001router \u304C\u3042\u308C\u3070 GET \u304C\u6B04\u306E\u5024\uFF08\u30D1\u30B9\u30EF\u30FC\u30C9\u3082\uFF09\u3092 URL \u3068\u5C65\u6B74\u306B\u8F09\u305B\u307E\u3059\u3002onsubmit#prevent: ${h} \u3068\u66F8\u304F\u304B\u3001\u30CF\u30F3\u30C9\u30E9\u3067 event.preventDefault() \u3092\u547C\u3093\u3067\u304F\u3060\u3055\u3044`,
10873
10950
  getterUntrackedRead: (root, sp) => `\u3053\u3053\u3067\u8FFD\u8DE1\u3055\u308C\u308B\u306E\u306F "${root}" \u3060\u3051\u3067\u3059\u3002"${sp}" \u304C\u5909\u308F\u3063\u3066\u3082\u3053\u306E getter \u306F\u518D\u8A55\u4FA1\u3055\u308C\u307E\u305B\u3093\uFF08\u30D1\u30B9\u8AAD\u307F\u53D6\u308A\u306E\u5148\u306E\u7D20\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u30A2\u30AF\u30BB\u30B9\u306F\u8FFD\u8DE1\u3055\u308C\u306A\u3044\uFF09\u3002this["${sp}"] \u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
10874
10951
  handlerFilterNotAllowed: (prop) => `\u30A4\u30D9\u30F3\u30C8\u30CF\u30F3\u30C9\u30E9 "${prop}" \u306B\u30D5\u30A3\u30EB\u30BF\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
@@ -10905,7 +10982,7 @@ var ja = {
10905
10982
  behaviorValueType: (key, type) => `$behavior \u306E "${key}" \u306F ${type === "boolean" ? "true \u304B false" : type} \u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF08\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u8AAD\u307F\u8FBC\u307F\u6642\u306B throw \u3057\u307E\u3059\uFF09`,
10906
10983
  configInVolume: (key, mountPath) => `${key} \u306F\u30DC\u30EA\u30E5\u30FC\u30E0\uFF08mount="${mountPath}"\uFF09\u3067\u306F\u5BA3\u8A00\u3067\u304D\u307E\u305B\u3093\uFF08\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u63A5\u304E\u6728\u3092\u62D2\u307F\u3001console.error \u3067\u5831\u544A\u3057\u307E\u3059 \u2014 \u3053\u306E state \u306F\u6728\u306B\u8F09\u308A\u307E\u305B\u3093\uFF09\u3002root \u306E state \u306B\u5BA3\u8A00\u3057\u3066\u304F\u3060\u3055\u3044 \u2014 \u30DC\u30EA\u30E5\u30FC\u30E0\u306F root \u306E\u30A8\u30F3\u30B8\u30F3\u306B\u63A5\u304E\u6728\u3055\u308C\u307E\u3059`,
10907
10984
  featuresNotArray: () => `$features \u306F\u5F8C\u4ED8\u3051\u306E\u540D\u524D\u306E\u914D\u5217\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF08\u4F8B: ["temporal", "formats"]\u3002\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u8AAD\u307F\u8FBC\u307F\u6642\u306B throw \u3057\u307E\u3059\uFF09`,
10908
- featureUnknown: (name, names, suggestion2) => `"${name}" \u306F\u5F8C\u4ED8\u3051\u306E\u540D\u524D\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names.join("\u30FB")}\uFF09${suggestion2}`,
10985
+ featureUnknown: (name, names2, suggestion2) => `"${name}" \u306F\u5F8C\u4ED8\u3051\u306E\u540D\u524D\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names2.join("\u30FB")}\uFF09${suggestion2}`,
10909
10986
  volumeDeclarationRejected: (key, mountPath) => `${key} \u306F\u30DC\u30EA\u30E5\u30FC\u30E0\uFF08mount="${mountPath}"\uFF09\u3067\u306F\u5B9F\u884C\u3055\u308C\u307E\u305B\u3093\u3002\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u63A5\u304E\u6728\u3092\u62D2\u3093\u3067 console.error \u3067\u5831\u544A\u3057\u307E\u3059\uFF08\u3053\u306E state \u306F\u6728\u306B\u8F09\u308A\u307E\u305B\u3093\uFF09\u3002root \u306E state \u306B\u5BA3\u8A00\u3057\u3066\u304F\u3060\u3055\u3044`,
10910
10987
  volumeDeclarationNotRun: (key, mountPath) => `${key} \u306F\u30DC\u30EA\u30E5\u30FC\u30E0\uFF08mount="${mountPath}"\uFF09\u3067\u306F\u5B9F\u884C\u3055\u308C\u307E\u305B\u3093\uFF08\u30E9\u30F3\u30BF\u30A4\u30E0\u306F console.warn \u3067\u77E5\u3089\u305B\u3001\u3053\u306E\u5BA3\u8A00\u3092\u7121\u8996\u3057\u307E\u3059 \u2014 root \u306E state \u306E\u3082\u306E\u3067\u3059\uFF09\u3002root \u306E state \u306B\u5BA3\u8A00\u3057\u3066\u304F\u3060\u3055\u3044`,
10911
10988
  secondRoot: () => '\u540C\u3058 root \u306B 2 \u3064\u76EE\u306E <wcs-state> \u304C\u3042\u308A\u307E\u3059\u3002state \u306E\u6728\u306F root \u3054\u3068\u306B 1 \u3064\u3067\u3059\uFF08\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u5F8C\u304B\u3089\u8AAD\u307F\u8FBC\u3093\u3060\u65B9\u3092\u62D2\u3093\u3067 console.error \u3067\u5831\u544A\u3057\u307E\u3059\uFF09\u3002\u90E8\u5206\u6728\u306F <wcs-state mount="path"> \u3067\u63A5\u304E\u6728\u3057\u3066\u304F\u3060\u3055\u3044',
@@ -10918,6 +10995,7 @@ var ja = {
10918
10995
  nativeCommandUnknown: (method, tag, allowed) => `"${method}" \u306F\u30CD\u30A4\u30C6\u30A3\u30D6\u306E <${tag}> \u306B command \u3067\u547C\u3079\u308B\u30E1\u30BD\u30C3\u30C9\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u547C\u3079\u308B\u306E\u306F ${allowed}\u3002\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u521D\u671F\u5316\u3067 wcs/token-misconfigured \u3092\u6295\u3052\u307E\u3059\uFF09`,
10919
10996
  spreadNoBindable: (tag) => `'...'\uFF08spread\uFF09\u306F <${tag}> \u306B\u6709\u52B9\u306A wcBindable \u5BA3\u8A00\u304C\u5FC5\u8981\u3067\u3059 \u2014 \u3053\u306E\u30BF\u30B0\u306F\u5BA3\u8A00\u3092\u6301\u305F\u306A\u3044\u305F\u3081\u3001\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u30A8\u30E9\u30FC\u3092\u9001\u51FA\u3057\u307E\u3059`,
10920
10997
  tagEventTokenKeyUnknown: (name, tag, declared) => `eventToken \u306E\u30AD\u30FC "${name}" \u306F <${tag}> \u306E wcBindable \u30D7\u30ED\u30D1\u30C6\u30A3\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u751F DOM \u30A4\u30D9\u30F3\u30C8\u540D\u306F\u767A\u706B\u3057\u307E\u305B\u3093 \u2014 \u30D7\u30ED\u30D1\u30C6\u30A3\u540D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u5BA3\u8A00\u6E08\u307F: ${declared}\uFF09`,
10998
+ handleBoundAsValue: (name, tag) => `<${tag}> \u306E "${name}" \u306F\u751F\u304D\u305F\u30EA\u30BD\u30FC\u30B9\uFF08\u30CF\u30F3\u30C9\u30EB\uFF09\u3067\u3001\u5024\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002state \u306E\u30D1\u30B9\u306B\u675F\u306D\u308B\u3068\u3001\u30B9\u30CA\u30C3\u30D7\u30B7\u30E7\u30C3\u30C8\u3084 SSR \u306B\u8F09\u3089\u306A\u3044\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u304C state \u306B\u5165\u308A\u307E\u3059 \u2014 eventToken.${name}: \u3067\u53D7\u3051\u3001\u30B3\u30DE\u30F3\u30C9\u306E\u5F15\u6570\u3068\u3057\u3066\u6B21\u306E\u8981\u7D20\u3078\u76F4\u63A5\u6E21\u3057\u3066\u304F\u3060\u3055\u3044`,
10921
10999
  ariaAttrUnknown: (name) => `"${name}" \u306F WAI-ARIA \u306E\u5C5E\u6027\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002setAttribute \u306F\u305D\u306E\u307E\u307E\u66F8\u304D\u8FBC\u307F\u307E\u3059\u304C\u3001\u652F\u63F4\u6280\u8853\u306B\u306F\u9ED9\u3063\u3066\u7121\u8996\u3055\u308C\u307E\u3059`,
10922
11000
  didYouMean: (c) => `\u3002\u3082\u3057\u304B\u3057\u3066: "${c}"`,
10923
11001
  none: () => `\u306A\u3057`,
@@ -11070,6 +11148,13 @@ var en = {
11070
11148
  updatedCallbackUnbound: (p) => `$renderedCallback is binding-driven. "${p}" is not bound anywhere in this document, so this branch never runs. Use $watch to react without depending on what is rendered`,
11071
11149
  onHandlerThis: (name) => `The $on handler "${name}" uses this. A $on handler receives the state as its first argument (\`${name}(state, event) { state.x = \u2026 }\`) and this is undefined, so this.\u2026 throws when it is called \u2014 unlike $watch handlers and methods`,
11072
11150
  getterReadsLocation: (read) => `This getter reads ${read}, which is not state: it keeps the URL it first read (a navigation does not re-evaluate it). Read the URL through state \u2014 bind <wcs-router>'s path / searchParams`,
11151
+ getterReadsClock: (read) => `This getter reads ${read}. The time is not state, so it is not a dependency: the getter is cached and keeps returning its first value (an event token "redrawing" every frame does not change it). Keep the time in state \u2014 bind the value <wcs-raf> or <wcs-timer> writes`,
11152
+ updatedCallbackUnknownPath: (p) => `"${p}" is not a path of this state, so it is never in $renderedCallback's paths and this branch never runs`,
11153
+ commandTokenUnbound: (t) => `The command token "${t}" is emitted, but no command.<method>: ${t} binding in this document receives it, so the emit reaches nothing. Bind it on the element whose method it should call (command.focus: ${t})`,
11154
+ writePathMissing: (k) => `"${k}" is not a key the state declares. The write creates a new key and reaches no binding of a declared one`,
11155
+ readPathMissing: (p, top) => top ? `"${p}" is not a key the state declares. Reading it throws (#301)` : `Path "${p}" does not exist in the state definition. The read gives undefined, and what is computed from it is wrong without a word`,
11156
+ pathDynamicUnknownSpread: (sp) => `The keys ${sp} brings in cannot be read statically, so this state's paths are not checked (bindings, reads in getters, $watch keys). Declare the keys in the stateSchema of wcstack.manifest.json to have them checked; npx wcs-schema (@wcstack/typescript) derives it from the state's types (JSDoc or TypeScript)`,
11157
+ pathReadonlyTwoWay: (p, prop) => `"${p}" is a getter without a setter, and ${prop}: writes back what the reader enters, so every edit fails ("${p}" is a getter without a setter). Add a setter (set "${p}"(v) { \u2026 }), or bind it one way with #ro (${prop}#ro: ${p})`,
11073
11158
  submitWithoutPrevent: (h) => `onsubmit has no #prevent and "${h}" does not call preventDefault, so the browser submits the form too: the page reloads, or with the router a GET puts the fields (a password too) in the URL and the history. Write onsubmit#prevent: ${h}, or call event.preventDefault() in the handler`,
11074
11159
  getterUntrackedRead: (root, sp) => `Only "${root}" is tracked here: the getter is not re-evaluated when "${sp}" changes (plain property access after a path read is not tracked). Read this["${sp}"] instead`,
11075
11160
  handlerFilterNotAllowed: (prop) => `Filters cannot be applied to event handler "${prop}"`,
@@ -11106,7 +11191,7 @@ var en = {
11106
11191
  behaviorValueType: (key, type) => `$behavior "${key}" must be ${type === "boolean" ? "true or false" : type} (the runtime throws at load time)`,
11107
11192
  configInVolume: (key, mountPath) => `${key} cannot be declared in a volume (mount="${mountPath}"): the runtime refuses to graft the volume and reports that with console.error (this state is not on the tree). Declare it on the root state \u2014 a volume is grafted onto the root's engine`,
11108
11193
  featuresNotArray: () => `$features must be an array of add-on names (for example ["temporal", "formats"]; the runtime throws at load time)`,
11109
- featureUnknown: (name, names, suggestion2) => `"${name}" is not an add-on (${names.join(", ")})${suggestion2}`,
11194
+ featureUnknown: (name, names2, suggestion2) => `"${name}" is not an add-on (${names2.join(", ")})${suggestion2}`,
11110
11195
  volumeDeclarationRejected: (key, mountPath) => `${key} is not run in a volume (mount="${mountPath}"): the runtime refuses to graft the volume and reports that with console.error (this state is not on the tree). Declare it on the root state`,
11111
11196
  volumeDeclarationNotRun: (key, mountPath) => `${key} is not run in a volume (mount="${mountPath}"): the runtime says so with console.warn and ignores this declaration \u2014 it belongs to the root state. Declare it there`,
11112
11197
  secondRoot: () => 'A second <wcs-state> on the same root: there is one state tree per root (the runtime refuses the one that loads second and reports it with console.error). Graft a subtree with <wcs-state mount="path">',
@@ -11119,6 +11204,7 @@ var en = {
11119
11204
  nativeCommandUnknown: (method, tag, allowed) => `"${method}" is not a command of a native <${tag}> (its commands: ${allowed}; the runtime throws wcs/token-misconfigured at initialization)`,
11120
11205
  spreadNoBindable: (tag) => `'...' (spread) requires <${tag}> to expose a valid wcBindable declaration \u2014 this tag declares none, so the runtime raises an error`,
11121
11206
  tagEventTokenKeyUnknown: (name, tag, declared) => `eventToken key "${name}" is not a wcBindable property of <${tag}>. Raw DOM event names never fire \u2014 use the property name (declared: ${declared})`,
11207
+ handleBoundAsValue: (name, tag) => `"${name}" of <${tag}> is a live resource (a handle), not a value. Bound to a state path, it puts an object no snapshot or SSR can carry into the state \u2014 receive it with eventToken.${name}: and hand it to the next element as a command argument`,
11122
11208
  ariaAttrUnknown: (name) => `"${name}" is not a WAI-ARIA attribute. setAttribute writes it anyway, and assistive technology silently ignores it`,
11123
11209
  didYouMean: (c) => `. Did you mean "${c}"?`,
11124
11210
  none: () => `none`,
@@ -11421,8 +11507,8 @@ function derefUnion(node, rootDefs) {
11421
11507
  }
11422
11508
  return { kind: "ok", nodes: out };
11423
11509
  }
11424
- function firstDefined(nodes, pick) {
11425
- for (const n of nodes) {
11510
+ function firstDefined(nodes2, pick) {
11511
+ for (const n of nodes2) {
11426
11512
  const v = pick(n);
11427
11513
  if (v !== void 0) return v;
11428
11514
  }
@@ -11550,11 +11636,11 @@ var DELEGATED_EVENTS = /* @__PURE__ */ new Set([
11550
11636
  ]);
11551
11637
  var CUSTOM_ELEMENT_OWN_EVENTS = /* @__PURE__ */ new Set(["input", "change", "submit"]);
11552
11638
  function collectCurrentTargetHandlers(elements, html, fileReader) {
11553
- const names = /* @__PURE__ */ new Set();
11639
+ const names2 = /* @__PURE__ */ new Set();
11554
11640
  forEachStateMethod(elements, html, fileReader, "currentTarget", (name, params, body) => {
11555
- if (readsEventCurrentTarget(params, body)) names.add(name);
11641
+ if (readsEventCurrentTarget(params, body)) names2.add(name);
11556
11642
  });
11557
- return names;
11643
+ return names2;
11558
11644
  }
11559
11645
  function collectPreventDefaultHandlers(elements, html, fileReader) {
11560
11646
  const handlers = /* @__PURE__ */ new Map();
@@ -11801,6 +11887,18 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
11801
11887
  message: `${verdict.message}${pathTrimmed.startsWith(".") ? msgs.expansionSuffix(checkPath) : ""}`,
11802
11888
  severity: verdict.severity
11803
11889
  });
11890
+ } else if (writesBack(attr, propNoMod, parsed.property)) {
11891
+ const target = scopedPaths.find((p) => p.path === checkPath);
11892
+ if (target !== void 0 && target.kind === "computed" && target.settable !== true) {
11893
+ const pathStart = bindingStart + binding.indexOf(parsed.path);
11894
+ diagnostics.push({
11895
+ code: WcsDiagnosticCode.PathReadonly,
11896
+ start: pathStart,
11897
+ end: pathStart + pathTrimmed.length,
11898
+ message: msgs.pathReadonlyTwoWay(checkPath, propNoMod),
11899
+ severity: "error"
11900
+ });
11901
+ }
11804
11902
  }
11805
11903
  }
11806
11904
  }
@@ -11987,6 +12085,19 @@ function openTagBefore(html, valueStart) {
11987
12085
  const lt2 = html.lastIndexOf("<", valueStart);
11988
12086
  return lt2 === -1 ? "" : html.slice(lt2, valueStart);
11989
12087
  }
12088
+ function writesBack(attr, prop, written) {
12089
+ if (written.split("#").slice(1).some((modifier) => modifier.trim() === "ro")) return false;
12090
+ if (prop === "radio" || prop === "checkbox") return true;
12091
+ const tag = attr.tagName;
12092
+ if (tag === void 0 || tag.includes("-")) return false;
12093
+ if (tag === "input") {
12094
+ const type = (attr.inputType || "text").toLowerCase();
12095
+ if (type === "button") return false;
12096
+ if ((type === "radio" || type === "checkbox") && prop === "checked") return true;
12097
+ return prop === "value" || prop === "valueAsNumber" || prop === "valueAsDate";
12098
+ }
12099
+ return (tag === "select" || tag === "textarea") && prop === "value";
12100
+ }
11990
12101
  function findAllBindAttributes(html, attrName) {
11991
12102
  const attrs = [];
11992
12103
  const escaped = attrName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -12000,7 +12111,8 @@ function findAllBindAttributes(html, attrName) {
12000
12111
  const valueStart = tag.start + match.index + match[0].length;
12001
12112
  const valueEnd = html.indexOf(quote, valueStart);
12002
12113
  if (valueEnd === -1 || valueEnd > tag.end) continue;
12003
- attrs.push({ value: html.slice(valueStart, valueEnd), valueStart, tagName: tag.tagName });
12114
+ const inputType = tag.tagName === "input" ? extractAttribute(attrsText, "type") ?? void 0 : void 0;
12115
+ attrs.push({ value: html.slice(valueStart, valueEnd), valueStart, tagName: tag.tagName, ...inputType !== void 0 ? { inputType } : {} });
12004
12116
  regex.lastIndex = valueEnd - tag.start;
12005
12117
  }
12006
12118
  }
@@ -13209,6 +13321,9 @@ var BUILTIN_TAGS = {
13209
13321
  "start",
13210
13322
  "stop",
13211
13323
  "switchCamera"
13324
+ ],
13325
+ "handles": [
13326
+ "streamReady"
13212
13327
  ]
13213
13328
  },
13214
13329
  "wcs-recorder": {
@@ -14152,6 +14267,162 @@ var BUILTIN_TAGS = {
14152
14267
  }
14153
14268
  };
14154
14269
 
14270
+ // src/service/pageElements.ts
14271
+ var MAX_FILES = 32;
14272
+ var JS_TYPES = /* @__PURE__ */ new Set(["", "module", "text/javascript", "application/javascript", "text/ecmascript"]);
14273
+ function pageScripts(html) {
14274
+ const inline = [];
14275
+ const srcs = [];
14276
+ const re = /<script\b((?:"[^"]*"|'[^']*'|[^>"'])*)>([\s\S]*?)<\/script\s*>/gi;
14277
+ const text3 = html.replace(/<!--[\s\S]*?-->/g, (c) => " ".repeat(c.length));
14278
+ let m;
14279
+ while ((m = re.exec(text3)) !== null) {
14280
+ const attrs = m[1];
14281
+ const type = (extractAttribute(attrs, "type") ?? "").trim().toLowerCase();
14282
+ if (!JS_TYPES.has(type)) continue;
14283
+ const src = extractAttribute(attrs, "src");
14284
+ if (src !== null) srcs.push(src);
14285
+ else if (m[2].trim() !== "") inline.push(m[2]);
14286
+ }
14287
+ return { inline, srcs };
14288
+ }
14289
+ function joinRelative(from, spec) {
14290
+ if (!spec.startsWith("./") && !spec.startsWith("../")) return null;
14291
+ const dir = from.includes("/") ? from.slice(0, from.lastIndexOf("/") + 1) : "";
14292
+ const out = [];
14293
+ for (const seg of `${dir}${spec}`.split("/")) {
14294
+ if (seg === "" || seg === ".") continue;
14295
+ if (seg === ".." && out.length > 0 && out[out.length - 1] !== "..") out.pop();
14296
+ else out.push(seg);
14297
+ }
14298
+ return `./${out.join("/")}`;
14299
+ }
14300
+ function parseScript(source) {
14301
+ for (const sourceType of ["module", "script"]) {
14302
+ try {
14303
+ return parse3(source, { ecmaVersion: "latest", sourceType, allowHashBang: true });
14304
+ } catch {
14305
+ }
14306
+ }
14307
+ return null;
14308
+ }
14309
+ function* nodes(node) {
14310
+ yield node;
14311
+ for (const value of Object.values(node)) {
14312
+ if (Array.isArray(value)) {
14313
+ for (const v of value) if (v !== null && typeof v === "object" && typeof v.type === "string") yield* nodes(v);
14314
+ } else if (value !== null && typeof value === "object" && typeof value.type === "string") {
14315
+ yield* nodes(value);
14316
+ }
14317
+ }
14318
+ }
14319
+ var keyName = (key, computed) => computed ? null : key.type === "Identifier" ? key.name : key.type === "Literal" && typeof key.value === "string" ? key.value : null;
14320
+ function names(obj, key) {
14321
+ const prop = obj.properties.find((p) => p.type === "Property" && keyName(p.key, p.computed) === key);
14322
+ if (prop === void 0 || prop.type !== "Property") return void 0;
14323
+ if (prop.value.type !== "ArrayExpression") return null;
14324
+ const out = [];
14325
+ for (const el of prop.value.elements) {
14326
+ if (el === null || el.type !== "ObjectExpression" || el.properties.some((p) => p.type !== "Property")) return null;
14327
+ const name = el.properties.find((p) => p.type === "Property" && keyName(p.key, p.computed) === "name");
14328
+ if (name === void 0 || name.type !== "Property" || name.value.type !== "Literal" || typeof name.value.value !== "string") return null;
14329
+ out.push(name.value.value);
14330
+ }
14331
+ return out;
14332
+ }
14333
+ function contractOf(value) {
14334
+ if (value.type !== "ObjectExpression" || value.properties.some((p) => p.type !== "Property")) return "unknown";
14335
+ const properties = names(value, "properties");
14336
+ const inputs = names(value, "inputs");
14337
+ const commands = names(value, "commands");
14338
+ if (properties === null || inputs === null || commands === null) return "unknown";
14339
+ return {
14340
+ properties: properties ?? [],
14341
+ inputs: Object.fromEntries((inputs ?? []).map((n) => [n, null])),
14342
+ commands: commands ?? []
14343
+ };
14344
+ }
14345
+ function declaredBy(cls) {
14346
+ let declared = "none";
14347
+ for (const member of cls.body.body) {
14348
+ if (member.type !== "PropertyDefinition" && member.type !== "MethodDefinition" || !member.static) continue;
14349
+ if (keyName(member.key, member.computed) !== "wcBindable") continue;
14350
+ if (member.type === "PropertyDefinition") {
14351
+ declared = member.value === null || member.value === void 0 ? "unknown" : contractOf(member.value);
14352
+ } else {
14353
+ const body = member.kind === "get" ? member.value.body.body : [];
14354
+ const ret = body.length === 1 && body[0].type === "ReturnStatement" ? body[0].argument : null;
14355
+ declared = ret === null || ret === void 0 ? "unknown" : contractOf(ret);
14356
+ }
14357
+ }
14358
+ const sup = cls.superClass;
14359
+ return { declared, superName: sup !== null && sup !== void 0 && sup.type === "Identifier" ? sup.name : null };
14360
+ }
14361
+ function isDefine(callee) {
14362
+ if (callee.type !== "MemberExpression" || keyName(callee.property, callee.computed) !== "define") return false;
14363
+ const o = callee.object;
14364
+ return o.type === "Identifier" && o.name === "customElements" || o.type === "MemberExpression" && keyName(o.property, o.computed) === "customElements";
14365
+ }
14366
+ function collectPageElementContracts(html, fileReader) {
14367
+ const { inline, srcs } = pageScripts(html);
14368
+ const programs = [];
14369
+ const read = /* @__PURE__ */ new Set();
14370
+ const queue = srcs.map((spec) => ({ from: "", spec: spec.startsWith(".") ? spec : `./${spec}` }));
14371
+ const visit2 = (program, from) => {
14372
+ programs.push(program);
14373
+ for (const n of nodes(program)) {
14374
+ const source = n.type === "ImportDeclaration" || n.type === "ExportAllDeclaration" || n.type === "ExportNamedDeclaration" ? n.source : n.type === "ImportExpression" ? n.source : null;
14375
+ if (source !== null && source !== void 0 && source.type === "Literal" && typeof source.value === "string") queue.push({ from, spec: source.value });
14376
+ }
14377
+ };
14378
+ for (const source of inline) {
14379
+ const program = parseScript(source);
14380
+ if (program !== null) visit2(program, "");
14381
+ }
14382
+ while (queue.length > 0 && fileReader !== void 0 && read.size < MAX_FILES) {
14383
+ const { from, spec } = queue.shift();
14384
+ const path = joinRelative(from, spec);
14385
+ if (path === null || read.has(path) || !/\.m?js$/.test(path)) continue;
14386
+ read.add(path);
14387
+ const text3 = fileReader(path);
14388
+ const program = text3 === void 0 ? null : parseScript(text3);
14389
+ if (program !== null) visit2(program, path);
14390
+ }
14391
+ const classes = /* @__PURE__ */ new Map();
14392
+ const defines = [];
14393
+ for (const program of programs) {
14394
+ for (const n of nodes(program)) {
14395
+ if (n.type === "ClassDeclaration" && n.id !== null && !classes.has(n.id.name)) classes.set(n.id.name, declaredBy(n));
14396
+ else if (n.type === "VariableDeclarator" && n.id.type === "Identifier" && n.init?.type === "ClassExpression" && !classes.has(n.id.name)) {
14397
+ classes.set(n.id.name, declaredBy(n.init));
14398
+ } else if (n.type === "CallExpression" && isDefine(n.callee) && n.arguments.length >= 2) {
14399
+ const [tag, cls] = n.arguments;
14400
+ if (tag.type !== "Literal" || typeof tag.value !== "string") continue;
14401
+ if (cls.type === "ClassExpression") defines.push({ tag: tag.value, info: declaredBy(cls) });
14402
+ else if (cls.type === "Identifier") defines.push({ tag: tag.value, info: cls.name });
14403
+ }
14404
+ }
14405
+ }
14406
+ const resolve2 = (info, depth) => {
14407
+ if (info.declared === "unknown") return null;
14408
+ if (info.declared !== "none") return info.declared;
14409
+ const sup = info.superName === null ? void 0 : classes.get(info.superName);
14410
+ return sup === void 0 || depth > 16 ? null : resolve2(sup, depth + 1);
14411
+ };
14412
+ const out = /* @__PURE__ */ new Map();
14413
+ for (const { tag, info } of defines) {
14414
+ const name = tag.toLowerCase();
14415
+ if (name.startsWith("wcs-") || out.has(name)) continue;
14416
+ const cls = typeof info === "string" ? classes.get(info) : info;
14417
+ const contract = cls === void 0 ? null : resolve2(cls, 0);
14418
+ if (contract !== null) out.set(name, contract);
14419
+ }
14420
+ return out;
14421
+ }
14422
+ function mayDefineElements(html) {
14423
+ return /customElements|<script\b[^>]*\bsrc\s*=/i.test(html);
14424
+ }
14425
+
14155
14426
  // src/service/ioNodeValidator.ts
14156
14427
  var HTML_SINK_PROPERTIES = /* @__PURE__ */ new Set(["html", "innerHTML", "outerHTML", "srcdoc"]);
14157
14428
  var STRUCTURAL_DIRECTIVES3 = /* @__PURE__ */ new Set(["for", "if", "elseif", "else"]);
@@ -14166,7 +14437,6 @@ function validateIoNodes(html, bindAttribute = "data-wcs", stateTagName = "wcs-s
14166
14437
  const diagnostics = [];
14167
14438
  const msgs = getMessages(locale2);
14168
14439
  const occurrences = findBuiltinTagOccurrences(html);
14169
- if (occurrences.length === 0) return diagnostics;
14170
14440
  let statePaths = null;
14171
14441
  const getPaths = () => statePaths ??= getStatePathsFromHtml(html, stateTagName, fileReader);
14172
14442
  for (const occ of occurrences) {
@@ -14194,32 +14464,35 @@ function validateIoNodes(html, bindAttribute = "data-wcs", stateTagName = "wcs-s
14194
14464
  }
14195
14465
  if (contract.properties.length === 0 && contract.commands.length === 0 && Object.keys(contract.inputs).length === 0) continue;
14196
14466
  const hasManual = hasBooleanAttribute(occ.attrsText, "manual");
14197
- let exprOffset = 0;
14198
- for (const expr of splitBindingExpressions(bindAttr.value)) {
14199
- const exprStart = valueStart + exprOffset;
14200
- exprOffset += expr.length + 1;
14201
- const parsed = parseBindingExpression(expr);
14202
- const property = parsed.property;
14203
- if (!property) continue;
14204
- const propIndex = expr.indexOf(property);
14205
- const start = propIndex === -1 ? exprStart : exprStart + propIndex;
14206
- const end = propIndex === -1 ? exprStart + expr.length : start + property.length;
14207
- validateBindingAgainstContract(
14208
- occ.tagName,
14209
- contract,
14210
- parsed,
14211
- property,
14212
- start,
14213
- end,
14214
- hasManual,
14215
- getPaths,
14216
- diagnostics,
14217
- msgs
14218
- );
14467
+ checkBindings(occ.tagName, contract, bindAttr.value, valueStart, hasManual, getPaths, diagnostics, msgs);
14468
+ }
14469
+ if (mayDefineElements(html)) {
14470
+ const own2 = findPageTagOccurrences(html, bindAttribute);
14471
+ const contracts = own2.length > 0 ? collectPageElementContracts(html, fileReader) : null;
14472
+ for (const occ of own2) {
14473
+ const contract = contracts.get(occ.tagName);
14474
+ if (contract === void 0) continue;
14475
+ if (contract.properties.length === 0 && contract.commands.length === 0 && Object.keys(contract.inputs).length === 0) continue;
14476
+ const bindAttr = extractAttributeValue(occ.attrsText, bindAttribute);
14477
+ checkBindings(occ.tagName, contract, bindAttr.value, occ.attrsStart + bindAttr.valueOffsetInAttrs, false, getPaths, diagnostics, msgs);
14219
14478
  }
14220
14479
  }
14221
14480
  return diagnostics;
14222
14481
  }
14482
+ function checkBindings(tagName, contract, value, valueStart, hasManual, getPaths, diagnostics, msgs) {
14483
+ let exprOffset = 0;
14484
+ for (const expr of splitBindingExpressions(value)) {
14485
+ const exprStart = valueStart + exprOffset;
14486
+ exprOffset += expr.length + 1;
14487
+ const parsed = parseBindingExpression(expr);
14488
+ const property = parsed.property;
14489
+ if (!property) continue;
14490
+ const propIndex = expr.indexOf(property);
14491
+ const start = propIndex === -1 ? exprStart : exprStart + propIndex;
14492
+ const end = propIndex === -1 ? exprStart + expr.length : start + property.length;
14493
+ validateBindingAgainstContract(tagName, contract, parsed, property, start, end, hasManual, getPaths, diagnostics, msgs);
14494
+ }
14495
+ }
14223
14496
  function validateBindingAgainstContract(tagName, contract, parsed, property, start, end, hasManual, getPaths, diagnostics, msgs) {
14224
14497
  const hashIndex = property.indexOf("#");
14225
14498
  const modifiers = hashIndex === -1 ? "" : property.slice(hashIndex + 1);
@@ -14278,6 +14551,7 @@ function validateBindingAgainstContract(tagName, contract, parsed, property, sta
14278
14551
  }
14279
14552
  return;
14280
14553
  }
14554
+ if (!tagName.startsWith("wcs-") && property.includes(".")) return;
14281
14555
  if (!contract.properties.includes(property) && !(property in contract.inputs) && !HTML_SINK_PROPERTIES.has(property)) {
14282
14556
  const members = [...contract.properties, ...inputNames];
14283
14557
  diagnostics.push({
@@ -14291,7 +14565,19 @@ function validateBindingAgainstContract(tagName, contract, parsed, property, sta
14291
14565
  });
14292
14566
  return;
14293
14567
  }
14294
- if (property === "trigger" && "trigger" in contract.inputs && parsed.path) {
14568
+ if (contract.handles?.includes(property)) {
14569
+ diagnostics.push({
14570
+ code: WcsDiagnosticCode.HandleBoundAsValue,
14571
+ start,
14572
+ end,
14573
+ severity: "warning",
14574
+ tag: tagName,
14575
+ member: property,
14576
+ message: msgs.handleBoundAsValue(property, tagName)
14577
+ });
14578
+ return;
14579
+ }
14580
+ if (tagName.startsWith("wcs-") && property === "trigger" && "trigger" in contract.inputs && parsed.path) {
14295
14581
  const cand = findDataSlot(getPaths(), parsed.path);
14296
14582
  if (cand?.rawInitial === "true") {
14297
14583
  diagnostics.push({
@@ -14368,6 +14654,17 @@ function findBuiltinTagOccurrences(html) {
14368
14654
  }
14369
14655
  return out;
14370
14656
  }
14657
+ function findPageTagOccurrences(html, bindAttribute) {
14658
+ const out = [];
14659
+ for (const region of findStartTagRegions(html)) {
14660
+ const tagName = region.tagName;
14661
+ if (!tagName.includes("-") || tagName.startsWith("wcs-")) continue;
14662
+ const attrsText = html.slice(region.start, region.end);
14663
+ if (extractAttributeValue(attrsText, bindAttribute) === null) continue;
14664
+ out.push({ tagName, tagStart: region.start - tagName.length - 1, attrsText, attrsStart: region.start });
14665
+ }
14666
+ return out;
14667
+ }
14371
14668
  function extractAttributeValue(attrsText, attrName) {
14372
14669
  const escaped = attrName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14373
14670
  const regex = new RegExp(`(?:^|\\s)${escaped}\\s*=\\s*(["'])`, "i");
@@ -14813,7 +15110,7 @@ function validateWatchDeclarations(html, stateTagName = "wcs-state", locale2, fi
14813
15110
  const scopes = {
14814
15111
  mounts: volumes?.scopes.mounts ?? [],
14815
15112
  unresolvedMounts: volumes?.scopes.unresolvedMounts ?? NO_MOUNTS,
14816
- rootUnresolved: own2.length === 0 && !isReadableStateScript(block.content)
15113
+ rootUnresolved: !scriptReadable(block.content, own2)
14817
15114
  };
14818
15115
  for (const entry of entries) {
14819
15116
  const diagnostic = validateEntry(entry, pathSet, paths, scopes, msgs);
@@ -14834,10 +15131,10 @@ var NO_MOUNTS = /* @__PURE__ */ new Set();
14834
15131
  function assignVolumes(elements, html) {
14835
15132
  const chainOf = createTemplateChain(html);
14836
15133
  const innermost = (chain) => chain.length > 0 ? chain[chain.length - 1] : -1;
14837
- const treeOf = (root) => innermost(chainOf(root.tagStart));
15134
+ const treeOf2 = (root) => innermost(chainOf(root.tagStart));
14838
15135
  const rootTrees = /* @__PURE__ */ new Set();
14839
15136
  for (const element2 of elements) {
14840
- if (element2.mountPath === null && !element2.bindComponent) rootTrees.add(treeOf(element2));
15137
+ if (element2.mountPath === null && !element2.bindComponent) rootTrees.add(treeOf2(element2));
14841
15138
  }
14842
15139
  const volumes = /* @__PURE__ */ new Map();
14843
15140
  for (const element2 of elements) {
@@ -14854,7 +15151,7 @@ function assignVolumes(elements, html) {
14854
15151
  if (list === void 0) volumes.set(tree, [element2]);
14855
15152
  else list.push(element2);
14856
15153
  }
14857
- return { treeOf, volumes };
15154
+ return { treeOf: treeOf2, volumes };
14858
15155
  }
14859
15156
  function validateEntry(entry, pathSet, paths, scopes, msgs) {
14860
15157
  const { key } = entry;
@@ -15842,8 +16139,8 @@ function validateVolumeBlock2(block, mountPath, msgs, out) {
15842
16139
  }
15843
16140
  function validateBindComponentSource(html, tagStart, tagEnd, hasInlineScript, msgs, out) {
15844
16141
  const tag = html.slice(tagStart, tagEnd);
15845
- const names = parseAttributeNames(tag);
15846
- const sources = BIND_COMPONENT_SOURCE_ATTRIBUTES.filter((name) => names.has(name));
16142
+ const names2 = parseAttributeNames(tag);
16143
+ const sources = BIND_COMPONENT_SOURCE_ATTRIBUTES.filter((name) => names2.has(name));
15847
16144
  if (hasInlineScript) sources.push('<script type="module">');
15848
16145
  if (sources.length === 0) return;
15849
16146
  const prop = /\sbind-component\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>`=]+))/i.exec(tag);
@@ -15971,7 +16268,7 @@ var OLD_DECLARATION_KEY = /(^|[{,;\s])(\$streams|\$updatedCallback)(?=\s*(?:[:(]
15971
16268
  function collectDeclarationAliasReads(script) {
15972
16269
  return collectStateThisReads(script, OLD_DECLARATION_MEMBER_NAMES);
15973
16270
  }
15974
- function collectStateThisReads(script, names) {
16271
+ function collectStateThisReads(script, names2) {
15975
16272
  if (!hasDefaultExportObject(script)) return null;
15976
16273
  const out = [];
15977
16274
  const take = (refs, base) => {
@@ -15980,10 +16277,10 @@ function collectStateThisReads(script, names) {
15980
16277
  return true;
15981
16278
  };
15982
16279
  for (const callable of analyzeCallableBodies(script)) {
15983
- if (!take(collectThisMemberRefs(callable.body, names), callable.bodyStart)) return null;
16280
+ if (!take(collectThisMemberRefs(callable.body, names2), callable.bodyStart)) return null;
15984
16281
  }
15985
16282
  for (const handler of analyzeWatchHandlerSources(script)) {
15986
- const refs = handler.kind === "body" ? collectThisMemberRefs(handler.text, names) : collectThisMemberRefsInValue(handler.text, names);
16283
+ const refs = handler.kind === "body" ? collectThisMemberRefs(handler.text, names2) : collectThisMemberRefsInValue(handler.text, names2);
15987
16284
  if (!take(refs, handler.start)) return null;
15988
16285
  }
15989
16286
  out.sort((a, b) => a.start - b.start);
@@ -16191,6 +16488,26 @@ function validateGetterLocationReads(script, scriptStart, locale2) {
16191
16488
  }
16192
16489
  return out;
16193
16490
  }
16491
+ var CLOCK_READ = /\bDate\s*\.\s*now\s*\(|\bnew\s+Date\s*\(\s*\)|\bperformance\s*\.\s*now\s*\(/;
16492
+ function validateGetterClockReads(script, scriptStart, locale2) {
16493
+ if (!/Date|performance/.test(script)) return [];
16494
+ const msgs = getMessages(locale2);
16495
+ const out = [];
16496
+ for (const getter of analyzeCallableBodies(script)) {
16497
+ if (getter.kind !== "getter" || getter.accessor !== "get") continue;
16498
+ const read = CLOCK_READ.exec(maskCommentsAndStrings(getter.body));
16499
+ if (read === null) continue;
16500
+ const text3 = read[0].startsWith("new") ? "new Date()" : read[0].startsWith("performance") ? "performance.now()" : "Date.now()";
16501
+ out.push({
16502
+ code: WcsDiagnosticCode.GetterUntrackedRead,
16503
+ start: scriptStart + getter.bodyStart + read.index,
16504
+ end: scriptStart + getter.bodyStart + read.index + read[0].length,
16505
+ message: msgs.getterReadsClock(text3),
16506
+ severity: "warning"
16507
+ });
16508
+ }
16509
+ return out;
16510
+ }
16194
16511
  function onHandlerStateParam(script, handler) {
16195
16512
  if (handler.kind === "body") {
16196
16513
  const head = script.slice(Math.max(0, handler.start - 400), handler.start);
@@ -16388,15 +16705,22 @@ function validateUpdatedCallbackDemand(html, stateTagName, bindAttrName, locale2
16388
16705
  const reported = /* @__PURE__ */ new Set();
16389
16706
  while ((match = PATH_TEST_LITERAL.exec(body)) !== null) {
16390
16707
  const path = match[2];
16391
- if (path.length === 0 || !declared.has(path) || bound.has(path)) continue;
16392
- if (reported.has(path)) continue;
16708
+ if (path.length === 0 || bound.has(path) || reported.has(path)) continue;
16709
+ let message;
16710
+ if (declared.has(path)) {
16711
+ message = msgs.updatedCallbackUnbound(path);
16712
+ } else {
16713
+ const near = suggestion(path, [...declared, ...bound], msgs);
16714
+ if (near === "") continue;
16715
+ message = msgs.updatedCallbackUnknownPath(path) + near;
16716
+ }
16393
16717
  reported.add(path);
16394
16718
  const quoteAt = match.index + match[0].length - path.length - 1;
16395
16719
  out.push({
16396
16720
  code: WcsDiagnosticCode.UpdatedCallbackUnbound,
16397
16721
  start: block.contentStart + callback.bodyStart + quoteAt,
16398
16722
  end: block.contentStart + callback.bodyStart + quoteAt + path.length,
16399
- message: msgs.updatedCallbackUnbound(path),
16723
+ message,
16400
16724
  severity: "warning"
16401
16725
  });
16402
16726
  }
@@ -16409,8 +16733,8 @@ function collectBoundPaths(html, stateTagName, bindAttrName) {
16409
16733
  for (const occurrence of index.occurrences) {
16410
16734
  bound.add(occurrence.path);
16411
16735
  if (!occurrence.path.startsWith(".")) continue;
16412
- const forPath = getInnermostForPath(html, occurrence.pathRange.start, bindAttrName);
16413
- if (forPath === null || forPath.startsWith(".")) continue;
16736
+ const forPath = getResolvedForListPath(html, occurrence.pathRange.start, bindAttrName);
16737
+ if (forPath === null) continue;
16414
16738
  bound.add(
16415
16739
  occurrence.path === "." ? `${forPath}.*` : `${forPath}.*.${occurrence.path.slice(1)}`
16416
16740
  );
@@ -16483,6 +16807,7 @@ function validateSemantics(html, stateTagName = "wcs-state", locale2, bindAttrNa
16483
16807
  out.push(...validateGetterCycles(block.content, block.contentStart, locale2));
16484
16808
  out.push(...validateGetterUntrackedReads(block.content, block.contentStart, getNestedWriteRoots, locale2));
16485
16809
  out.push(...validateGetterLocationReads(block.content, block.contentStart, locale2));
16810
+ out.push(...validateGetterClockReads(block.content, block.contentStart, locale2));
16486
16811
  out.push(...validateOnHandlerThis(block.content, block.contentStart, locale2));
16487
16812
  out.push(...validateInPlaceChanges(block.content, block.contentStart, locale2));
16488
16813
  }
@@ -16491,6 +16816,169 @@ function validateSemantics(html, stateTagName = "wcs-state", locale2, bindAttrNa
16491
16816
  return out;
16492
16817
  }
16493
16818
 
16819
+ // src/service/scriptStateUseValidator.ts
16820
+ var COMMAND_USE = /\.\s*\$command\s*\.\s*([A-Za-z_$][\w$]*)/dg;
16821
+ var EMIT_AFTER = /^\s*\.\s*emit\s*\(/;
16822
+ var THIS_WRITE = /\bthis\s*\.\s*([A-Za-z_][\w$]*)\s*(?:=(?![=>])|[-+*/%&|^]=|\*\*=|<<=|>>>?=|&&=|\|\|=|\?\?=|\+\+|--)/dg;
16823
+ var PRE_THIS_WRITE = /(?:\+\+|--)\s*this\s*\.\s*([A-Za-z_][\w$]*)/dg;
16824
+ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bindAttrName = "data-wcs") {
16825
+ const blocks = parseLoadedScriptBlocks(html, stateTagName).filter((block) => isReadableStateScript(block.content));
16826
+ if (blocks.length === 0) return [];
16827
+ const msgs = getMessages(locale2);
16828
+ const out = [];
16829
+ let receivers = null;
16830
+ let markupEmits = null;
16831
+ const bindings = () => {
16832
+ if (receivers !== null) return;
16833
+ receivers = /* @__PURE__ */ new Set();
16834
+ markupEmits = /* @__PURE__ */ new Map();
16835
+ for (const o of buildReferenceIndex(html, { bindAttribute: bindAttrName, stateTagName }).occurrences) {
16836
+ if (!o.path.startsWith("$command.")) continue;
16837
+ const name = o.path.slice("$command.".length);
16838
+ const prop = o.propName ?? "";
16839
+ if (prop.startsWith("command.")) receivers.add(name);
16840
+ else if (prop.startsWith("on") && !markupEmits.has(name)) markupEmits.set(name, o.pathRange);
16841
+ }
16842
+ };
16843
+ for (const block of blocks) {
16844
+ const paths = analyzeStatePaths(block.content);
16845
+ const masked = maskCommentsAndStrings(block.content);
16846
+ const declared = paths.filter((p) => p.kind === "command").map((p) => p.path.slice("$command.".length));
16847
+ if (block.mountPath === null && declared.length > 0) {
16848
+ const emitted = /* @__PURE__ */ new Map();
16849
+ COMMAND_USE.lastIndex = 0;
16850
+ let match;
16851
+ while ((match = COMMAND_USE.exec(masked)) !== null) {
16852
+ const name = match[1];
16853
+ const [start, end] = match.indices[1];
16854
+ if (!declared.includes(name)) {
16855
+ out.push({
16856
+ code: WcsDiagnosticCode.TokenUndeclared,
16857
+ start: block.contentStart + start,
16858
+ end: block.contentStart + end,
16859
+ // `$command` holds the declared tokens only: `.emit()` on what it lacks is a TypeError
16860
+ message: msgs.commandTokenUndeclared(`$command.${name}`) + suggestion(name, declared, msgs),
16861
+ severity: "error"
16862
+ });
16863
+ } else if (!emitted.has(name) && EMIT_AFTER.test(masked.slice(match.index + match[0].length))) {
16864
+ emitted.set(name, { start: block.contentStart + start, end: block.contentStart + end });
16865
+ }
16866
+ }
16867
+ bindings();
16868
+ for (const name of declared) {
16869
+ if (receivers.has(name)) continue;
16870
+ const at2 = emitted.get(name) ?? markupEmits.get(name);
16871
+ if (at2 === void 0) continue;
16872
+ out.push({
16873
+ code: WcsDiagnosticCode.CommandTokenUnbound,
16874
+ start: at2.start,
16875
+ end: at2.end,
16876
+ message: msgs.commandTokenUnbound(`$command.${name}`),
16877
+ severity: "warning"
16878
+ });
16879
+ }
16880
+ }
16881
+ const keys = [...new Set(paths.map((p) => p.path.split(".")[0]).filter((key) => key !== "" && !key.startsWith("$")))];
16882
+ const reported = /* @__PURE__ */ new Set();
16883
+ for (const pattern of [THIS_WRITE, PRE_THIS_WRITE]) {
16884
+ pattern.lastIndex = 0;
16885
+ let match;
16886
+ while ((match = pattern.exec(masked)) !== null) {
16887
+ const key = match[1];
16888
+ if (keys.includes(key) || reported.has(key)) continue;
16889
+ const near = suggestion(key, keys, msgs);
16890
+ if (near === "") continue;
16891
+ reported.add(key);
16892
+ const [start, end] = match.indices[1];
16893
+ out.push({
16894
+ code: WcsDiagnosticCode.WritePathMissing,
16895
+ start: block.contentStart + start,
16896
+ end: block.contentStart + end,
16897
+ message: msgs.writePathMissing(key) + near,
16898
+ severity: "warning"
16899
+ });
16900
+ }
16901
+ }
16902
+ }
16903
+ return out;
16904
+ }
16905
+
16906
+ // src/service/scriptReadValidator.ts
16907
+ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileReader, applicationSchema) {
16908
+ const blocks = parseLoadedScriptBlocks(html, stateTagName);
16909
+ if (blocks.length === 0) return [];
16910
+ const msgs = getMessages(locale2);
16911
+ const index = getStatePathIndex(html, stateTagName, fileReader);
16912
+ const candidates = mergeSchemaCandidates(index.paths, applicationSchema);
16913
+ const candidateSet = new Set(candidates.map((p) => p.path));
16914
+ let tree = null;
16915
+ const out = [];
16916
+ for (const block of blocks) {
16917
+ const spread = applicationSchema === void 0 ? findTopLevelSpread(block.content) : null;
16918
+ if (spread !== null) {
16919
+ out.push({
16920
+ code: WcsDiagnosticCode.PathDynamicUnknown,
16921
+ start: block.contentStart + spread.start,
16922
+ end: block.contentStart + spread.end,
16923
+ message: msgs.pathDynamicUnknownSpread(block.content.slice(spread.start, spread.end)),
16924
+ severity: "info"
16925
+ });
16926
+ }
16927
+ const prefix = block.mountPath === null || block.mountPath === "" ? "" : `${block.mountPath}.`;
16928
+ for (const callable of analyzeCallableBodies(block.content)) {
16929
+ for (const read of collectGetterReads(callable.body) ?? []) {
16930
+ if (read.written || read.path.split(".").some((s) => s === "" || s.startsWith("$")) || hasRecursionWildcard(read.path)) continue;
16931
+ const path = prefix + read.path;
16932
+ if (pathExistsInCandidates(path, candidates, candidateSet)) continue;
16933
+ if (applicationSchema !== void 0 ? resolveIndexedSchemaPath(applicationSchema, path).kind !== "nonexistent" : isUnresolvedPath(path, index.scopes)) continue;
16934
+ const near = nearName(path, tree ??= treeOf(candidates));
16935
+ if (near === null) continue;
16936
+ const said = suggestion(near.segment, near.names, msgs);
16937
+ if (said === "") continue;
16938
+ const at2 = block.contentStart + callable.bodyStart;
16939
+ out.push({
16940
+ code: WcsDiagnosticCode.ReadPathMissing,
16941
+ start: at2 + read.start,
16942
+ end: read.form === "member" ? at2 + read.start + statePart(callable.body.slice(read.start, read.end)) : at2 + read.end,
16943
+ message: msgs.readPathMissing(read.path, !read.path.includes(".")) + said,
16944
+ // a stateSchema says the path is not there, as for a binding's `wcs/path-nonexistent`
16945
+ severity: applicationSchema !== void 0 ? "error" : "warning"
16946
+ });
16947
+ }
16948
+ }
16949
+ }
16950
+ return out;
16951
+ }
16952
+ var THIS_PART = /^this\s*(?:\?\.\s*|\.\s*)(?:[A-Za-z_$][\w$]*)|^this\s*(?:\?\.)?\s*\[\s*(["'`])[^"'`]*\1\s*\]/;
16953
+ function statePart(text3) {
16954
+ return THIS_PART.exec(text3)?.[0].length ?? text3.length;
16955
+ }
16956
+ function treeOf(candidates) {
16957
+ const tree = /* @__PURE__ */ new Map();
16958
+ for (const c of candidates) {
16959
+ let parent = "";
16960
+ for (const segment of c.path.split(".")) {
16961
+ let names2 = tree.get(parent);
16962
+ if (names2 === void 0) tree.set(parent, names2 = /* @__PURE__ */ new Set());
16963
+ names2.add(segment);
16964
+ parent = parent === "" ? segment : `${parent}.${segment}`;
16965
+ }
16966
+ }
16967
+ return tree;
16968
+ }
16969
+ function nearName(path, tree) {
16970
+ let parent = "";
16971
+ for (const segment of (hasIndexSegment(path) ? toWildcardForm(path) : path).split(".")) {
16972
+ const names2 = tree.get(parent);
16973
+ if (names2?.has(segment)) {
16974
+ parent = parent === "" ? segment : `${parent}.${segment}`;
16975
+ continue;
16976
+ }
16977
+ return { segment, names: [...names2 ?? []].filter((name) => name !== "*" && !name.startsWith("$")) };
16978
+ }
16979
+ return null;
16980
+ }
16981
+
16494
16982
  // src/core/sidecar/jsonSource.ts
16495
16983
  var JsonReader = class {
16496
16984
  constructor(text3) {
@@ -16878,13 +17366,104 @@ function joinRelativeSource(htmlSource, relativePath) {
16878
17366
  return dirSegments.join("/");
16879
17367
  }
16880
17368
 
17369
+ // src/core/externalState.ts
17370
+ var OPEN = '<script type="module">';
17371
+ var CLOSE = "</script>";
17372
+ function inlineExternalStates(html, stateTagName, fileReader) {
17373
+ let text3 = "";
17374
+ let from = 0;
17375
+ let shift = 0;
17376
+ const states = [];
17377
+ for (const element2 of parseWcsStateElements(html, stateTagName)) {
17378
+ const src = element2.srcSpan;
17379
+ if (src === void 0 || element2.srcAttr === void 0 || element2.stateAttr !== void 0 || element2.bindComponent) continue;
17380
+ const file = readStateScriptFile(element2.srcAttr, fileReader);
17381
+ if (file === void 0) continue;
17382
+ const blanks = [src];
17383
+ if (element2.jsonSpan !== void 0) blanks.push(element2.jsonSpan);
17384
+ blanks.sort((a, b) => a.start - b.start);
17385
+ for (const span of blanks) {
17386
+ text3 += html.slice(from, span.start) + " ".repeat(span.end - span.start);
17387
+ from = span.end;
17388
+ }
17389
+ text3 += html.slice(from, element2.tagEnd);
17390
+ from = element2.tagEnd;
17391
+ const content = file.text.replace(/<\/(script)/gi, "<\\$1");
17392
+ const at2 = element2.tagEnd + shift;
17393
+ const length = OPEN.length + content.length + CLOSE.length;
17394
+ text3 += OPEN + content + CLOSE;
17395
+ states.push({
17396
+ path: file.path,
17397
+ text: file.text,
17398
+ at: at2,
17399
+ contentAt: at2 + OPEN.length,
17400
+ length,
17401
+ valueStart: src.valueStart,
17402
+ valueEnd: src.valueEnd,
17403
+ position: createPositionMapper(file.text)
17404
+ });
17405
+ shift += length;
17406
+ }
17407
+ if (states.length === 0) return null;
17408
+ return { text: text3 + html.slice(from), states };
17409
+ }
17410
+ function locateInlined(page, offset2) {
17411
+ let shift = 0;
17412
+ for (const state of page.states) {
17413
+ if (offset2 < state.at) break;
17414
+ if (offset2 < state.at + state.length) {
17415
+ return { state, offset: Math.min(Math.max(offset2 - state.contentAt, 0), state.text.length) };
17416
+ }
17417
+ shift += state.length;
17418
+ }
17419
+ return { offset: offset2 - shift };
17420
+ }
17421
+
16881
17422
  // src/core/validateDocument.ts
16882
17423
  function validateDocument(text3, options = {}) {
17424
+ const stateTagName = options.stateTagName ?? "wcs-state";
17425
+ const fileReader = options.fileReader;
17426
+ const applicationSchema = options.applicationSchema ?? (fileReader !== void 0 ? discoverApplicationManifest(fileReader)?.schema : void 0);
17427
+ const found = validateText(text3, options, applicationSchema);
17428
+ const page = fileReader === void 0 ? null : inlineExternalStates(text3, stateTagName, fileReader);
17429
+ if (page === null) return found;
17430
+ const key = (d) => [d.code, d.start, d.end, d.message, d.origin?.path, d.origin?.start].join("\0");
17431
+ const seen2 = new Set(found.map(key));
17432
+ const out = [...found];
17433
+ for (const d of validateText(page.text, options, applicationSchema)) {
17434
+ const start = locateInlined(page, d.start);
17435
+ const end = locateInlined(page, d.end);
17436
+ let mapped;
17437
+ if (start.state !== void 0) {
17438
+ const state = start.state;
17439
+ const fileEnd = end.state === state ? Math.max(end.offset, start.offset) : start.offset;
17440
+ mapped = {
17441
+ ...d,
17442
+ start: state.valueStart,
17443
+ end: state.valueEnd,
17444
+ origin: {
17445
+ path: state.path,
17446
+ start: start.offset,
17447
+ end: fileEnd,
17448
+ startPosition: state.position(start.offset),
17449
+ endPosition: state.position(fileEnd)
17450
+ }
17451
+ };
17452
+ } else {
17453
+ mapped = { ...d, start: start.offset, end: end.state === void 0 ? Math.max(end.offset, start.offset) : start.offset };
17454
+ }
17455
+ const k = key(mapped);
17456
+ if (seen2.has(k)) continue;
17457
+ seen2.add(k);
17458
+ out.push(mapped);
17459
+ }
17460
+ return sortDiagnostics(out);
17461
+ }
17462
+ function validateText(text3, options, applicationSchema) {
16883
17463
  const bindAttribute = options.bindAttribute ?? "data-wcs";
16884
17464
  const stateTagName = options.stateTagName ?? "wcs-state";
16885
17465
  const locale2 = options.locale;
16886
17466
  const fileReader = options.fileReader;
16887
- const applicationSchema = options.applicationSchema ?? (fileReader !== void 0 ? discoverApplicationManifest(fileReader)?.schema : void 0);
16888
17467
  const out = [];
16889
17468
  out.push(...validateBindings(text3, bindAttribute, stateTagName, locale2, fileReader, applicationSchema));
16890
17469
  out.push(...validateTemplateSyntax(text3, stateTagName, bindAttribute, locale2, fileReader, applicationSchema));
@@ -16893,6 +17472,8 @@ function validateDocument(text3, options = {}) {
16893
17472
  out.push(...validateAriaAttributes(text3, bindAttribute, locale2));
16894
17473
  out.push(...validateDocumentEnv(text3, locale2));
16895
17474
  out.push(...validateSemantics(text3, stateTagName, locale2, bindAttribute));
17475
+ out.push(...validateScriptStateUses(text3, stateTagName, locale2, bindAttribute));
17476
+ out.push(...validateScriptReads(text3, stateTagName, locale2, fileReader, applicationSchema));
16896
17477
  out.push(...validateArrayMutations(text3, stateTagName, locale2));
16897
17478
  out.push(...validateWatchDeclarations(text3, stateTagName, locale2, fileReader));
16898
17479
  out.push(...validateScanDeclarations(text3, stateTagName, locale2));
@@ -17064,6 +17645,7 @@ function runValidation(inputs, options = {}) {
17064
17645
  explicitSchema = result.resolvedSchema;
17065
17646
  }
17066
17647
  }
17648
+ const inFiles = /* @__PURE__ */ new Map();
17067
17649
  for (const input of inputs) {
17068
17650
  if (input.kind !== "html") continue;
17069
17651
  let applicationSchema = explicitSchema;
@@ -17083,8 +17665,24 @@ function runValidation(inputs, options = {}) {
17083
17665
  ...input.fileReader !== void 0 ? { fileReader: input.fileReader } : {},
17084
17666
  ...applicationSchema !== void 0 ? { applicationSchema } : {}
17085
17667
  };
17086
- diagnosticsBySource.set(input.source, validateDocument(input.text, docOptions));
17668
+ const own2 = [];
17669
+ for (const d of validateDocument(input.text, docOptions)) {
17670
+ if (d.origin === void 0) {
17671
+ own2.push(d);
17672
+ continue;
17673
+ }
17674
+ const source = joinRelativeSource(input.source, d.origin.path);
17675
+ if (!textBySource.has(source)) textBySource.set(source, input.fileReader?.(d.origin.path) ?? "");
17676
+ let list = inFiles.get(source);
17677
+ if (list === void 0) inFiles.set(source, list = []);
17678
+ const { origin, ...rest } = d;
17679
+ if (!list.some((x) => x.code === d.code && x.start === origin.start && x.end === origin.end && x.message === d.message)) {
17680
+ list.push({ ...rest, start: origin.start, end: origin.end });
17681
+ }
17682
+ }
17683
+ diagnosticsBySource.set(input.source, own2);
17087
17684
  }
17685
+ for (const [source, list] of inFiles) diagnosticsBySource.set(source, sortDiagnostics(list));
17088
17686
  const lines = [];
17089
17687
  let errorCount = 0;
17090
17688
  let warningCount = 0;