@wcstack/lint 4.25.0 → 4.27.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
@@ -191,6 +191,11 @@ var WcsDiagnosticCode = {
191
191
  // --- sidecar vs live declaration drift ---
192
192
  DriftMissingMember: "wcs/drift-missing-member",
193
193
  DriftEventMismatch: "wcs/drift-event-mismatch",
194
+ // stateSchema と state のスクリプトのトップレベルのキーが食い違う(スクリプトにあって schema に無い・schema にあって
195
+ // スクリプトに無い)。schema はスクリプトから作る派生物なので古い: 名前を変えたキーの束縛の取り残しが通り、新しいキーは
196
+ // `wcs/path-nonexistent` になる(継ぎ目アプリ lending-desk — `wcs-schema check` だけが気付いた)。`<wcs-state>` の上で
197
+ // 1 回、キーを挙げて `wcs-schema emit` を案内する。warning(4.26)。
198
+ DriftStateKey: "wcs/drift-state-key",
194
199
  // --- path / type resolution against a stateSchema ---
195
200
  PathNonexistent: "wcs/path-nonexistent",
196
201
  PathTypeMismatch: "wcs/path-type-mismatch",
@@ -223,6 +228,10 @@ var WcsDiagnosticCode = {
223
228
  FilterArity: "wcs/filter-arity",
224
229
  FilterArgType: "wcs/filter-arg-type",
225
230
  FilterInputType: "wcs/filter-input-type",
231
+ // 比較のフィルタ(`eq` / `ne`)のリテラルの引数が、入力の値の取りうる有限の集合(stateSchema の `enum` / `const` /
232
+ // `anyOf` の const、JSDoc のリテラルの合併)に無い: `status|eq('aproved')` は決して真にならない(`ne` は常に真)。
233
+ // 綴りの近い値を挙げる。warning(4.26、継ぎ目アプリ lending-desk — バッジの色が黙って消えた)。
234
+ FilterArgEnum: "wcs/filter-arg-enum",
226
235
  BindingPathMissing: "wcs/binding-path-missing",
227
236
  BindingTypeExpectation: "wcs/binding-type-expectation",
228
237
  TokenUndeclared: "wcs/token-undeclared",
@@ -491,7 +500,7 @@ var WcsDiagnosticCode = {
491
500
  // 受ける要素のメソッドはイベントを第 1 引数として呼ばれる。データを取るコマンド(組み込みタグの、引数を宣言する
492
501
  // メソッド)ではそれが原因から遠い所で失敗する — `<wcs-screen-orientation>` の `lock(event)` と `<wcs-share>` の
493
502
  // `share(event)` はブラウザの TypeError が `error` に出るだけ、`<wcs-credential>` の `get(event)` は何も言わず null
494
- // (stamp-rally)。`on*:` の束縛に出す。`<wcs-fetch>` の `fetch`(4.24 から url の位置の文字列でない値を無視する)と
503
+ // (stamp-rally)。`on*:` の束縛に出す。`<wcs-fetch>` の `fetch`(url の位置のイベントは無視する。4.26 から `URL` も受け、ほかの値は `[wcs/fetch-url-argument]`)と
495
504
  // ネイティブ要素のコマンド(native-commands の後付けは第 1 引数がイベントなら引数なしで呼ぶ)は対象外。warning。
496
505
  CommandEventArgument: "wcs/command-event-argument",
497
506
  // 既知のカスタム要素の出力だけのメンバー(`<wcs-fullscreen>` の `active: viewerFs`)に束ねたパスへ、スクリプトが
@@ -987,10 +996,13 @@ var SENTENCES = {
987
996
  // an import that does not resolve (Chromium "Failed to resolve module specifier", Firefox "… specifier …",
988
997
  // WebKit "does not resolve"): the blob: URL is the base — no CSP is involved (community-hall, D6). (A browser's
989
998
  // own sentence ends with a period of its own: one is enough)
999
+ // a script that does not parse (Chromium / WebKit "Unexpected token ':'", Firefox "unexpected token: ':'", "missing
1000
+ // ; before statement", "expected expression"): the browser runs it as written, and TypeScript syntax is the usual
1001
+ // cause — a CSP refusal says so in its own words (docs/seam-apps.md, lending-desk)
990
1002
  [
991
1003
  43
992
1004
  /* InlineFailed */
993
- ]: (detail) => `Failed to evaluate the inline <script> of <wcs-state>: ${String(detail).replace(/\.$/, "")}. ${/specifier|does not resolve/i.test(String(detail)) ? `An inline state is evaluated from a blob: URL, against which a relative or root-relative import ("./x.js", "/js/x.js") does not resolve: import a full URL, or a name the page's import map gives ({ "imports": { "@app/": "/js/" } }), or move the state into a file (src="./state.js").` : `If this page sets a Content-Security-Policy, see ${CSP_GUIDE}`}`,
1005
+ ]: (detail) => `Failed to evaluate the inline <script> of <wcs-state>: ${String(detail).replace(/\.$/, "")}. ${/specifier|does not resolve/i.test(String(detail)) ? `An inline state is evaluated from a blob: URL, against which a relative or root-relative import ("./x.js", "/js/x.js") does not resolve: import a full URL, or a name the page's import map gives ({ "imports": { "@app/": "/js/" } }), or move the state into a file (src="./state.js").` : /expected|missing/i.test(String(detail)) ? `The script does not parse as JavaScript: the browser runs it as written, so TypeScript syntax (a type annotation "x: number", "import type", "as T", "x!") is a syntax error here. Write the types in JSDoc (/** @type {number} */), or put the state in a file a build compiles (src="./state.ts").` : `If this page sets a Content-Security-Policy, see ${CSP_GUIDE}`}`,
994
1006
  [
995
1007
  17
996
1008
  /* TokenSubscriberThrew */
@@ -2634,7 +2646,7 @@ function getWcsManifest() {
2634
2646
  }
2635
2647
 
2636
2648
  // ../state/package.json
2637
- var version = "4.25.0";
2649
+ var version = "4.27.0";
2638
2650
 
2639
2651
  // src/service/wcsManifest.ts
2640
2652
  var ENGINE_VERSION = version;
@@ -8456,8 +8468,65 @@ function parse3(input, options) {
8456
8468
  return Parser.parse(input, options);
8457
8469
  }
8458
8470
 
8471
+ // src/service/typeErasure.ts
8472
+ function stripper() {
8473
+ const proc = globalThis.process;
8474
+ if (proc === void 0 || typeof proc.getBuiltinModule !== "function") return null;
8475
+ const mod = proc.getBuiltinModule("node:module");
8476
+ return typeof mod?.stripTypeScriptTypes === "function" ? mod.stripTypeScriptTypes : null;
8477
+ }
8478
+ function quietly(proc, fn) {
8479
+ const emit2 = proc.emitWarning;
8480
+ proc.emitWarning = (...args) => {
8481
+ const [warning, type] = args;
8482
+ const text3 = typeof warning === "string" ? warning : warning instanceof Error ? warning.message : "";
8483
+ const kind = typeof type === "string" ? type : type?.type;
8484
+ if ((kind === "ExperimentalWarning" || warning instanceof Error && warning.name === "ExperimentalWarning") && /strip|typescript/i.test(text3)) return;
8485
+ emit2.apply(proc, args);
8486
+ };
8487
+ try {
8488
+ return fn();
8489
+ } finally {
8490
+ proc.emitWarning = emit2;
8491
+ }
8492
+ }
8493
+ var erased = /* @__PURE__ */ new Map();
8494
+ var MAX_ERASED = 64;
8495
+ function eraseTypeScript(code) {
8496
+ const cached = erased.get(code);
8497
+ if (cached !== void 0 || erased.has(code)) return cached ?? null;
8498
+ const strip = stripper();
8499
+ if (strip === null) return null;
8500
+ const proc = globalThis.process;
8501
+ let out;
8502
+ try {
8503
+ const result = quietly(proc, () => strip(code, { mode: "strip" }));
8504
+ out = typeof result === "string" && result.length === code.length ? result : null;
8505
+ } catch {
8506
+ out = null;
8507
+ }
8508
+ if (erased.size >= MAX_ERASED) erased.delete(erased.keys().next().value);
8509
+ erased.set(code, out);
8510
+ return out;
8511
+ }
8512
+ function parseErasingTypes(source, options) {
8513
+ try {
8514
+ return parse3(source, options);
8515
+ } catch (error) {
8516
+ const js = eraseTypeScript(source);
8517
+ if (js === null) throw error;
8518
+ return parse3(js, options);
8519
+ }
8520
+ }
8521
+
8459
8522
  // src/service/jsdocType.ts
8460
8523
  var UNKNOWN = { kind: "unknown" };
8524
+ function importTypeName(specifier, name) {
8525
+ return `import("${specifier}").${name}`;
8526
+ }
8527
+ function isImportTypeName(name) {
8528
+ return name.startsWith('import("');
8529
+ }
8461
8530
  var NULL_TYPE = { kind: "name", name: "null" };
8462
8531
  var ARRAY_GENERICS = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
8463
8532
  var INDEX_GENERICS = /* @__PURE__ */ new Set(["Record", "Object"]);
@@ -8491,7 +8560,7 @@ function tokenize(text3) {
8491
8560
  }
8492
8561
  const num = /^-?\d+(?:\.\d+)?/.exec(text3.slice(i));
8493
8562
  if (num) {
8494
- tokens.push({ t: "number" });
8563
+ tokens.push({ t: "number", v: Number(num[0]) });
8495
8564
  i += num[0].length;
8496
8565
  continue;
8497
8566
  }
@@ -8505,7 +8574,7 @@ function tokenize(text3) {
8505
8574
  }
8506
8575
  return tokens;
8507
8576
  }
8508
- function parseJsDocType(text3) {
8577
+ function parseJsDocType(text3, options = {}) {
8509
8578
  const tokens = tokenize(text3);
8510
8579
  if (tokens === null || tokens.length === 0) return null;
8511
8580
  let pos = 0;
@@ -8550,7 +8619,7 @@ function parseJsDocType(text3) {
8550
8619
  if (token === void 0) return null;
8551
8620
  if (token.t === "string" || token.t === "number") {
8552
8621
  pos++;
8553
- return UNKNOWN;
8622
+ return { kind: "literal", value: token.v };
8554
8623
  }
8555
8624
  if (token.t === "punct") {
8556
8625
  if (token.v === "{") return parseObject();
@@ -8583,7 +8652,20 @@ function parseJsDocType(text3) {
8583
8652
  return null;
8584
8653
  }
8585
8654
  pos++;
8655
+ if (token.v === "true" || token.v === "false") return { kind: "literal", value: token.v === "true" };
8586
8656
  let name = token.v;
8657
+ if (name === "import" && isPunct("(")) {
8658
+ const spec = tokens[pos + 1];
8659
+ if (spec?.t !== "string" || tokens[pos + 2]?.t !== "punct" || tokens[pos + 2].v !== ")") return null;
8660
+ pos += 3;
8661
+ const members = [];
8662
+ while (isPunct(".") && tokens[pos + 1]?.t === "name") {
8663
+ members.push(tokens[pos + 1].v);
8664
+ pos += 2;
8665
+ }
8666
+ if (members.length === 0) return UNKNOWN;
8667
+ name = importTypeName(spec.v, members.join("."));
8668
+ }
8587
8669
  while (isPunct(".") && tokens[pos + 1]?.t === "name") {
8588
8670
  name += "." + tokens[pos + 1].v;
8589
8671
  pos += 2;
@@ -8646,6 +8728,8 @@ function parseJsDocType(text3) {
8646
8728
  const fields = [];
8647
8729
  let index;
8648
8730
  while (!isPunct("}")) {
8731
+ const modified = tokens[pos + 1];
8732
+ if (peek()?.t === "name" && peek().v === "readonly" && modified !== void 0 && (modified.t === "name" || modified.t === "string" || modified.t === "punct" && modified.v === "[")) pos++;
8649
8733
  const key = peek();
8650
8734
  if (key === void 0) return null;
8651
8735
  if (key.t === "punct" && key.v === "[") {
@@ -8660,15 +8744,41 @@ function parseJsDocType(text3) {
8660
8744
  if (key.t !== "name" && key.t !== "string") return null;
8661
8745
  pos++;
8662
8746
  expect("?");
8663
- if (!expect(":")) return null;
8664
- const type2 = parseUnion();
8665
- if (type2 === null) return null;
8666
- fields.push({ name: key.v, type: type2 });
8747
+ if (options.typescript === true && (isPunct("(") || isPunct("<"))) {
8748
+ if (!skipMember()) return null;
8749
+ } else {
8750
+ if (!expect(":")) return null;
8751
+ const type2 = parseUnion();
8752
+ if (type2 === null) return null;
8753
+ fields.push({ name: key.v, type: type2 });
8754
+ }
8667
8755
  }
8668
- if (!expect(",") && !expect(";")) break;
8756
+ if (!expect(",") && !expect(";") && !startsMember()) break;
8669
8757
  }
8670
8758
  return expect("}") ? { kind: "object", fields, ...index !== void 0 ? { index } : {} } : null;
8671
8759
  };
8760
+ const skipMember = () => {
8761
+ let depth = 0;
8762
+ while (pos < tokens.length) {
8763
+ const token = tokens[pos];
8764
+ if (token.t === "punct") {
8765
+ if (depth === 0 && (token.v === "," || token.v === ";" || token.v === "}")) return true;
8766
+ if (token.v === "(" || token.v === "[" || token.v === "{" || token.v === "<") depth++;
8767
+ else if (token.v === ")" || token.v === "]" || token.v === "}" || token.v === ">") depth--;
8768
+ }
8769
+ pos++;
8770
+ }
8771
+ return false;
8772
+ };
8773
+ const startsMember = () => {
8774
+ const token = peek();
8775
+ const after = tokens[pos + 1];
8776
+ if (token === void 0 || after === void 0) return false;
8777
+ if (token.t === "punct") return token.v === "[";
8778
+ if (token.t !== "name" && token.t !== "string") return false;
8779
+ if (after.t === "punct") return [":", "?", "(", "<"].includes(after.v);
8780
+ return token.t === "name" && token.v === "readonly" && (after.t === "name" || after.t === "string");
8781
+ };
8672
8782
  const skipUntilClose = (open, close) => {
8673
8783
  let depth = 0;
8674
8784
  while (pos < tokens.length) {
@@ -8767,6 +8877,7 @@ function jsDocTypeHint(type, typedefs = /* @__PURE__ */ new Map()) {
8767
8877
  for (const member of flattenJsDocType(type, typedefs)) {
8768
8878
  if (member.kind === "array") hints.add("array");
8769
8879
  else if (member.kind === "object") hints.add("object");
8880
+ else if (member.kind === "literal") hints.add(typeof member.value);
8770
8881
  else if (member.kind === "name") {
8771
8882
  const lower2 = member.name.toLowerCase();
8772
8883
  if (lower2 === "string" || lower2 === "number" || lower2 === "boolean" || lower2 === "object") hints.add(lower2);
@@ -8776,6 +8887,15 @@ function jsDocTypeHint(type, typedefs = /* @__PURE__ */ new Map()) {
8776
8887
  }
8777
8888
  return hints.size === 0 ? void 0 : [...hints].sort().join("|");
8778
8889
  }
8890
+ function jsDocLiteralValues(type, typedefs) {
8891
+ const values = [];
8892
+ for (const member of flattenJsDocType(type, typedefs)) {
8893
+ if (member.kind === "literal") values.push(member.value);
8894
+ else if (member.kind === "name" && (member.name === "null" || member.name === "undefined")) values.push(null);
8895
+ else return null;
8896
+ }
8897
+ return values.some((v) => v !== null) ? [...new Set(values)] : null;
8898
+ }
8779
8899
  function jsDocShape(type, typedefs) {
8780
8900
  const elements = [];
8781
8901
  const fields = [];
@@ -8807,7 +8927,7 @@ function parseModule(text3) {
8807
8927
  if (programs.has(text3)) return programs.get(text3);
8808
8928
  let program;
8809
8929
  try {
8810
- program = parse3(text3, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true, allowAwaitOutsideFunction: true });
8930
+ program = parseErasingTypes(text3, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true, allowAwaitOutsideFunction: true });
8811
8931
  } catch {
8812
8932
  program = null;
8813
8933
  }
@@ -9128,6 +9248,254 @@ function coversSuffix(spec, familySuffix, suffix) {
9128
9248
  return false;
9129
9249
  }
9130
9250
 
9251
+ // src/service/typeImports.ts
9252
+ var IMPORT_TYPE = /\bimport\s*\(\s*(["'])([^"'\n]+)\1\s*\)\s*\.\s*([$A-Za-z_][$\w]*(?:\s*\.\s*[$A-Za-z_][$\w]*)*)/g;
9253
+ var LEAF_NAMES = /* @__PURE__ */ new Set([
9254
+ "string",
9255
+ "number",
9256
+ "boolean",
9257
+ "null",
9258
+ "undefined",
9259
+ "bigint",
9260
+ "symbol",
9261
+ "void",
9262
+ "never",
9263
+ "String",
9264
+ "Number",
9265
+ "Boolean",
9266
+ "Date",
9267
+ "RegExp",
9268
+ "Function",
9269
+ "Array",
9270
+ "ReadonlyArray"
9271
+ ]);
9272
+ var OPEN = { kind: "object", fields: [], index: { kind: "unknown" } };
9273
+ var TS = { typescript: true };
9274
+ var MAX_DEPTH = 12;
9275
+ var modulesByReader = /* @__PURE__ */ new WeakMap();
9276
+ function resolveImportedTypes(script, location) {
9277
+ const out = /* @__PURE__ */ new Map();
9278
+ if (location === void 0 || !script.includes("import")) return out;
9279
+ const scan = maskCommentsAndStrings(script);
9280
+ for (const comment of findJsDocComments(script, scan)) {
9281
+ for (const m of comment.text.matchAll(IMPORT_TYPE)) {
9282
+ const specifier = m[2];
9283
+ const name = m[3].replace(/\s+/g, "");
9284
+ const key = importTypeName(specifier, name);
9285
+ if (out.has(key)) continue;
9286
+ const target = readTypeModule(location.fileReader, location.path, specifier);
9287
+ const type = target === null ? null : resolveInModule(location.fileReader, target, name, 0, /* @__PURE__ */ new Set());
9288
+ if (type !== null) out.set(key, type);
9289
+ }
9290
+ }
9291
+ return out;
9292
+ }
9293
+ function readTypeModule(reader, from, specifier) {
9294
+ const joined = joinModulePath(from, specifier);
9295
+ if (joined === void 0) return null;
9296
+ const candidates = /\.(?:d\.)?m?ts$/.test(joined) ? [joined] : /\.m?jsx?$/.test(joined) ? [joined.replace(/\.(m?)jsx?$/, ".$1ts"), joined.replace(/\.(m?)jsx?$/, ".d.$1ts"), joined] : [`${joined}.ts`, `${joined}.d.ts`, `${joined}.js`, `${joined}/index.ts`, `${joined}/index.d.ts`, `${joined}/index.js`];
9297
+ let files = modulesByReader.get(reader);
9298
+ if (files === void 0) modulesByReader.set(reader, files = /* @__PURE__ */ new Map());
9299
+ for (const path of candidates) {
9300
+ if (files.has(path)) {
9301
+ const known = files.get(path);
9302
+ if (known !== null) return known;
9303
+ continue;
9304
+ }
9305
+ const text3 = reader(path);
9306
+ const module2 = text3 === void 0 ? null : readDeclarations(path, text3);
9307
+ files.set(path, module2);
9308
+ if (module2 !== null) return module2;
9309
+ }
9310
+ return null;
9311
+ }
9312
+ function resolveInModule(reader, module2, name, depth, visiting) {
9313
+ const key = `${module2.path}#${name}`;
9314
+ if (visiting.has(key) || depth > MAX_DEPTH) return OPEN;
9315
+ const inner = /* @__PURE__ */ new Set([...visiting, key]);
9316
+ const declared = module2.declarations.get(name);
9317
+ if (declared !== void 0) return substitute(reader, module2, declared, depth + 1, inner);
9318
+ const head = name.split(".")[0];
9319
+ const imported = module2.imports.get(head);
9320
+ if (imported !== void 0) {
9321
+ const target = readTypeModule(reader, module2.path, imported.specifier);
9322
+ const rest = name.slice(head.length);
9323
+ return target === null ? null : resolveInModule(reader, target, imported.name + rest, depth + 1, inner);
9324
+ }
9325
+ for (const specifier of module2.stars) {
9326
+ const target = readTypeModule(reader, module2.path, specifier);
9327
+ const found = target === null ? null : resolveInModule(reader, target, name, depth + 1, inner);
9328
+ if (found !== null) return found;
9329
+ }
9330
+ return null;
9331
+ }
9332
+ function substitute(reader, module2, type, depth, visiting) {
9333
+ switch (type.kind) {
9334
+ case "name": {
9335
+ if (LEAF_NAMES.has(type.name)) return type;
9336
+ if (isImportTypeName(type.name)) {
9337
+ const m = /^import\("([^"]*)"\)\.(.+)$/.exec(type.name);
9338
+ const target = readTypeModule(reader, module2.path, m[1]);
9339
+ return (target === null ? null : resolveInModule(reader, target, m[2], depth, visiting)) ?? type;
9340
+ }
9341
+ return resolveInModule(reader, module2, type.name, depth, visiting) ?? OPEN;
9342
+ }
9343
+ case "object":
9344
+ return {
9345
+ kind: "object",
9346
+ fields: type.fields.map((f) => ({ name: f.name, type: substitute(reader, module2, f.type, depth, visiting) })),
9347
+ ...type.index !== void 0 ? { index: substitute(reader, module2, type.index, depth, visiting) } : {}
9348
+ };
9349
+ case "array":
9350
+ return { kind: "array", element: substitute(reader, module2, type.element, depth, visiting) };
9351
+ case "union":
9352
+ return { kind: "union", members: type.members.map((m) => substitute(reader, module2, m, depth, visiting)) };
9353
+ case "unknown":
9354
+ return OPEN;
9355
+ default:
9356
+ return type;
9357
+ }
9358
+ }
9359
+ var DECLARATION_HEAD = /(?:^|[\n;{}])[ \t]*(?:export[ \t]+)?(?:declare[ \t]+)?(interface|type)[ \t]+([$A-Za-z_][$\w]*)/g;
9360
+ function readDeclarations(path, source) {
9361
+ const scan = maskCommentsAndStrings(source);
9362
+ const blanked = blankComments(source, scan);
9363
+ const depthAt = braceDepths(scan);
9364
+ const declarations = /* @__PURE__ */ new Map();
9365
+ for (const [name, type] of source.includes("@typedef") ? collectJsDocTypedefs(source, scan) : /* @__PURE__ */ new Map()) {
9366
+ declarations.set(name, type);
9367
+ }
9368
+ DECLARATION_HEAD.lastIndex = 0;
9369
+ for (const m of scan.matchAll(DECLARATION_HEAD)) {
9370
+ const at2 = m.index + m[0].length;
9371
+ if (depthAt[at2] !== 0) continue;
9372
+ const name = m[2];
9373
+ let i = skipTypeParameters(scan, at2);
9374
+ if (m[1] === "interface") {
9375
+ const open = scan.indexOf("{", i);
9376
+ if (open < 0) continue;
9377
+ const bases = /^\s*extends\s+([\s\S]*)$/.exec(scan.slice(i, open))?.[1];
9378
+ const body = parseJsDocType(`{${blanked.slice(open + 1, matchClose(scan, open))}}`, TS);
9379
+ if (body === null) continue;
9380
+ const parents = bases === void 0 ? [] : splitBases(bases).map((b) => parseJsDocType(b, TS) ?? OPEN);
9381
+ declarations.set(name, parents.length === 0 ? body : { kind: "union", members: [...parents, body] });
9382
+ } else {
9383
+ const eq3 = /^\s*=/.exec(scan.slice(i));
9384
+ if (eq3 === null) continue;
9385
+ i += eq3[0].length;
9386
+ const end = typeAliasEnd(scan, i);
9387
+ const type = parseJsDocType(blanked.slice(i, end).trim(), TS);
9388
+ if (type !== null) declarations.set(name, type);
9389
+ }
9390
+ }
9391
+ const { imports, stars } = readTypeImports(source, scan, depthAt);
9392
+ return { path, declarations, imports, stars };
9393
+ }
9394
+ function blankComments(source, scan) {
9395
+ let out = "";
9396
+ let from = 0;
9397
+ for (const m of scan.matchAll(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g)) {
9398
+ const at2 = m.index;
9399
+ out += source.slice(from, at2) + m[0].replace(/[^\n]/g, " ");
9400
+ from = at2 + m[0].length;
9401
+ }
9402
+ return out + source.slice(from);
9403
+ }
9404
+ function braceDepths(scan) {
9405
+ const out = new Array(scan.length + 1);
9406
+ let depth = 0;
9407
+ for (let i = 0; i < scan.length; i++) {
9408
+ out[i] = depth;
9409
+ if (scan[i] === "{") depth++;
9410
+ else if (scan[i] === "}") depth = Math.max(0, depth - 1);
9411
+ }
9412
+ out[scan.length] = depth;
9413
+ return out;
9414
+ }
9415
+ function skipTypeParameters(scan, at2) {
9416
+ let i = at2;
9417
+ while (/\s/.test(scan[i] ?? "")) i++;
9418
+ if (scan[i] !== "<") return at2;
9419
+ let depth = 0;
9420
+ for (; i < scan.length; i++) {
9421
+ if (scan[i] === "<") depth++;
9422
+ else if (scan[i] === ">" && scan[i - 1] !== "=" && --depth === 0) return i + 1;
9423
+ }
9424
+ return at2;
9425
+ }
9426
+ function matchClose(scan, open) {
9427
+ let depth = 0;
9428
+ for (let i = open; i < scan.length; i++) {
9429
+ if (scan[i] === "{") depth++;
9430
+ else if (scan[i] === "}" && --depth === 0) return i;
9431
+ }
9432
+ return scan.length;
9433
+ }
9434
+ function splitBases(text3) {
9435
+ const out = [];
9436
+ let depth = 0;
9437
+ let start = 0;
9438
+ for (let i = 0; i < text3.length; i++) {
9439
+ if (text3[i] === "<" || text3[i] === "(" || text3[i] === "{" || text3[i] === "[") depth++;
9440
+ else if (text3[i] === ">" && text3[i - 1] !== "=" || text3[i] === ")" || text3[i] === "}" || text3[i] === "]") depth--;
9441
+ else if (text3[i] === "," && depth === 0) {
9442
+ out.push(text3.slice(start, i).trim());
9443
+ start = i + 1;
9444
+ }
9445
+ }
9446
+ out.push(text3.slice(start).trim());
9447
+ return out.filter((b) => b !== "");
9448
+ }
9449
+ function typeAliasEnd(scan, start) {
9450
+ let depth = 0;
9451
+ for (let i = start; i < scan.length; i++) {
9452
+ const ch = scan[i];
9453
+ if (ch === "=" && scan[i + 1] === ">") {
9454
+ i++;
9455
+ } else if (ch === "(" || ch === "[" || ch === "{" || ch === "<") {
9456
+ depth++;
9457
+ } else if (ch === ")" || ch === "]" || ch === "}" || ch === ">") {
9458
+ depth--;
9459
+ } else if (depth === 0 && ch === ";") {
9460
+ return i;
9461
+ } else if (depth === 0 && ch === "\n") {
9462
+ const before = scan.slice(start, i).trim();
9463
+ const after = scan.slice(i + 1).trimStart();
9464
+ if (before === "" || /[|&=,?:]$/.test(before) || /^[|&?:.]/.test(after)) continue;
9465
+ return i;
9466
+ }
9467
+ }
9468
+ return scan.length;
9469
+ }
9470
+ function readTypeImports(text3, scan, depthAt) {
9471
+ const imports = /* @__PURE__ */ new Map();
9472
+ const stars = [];
9473
+ const re = /\b(import|export)\s+(?:type\s+)?(\{[^}]*\}|\*)\s*from\s*(["'])/g;
9474
+ for (const m of scan.matchAll(re)) {
9475
+ const at2 = m.index;
9476
+ if (depthAt[at2] !== 0) continue;
9477
+ const quoteAt = at2 + m[0].length - 1;
9478
+ const close = scan.indexOf(m[3], quoteAt + 1);
9479
+ if (close < 0) continue;
9480
+ const specifier = text3.slice(quoteAt + 1, close);
9481
+ if (m[2] === "*") {
9482
+ if (m[1] === "export") stars.push(specifier);
9483
+ continue;
9484
+ }
9485
+ for (const part of m[2].slice(1, -1).split(",")) {
9486
+ const spec = /^\s*(?:type\s+)?([$A-Za-z_][$\w]*)(?:\s+as\s+([$A-Za-z_][$\w]*))?\s*$/.exec(part);
9487
+ if (spec === null) continue;
9488
+ imports.set(spec[2] ?? spec[1], { specifier, name: spec[1] });
9489
+ }
9490
+ }
9491
+ return { imports, stars };
9492
+ }
9493
+ function withImportedTypes(typedefs, script, location) {
9494
+ const imported = resolveImportedTypes(script, location);
9495
+ if (imported.size === 0) return typedefs;
9496
+ return new Map([...typedefs, ...imported]);
9497
+ }
9498
+
9131
9499
  // src/service/stateAnalyzer.ts
9132
9500
  var RESERVED_STREAMS_KEYS = /* @__PURE__ */ new Set(["$stream", "$streams"]);
9133
9501
  var RESERVED_COMMAND_TOKENS_KEY = "$commandTokens";
@@ -9146,7 +9514,8 @@ function analyzeStatePaths(scriptContent, location) {
9146
9514
  const pendingListKeys = [];
9147
9515
  const recursionSpec = specFromRecursionValue(topLevelProps.find((p) => p.name === RESERVED_RECURSION_KEY));
9148
9516
  const effectiveDescriptors = effectiveTopLevelDescriptors(topLevelProps);
9149
- const typedefs = scriptContent.includes("@typedef") ? collectJsDocTypedefs(scriptContent, maskCommentsAndStrings(scriptContent)) : /* @__PURE__ */ new Map();
9517
+ const localTypedefs = scriptContent.includes("@typedef") ? collectJsDocTypedefs(scriptContent, maskCommentsAndStrings(scriptContent)) : /* @__PURE__ */ new Map();
9518
+ const typedefs = scriptContent.includes("import") ? withImportedTypes(localTypedefs, scriptContent, location) : localTypedefs;
9150
9519
  for (const prop of topLevelProps) {
9151
9520
  if (prop.name.startsWith("$")) {
9152
9521
  collectReservedKeyPaths(prop, paths, pendingStreamValues, pendingListKeys);
@@ -9164,7 +9533,8 @@ function analyzeStatePaths(scriptContent, location) {
9164
9533
  if (!paths.some((p) => p.path === prop.name)) {
9165
9534
  const recursive = hasRecursionWildcard(prop.name);
9166
9535
  const settable = !recursive && effective !== "data" && effective.set;
9167
- paths.push({ path: prop.name, kind: recursive ? "recursive" : "computed", ...settable ? { settable } : {} });
9536
+ const declared = prop.declaredType === void 0 ? {} : declaredTypeFacts(prop.declaredType, typedefs);
9537
+ paths.push({ path: prop.name, kind: recursive ? "recursive" : "computed", ...settable ? { settable } : {}, ...declared });
9168
9538
  }
9169
9539
  if (prop.declaredType !== void 0) pushDeclaredShapePaths(prop.name, prop.declaredType, paths, 0, typedefs);
9170
9540
  continue;
@@ -9287,13 +9657,15 @@ function analyzeHandlerSources(scriptContent, key) {
9287
9657
  const leading = prop.value.length - prop.value.trimStart().length;
9288
9658
  const innerStart = root.start + prop.valueStart + leading + 1;
9289
9659
  const out = [];
9290
- for (const entry of parseTopLevelProperties(extractObjectContent(prop.value))) {
9660
+ const content = extractObjectContent(prop.value);
9661
+ for (const entry of parseTopLevelProperties(content)) {
9291
9662
  if (entry.value === void 0 || entry.valueStart === void 0) continue;
9292
9663
  out.push({
9293
9664
  name: entry.name,
9294
9665
  kind: entry.kind === "data" ? "value" : "body",
9295
9666
  text: entry.value,
9296
- start: innerStart + entry.valueStart
9667
+ start: innerStart + entry.valueStart,
9668
+ ...entry.paramsStart !== void 0 && entry.paramsEnd !== void 0 ? { params: content.slice(entry.paramsStart, entry.paramsEnd) } : {}
9297
9669
  });
9298
9670
  }
9299
9671
  return out;
@@ -9320,6 +9692,39 @@ function analyzeDeclarationEntries(scriptContent, key) {
9320
9692
  ...entry.kind === "data" && entry.value !== void 0 && entry.valueStart !== void 0 ? { value: entry.value.trim(), valueStart: entry.valueStart } : {}
9321
9693
  }));
9322
9694
  }
9695
+ function analyzeTopLevelStateKeys(scriptContent) {
9696
+ const root = locateDefaultExportObject(scriptContent);
9697
+ if (!root || hasTopLevelSpread(scriptContent)) return null;
9698
+ const scan = maskCommentsAndStrings(root.content).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, (c) => " ".repeat(c.length));
9699
+ let depth = 0;
9700
+ let start = 0;
9701
+ for (let i = 0; i <= scan.length; i++) {
9702
+ const ch = scan[i];
9703
+ if (ch === "{" || ch === "[" || ch === "(") {
9704
+ if (depth === 0 && ch === "[" && /^\s*(?:(?:get|set|async|static)\s+)?\*?\s*$/.test(scan.slice(start, i))) return null;
9705
+ depth++;
9706
+ } else if (ch === "}" || ch === "]" || ch === ")") {
9707
+ depth--;
9708
+ } else if (ch === "," && depth === 0 || i === scan.length) {
9709
+ start = i + 1;
9710
+ }
9711
+ }
9712
+ const keys = [];
9713
+ const methods = [];
9714
+ let materializes = false;
9715
+ for (const prop of withShorthands(root.content, parseTopLevelProperties(root.content))) {
9716
+ if (prop.name.startsWith("$")) {
9717
+ if (RESERVED_STREAMS_KEYS.has(prop.name) || prop.name === RESERVED_SCAN_KEY) materializes = true;
9718
+ continue;
9719
+ }
9720
+ if (prop.kind === "method") {
9721
+ if (!methods.includes(prop.name)) methods.push(prop.name);
9722
+ } else if (!prop.name.includes(".") && !keys.includes(prop.name)) {
9723
+ keys.push(prop.name);
9724
+ }
9725
+ }
9726
+ return { keys, methods, materializes };
9727
+ }
9323
9728
  function hasDefaultExportObject(scriptContent) {
9324
9729
  return locateDefaultExportObject(scriptContent) !== null;
9325
9730
  }
@@ -9404,6 +9809,7 @@ function analyzeCallableBodies(scriptContent) {
9404
9809
  body: prop.value ?? "",
9405
9810
  bodyStart: root.start + (prop.valueStart ?? 0),
9406
9811
  accessor: prop.accessor,
9812
+ ...prop.paramsStart !== void 0 && prop.paramsEnd !== void 0 ? { params: root.content.slice(prop.paramsStart, prop.paramsEnd) } : {},
9407
9813
  ...prop.listed !== void 0 ? { listed: { ...prop.listed, start: root.start + prop.listed.start, end: root.start + prop.listed.end } } : {}
9408
9814
  });
9409
9815
  }
@@ -9649,7 +10055,7 @@ function collectGetterResultShapes(script, rootStart, props, effective, paths) {
9649
10055
  const before = paths.length;
9650
10056
  for (const [name, prop] of getters) {
9651
10057
  const shape = getterResultShape(prop.value, paths);
9652
- if (shape !== null) applyResultShape(name, shape, paths);
10058
+ if (shape !== null) applyResultShape(name, shape, paths, true);
9653
10059
  }
9654
10060
  const aliasesByBody = /* @__PURE__ */ new Map();
9655
10061
  for (const assignment of assignments) {
@@ -9667,12 +10073,25 @@ function collectGetterResultShapes(script, rootStart, props, effective, paths) {
9667
10073
  function getterResultShape(body, paths) {
9668
10074
  const scan = maskCommentsAndStrings(body);
9669
10075
  const aliases = collectAliases(body, paths);
10076
+ const texts = [];
9670
10077
  const shapes = [];
9671
10078
  for (const start of ownReturnEnds(scan)) {
9672
- const shape = expressionShape(readExpression(body, scan, start), paths, aliases);
9673
- if (shape !== null) shapes.push(shape);
9674
- }
9675
- return shapes.length === 0 ? null : mergeShapes(shapes);
10079
+ const text3 = readExpression(body, scan, start);
10080
+ texts.push(text3);
10081
+ shapes.push(expressionShape(text3, paths, aliases));
10082
+ }
10083
+ return mergeAlternatives(texts, shapes);
10084
+ }
10085
+ function mergeAlternatives(texts, shapes) {
10086
+ const read = shapes.filter((s) => s !== null);
10087
+ if (read.length === 0) return null;
10088
+ const merged = mergeShapes(read);
10089
+ const open = read.find((s) => s.openRows !== void 0);
10090
+ if (open !== void 0) return { ...merged, openRows: open.openRows };
10091
+ if (!merged.isList) return merged;
10092
+ const onlyEmpty = read.every((s) => !s.isList || s.mirrors.length === 0 && s.fields.length === 0 && s.opaque !== true);
10093
+ const unknownAt = shapes.findIndex((s, i) => s === null && texts[i].trim() !== "" || s !== null && !s.isList && s.fields.length === 0);
10094
+ return onlyEmpty && unknownAt >= 0 ? { ...merged, openRows: texts[unknownAt].trim() } : merged;
9676
10095
  }
9677
10096
  var BLOCK_HEADS = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "catch", "with"]);
9678
10097
  function ownReturnEnds(scan) {
@@ -9778,13 +10197,13 @@ function expressionShape(text3, paths, aliases, keepOpaque = false) {
9778
10197
  const scan = maskCommentsAndStrings(expr);
9779
10198
  const ternary = splitTernary(scan);
9780
10199
  if (ternary !== null) {
9781
- const branches = [expr.slice(ternary[0] + 1, ternary[1]), expr.slice(ternary[1] + 1)].map((part) => expressionShape(part, paths, aliases)).filter((s) => s !== null);
9782
- return branches.length === 0 ? null : mergeShapes(branches);
10200
+ const texts = [expr.slice(ternary[0] + 1, ternary[1]), expr.slice(ternary[1] + 1)];
10201
+ return mergeAlternatives(texts, texts.map((part) => expressionShape(part, paths, aliases)));
9783
10202
  }
9784
10203
  const operands = splitTopLevel(scan, /\|\||\?\?/g);
9785
10204
  if (operands.length > 1) {
9786
- const sides = operands.map(([s, e]) => expressionShape(expr.slice(s, e), paths, aliases)).filter((s) => s !== null);
9787
- return sides.length === 0 ? null : mergeShapes(sides);
10205
+ const texts = operands.map(([s, e]) => expr.slice(s, e));
10206
+ return mergeAlternatives(texts, texts.map((part) => expressionShape(part, paths, aliases)));
9788
10207
  }
9789
10208
  if (scan.startsWith("{")) {
9790
10209
  if (extractDelimitedContent(expr, scan, 0, "{", "}").length !== expr.length - 2) return null;
@@ -9956,10 +10375,18 @@ function mapRows(args, shape, paths, outer) {
9956
10375
  ]
9957
10376
  };
9958
10377
  }
9959
- function applyResultShape(getter, shape, paths) {
10378
+ function applyResultShape(getter, shape, paths, openRows = false) {
9960
10379
  if (shape.isList) {
9961
10380
  if (!hasPath(paths, `${getter}.*`)) paths.push({ path: `${getter}.*`, kind: "list" });
9962
10381
  if (!hasPath(paths, `${getter}.length`)) paths.push({ path: `${getter}.length`, kind: "data", typeHint: "number" });
10382
+ if (openRows && shape.openRows !== void 0) {
10383
+ const rows = paths.find((p) => p.path === `${getter}.*`);
10384
+ const fields = paths.some((p) => p.path.startsWith(`${getter}.*.`) && (p.kind === "data" || p.kind === "list"));
10385
+ if (rows.typed !== true && rows.opaque === void 0 && !fields) {
10386
+ const flat = shape.openRows.replace(/\s+/g, " ");
10387
+ rows.opaque = { name: flat.length <= MAX_UNREAD_TEXT ? flat : `${flat.slice(0, MAX_UNREAD_TEXT - 1)}\u2026` };
10388
+ }
10389
+ }
9963
10390
  }
9964
10391
  for (const { from, to } of shape.mirrors) {
9965
10392
  if (from === getter || from.startsWith(`${getter}.`)) continue;
@@ -10111,9 +10538,17 @@ function pushDataPropertyPathsAt(path, prop, paths, depth, typedefs, scope) {
10111
10538
  }
10112
10539
  if (prop.declaredType !== void 0) {
10113
10540
  candidate.typed = true;
10541
+ const facts = declaredTypeFacts(prop.declaredType, typedefs);
10542
+ if (candidate.typeHint === void 0 && facts.typeHint !== void 0) candidate.typeHint = facts.typeHint;
10543
+ if (facts.literals !== void 0) candidate.literals = facts.literals;
10114
10544
  pushDeclaredShapePaths(path, prop.declaredType, paths, depth, typedefs);
10115
10545
  }
10116
10546
  }
10547
+ function declaredTypeFacts(type, typedefs) {
10548
+ const typeHint = jsDocTypeHint(type, typedefs);
10549
+ const literals = jsDocLiteralValues(type, typedefs);
10550
+ return { ...typeHint !== void 0 ? { typeHint } : {}, ...literals !== null ? { literals } : {} };
10551
+ }
10117
10552
  var MAX_SPREAD_HOPS = 8;
10118
10553
  function objectLiteralKeys(content, scope, shorthands, hops = 0) {
10119
10554
  const explicit = parseTopLevelProperties(content);
@@ -10325,6 +10760,12 @@ function pushDeclaredShapePaths(path, type, paths, depth, typedefs) {
10325
10760
  const candidate = paths.find((p) => p.path === path);
10326
10761
  if (candidate !== void 0) candidate.openKeys = true;
10327
10762
  }
10763
+ const unread = unreadImportType(type, typedefs);
10764
+ if (unread !== null) {
10765
+ const candidate = paths.find((p) => p.path === path);
10766
+ if (candidate !== void 0 && candidate.opaque === void 0) candidate.opaque = { type: unread };
10767
+ return;
10768
+ }
10328
10769
  if (shape.element !== null) {
10329
10770
  if (!hasPath(paths, `${path}.*`)) paths.push({ path: `${path}.*`, kind: "list" });
10330
10771
  if (!hasPath(paths, `${path}.length`)) paths.push({ path: `${path}.length`, kind: "data", typeHint: "number" });
@@ -10335,12 +10776,23 @@ function pushDeclaredShapePaths(path, type, paths, depth, typedefs) {
10335
10776
  for (const field of shape.fields) {
10336
10777
  const fieldPath = `${path}.${field.name}`;
10337
10778
  if (!hasPath(paths, fieldPath)) {
10338
- paths.push(withHint({ path: fieldPath, kind: "data" }, jsDocTypeHint(field.type, typedefs)));
10779
+ const literals = jsDocLiteralValues(field.type, typedefs);
10780
+ paths.push(withHint({ path: fieldPath, kind: "data", ...literals !== null ? { literals } : {} }, jsDocTypeHint(field.type, typedefs)));
10339
10781
  }
10340
10782
  markTyped(paths, fieldPath);
10341
10783
  pushDeclaredShapePaths(fieldPath, field.type, paths, depth + 1, typedefs);
10342
10784
  }
10343
10785
  }
10786
+ function unreadImportType(type, typedefs) {
10787
+ for (const member of flattenJsDocType(type, typedefs)) {
10788
+ if (member.kind === "name" && isImportTypeName(member.name)) return member.name;
10789
+ if (member.kind === "array") {
10790
+ const element2 = flattenJsDocType(member.element, typedefs).find((m) => m.kind === "name" && isImportTypeName(m.name));
10791
+ if (element2 !== void 0) return `${element2.name}[]`;
10792
+ }
10793
+ }
10794
+ return null;
10795
+ }
10344
10796
  function markTyped(paths, path) {
10345
10797
  const candidate = paths.find((p) => p.path === path);
10346
10798
  if (candidate !== void 0 && (candidate.kind === "data" || candidate.kind === "list")) candidate.typed = true;
@@ -10483,9 +10935,10 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
10483
10935
  const props = [];
10484
10936
  const scan = maskCommentsAndStrings(objectContent);
10485
10937
  const params = String.raw`\((?:[^()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*\)`;
10938
+ const typeParams = String.raw`(?:<(?:[^<>()]|<(?:[^<>()]|<[^<>()]*>)*>)*>\s*)?`;
10486
10939
  const dataKey = allowEmptyDataKeys ? String.raw`(?:"([^"]*)"|'([^']*)'|([$\w]+))` : String.raw`(?:"([^"]+)"|'([^']+)'|([$\w]+))`;
10487
10940
  const regex = new RegExp(
10488
- String.raw`(?:(?:get|set)\s+(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params}\s*\{)|(?:(?:async\s+)?(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params}\s*\{)|(?:${dataKey}\s*:\s*)`,
10941
+ String.raw`(?:(?:get|set)\s+(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params})|(?:(?:async\s+)?(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${typeParams}${params})|(?:${dataKey}\s*:\s*)`,
10489
10942
  "gd"
10490
10943
  );
10491
10944
  let match;
@@ -10498,11 +10951,21 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
10498
10951
  nameSpan = [span[0], span[1]];
10499
10952
  return objectContent.slice(span[0], span[1]);
10500
10953
  };
10954
+ const headEnd = match.index + match[0].length;
10955
+ const isCallable = indices[1] !== void 0 || indices[2] !== void 0 || indices[3] !== void 0 || indices[4] !== void 0 || indices[5] !== void 0 || indices[6] !== void 0;
10956
+ const bodyBrace = isCallable ? bodyBraceAfter(scan, headEnd) : -1;
10957
+ if (isCallable && bodyBrace < 0) {
10958
+ regex.lastIndex = headEnd;
10959
+ continue;
10960
+ }
10961
+ const paramsSpan = () => {
10962
+ const open = scan.indexOf("(", nameSpan[1]);
10963
+ return { paramsStart: open + 1, paramsEnd: headEnd - 1 };
10964
+ };
10501
10965
  const skipBody = () => {
10502
- const braceStart = match.index + match[0].length - 1;
10503
- const body = extractBracedContent(objectContent, scan, braceStart);
10504
- regex.lastIndex = braceStart + body.length + 2;
10505
- return { body, bodyStart: braceStart + 1 };
10966
+ const body = extractBracedContent(objectContent, scan, bodyBrace);
10967
+ regex.lastIndex = bodyBrace + body.length + 2;
10968
+ return { body, bodyStart: bodyBrace + 1 };
10506
10969
  };
10507
10970
  const accessorName = nameAt(1) ?? nameAt(2) ?? nameAt(3);
10508
10971
  if (accessorName) {
@@ -10528,6 +10991,7 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
10528
10991
  }
10529
10992
  const methodName = nameAt(4) ?? nameAt(5) ?? nameAt(6);
10530
10993
  if (methodName) {
10994
+ const span = paramsSpan();
10531
10995
  const { body, bodyStart } = skipBody();
10532
10996
  props.push({
10533
10997
  name: methodName,
@@ -10535,7 +10999,8 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
10535
10999
  value: body,
10536
11000
  valueStart: bodyStart,
10537
11001
  nameStart: nameSpan[0],
10538
- nameEnd: nameSpan[1]
11002
+ nameEnd: nameSpan[1],
11003
+ ...span
10539
11004
  });
10540
11005
  continue;
10541
11006
  }
@@ -10563,6 +11028,75 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
10563
11028
  }
10564
11029
  return props;
10565
11030
  }
11031
+ var TYPE_OPERATOR_WORDS = /* @__PURE__ */ new Set([
11032
+ "keyof",
11033
+ "typeof",
11034
+ "readonly",
11035
+ "unique",
11036
+ "infer",
11037
+ "extends",
11038
+ "is",
11039
+ "asserts",
11040
+ "new",
11041
+ "abstract"
11042
+ ]);
11043
+ function bodyBraceAfter(scan, from) {
11044
+ let i = from;
11045
+ while (i < scan.length && /\s/.test(scan[i])) i++;
11046
+ if (scan[i] === "{") return i;
11047
+ if (scan[i] !== ":") return -1;
11048
+ let expect = true;
11049
+ let depth = 0;
11050
+ for (i++; i < scan.length; i++) {
11051
+ const ch = scan[i];
11052
+ if (/\s/.test(ch)) continue;
11053
+ if (ch === '"' || ch === "'" || ch === "`") {
11054
+ const close = scan.indexOf(ch, i + 1);
11055
+ if (close < 0) return -1;
11056
+ i = close;
11057
+ expect = false;
11058
+ } else if (ch === "=" && scan[i + 1] === ">") {
11059
+ i++;
11060
+ expect = true;
11061
+ } else if (ch === "{") {
11062
+ if (depth === 0 && !expect) return i;
11063
+ const close = matchingBrace(scan, i);
11064
+ if (close < 0) return -1;
11065
+ i = close;
11066
+ expect = false;
11067
+ } else if (ch === "(" || ch === "[" || ch === "<") {
11068
+ depth++;
11069
+ expect = true;
11070
+ } else if (ch === ")" || ch === "]" || ch === ">") {
11071
+ if (depth === 0) return -1;
11072
+ depth--;
11073
+ expect = false;
11074
+ } else if (ch === "}" || ch === ";") {
11075
+ return -1;
11076
+ } else if (ch === ",") {
11077
+ if (depth === 0) return -1;
11078
+ expect = true;
11079
+ } else if (ch === "|" || ch === "&" || ch === "?" || ch === ":" || ch === ".") {
11080
+ expect = true;
11081
+ } else if (/[$\w]/.test(ch)) {
11082
+ let j = i;
11083
+ while (j < scan.length && /[$\w]/.test(scan[j])) j++;
11084
+ expect = TYPE_OPERATOR_WORDS.has(scan.slice(i, j));
11085
+ i = j - 1;
11086
+ } else {
11087
+ expect = false;
11088
+ }
11089
+ }
11090
+ return -1;
11091
+ }
11092
+ function matchingBrace(scan, open) {
11093
+ let depth = 0;
11094
+ for (let i = open; i < scan.length; i++) {
11095
+ if (scan[i] === "{") depth++;
11096
+ else if (scan[i] === "}" && --depth === 0) return i;
11097
+ }
11098
+ return -1;
11099
+ }
10566
11100
  function maskCommentsAndStrings(source) {
10567
11101
  const out = source.split("");
10568
11102
  const len = source.length;
@@ -10780,6 +11314,25 @@ function schemaTypeHint(nodes2) {
10780
11314
  }
10781
11315
  return hints.size === 0 ? void 0 : [...hints].join("|");
10782
11316
  }
11317
+ function schemaLiteralValues(nodes2) {
11318
+ if (nodes2.length === 0) return null;
11319
+ const values = [];
11320
+ const scalar = (v) => v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean";
11321
+ for (const n of nodes2) {
11322
+ if (Array.isArray(n.enum)) {
11323
+ if (!n.enum.every(scalar)) return null;
11324
+ values.push(...n.enum);
11325
+ } else if (n.const !== void 0) {
11326
+ if (!scalar(n.const)) return null;
11327
+ values.push(n.const);
11328
+ } else if (n.type === "null") {
11329
+ values.push(null);
11330
+ } else {
11331
+ return null;
11332
+ }
11333
+ }
11334
+ return values.some((v) => v !== null) ? [...new Set(values)] : null;
11335
+ }
10783
11336
  function collectSchemaObjectPaths(node, prefix, paths, defs, depth) {
10784
11337
  if (depth >= MAX_OBJECT_NEST_DEPTH) return;
10785
11338
  const seen2 = /* @__PURE__ */ new Set();
@@ -10796,7 +11349,8 @@ function collectSchemaObjectPaths(node, prefix, paths, defs, depth) {
10796
11349
  function pushSchemaValuePaths(path, node, paths, defs, depth) {
10797
11350
  const nodes2 = derefSchemaNodes(node, defs);
10798
11351
  const typeHint = schemaTypeHint(nodes2);
10799
- paths.push(withHint({ path, kind: "data", fromSchema: true }, typeHint));
11352
+ const literals = schemaLiteralValues(nodes2);
11353
+ paths.push(withHint({ path, kind: "data", fromSchema: true, ...literals !== null ? { literals } : {} }, typeHint));
10800
11354
  const items = nodes2.map((n) => n.items).find((i) => i !== void 0 && i !== null && typeof i === "object");
10801
11355
  const isArray2 = items !== void 0 || (typeHint?.split("|").includes("array") ?? false);
10802
11356
  if (isArray2) {
@@ -12779,7 +13333,7 @@ function joinRelative(from, spec) {
12779
13333
  function parseScript(source) {
12780
13334
  for (const sourceType of ["module", "script"]) {
12781
13335
  try {
12782
- return parse3(source, { ecmaVersion: "latest", sourceType, allowHashBang: true });
13336
+ return parseErasingTypes(source, { ecmaVersion: "latest", sourceType, allowHashBang: true });
12783
13337
  } catch {
12784
13338
  }
12785
13339
  }
@@ -12867,11 +13421,13 @@ function readPageElementContracts(html, fileReader) {
12867
13421
  }
12868
13422
  while (queue.length > 0 && fileReader !== void 0 && read.size < MAX_FILES) {
12869
13423
  const { from, spec } = queue.shift();
12870
- const path = joinRelative(from, spec);
12871
- if (path === null || read.has(path) || !/\.m?js$/.test(path)) continue;
13424
+ const joined = joinRelative(from, spec);
13425
+ if (joined === null) continue;
13426
+ const paths = /\.m?[jt]s$/.test(joined) ? [joined, .../\.m?js$/.test(joined) ? [joined.replace(/js$/, "ts")] : []] : /\/[^/.]+$/.test(joined) ? [`${joined}.ts`, `${joined}.js`] : [];
13427
+ const path = paths.find((p) => read.has(p) || fileReader(p) !== void 0);
13428
+ if (path === void 0 || read.has(path)) continue;
12872
13429
  read.add(path);
12873
- const text3 = fileReader(path);
12874
- const program = text3 === void 0 ? null : parseScript(text3);
13430
+ const program = parseScript(fileReader(path));
12875
13431
  if (program !== null) visit2(program, path);
12876
13432
  }
12877
13433
  const classes = /* @__PURE__ */ new Map();
@@ -13185,7 +13741,7 @@ var collecting = {};
13185
13741
  function collectGetterReads(body, options = {}) {
13186
13742
  let program;
13187
13743
  try {
13188
- program = parse3(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13744
+ program = parseErasingTypes(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13189
13745
  } catch {
13190
13746
  return null;
13191
13747
  }
@@ -13575,7 +14131,7 @@ function visitDestructure(pattern, prefix, scope, out) {
13575
14131
  function collectThisMemberRefs(body, names2) {
13576
14132
  let program;
13577
14133
  try {
13578
- program = parse3(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
14134
+ program = parseErasingTypes(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13579
14135
  } catch {
13580
14136
  return null;
13581
14137
  }
@@ -13588,7 +14144,7 @@ var VALUE_SUFFIX = ")\n})";
13588
14144
  function collectThisMemberRefsInValue(value, names2) {
13589
14145
  let program;
13590
14146
  try {
13591
- program = parse3(VALUE_PREFIX + value + VALUE_SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
14147
+ program = parseErasingTypes(VALUE_PREFIX + value + VALUE_SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13592
14148
  } catch {
13593
14149
  return null;
13594
14150
  }
@@ -13633,7 +14189,7 @@ function thisMemberName(node) {
13633
14189
  function readsEventCurrentTarget(params, body) {
13634
14190
  let program;
13635
14191
  try {
13636
- program = parse3(`(async function* (${params}) {
14192
+ program = parseErasingTypes(`(async function* (${params}) {
13637
14193
  ${body}
13638
14194
  })`, { ecmaVersion: "latest", sourceType: "module" });
13639
14195
  } catch {
@@ -13731,7 +14287,7 @@ function findOwnThis(text3, kind) {
13731
14287
  let program;
13732
14288
  const prefix = kind === "body" ? PREFIX : VALUE_PREFIX;
13733
14289
  try {
13734
- program = parse3(prefix + text3 + (kind === "body" ? SUFFIX : VALUE_SUFFIX), { ecmaVersion: "latest", sourceType: "module" });
14290
+ program = parseErasingTypes(prefix + text3 + (kind === "body" ? SUFFIX : VALUE_SUFFIX), { ecmaVersion: "latest", sourceType: "module" });
13735
14291
  } catch {
13736
14292
  return null;
13737
14293
  }
@@ -13781,7 +14337,7 @@ function findInPlaceChanges(text3, kind, root) {
13781
14337
  const prefix = kind === "body" ? PREFIX : VALUE_PREFIX;
13782
14338
  let program;
13783
14339
  try {
13784
- program = parse3(prefix + text3 + (kind === "body" ? SUFFIX : VALUE_SUFFIX), { ecmaVersion: "latest", sourceType: "module" });
14340
+ program = parseErasingTypes(prefix + text3 + (kind === "body" ? SUFFIX : VALUE_SUFFIX), { ecmaVersion: "latest", sourceType: "module" });
13785
14341
  } catch {
13786
14342
  return [];
13787
14343
  }
@@ -13894,7 +14450,7 @@ var LOCATION_VARYING = /* @__PURE__ */ new Set(["pathname", "search", "hash", "h
13894
14450
  function findLocationRead(body) {
13895
14451
  let program;
13896
14452
  try {
13897
- program = parse3(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
14453
+ program = parseErasingTypes(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13898
14454
  } catch {
13899
14455
  return null;
13900
14456
  }
@@ -13974,7 +14530,7 @@ function ambientKindOf(names2) {
13974
14530
  function findAmbientRead(body, outer = /* @__PURE__ */ new Set()) {
13975
14531
  let program;
13976
14532
  try {
13977
- program = parse3(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
14533
+ program = parseErasingTypes(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13978
14534
  } catch {
13979
14535
  return null;
13980
14536
  }
@@ -14067,7 +14623,7 @@ function moduleBindingNames(script) {
14067
14623
  const names2 = /* @__PURE__ */ new Set();
14068
14624
  let program;
14069
14625
  try {
14070
- program = parse3(script, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true, allowAwaitOutsideFunction: true });
14626
+ program = parseErasingTypes(script, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true, allowAwaitOutsideFunction: true });
14071
14627
  } catch {
14072
14628
  return names2;
14073
14629
  }
@@ -14113,6 +14669,10 @@ function shortSeed(raw) {
14113
14669
  const flat = raw.replace(/\s+/g, " ");
14114
14670
  return flat.length <= 32 ? flat : `${flat.slice(0, 29)}\u2026`;
14115
14671
  }
14672
+ var MAX_LISTED_KEYS = 10;
14673
+ function listKeys(keys) {
14674
+ return keys.length <= MAX_LISTED_KEYS ? keys.join(", ") : `${keys.slice(0, MAX_LISTED_KEYS).join(", ")} \u2026 (+${keys.length - MAX_LISTED_KEYS})`;
14675
+ }
14116
14676
  var JA_EXPECTED_LABEL = {
14117
14677
  array: "\u914D\u5217\u578B\u306E\u30D1\u30B9",
14118
14678
  boolean: "\u30D6\u30FC\u30EA\u30A2\u30F3\u578B",
@@ -14183,6 +14743,8 @@ var ja = {
14183
14743
  stateSrcUnread: (src) => `"${src}" \u3092\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u3053\u306E state \u306E\u30D1\u30B9\u3082\u30B9\u30AF\u30EA\u30D7\u30C8\u306E\u898F\u5247\u3082\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\u3002src \u306F\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u8AAD\u307F\u307E\u3059\uFF08URL \u306F\u8AAD\u307E\u305A\u3001/ \u304B\u3089\u59CB\u307E\u308B\u30D1\u30B9\u306F wcs-validate --root=<\u30B5\u30A4\u30C8\u306E\u30EB\u30FC\u30C8> \u306E\u3068\u304D\u3060\u3051\u305D\u306E\u4E0B\u3067\u8AAD\u307F\u307E\u3059\uFF09\u3002\u30B5\u30FC\u30D0\u30FC\u3068\u540C\u3058\u4E26\u3073\u306B\u7F6E\u3044\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u3001\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u6307\u3059\u304B\u3001--root \u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044`,
14184
14744
  stateAbsent: (tag) => `\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u306B\u306F\u675F\u7E1B\u304C\u3042\u308A\u307E\u3059\u304C <${tag}> \u304C\u7121\u3044\u306E\u3067\u3001\u675F\u7E1B\u306E\u30D1\u30B9\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u30DA\u30FC\u30B8\u304C\u53D6\u308A\u8FBC\u3080\u65AD\u7247\u3084\u3001state \u3092\u30B9\u30AF\u30EA\u30D7\u30C8\u3067\u4F5C\u308B\u30DA\u30FC\u30B8\uFF09\u3002state \u306E\u3042\u308B\u30DA\u30FC\u30B8\u3092\u691C\u67FB\u3059\u308B\u304B\u3001\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u306E\u96A3\uFF08\u304B\u4E0A\uFF09\u306E wcstack.manifest.json \u306E stateSchema \u306B\u30D1\u30B9\u3092\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059`,
14185
14745
  pathDynamicUnknownValue: (path, n, name, from) => `"${path}" \u306E\u5024${name === void 0 ? "" : from === void 0 ? `\uFF08${name}\uFF09` : `\uFF08${name}\u3002"${from}" \u304B\u3089 import\uFF09`}\u306F\u9759\u7684\u306B\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u305D\u306E\u4E0B\u306B\u675F\u306D\u305F\u30D1\u30B9\uFF08${n} \u4EF6\uFF09\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\u3002\u30AD\u30FC\u306B JSDoc \u306E @type \u2014 \u5F62\u304B\u3001\u30E2\u30B8\u30E5\u30FC\u30EB\u306E\u30EA\u30C6\u30E9\u30EB\u3092\u6307\u3059 typeof import("./file.js").name\uFF08\u8F9E\u66F8\u306A\u3089\u5168\u90E8\u306E\u30AD\u30FC\u3092\u6301\u3064\u65E2\u5B9A\u306E\u8A00\u8A9E\u306E\u30D5\u30A1\u30A4\u30EB\uFF09\u2014 \u3092\u4ED8\u3051\u308B\u304B\u3001wcstack.manifest.json \u306E stateSchema \u306B\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059`,
14746
+ pathDynamicUnknownType: (path, n, type) => `"${path}" \u306E JSDoc \u306E\u578B ${type} \u306F\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u305D\u306E\u4E0B\u306B\u675F\u306D\u305F\u30D1\u30B9\uFF08${n} \u4EF6\uFF09\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u8AAD\u3080\u306E\u306F\u3001\u8AAD\u3081\u308B\u30D5\u30A1\u30A4\u30EB\u306E export interface / export type\u3001.js \u306E @typedef\uFF09\u3002\u5F62\u3092\u305D\u306E\u5834\u3067\u66F8\u304F\u304B\u3001\u540C\u3058\u30B9\u30AF\u30EA\u30D7\u30C8\u306E @typedef \u306B\u3059\u308B\u304B\u3001wcstack.manifest.json \u306E stateSchema \u306B\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059`,
14747
+ stateSchemaDrift: (inScript, inSchema) => `\u3053\u306E\u30DA\u30FC\u30B8\u306B\u5F53\u3066\u305F stateSchema \u304C state \u306E\u30B9\u30AF\u30EA\u30D7\u30C8\u3068\u98DF\u3044\u9055\u3063\u3066\u3044\u307E\u3059${inScript.length > 0 ? `\uFF08\u30B9\u30AF\u30EA\u30D7\u30C8\u306B\u3042\u3063\u3066 schema \u306B\u7121\u3044\u30AD\u30FC: ${listKeys(inScript)}\uFF09` : ""}${inSchema.length > 0 ? `\uFF08schema \u306B\u3042\u3063\u3066\u30B9\u30AF\u30EA\u30D7\u30C8\u306B\u7121\u3044\u30AD\u30FC: ${listKeys(inSchema)}\uFF09` : ""}\u3002schema \u306F\u30B9\u30AF\u30EA\u30D7\u30C8\u304B\u3089\u4F5C\u308B\u6D3E\u751F\u7269\u306A\u306E\u3067\u3001\u53E4\u3044\u304B\u3001\u5225\u306E state\uFF08\u5225\u306E\u30DA\u30FC\u30B8\uFF09\u306E\u3082\u306E\u3067\u3059 \u2014 \u305D\u306E\u307E\u307E\u691C\u67FB\u3059\u308B\u3068\u3001\u540D\u524D\u3092\u5909\u3048\u305F\u30AD\u30FC\u3078\u306E\u675F\u7E1B\u304C\u901A\u308A\u3001\u3042\u308B\u30AD\u30FC\u304C\u5B58\u5728\u3057\u306A\u3044\u3068\u8A00\u308F\u308C\u307E\u3059\u3002wcs-schema emit \u3067\u4F5C\u308A\u76F4\u3057\uFF08\u4F5C\u3063\u305F manifest \u306F\u5143\u306E state \u306E\u30D5\u30A1\u30A4\u30EB\u3092 stateSource \u306B\u8A18\u3057\u3001lint \u306F\u305D\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u8AAD\u3080\u30DA\u30FC\u30B8\u306B\u3060\u3051\u5F53\u3066\u307E\u3059\uFF09\u3001CI \u3067\u306F wcs-schema check \u3067\u98DF\u3044\u9055\u3044\u3092\u6B62\u3081\u3066\u304F\u3060\u3055\u3044`,
14186
14748
  pathDynamicUnknownOutput: (path, n, tag, member) => `"${path}" \u306F <${tag}> \u306E\u51FA\u529B "${member}" \u304C\u66F8\u304F\u306E\u3067\u3001\u4E2D\u8EAB\u306F\u8981\u7D20\u304C\u6E21\u3059\u3082\u306E\u3067\u3059\u3002\u305D\u306E\u5F62\u306F\u9759\u7684\u306B\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u305D\u306E\u4E0B\u306B\u675F\u306D\u305F\u30D1\u30B9\uFF08${n} \u4EF6\uFF09\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\u3002\u30AD\u30FC\u306B\u5F62\u3092\u8868\u3059 JSDoc \u306E @type \u3092\u4ED8\u3051\u308B\u304B\u3001wcstack.manifest.json \u306E stateSchema \u306B\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059`,
14187
14749
  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`,
14188
14750
  pathDynamicUnknownObjectSpread: (path, n, sp, from) => `${sp}${from === void 0 ? "" : `\uFF08"${from}" \u304B\u3089 import\uFF09`}\u304C "${path}" \u306B\u6301\u3061\u8FBC\u3080\u30AD\u30FC\u306F\u9759\u7684\u306B\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u305D\u306E\u4E0B\u306B\u675F\u306D\u305F\u30D1\u30B9\uFF08${n} \u4EF6\uFF09\u306F\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\u3002\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u30EA\u30C6\u30E9\u30EB\u3092\u675F\u7E1B\u3059\u308B\u30E2\u30B8\u30E5\u30FC\u30EB\u306E const \u3092 spread \u3059\u308B\u304B\u3001\u30AD\u30FC\u306B\u5F62\u3092\u8868\u3059 JSDoc \u306E @type \u3092\u4ED8\u3051\u308B\u304B\u3001wcstack.manifest.json \u306E stateSchema \u306B\u5BA3\u8A00\u3059\u308B\u3068\u691C\u67FB\u3055\u308C\u307E\u3059`,
@@ -14220,6 +14782,7 @@ var ja = {
14220
14782
  filterMaxArgs: (n, max, c) => `\u30D5\u30A3\u30EB\u30BF "${n}" \u306E\u5F15\u6570\u306F\u6700\u5927 ${max} \u500B\u3067\u3059\uFF08${c} \u500B\u6307\u5B9A\uFF09`,
14221
14783
  filterArgType: (n, i, exp, arg, act) => `\u30D5\u30A3\u30EB\u30BF "${n}" \u306E\u7B2C${i}\u5F15\u6570\u306F ${exp} \u578B\u304C\u5FC5\u8981\u3067\u3059\uFF08"${arg}" \u306F ${act} \u578B\uFF09`,
14222
14784
  filterInputType: (n, accepts, cur) => `\u30D5\u30A3\u30EB\u30BF "${n}" \u306F ${accepts} \u578B\u306E\u5165\u529B\u304C\u5FC5\u8981\u3067\u3059\uFF08\u73FE\u5728\u306E\u578B: ${cur}\uFF09`,
14785
+ filterArgEnum: (n, arg, members, suggestion2) => `"${n}(${arg})" \u306E ${arg} \u306F\u3001\u6BD4\u3079\u308B\u5024\u304C\u53D6\u308A\u3046\u308B\u5024\uFF08${members.join(" | ")}\uFF09\u306B\u3042\u308A\u307E\u305B\u3093 \u2014 ${n === "ne" ? "\u3044\u3064\u3082\u771F" : "\u6C7A\u3057\u3066\u771F\u306B\u306A\u308A\u307E\u305B\u3093"}${suggestion2}`,
14223
14786
  moustacheFouc: (e) => `<template> \u5916\u306E {{ }} \u69CB\u6587\u306F FOUC\uFF08\u521D\u671F\u8868\u793A\u6642\u306B\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u6587\u5B57\u5217\u304C\u898B\u3048\u308B\uFF09\u306E\u539F\u56E0\u306B\u306A\u308A\u307E\u3059\u3002<!--@@:${e}--> \u307E\u305F\u306F\u30B3\u30E1\u30F3\u30C8\u69CB\u6587\u306E\u4F7F\u7528\u3092\u691C\u8A0E\u3057\u3066\u304F\u3060\u3055\u3044\u3002`,
14224
14787
  moustacheFoucTextParent: (e, tag) => `<template> \u5916\u306E {{ }} \u69CB\u6587\u306F FOUC\uFF08\u521D\u671F\u8868\u793A\u6642\u306B\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u6587\u5B57\u5217\u304C\u898B\u3048\u308B\uFF09\u306E\u539F\u56E0\u306B\u306A\u308A\u307E\u3059\u3002<${tag}> \u306E\u4E2D\u306E\u30B3\u30E1\u30F3\u30C8\u69CB\u6587\u306F\u675F\u7E1B\u306B\u306A\u308A\u307E\u305B\u3093 \u2014 \u8981\u7D20\u306B\u675F\u306D\u3066\u304F\u3060\u3055\u3044\uFF08<${tag} data-wcs="${tag === "textarea" ? "value" : "textContent"}: ${e}">\uFF09\u3002`,
14225
14788
  textBindingInHead: (w) => `${w} \u306F\u6587\u66F8\u306E <head> \u306E\u4E2D\u306B\u3042\u308A\u307E\u3059\u304C\u3001<wcs-state> \u304C\u675F\u306D\u308B\u306E\u306F <body> \u3068\u30B7\u30E3\u30C9\u30A6\u30EB\u30FC\u30C8\u3060\u3051\u306A\u306E\u3067\u3001\u66F8\u3044\u305F\u307E\u307E\u306E\u6587\u5B57\u304C\u51FA\u307E\u3059\u3002\u30BF\u30A4\u30C8\u30EB\u306F state \u306E\u30B9\u30AF\u30EA\u30D7\u30C8\u304B\u3089 document.title \u306B\u66F8\u304F\uFF08$connectedCallback \u3068 $watch \u306E\u30CF\u30F3\u30C9\u30E9\uFF09\u304B\u3001\u30EB\u30FC\u30C8\u306E <wcs-head> \u306E <title> \u306B\u7F6E\u3044\u3066\u304F\u3060\u3055\u3044`,
@@ -14458,6 +15021,8 @@ var en = {
14458
15021
  stateSrcUnread: (src) => `"${src}" cannot be read, so this state's paths and script rules are not checked. A src is read relative to this file (a URL is not read, and a path from / only under wcs-validate --root=<the site's root>): point it at the file laid out as on the server, relative to this file, or pass --root`,
14459
15022
  stateAbsent: (tag) => `This file has bindings but no <${tag}>, so the paths they bind are not checked (a fragment a page includes, or a page whose state is made by script). Check the page that holds the state, or declare the paths in the stateSchema of a wcstack.manifest.json next to (or above) this file to have them checked`,
14460
15023
  pathDynamicUnknownValue: (path, n, name, from) => `The value of "${path}"${name === void 0 ? "" : from === void 0 ? ` (${name})` : ` (${name}, imported from "${from}")`} cannot be read statically, so the ${n === 1 ? "path" : `${n} paths`} bound under it ${n === 1 ? "is" : "are"} not checked. Give the key a JSDoc @type \u2014 its shape, or typeof import("./file.js").name for a module's literal (for a dictionary, the default language's file, which has every key) \u2014 or declare it in the stateSchema of wcstack.manifest.json to have them checked`,
15024
+ pathDynamicUnknownType: (path, n, type) => `The JSDoc type ${type} of "${path}" cannot be read, so the ${n === 1 ? "path" : `${n} paths`} bound under it ${n === 1 ? "is" : "are"} not checked (read are an export interface / export type of a file it can read, and a @typedef in a .js). Write the shape in place, make it a @typedef in the same script, or declare it in the stateSchema of wcstack.manifest.json to have them checked`,
15025
+ stateSchemaDrift: (inScript, inSchema) => `The stateSchema applied to this page disagrees with its state's script${inScript.length > 0 ? ` (in the script, not in the schema: ${listKeys(inScript)})` : ""}${inSchema.length > 0 ? ` (in the schema, not in the script: ${listKeys(inSchema)})` : ""}. The schema is derived from a script: it is stale, or another state's (another page's). Checked against it, a binding to a renamed key passes and a key is said not to exist. Regenerate it with wcs-schema emit (the manifest it writes names its state file in stateSource, and the lint applies it only to the pages that load that file), and run wcs-schema check in CI to stop the drift`,
14461
15026
  pathDynamicUnknownOutput: (path, n, tag, member) => `"${path}" is written by "${member}" of <${tag}>, an output, so it holds whatever the element gives: its shape cannot be read statically, and the ${n === 1 ? "path" : `${n} paths`} bound under it ${n === 1 ? "is" : "are"} not checked. Give the key a JSDoc @type with its shape, or declare it in the stateSchema of wcstack.manifest.json to have them checked`,
14462
15027
  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)`,
14463
15028
  pathDynamicUnknownObjectSpread: (path, n, sp, from) => `The keys ${sp}${from === void 0 ? "" : ` (imported from "${from}")`} brings into "${path}" cannot be read statically, so the ${n === 1 ? "path" : `${n} paths`} bound under it ${n === 1 ? "is" : "are"} not checked. Spread a const of the module bound to an object literal, give the key a JSDoc @type with its shape, or declare it in the stateSchema of wcstack.manifest.json to have them checked`,
@@ -14495,6 +15060,7 @@ var en = {
14495
15060
  filterMaxArgs: (n, max, c) => `Filter "${n}" accepts at most ${max} argument(s) (${c} given)`,
14496
15061
  filterArgType: (n, i, exp, arg, act) => `Argument ${i} of filter "${n}" must be of type ${exp} ("${arg}" is ${act})`,
14497
15062
  filterInputType: (n, accepts, cur) => `Filter "${n}" requires input of type ${accepts} (current type: ${cur})`,
15063
+ filterArgEnum: (n, arg, members, suggestion2) => `${arg} in "${n}(${arg})" is not a value the compared value takes (${members.join(" | ")}): it is ${n === "ne" ? "always true" : "never true"}${suggestion2}`,
14498
15064
  moustacheFouc: (e) => `{{ }} outside a <template> causes FOUC (the raw template string is visible before binding). Consider the comment syntax <!--@@:${e}--> instead.`,
14499
15065
  moustacheFoucTextParent: (e, tag) => `{{ }} outside a <template> causes FOUC (the raw template string is visible before binding). A comment binding is not bound inside <${tag}>: bind the element instead (<${tag} data-wcs="${tag === "textarea" ? "value" : "textContent"}: ${e}">).`,
14500
15066
  textBindingInHead: (w) => `${w} is in the document's <head>, and a <wcs-state> binds only the <body> and shadow roots, so it stays as written. Write document.title from the state's script ($connectedCallback and a $watch handler), or put the <title> in a route's <wcs-head>`,
@@ -15084,7 +15650,7 @@ function literalArrayLength(arg) {
15084
15650
  if (parts === null) return null;
15085
15651
  return parts.args.filter((part) => part.trim().length > 0).length;
15086
15652
  }
15087
- function blankComments(source) {
15653
+ function blankComments2(source) {
15088
15654
  const out = source.split("");
15089
15655
  let i = 0;
15090
15656
  while (i < source.length) {
@@ -15192,7 +15758,7 @@ function validateBehavior(block, msgs, out) {
15192
15758
  if (entry.value === void 0 || entry.valueStart === void 0) continue;
15193
15759
  const valueKind = literalKind(entry.value);
15194
15760
  if (valueKind !== type && valueKind !== "unknown") {
15195
- const blanked = blankComments(entry.value);
15761
+ const blanked = blankComments2(entry.value);
15196
15762
  const lead = blanked.length - blanked.trimStart().length;
15197
15763
  const start = base + entry.valueStart + lead;
15198
15764
  push(out, WcsDiagnosticCode.BehaviorInvalid, start, start + blanked.trim().length, msgs.behaviorValueType(entry.name, type));
@@ -15220,7 +15786,7 @@ function validateFeatures(block, msgs, out) {
15220
15786
  }
15221
15787
  return;
15222
15788
  }
15223
- for (const element2 of arrayElements(blankComments(decl.value))) {
15789
+ for (const element2 of arrayElements(blankComments2(decl.value))) {
15224
15790
  const elementKind = literalKind(element2.text);
15225
15791
  const start = base + decl.valueStart + element2.start;
15226
15792
  if (elementKind === "string") {
@@ -15281,7 +15847,7 @@ function validateFeaturesAttributes(html, stateTagName, msgs, out) {
15281
15847
  }
15282
15848
  }
15283
15849
  function literalKind(value) {
15284
- const text3 = blankComments(value).trim();
15850
+ const text3 = blankComments2(value).trim();
15285
15851
  const scan = maskCommentsAndStrings(text3).trim();
15286
15852
  if (/^(["'])[^"']*\1$/.test(scan)) return "string";
15287
15853
  if (/^`[^`]*`$/.test(scan)) return text3.includes("${") ? "unknown" : "string";
@@ -15339,7 +15905,7 @@ function scriptTokenNames(script, key) {
15339
15905
  if (declaration === null) return maskCommentsAndStrings(script).includes(key) ? null : [];
15340
15906
  if (declaration.kind !== "data" || declaration.value === void 0 || literalKind(declaration.value) !== "array") return null;
15341
15907
  const names2 = [];
15342
- for (const element2 of arrayElements(blankComments(declaration.value))) {
15908
+ for (const element2 of arrayElements(blankComments2(declaration.value))) {
15343
15909
  if (literalKind(element2.text) !== "string") return null;
15344
15910
  names2.push(element2.text.slice(1, -1));
15345
15911
  }
@@ -15445,11 +16011,8 @@ function forEachStateMethod(elements, html, fileReader, spelling, fn) {
15445
16011
  if ((insideTemplate ??= createTemplateTester(html))(element2.tagStart)) continue;
15446
16012
  for (const script of scripts) {
15447
16013
  for (const callable of analyzeCallableBodies(script)) {
15448
- if (callable.kind !== "method" || spelling !== null && !callable.body.includes(spelling)) continue;
15449
- const head = script.slice(callable.end, callable.bodyStart - 1);
15450
- const params = /\(([\s\S]*)\)\s*$/.exec(head);
15451
- if (params === null) continue;
15452
- fn(volume === null ? callable.name : `${volume}.${callable.name}`, params[1], callable.body);
16014
+ if (callable.kind !== "method" || callable.params === void 0 || spelling !== null && !callable.body.includes(spelling)) continue;
16015
+ fn(volume === null ? callable.name : `${volume}.${callable.name}`, callable.params, callable.body);
15453
16016
  }
15454
16017
  }
15455
16018
  }
@@ -15863,15 +16426,11 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
15863
16426
  }
15864
16427
  if (parsed.path && statePaths.length > 0) {
15865
16428
  const pathTrimmed = parsed.path.trim();
15866
- if (pathTrimmed && !pathTrimmed.startsWith(".") && !isLiteral(pathTrimmed)) {
15867
- const chainDiags = validateFilterChainTypes(
15868
- candidateKeyOf(pathTrimmed, (c) => scopedPathSet.has(c)),
15869
- parsed.filters,
15870
- scopedPaths,
15871
- bindingStart,
15872
- msgs
15873
- );
15874
- diagnostics.push(...chainDiags);
16429
+ const typed = pathTrimmed.startsWith(".") ? expandRowPath(pathTrimmed, html, attr.valueStart, attrName) : pathTrimmed;
16430
+ if (typed && !isLiteral(typed)) {
16431
+ const key = candidateKeyOf(typed, (c) => scopedPathSet.has(c));
16432
+ diagnostics.push(...validateFilterChainTypes(key, parsed.filters, scopedPaths, bindingStart, msgs));
16433
+ diagnostics.push(...validateFilterArgEnum(key, parsed.filters, scopedPaths, binding, bindingStart, msgs));
15875
16434
  }
15876
16435
  }
15877
16436
  }
@@ -16210,15 +16769,17 @@ function validateFilterChainTypes(path, filters, statePaths, bindingStart, msgs)
16210
16769
  for (const filter of filters) {
16211
16770
  const info = filterMap.get(filter.name);
16212
16771
  if (!info) break;
16213
- if (info.acceptTypes !== "any") {
16214
- const currentTypes = currentType.split("|");
16215
- const hasMatch = currentTypes.some((t) => info.acceptTypes.includes(t));
16772
+ const dateFilter = DATE_VALUE_FILTERS.has(filter.name);
16773
+ const acceptTypes = dateFilter ? ["object"] : info.acceptTypes;
16774
+ const currentTypes = dateFilter ? currentType.split("|").filter((t) => t !== "null") : currentType.split("|");
16775
+ if (acceptTypes !== "any" && currentTypes.length > 0) {
16776
+ const hasMatch = currentTypes.some((t) => acceptTypes.includes(t));
16216
16777
  if (!hasMatch) {
16217
16778
  diagnostics.push({
16218
16779
  code: WcsDiagnosticCode.FilterInputType,
16219
16780
  start: bindingStart + filter.offset,
16220
16781
  end: bindingStart + filter.offset + filter.name.length,
16221
- message: msgs.filterInputType(filter.name, info.acceptTypes.join("|"), currentType),
16782
+ message: msgs.filterInputType(filter.name, DATE_VALUE_FILTERS.has(filter.name) ? "Date" : acceptTypes.join("|"), currentType),
16222
16783
  severity: "warning"
16223
16784
  });
16224
16785
  }
@@ -16229,6 +16790,35 @@ function validateFilterChainTypes(path, filters, statePaths, bindingStart, msgs)
16229
16790
  }
16230
16791
  return diagnostics;
16231
16792
  }
16793
+ var DATE_VALUE_FILTERS = /* @__PURE__ */ new Set(["date", "time", "datetime", "ymd", "hms"]);
16794
+ var COMPARISON_FILTERS = /* @__PURE__ */ new Set(["eq", "ne"]);
16795
+ function validateFilterArgEnum(path, filters, statePaths, binding, bindingStart, msgs) {
16796
+ const first = filters[0];
16797
+ if (first === void 0 || !COMPARISON_FILTERS.has(first.name) || first.args.length !== 1) return [];
16798
+ const literals = statePaths.find((p) => p.path === path)?.literals;
16799
+ if (literals === void 0 || literals.length === 0) return [];
16800
+ const arg = first.args[0].trim();
16801
+ const quoted = /^(["'])([\s\S]*)\1$/.exec(arg);
16802
+ const text3 = quoted !== null ? quoted[2] : arg;
16803
+ const matches = literals.some((value) => typeof value === "string" && value === text3 || typeof value === "number" && text3.trim() !== "" && Number(text3) === value || quoted === null && (value === null ? text3 === "null" : typeof value === "boolean" && String(value) === text3));
16804
+ if (matches) return [];
16805
+ const at2 = binding.indexOf(arg, first.argsOffset);
16806
+ const start = bindingStart + (at2 >= 0 ? at2 : first.offset);
16807
+ const members = literals.map((value) => typeof value === "string" ? `'${value}'` : String(value));
16808
+ const strings = literals.filter((value) => typeof value === "string");
16809
+ return [{
16810
+ code: WcsDiagnosticCode.FilterArgEnum,
16811
+ start,
16812
+ end: start + (at2 >= 0 ? arg.length : first.name.length),
16813
+ message: msgs.filterArgEnum(first.name, arg, members, suggestion(text3, strings, msgs)),
16814
+ severity: "warning"
16815
+ }];
16816
+ }
16817
+ function expandRowPath(path, html, offset2, attrName) {
16818
+ const forPath = getRowShorthandForPath(html, offset2, attrName);
16819
+ if (!forPath || forPath.startsWith(".")) return "";
16820
+ return path === "." ? `${forPath}.*` : `${forPath}.*.${path.slice(1)}`;
16821
+ }
16232
16822
  function resolveResultType(path, filters, statePaths) {
16233
16823
  const pathInfo = statePaths.find((p) => p.path === path);
16234
16824
  if (!pathInfo?.typeHint) return null;
@@ -16314,8 +16904,10 @@ function declaredTypesOf(rawType, typedefs) {
16314
16904
  const out = [];
16315
16905
  for (const member of flattenJsDocType(parsed, typedefs)) {
16316
16906
  if (member.kind === "unknown") return null;
16907
+ if (member.kind === "name" && isImportTypeName(member.name)) return null;
16317
16908
  if (member.kind === "array") out.push("array");
16318
16909
  else if (member.kind === "object") out.push("object");
16910
+ else if (member.kind === "literal") out.push(typeof member.value);
16319
16911
  else if (member.kind === "name") out.push(normalizeType(member.name));
16320
16912
  }
16321
16913
  return out;
@@ -17495,7 +18087,7 @@ function validateFormInputs(html, bindAttribute = "data-wcs", stateTagName = "wc
17495
18087
  continue;
17496
18088
  }
17497
18089
  if (name !== "value" || inputGivesNumber(p) !== false) continue;
17498
- const statePath = expandRowPath(path, html, attr.valueStart, bindAttribute);
18090
+ const statePath = expandRowPath2(path, html, attr.valueStart, bindAttribute);
17499
18091
  if (statePath === null) continue;
17500
18092
  const t = getTypes();
17501
18093
  const key = candidateKeyOf(statePath, t.has);
@@ -17554,7 +18146,7 @@ function givesBackWhatWasWritten(filter, p) {
17554
18146
  return false;
17555
18147
  }
17556
18148
  }
17557
- function expandRowPath(path, html, offset2, bindAttribute) {
18149
+ function expandRowPath2(path, html, offset2, bindAttribute) {
17558
18150
  if (!path.startsWith(".")) return path;
17559
18151
  if (getRowShorthandForPath(html, offset2, bindAttribute) === null) return null;
17560
18152
  const list = getResolvedForListPath(html, offset2, bindAttribute);
@@ -18265,6 +18857,7 @@ function validateGetterAmbientReads(script, scriptStart, locale2) {
18265
18857
  }
18266
18858
  function onHandlerStateParam(script, handler) {
18267
18859
  if (handler.kind === "body") {
18860
+ if (handler.params !== void 0) return /^\s*([A-Za-z_$][\w$]*)/.exec(handler.params)?.[1] ?? null;
18268
18861
  const head = script.slice(Math.max(0, handler.start - 400), handler.start);
18269
18862
  return /\(\s*([A-Za-z_$][\w$]*)[^()]*\)\s*\{\s*$/.exec(head)?.[1] ?? null;
18270
18863
  }
@@ -18481,13 +19074,13 @@ function findPathTests(body, param) {
18481
19074
  for (const m of body.matchAll(new RegExp(String.raw`(?<![\w$.])(?:${el})\s*(?:\?\.|\.)\s*startsWith\s*\(\s*${STRING}`, "g"))) push3(m, true);
18482
19075
  for (const m of body.matchAll(new RegExp(String.raw`\bswitch\s*\(\s*(?:${el})\s*\)\s*\{`, "g"))) {
18483
19076
  const open = m.index + m[0].length - 1;
18484
- const block = body.slice(open, matchingBrace(body, open));
19077
+ const block = body.slice(open, matchingBrace2(body, open));
18485
19078
  for (const c of block.matchAll(new RegExp(String.raw`\bcase\s+${STRING}\s*:`, "g"))) push3(c, false, open);
18486
19079
  }
18487
19080
  }
18488
19081
  return out.sort((a, b) => a.at - b.at);
18489
19082
  }
18490
- function matchingBrace(text3, open) {
19083
+ function matchingBrace2(text3, open) {
18491
19084
  let depth = 0;
18492
19085
  for (let i = open; i < text3.length; i++) {
18493
19086
  const ch = text3[i];
@@ -18517,7 +19110,7 @@ function validateUpdatedCallbackDemand(html, stateTagName, bindAttrName, locale2
18517
19110
  if (param === void 0) continue;
18518
19111
  const declared = new Set(analyzeStatePaths(block.content).map((p) => p.path));
18519
19112
  const bound = boundPaths;
18520
- const body = blankComments(callback.body);
19113
+ const body = blankComments2(callback.body);
18521
19114
  const reported = /* @__PURE__ */ new Set();
18522
19115
  for (const test of findPathTests(body, param)) {
18523
19116
  const path = test.path;
@@ -18737,8 +19330,8 @@ function stateBodies(script, root) {
18737
19330
  }
18738
19331
  return out;
18739
19332
  }
18740
- var FUNCTION_HEAD = /^\s*(?:async\s+)?function\b[^(]*\(\s*([A-Za-z_$][\w$]*)?[^()]*\)\s*\{/;
18741
- var ARROW_HEAD = /^\s*(?:async\s+)?(?:\(\s*([A-Za-z_$][\w$]*)?[^()]*\)|([A-Za-z_$][\w$]*))\s*=>\s*\{/;
19333
+ var FUNCTION_HEAD = /^\s*(?:async\s+)?function\b[^(]*\(\s*([A-Za-z_$][\w$]*)?[^()]*\)\s*(?::[^{}=;]*)?\{/;
19334
+ var ARROW_HEAD = /^\s*(?:async\s+)?(?:\(\s*([A-Za-z_$][\w$]*)?[^()]*\)\s*(?::[^{}=;]*)?|([A-Za-z_$][\w$]*)\s*)=>\s*\{/;
18742
19335
  function functionBody(handler, arrows) {
18743
19336
  const scan = maskCommentsAndStrings(handler.text);
18744
19337
  const head = FUNCTION_HEAD.exec(scan) ?? (arrows ? ARROW_HEAD.exec(scan) : null);
@@ -19141,7 +19734,7 @@ function namedPackages(text3) {
19141
19734
  return out.flatMap((p) => p === "wcstack" ? [...BUNDLE_PACKAGES] : [p]);
19142
19735
  }
19143
19736
  var MAX_FILES2 = 32;
19144
- var MAX_DEPTH = 4;
19737
+ var MAX_DEPTH2 = 4;
19145
19738
  function validatePackageLoads(html, locale2, fileReader) {
19146
19739
  const msgs = getMessages(locale2);
19147
19740
  const scan = blankHtmlComments(html);
@@ -19389,7 +19982,7 @@ function readLocalModules(entries, fileReader, loads) {
19389
19982
  const { spec, from, depth } = queue.shift();
19390
19983
  const path = joinModulePath(from, spec);
19391
19984
  if (seen2.has(path)) continue;
19392
- if (seen2.size >= MAX_FILES2 || depth > MAX_DEPTH) {
19985
+ if (seen2.size >= MAX_FILES2 || depth > MAX_DEPTH2) {
19393
19986
  loads.unclear = true;
19394
19987
  return;
19395
19988
  }
@@ -19412,7 +20005,7 @@ function readLocalModules(entries, fileReader, loads) {
19412
20005
 
19413
20006
  // src/service/watchDeclarationValidator.ts
19414
20007
  var STATE_NAME_SEPARATOR = "@";
19415
- function validateWatchDeclarations(html, stateTagName = "wcs-state", locale2, fileReader, bindAttribute) {
20008
+ function validateWatchDeclarations(html, stateTagName = "wcs-state", locale2, fileReader, bindAttribute, applicationSchema) {
19416
20009
  const msgs = getMessages(locale2);
19417
20010
  const out = [];
19418
20011
  const elements = parseWcsStateElements(html, stateTagName);
@@ -19457,7 +20050,7 @@ function validateWatchDeclarations(html, stateTagName = "wcs-state", locale2, fi
19457
20050
  opaquePaths: bindAttribute === void 0 ? opaque2 : [...opaque2, ...openOutputSlots(html, bindAttribute, fileReader, paths, opaque2).map((slot) => slot.path)]
19458
20051
  };
19459
20052
  for (const entry of entries) {
19460
- const diagnostic = validateEntry(entry, pathSet, paths, scopes, msgs);
20053
+ const diagnostic = validateEntry(entry, pathSet, paths, scopes, msgs, applicationSchema);
19461
20054
  if (diagnostic === null) continue;
19462
20055
  out.push({
19463
20056
  code: diagnostic.code,
@@ -19497,7 +20090,7 @@ function assignVolumes(elements, html) {
19497
20090
  }
19498
20091
  return { treeOf, volumes };
19499
20092
  }
19500
- function validateEntry(entry, pathSet, paths, scopes, msgs) {
20093
+ function validateEntry(entry, pathSet, paths, scopes, msgs, schema) {
19501
20094
  const { key } = entry;
19502
20095
  const invalid = (message) => ({ code: WcsDiagnosticCode.WatchDeclarationInvalid, message, severity: "error" });
19503
20096
  if (key.includes(STATE_NAME_SEPARATOR)) {
@@ -19519,7 +20112,9 @@ function validateEntry(entry, pathSet, paths, scopes, msgs) {
19519
20112
  if (entry.definitelyNotFunction) {
19520
20113
  return invalid(msgs.watchHandlerNotFunction(key));
19521
20114
  }
19522
- if (!isUnresolvedPath(key, scopes) && !pathSet.has(key) && !pathSet.has(toWildcardForm(key)) && !matchesRecursion(collectRecursionSpecs(paths), key, (p) => pathSet.has(p))) {
20115
+ const inCandidates = pathSet.has(key) || pathSet.has(toWildcardForm(key)) || matchesRecursion(collectRecursionSpecs(paths), key, (p) => pathSet.has(p));
20116
+ const missing = inCandidates ? false : schema !== void 0 ? resolveIndexedSchemaPath(schema, key).kind === "nonexistent" : !isUnresolvedPath(key, scopes);
20117
+ if (missing) {
19523
20118
  return {
19524
20119
  code: WcsDiagnosticCode.WatchPathMissing,
19525
20120
  message: msgs.watchPathMissing(key),
@@ -19542,7 +20137,7 @@ function validateScanDeclarations(html, stateTagName = "wcs-state", locale2) {
19542
20137
  const spans = analyzeDeclarationSpans(block.content);
19543
20138
  if (spans.length > 0) {
19544
20139
  const declaration = findTopLevelDeclaration(block.content, SCAN_KEY);
19545
- if (declaration?.kind === "data" && declaration.value !== void 0 && blankComments(declaration.value).trim() === "undefined") continue;
20140
+ if (declaration?.kind === "data" && declaration.value !== void 0 && blankComments2(declaration.value).trim() === "undefined") continue;
19546
20141
  for (const span of spans) {
19547
20142
  if (span.name !== SCAN_KEY) continue;
19548
20143
  out.push({
@@ -20150,7 +20745,7 @@ function validateVolumeBlock2(block, mountPath, msgs, out) {
20150
20745
  if (severity === void 0) continue;
20151
20746
  if (span.kind === "data") {
20152
20747
  const declaration = findTopLevelDeclaration(block.content, span.name);
20153
- if (declaration?.value !== void 0 && blankComments(declaration.value).trim() === "undefined") continue;
20748
+ if (declaration?.value !== void 0 && blankComments2(declaration.value).trim() === "undefined") continue;
20154
20749
  }
20155
20750
  push3(span.name, span.start, severity);
20156
20751
  }
@@ -20307,7 +20902,7 @@ function declaredNames(script, names2) {
20307
20902
  const decl = findTopLevelDeclaration(script, "$eventTokens");
20308
20903
  if (decl === null || decl.value === void 0 || decl.valueStart === void 0 || literalKind(decl.value) !== "array") return [];
20309
20904
  const out = [];
20310
- for (const element2 of arrayElements(blankComments(decl.value))) {
20905
+ for (const element2 of arrayElements(blankComments2(decl.value))) {
20311
20906
  if (literalKind(element2.text) !== "string") continue;
20312
20907
  const name = element2.text.slice(1, -1);
20313
20908
  if (!names2.includes(name) || out.some((o) => o.name === name)) continue;
@@ -20385,7 +20980,7 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
20385
20980
  code: WcsDiagnosticCode.PathDynamicUnknown,
20386
20981
  start: block.contentStart + span.start,
20387
20982
  end: block.contentStart + span.end,
20388
- message: candidate.opaque?.spread !== void 0 ? msgs.pathDynamicUnknownObjectSpread(path, count, candidate.opaque.spread, candidate.opaque.from) : msgs.pathDynamicUnknownValue(path, count, candidate.opaque?.name, candidate.opaque?.from),
20983
+ message: candidate.opaque?.spread !== void 0 ? msgs.pathDynamicUnknownObjectSpread(path, count, candidate.opaque.spread, candidate.opaque.from) : candidate.opaque?.type !== void 0 ? msgs.pathDynamicUnknownType(path, count, candidate.opaque.type) : msgs.pathDynamicUnknownValue(path, count, candidate.opaque?.name, candidate.opaque?.from),
20389
20984
  severity: "info"
20390
20985
  });
20391
20986
  }
@@ -20760,7 +21355,7 @@ function findTopLevelReads(source) {
20760
21355
  if (!/localStorage|sessionStorage|cookie/.test(source)) return [];
20761
21356
  let program;
20762
21357
  try {
20763
- program = parse3(source, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true });
21358
+ program = parseErasingTypes(source, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true });
20764
21359
  } catch {
20765
21360
  return [];
20766
21361
  }
@@ -20857,6 +21452,58 @@ function validateStateSources(html, stateTagName = "wcs-state", locale2, fileRea
20857
21452
  }
20858
21453
  return out;
20859
21454
  }
21455
+ function validateStateSchemaDrift(html, stateTagName = "wcs-state", locale2, fileReader, applicationSchema) {
21456
+ if (applicationSchema === void 0) return [];
21457
+ const schemaKeys = schemaTopLevelKeys(applicationSchema);
21458
+ if (schemaKeys === null) return [];
21459
+ const elements = parseWcsStateElements(html, stateTagName);
21460
+ const insideTemplate = createTemplateTester(html);
21461
+ const roots = elements.filter((e) => e.mountPath === null && !e.bindComponent && !insideTemplate(e.tagStart));
21462
+ if (roots.length !== 1) return [];
21463
+ const root = roots[0];
21464
+ let script;
21465
+ if (root.stateAttr !== void 0) return [];
21466
+ if (root.srcAttr !== void 0) {
21467
+ if (root.srcAttr.endsWith(".json") || fileReader === void 0) return [];
21468
+ script = readStateScriptFile(root.srcAttr, fileReader)?.text;
21469
+ } else if (root.jsonAttr === void 0 && root.scriptBlocks.length === 1) {
21470
+ script = root.scriptBlocks[0].content;
21471
+ }
21472
+ if (script === void 0) return [];
21473
+ const declared = analyzeTopLevelStateKeys(script);
21474
+ if (declared === null || declared.materializes) return [];
21475
+ const mountRoots = new Set(elements.flatMap((e) => e.mountPath === null || e.mountPath === "" ? [] : [e.mountPath.split(".")[0]]));
21476
+ const inScriptOnly = declared.keys.filter((key) => !schemaKeys.has(key));
21477
+ const inSchemaOnly = [...schemaKeys].filter((key) => !declared.keys.includes(key) && !mountRoots.has(key));
21478
+ if (inScriptOnly.length === 0 && inSchemaOnly.length === 0) return [];
21479
+ return [{
21480
+ code: WcsDiagnosticCode.DriftStateKey,
21481
+ start: root.tagStart,
21482
+ end: root.tagStart + 1 + stateTagName.length,
21483
+ message: getMessages(locale2).stateSchemaDrift(inScriptOnly, inSchemaOnly),
21484
+ severity: "warning"
21485
+ }];
21486
+ }
21487
+ function schemaTopLevelKeys(schema) {
21488
+ const defs = schema.$defs ?? {};
21489
+ const keys = /* @__PURE__ */ new Set();
21490
+ let found = false;
21491
+ const visit2 = (node, depth) => {
21492
+ if (node === void 0 || node === null || typeof node !== "object" || depth > 8) return;
21493
+ if (typeof node.$ref === "string") {
21494
+ const m = /^#\/\$defs\/(.+)$/.exec(node.$ref);
21495
+ if (m !== null) visit2(defs[m[1].replace(/~1/g, "/").replace(/~0/g, "~")], depth + 1);
21496
+ return;
21497
+ }
21498
+ if (Array.isArray(node.anyOf)) for (const branch of node.anyOf) visit2(branch, depth + 1);
21499
+ if (node.properties !== void 0 && typeof node.properties === "object") {
21500
+ found = true;
21501
+ for (const key of Object.keys(node.properties)) if (!key.startsWith("$")) keys.add(key);
21502
+ }
21503
+ };
21504
+ visit2(schema, 0);
21505
+ return found ? keys : null;
21506
+ }
20860
21507
  function validateStateAbsent(html, bindAttribute = "data-wcs", stateTagName = "wcs-state", locale2, applicationSchema) {
20861
21508
  if (applicationSchema !== void 0) return [];
20862
21509
  if (!html.includes(bindAttribute) && !html.includes("@@")) return [];
@@ -21143,6 +21790,7 @@ function resolvePackageContracts(loaded) {
21143
21790
  const filterOwner = /* @__PURE__ */ new Map();
21144
21791
  let schemaOwner;
21145
21792
  let schemaWinner;
21793
+ let schemaStateSource;
21146
21794
  let hasApplicationArtifact = false;
21147
21795
  for (const lm of loaded) {
21148
21796
  if (lm.manifest === null) continue;
@@ -21204,6 +21852,7 @@ function resolvePackageContracts(loaded) {
21204
21852
  if (schemaOwner === void 0) {
21205
21853
  schemaOwner = lm.artifact.source;
21206
21854
  schemaWinner = schema;
21855
+ schemaStateSource = application.stateSource;
21207
21856
  } else {
21208
21857
  schemaWinner = void 0;
21209
21858
  ctxFor(lm).add(
@@ -21223,7 +21872,15 @@ function resolvePackageContracts(loaded) {
21223
21872
  const kept = diags.filter((d) => !(d.code === WcsDiagnosticCode.ManifestOverride && d.tag !== void 0 && collided.has(d.tag)));
21224
21873
  if (kept.length > 0) diagnosticsBySource.set(source, kept);
21225
21874
  }
21226
- return { tags: winners, applicationSchema: schemaWinner, hasApplicationArtifact, diagnosticsBySource };
21875
+ const stateSource = schemaWinner !== void 0 && typeof schemaStateSource === "string" && schemaStateSource.trim() !== "" ? schemaStateSource.trim() : void 0;
21876
+ return {
21877
+ tags: winners,
21878
+ applicationSchema: schemaWinner,
21879
+ ...schemaWinner !== void 0 ? { applicationSchemaSource: schemaOwner } : {},
21880
+ ...stateSource !== void 0 ? { applicationStateSource: stateSource } : {},
21881
+ hasApplicationArtifact,
21882
+ diagnosticsBySource
21883
+ };
21227
21884
  }
21228
21885
 
21229
21886
  // src/core/sidecar/discover.ts
@@ -21235,7 +21892,14 @@ function discoverApplicationManifest(fileReader) {
21235
21892
  const text3 = fileReader(relativePath);
21236
21893
  if (text3 === void 0) continue;
21237
21894
  const loaded = loadManifest({ text: text3, source: relativePath });
21238
- return { relativePath, text: text3, loaded, schema: applicationSchemaOf(loaded) };
21895
+ const stateSource = applicationStateSourceOf(loaded);
21896
+ return {
21897
+ relativePath,
21898
+ text: text3,
21899
+ loaded,
21900
+ schema: applicationSchemaOf(loaded),
21901
+ stateSource: stateSource === void 0 ? void 0 : stateSourceFromPage("_", relativePath, stateSource)
21902
+ };
21239
21903
  }
21240
21904
  return void 0;
21241
21905
  }
@@ -21249,6 +21913,56 @@ function applicationSchemaOf(loaded) {
21249
21913
  }
21250
21914
  return void 0;
21251
21915
  }
21916
+ function applicationStateSourceOf(loaded) {
21917
+ const manifest2 = loaded.manifest;
21918
+ if (manifest2 === null || manifest2.kind !== "application") return void 0;
21919
+ const stateSource = manifest2.manifestExtensions?.["wcstack.application"]?.stateSource;
21920
+ return typeof stateSource === "string" && stateSource.trim() !== "" ? stateSource.trim() : void 0;
21921
+ }
21922
+ function segmentsOf(path) {
21923
+ const norm = path.replace(/\\/g, "/");
21924
+ const absolute = norm.startsWith("/") || /^[A-Za-z]:\//.test(norm);
21925
+ const segments = [];
21926
+ for (const segment of norm.split("/")) {
21927
+ if (segment === "" || segment === ".") continue;
21928
+ if (segment === ".." && segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
21929
+ else segments.push(/^[A-Za-z]:$/.test(segment) ? segment.toUpperCase() : segment);
21930
+ }
21931
+ return { absolute, segments };
21932
+ }
21933
+ function stateSourceFromPage(pageSource, manifestSource, stateSource) {
21934
+ const page = segmentsOf(pageSource);
21935
+ const manifest2 = segmentsOf(manifestSource);
21936
+ if (page.absolute !== manifest2.absolute) return void 0;
21937
+ const target = segmentsOf([...manifest2.segments.slice(0, -1), stateSource].join("/")).segments;
21938
+ const dir = page.segments.slice(0, -1);
21939
+ let common = 0;
21940
+ while (common < dir.length && common < target.length && dir[common] === target[common] && dir[common] !== "..") common++;
21941
+ return [...dir.slice(common).map(() => ".."), ...target.slice(common)].join("/");
21942
+ }
21943
+ function sameStateFile(a, b) {
21944
+ const canonical = (p) => p.replace(/\.ts$/, ".js").replace(/\.mts$/, ".mjs");
21945
+ return canonical(a) === canonical(b);
21946
+ }
21947
+ function schemaAppliesToPage(html, stateTagName, stateSource, fileReader) {
21948
+ const roots = parseWcsStateElements(html, stateTagName).filter((e) => e.mountPath === null && !e.bindComponent && e.srcAttr !== void 0);
21949
+ if (roots.length === 0) return false;
21950
+ const insideTemplate = createTemplateTester(html);
21951
+ const target = segmentsOf(stateSource).segments.join("/");
21952
+ for (const root of roots) {
21953
+ if (insideTemplate(root.tagStart)) continue;
21954
+ const src = root.srcAttr.trim().replace(/[?#].*$/, "");
21955
+ if (src === "" || /^[a-z][a-z0-9+.-]*:/i.test(src) || src.startsWith("//")) continue;
21956
+ if (sameStateFile(segmentsOf(src).segments.join("/"), target)) return true;
21957
+ if (fileReader !== void 0 && sameContent(src, stateSource, fileReader)) return true;
21958
+ }
21959
+ return false;
21960
+ }
21961
+ function sameContent(a, b, fileReader) {
21962
+ const twins = (p) => [p, p.replace(/\.(m?)js$/, ".$1ts"), p.replace(/\.(m?)ts$/, ".$1js")];
21963
+ const texts = new Set(twins(a).map((p) => fileReader(p)).filter((t) => t !== void 0 && t !== ""));
21964
+ return texts.size > 0 && twins(b).some((p) => texts.has(fileReader(p) ?? "\0"));
21965
+ }
21252
21966
  function joinRelativeSource(htmlSource, relativePath) {
21253
21967
  const sepIndex = Math.max(htmlSource.lastIndexOf("/"), htmlSource.lastIndexOf("\\"));
21254
21968
  const dirSegments = sepIndex === -1 ? [] : htmlSource.slice(0, sepIndex).split(/[\\/]/);
@@ -21325,11 +22039,13 @@ function locateInlined(page, offset2) {
21325
22039
  function validateDocument(text3, options = {}) {
21326
22040
  const stateTagName = options.stateTagName ?? "wcs-state";
21327
22041
  const fileReader = options.fileReader;
21328
- const applicationSchema = options.applicationSchema ?? (fileReader !== void 0 ? discoverApplicationManifest(fileReader)?.schema : void 0);
22042
+ const applicationSchema = applicationSchemaFor(text3, stateTagName, options);
21329
22043
  const found = [
21330
22044
  ...validateText(text3, options, applicationSchema),
21331
22045
  ...validateStateSources(text3, stateTagName, options.locale, fileReader),
21332
- ...validateStateAbsent(text3, options.bindAttribute ?? "data-wcs", stateTagName, options.locale, applicationSchema)
22046
+ ...validateStateAbsent(text3, options.bindAttribute ?? "data-wcs", stateTagName, options.locale, applicationSchema),
22047
+ // a stateSchema whose top-level keys are not the root state script's: stale (once, on the page's `<wcs-state>`)
22048
+ ...validateStateSchemaDrift(text3, stateTagName, options.locale, fileReader, applicationSchema)
21333
22049
  ];
21334
22050
  const page = fileReader === void 0 ? null : inlineExternalStates(text3, stateTagName, fileReader);
21335
22051
  if (page === null) return sortDiagnostics(found);
@@ -21365,6 +22081,17 @@ function validateDocument(text3, options = {}) {
21365
22081
  }
21366
22082
  return sortDiagnostics(out);
21367
22083
  }
22084
+ function applicationSchemaFor(text3, stateTagName, options) {
22085
+ let schema = options.applicationSchema;
22086
+ let stateSource = options.applicationStateSource;
22087
+ if (schema === void 0 && options.fileReader !== void 0) {
22088
+ const discovered = discoverApplicationManifest(options.fileReader);
22089
+ schema = discovered?.schema;
22090
+ stateSource = discovered?.stateSource;
22091
+ }
22092
+ if (schema === void 0 || stateSource === void 0) return schema;
22093
+ return schemaAppliesToPage(text3, stateTagName, stateSource, options.fileReader) ? schema : void 0;
22094
+ }
21368
22095
  function validateText(text3, options, applicationSchema) {
21369
22096
  const bindAttribute = options.bindAttribute ?? "data-wcs";
21370
22097
  const stateTagName = options.stateTagName ?? "wcs-state";
@@ -21391,7 +22118,7 @@ function validateText(text3, options, applicationSchema) {
21391
22118
  out.push(...validateAccessorLists(text3, stateTagName, locale2));
21392
22119
  out.push(...validateArrayMutations(text3, stateTagName, locale2));
21393
22120
  out.push(...validateModuleTopReads(text3, stateTagName, locale2));
21394
- out.push(...validateWatchDeclarations(text3, stateTagName, locale2, fileReader, bindAttribute));
22121
+ out.push(...validateWatchDeclarations(text3, stateTagName, locale2, fileReader, bindAttribute, applicationSchema));
21395
22122
  out.push(...validateScanDeclarations(text3, stateTagName, locale2));
21396
22123
  out.push(...validateRecursion(text3, stateTagName, locale2));
21397
22124
  out.push(...validateConfigDeclarations(text3, stateTagName, locale2));
@@ -21536,6 +22263,8 @@ function validateManifestSet(input) {
21536
22263
  byArtifact: sortedByArtifact,
21537
22264
  resolvedTags,
21538
22265
  resolvedSchema: resolved.applicationSchema,
22266
+ ...resolved.applicationSchemaSource !== void 0 ? { resolvedSchemaSource: resolved.applicationSchemaSource } : {},
22267
+ ...resolved.applicationStateSource !== void 0 ? { resolvedStateSource: resolved.applicationStateSource } : {},
21539
22268
  hasApplicationArtifact: resolved.hasApplicationArtifact
21540
22269
  };
21541
22270
  }
@@ -21557,6 +22286,7 @@ function runValidation(inputs, options = {}) {
21557
22286
  const textBySource = new Map(inputs.map((i) => [i.source, i.text]));
21558
22287
  const manifestInputs = inputs.filter((i) => i.kind === "manifest");
21559
22288
  let explicitSchema;
22289
+ let explicitStateSource;
21560
22290
  let haveExplicitApplication = false;
21561
22291
  if (manifestInputs.length > 0) {
21562
22292
  const result = validateManifestSet({
@@ -21569,6 +22299,9 @@ function runValidation(inputs, options = {}) {
21569
22299
  if (result.hasApplicationArtifact) {
21570
22300
  haveExplicitApplication = true;
21571
22301
  explicitSchema = result.resolvedSchema;
22302
+ if (result.resolvedSchemaSource !== void 0 && result.resolvedStateSource !== void 0) {
22303
+ explicitStateSource = { manifest: result.resolvedSchemaSource, stateSource: result.resolvedStateSource };
22304
+ }
21572
22305
  }
21573
22306
  }
21574
22307
  const inFiles = /* @__PURE__ */ new Map();
@@ -21579,9 +22312,11 @@ function runValidation(inputs, options = {}) {
21579
22312
  nothingToCheck.push(input.source);
21580
22313
  }
21581
22314
  let applicationSchema = explicitSchema;
22315
+ let applicationStateSource = explicitStateSource === void 0 ? void 0 : stateSourceFromPage(input.source, explicitStateSource.manifest, explicitStateSource.stateSource);
21582
22316
  if (!haveExplicitApplication && input.fileReader !== void 0) {
21583
22317
  const discovered = discoverApplicationManifest(input.fileReader);
21584
22318
  applicationSchema = discovered?.schema;
22319
+ applicationStateSource = discovered?.stateSource;
21585
22320
  if (discovered !== void 0) {
21586
22321
  const source = joinRelativeSource(input.source, discovered.relativePath);
21587
22322
  if (!diagnosticsBySource.has(source)) {
@@ -21593,7 +22328,8 @@ function runValidation(inputs, options = {}) {
21593
22328
  const docOptions = {
21594
22329
  ...options,
21595
22330
  ...input.fileReader !== void 0 ? { fileReader: input.fileReader } : {},
21596
- ...applicationSchema !== void 0 ? { applicationSchema } : {}
22331
+ ...applicationSchema !== void 0 ? { applicationSchema } : {},
22332
+ ...applicationSchema !== void 0 && applicationStateSource !== void 0 ? { applicationStateSource } : {}
21597
22333
  };
21598
22334
  const own3 = [];
21599
22335
  for (const d of validateDocument(input.text, docOptions)) {