@wcstack/lint 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/cli.cjs +483 -39
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -56,7 +56,7 @@ app.manifest.json:1:3 error wcs/manifest-broken Broken manifest JSON: ...
|
|
|
56
56
|
|
|
57
57
|
## state の契約を宣言する(`stateSchema`)
|
|
58
58
|
|
|
59
|
-
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count`
|
|
59
|
+
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count` は実行時には存在するかもしれないからです。`[]` で始まるリストの行のフィールドは、行を足す・置き換える代入式の行リテラルから読みます。外から届くリスト(`<wcs-fetch>` や `<wcs-storage>` が埋めるまで `null`)にはそのリテラルが無いので、プロパティの直前の JSDoc `@type` で形を宣言してください(`/** @type {{ id: number, name: string }[] | null} */ catalog: null`)。同じスクリプトの `@typedef` で行の型に名前を付け、`@type {Product[] | null}` と書いてもかまいません。HTML と同じ(または上の)ディレクトリに `application` sidecar を置くと、同じ typo が **error** になります:
|
|
60
60
|
|
|
61
61
|
```json
|
|
62
62
|
{
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ app.manifest.json:1:3 error wcs/manifest-broken Broken manifest JSON: ...
|
|
|
56
56
|
|
|
57
57
|
## Declaring a state contract (`stateSchema`)
|
|
58
58
|
|
|
59
|
-
Without a contract, a path the validator cannot resolve is only a **warning** (`wcs/binding-path-missing`): `count` may well exist at runtime even when the inline script cannot be read statically. Note that a list starting as `[]` does not need a contract just to name its row fields — the analyzer reads them from the row literals in the assignments that add or replace rows (`this.items = this.items.concat({ id, kind: "general" })`, `.toSpliced(i, n, { … })`, `.with(i, { … })`, `[...this.items, { … }]`); only a row passed as a variable (`concat(row)`) is invisible to it. Put an `application` sidecar next to (or above) the HTML and the same typo becomes an **error**:
|
|
59
|
+
Without a contract, a path the validator cannot resolve is only a **warning** (`wcs/binding-path-missing`): `count` may well exist at runtime even when the inline script cannot be read statically. Note that a list starting as `[]` does not need a contract just to name its row fields — the analyzer reads them from the row literals in the assignments that add or replace rows (`this.items = this.items.concat({ id, kind: "general" })`, `.toSpliced(i, n, { … })`, `.with(i, { … })`, `[...this.items, { … }]`); only a row passed as a variable (`concat(row)`) is invisible to it. A list that arrives from outside — `null` until `<wcs-fetch>` or `<wcs-storage>` fills it — has no such literal: declare its shape with a JSDoc `@type` before the property (`/** @type {{ id: number, name: string }[] | null} */ catalog: null`), or name the row type with a `@typedef` in the same script and write `@type {Product[] | null}`. Put an `application` sidecar next to (or above) the HTML and the same typo becomes an **error**:
|
|
60
60
|
|
|
61
61
|
```json
|
|
62
62
|
{
|
package/dist/cli.cjs
CHANGED
|
@@ -253,6 +253,13 @@ var WcsDiagnosticCode = {
|
|
|
253
253
|
TriggerSeededTruthy: "wcs/trigger-seeded-truthy",
|
|
254
254
|
// 非 manual <wcs-storage> value バインド先の空値シード(初期書き戻しが保存値を上書き)。
|
|
255
255
|
StorageSeedClobber: "wcs/storage-seed-clobber",
|
|
256
|
+
// `value#init=element` の <wcs-storage> バインド先の null 以外のリテラルシード
|
|
257
|
+
// (空のキーは null を読むので、初回の引き込みでシードが null に置き換わる)。
|
|
258
|
+
StorageInitSeed: "wcs/storage-init-seed",
|
|
259
|
+
// 組み込み I/O ノードの入力を束ねたパスの下へ、ページが書き込む(`value: cart` と
|
|
260
|
+
// `this["cart.0.quantity"] = …`)。束縛はそのパス自身への代入でしか当て直されないので、
|
|
261
|
+
// 下への書き込みは要素に届かない(storage なら保存されない)。
|
|
262
|
+
InputNestedWrite: "wcs/input-nested-write",
|
|
256
263
|
// --- accessibility (docs/a11y-design.md §8 / D9) ---
|
|
257
264
|
// `attr.aria-*` バインドの属性名が WAI-ARIA に存在しない(タイポ)。
|
|
258
265
|
// setAttribute はそのまま書き、支援技術は黙って無視する。severity は warning
|
|
@@ -2395,6 +2402,292 @@ function coversSuffix(spec, familySuffix, suffix) {
|
|
|
2395
2402
|
return false;
|
|
2396
2403
|
}
|
|
2397
2404
|
|
|
2405
|
+
// src/service/jsdocType.ts
|
|
2406
|
+
var UNKNOWN = { kind: "unknown" };
|
|
2407
|
+
var NULL_TYPE = { kind: "name", name: "null" };
|
|
2408
|
+
var ARRAY_GENERICS = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
2409
|
+
var MAX_RESOLVE_DEPTH = 8;
|
|
2410
|
+
function tokenize(text3) {
|
|
2411
|
+
const tokens = [];
|
|
2412
|
+
let i = 0;
|
|
2413
|
+
while (i < text3.length) {
|
|
2414
|
+
const ch = text3[i];
|
|
2415
|
+
if (/\s/.test(ch)) {
|
|
2416
|
+
i++;
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
if (ch === "=" && text3[i + 1] === ">") {
|
|
2420
|
+
tokens.push({ t: "punct", v: "=>" });
|
|
2421
|
+
i += 2;
|
|
2422
|
+
continue;
|
|
2423
|
+
}
|
|
2424
|
+
if ("{}[]<>()|,;:?!*.=".includes(ch)) {
|
|
2425
|
+
tokens.push({ t: "punct", v: ch });
|
|
2426
|
+
i++;
|
|
2427
|
+
continue;
|
|
2428
|
+
}
|
|
2429
|
+
if (ch === '"' || ch === "'") {
|
|
2430
|
+
const end = text3.indexOf(ch, i + 1);
|
|
2431
|
+
if (end === -1) return null;
|
|
2432
|
+
tokens.push({ t: "string", v: text3.slice(i + 1, end) });
|
|
2433
|
+
i = end + 1;
|
|
2434
|
+
continue;
|
|
2435
|
+
}
|
|
2436
|
+
const num = /^-?\d+(?:\.\d+)?/.exec(text3.slice(i));
|
|
2437
|
+
if (num) {
|
|
2438
|
+
tokens.push({ t: "number" });
|
|
2439
|
+
i += num[0].length;
|
|
2440
|
+
continue;
|
|
2441
|
+
}
|
|
2442
|
+
const name = /^[$A-Za-z_][$\w]*/.exec(text3.slice(i));
|
|
2443
|
+
if (name) {
|
|
2444
|
+
tokens.push({ t: "name", v: name[0] });
|
|
2445
|
+
i += name[0].length;
|
|
2446
|
+
continue;
|
|
2447
|
+
}
|
|
2448
|
+
return null;
|
|
2449
|
+
}
|
|
2450
|
+
return tokens;
|
|
2451
|
+
}
|
|
2452
|
+
function parseJsDocType(text3) {
|
|
2453
|
+
const tokens = tokenize(text3);
|
|
2454
|
+
if (tokens === null || tokens.length === 0) return null;
|
|
2455
|
+
let pos = 0;
|
|
2456
|
+
const peek = () => tokens[pos];
|
|
2457
|
+
const isPunct = (v) => {
|
|
2458
|
+
const token = tokens[pos];
|
|
2459
|
+
return token !== void 0 && token.t === "punct" && token.v === v;
|
|
2460
|
+
};
|
|
2461
|
+
const expect = (v) => {
|
|
2462
|
+
if (!isPunct(v)) return false;
|
|
2463
|
+
pos++;
|
|
2464
|
+
return true;
|
|
2465
|
+
};
|
|
2466
|
+
const parseUnion = () => {
|
|
2467
|
+
expect("|");
|
|
2468
|
+
const members = [];
|
|
2469
|
+
for (; ; ) {
|
|
2470
|
+
const member = parsePostfix();
|
|
2471
|
+
if (member === null) return null;
|
|
2472
|
+
members.push(member);
|
|
2473
|
+
if (!expect("|")) break;
|
|
2474
|
+
}
|
|
2475
|
+
if (isPunct("=>")) {
|
|
2476
|
+
pos++;
|
|
2477
|
+
if (parseUnion() === null) return null;
|
|
2478
|
+
return UNKNOWN;
|
|
2479
|
+
}
|
|
2480
|
+
return members.length === 1 ? members[0] : { kind: "union", members };
|
|
2481
|
+
};
|
|
2482
|
+
const parsePostfix = () => {
|
|
2483
|
+
let type2 = parsePrimary();
|
|
2484
|
+
if (type2 === null) return null;
|
|
2485
|
+
while (isPunct("[") && tokens[pos + 1]?.t === "punct" && tokens[pos + 1].v === "]") {
|
|
2486
|
+
pos += 2;
|
|
2487
|
+
type2 = { kind: "array", element: type2 };
|
|
2488
|
+
}
|
|
2489
|
+
return type2;
|
|
2490
|
+
};
|
|
2491
|
+
const parsePrimary = () => {
|
|
2492
|
+
const token = peek();
|
|
2493
|
+
if (token === void 0) return null;
|
|
2494
|
+
if (token.t === "string" || token.t === "number") {
|
|
2495
|
+
pos++;
|
|
2496
|
+
return UNKNOWN;
|
|
2497
|
+
}
|
|
2498
|
+
if (token.t === "punct") {
|
|
2499
|
+
if (token.v === "{") return parseObject();
|
|
2500
|
+
if (token.v === "(") {
|
|
2501
|
+
pos++;
|
|
2502
|
+
if (expect(")")) return isPunct("=>") ? UNKNOWN : null;
|
|
2503
|
+
const inner = parseUnion();
|
|
2504
|
+
if (inner === null) return null;
|
|
2505
|
+
if (isPunct(":") || isPunct(",")) {
|
|
2506
|
+
if (!skipUntilClose("(", ")")) return null;
|
|
2507
|
+
return UNKNOWN;
|
|
2508
|
+
}
|
|
2509
|
+
return expect(")") ? inner : null;
|
|
2510
|
+
}
|
|
2511
|
+
if (token.v === "?") {
|
|
2512
|
+
pos++;
|
|
2513
|
+
const next = peek();
|
|
2514
|
+
if (next === void 0 || next.t === "punct" && ["|", ",", ";", ")", ">", "]", "}", "="].includes(next.v)) return UNKNOWN;
|
|
2515
|
+
const inner = parsePostfix();
|
|
2516
|
+
return inner === null ? null : { kind: "union", members: [inner, NULL_TYPE] };
|
|
2517
|
+
}
|
|
2518
|
+
if (token.v === "!") {
|
|
2519
|
+
pos++;
|
|
2520
|
+
return parsePostfix();
|
|
2521
|
+
}
|
|
2522
|
+
if (token.v === "*") {
|
|
2523
|
+
pos++;
|
|
2524
|
+
return UNKNOWN;
|
|
2525
|
+
}
|
|
2526
|
+
return null;
|
|
2527
|
+
}
|
|
2528
|
+
pos++;
|
|
2529
|
+
let name = token.v;
|
|
2530
|
+
while (isPunct(".") && tokens[pos + 1]?.t === "name") {
|
|
2531
|
+
name += "." + tokens[pos + 1].v;
|
|
2532
|
+
pos += 2;
|
|
2533
|
+
}
|
|
2534
|
+
if ((name === "typeof" || name === "keyof") && peek()?.t === "name") {
|
|
2535
|
+
pos++;
|
|
2536
|
+
return UNKNOWN;
|
|
2537
|
+
}
|
|
2538
|
+
if (name === "function" && isPunct("(")) {
|
|
2539
|
+
pos++;
|
|
2540
|
+
if (!skipUntilClose("(", ")")) return null;
|
|
2541
|
+
if (expect(":")) {
|
|
2542
|
+
if (parsePostfix() === null) return null;
|
|
2543
|
+
}
|
|
2544
|
+
return UNKNOWN;
|
|
2545
|
+
}
|
|
2546
|
+
if (isPunct(".") && tokens[pos + 1]?.t === "punct" && tokens[pos + 1].v === "<") pos++;
|
|
2547
|
+
if (isPunct("<")) {
|
|
2548
|
+
pos++;
|
|
2549
|
+
const args = [];
|
|
2550
|
+
for (; ; ) {
|
|
2551
|
+
const arg = parseUnion();
|
|
2552
|
+
if (arg === null) return null;
|
|
2553
|
+
args.push(arg);
|
|
2554
|
+
if (!expect(",")) break;
|
|
2555
|
+
}
|
|
2556
|
+
if (!expect(">")) return null;
|
|
2557
|
+
return ARRAY_GENERICS.has(name) && args.length === 1 ? { kind: "array", element: args[0] } : UNKNOWN;
|
|
2558
|
+
}
|
|
2559
|
+
return { kind: "name", name };
|
|
2560
|
+
};
|
|
2561
|
+
const parseObject = () => {
|
|
2562
|
+
pos++;
|
|
2563
|
+
const fields = [];
|
|
2564
|
+
while (!isPunct("}")) {
|
|
2565
|
+
const key = peek();
|
|
2566
|
+
if (key === void 0) return null;
|
|
2567
|
+
if (key.t === "punct" && key.v === "[") {
|
|
2568
|
+
pos++;
|
|
2569
|
+
if (!skipUntilClose("[", "]")) return null;
|
|
2570
|
+
if (!expect(":") || parseUnion() === null) return null;
|
|
2571
|
+
} else {
|
|
2572
|
+
if (key.t !== "name" && key.t !== "string") return null;
|
|
2573
|
+
pos++;
|
|
2574
|
+
expect("?");
|
|
2575
|
+
if (!expect(":")) return null;
|
|
2576
|
+
const type2 = parseUnion();
|
|
2577
|
+
if (type2 === null) return null;
|
|
2578
|
+
fields.push({ name: key.v, type: type2 });
|
|
2579
|
+
}
|
|
2580
|
+
if (!expect(",") && !expect(";")) break;
|
|
2581
|
+
}
|
|
2582
|
+
return expect("}") ? { kind: "object", fields } : null;
|
|
2583
|
+
};
|
|
2584
|
+
const skipUntilClose = (open, close) => {
|
|
2585
|
+
let depth = 0;
|
|
2586
|
+
while (pos < tokens.length) {
|
|
2587
|
+
const token = tokens[pos++];
|
|
2588
|
+
if (token.t !== "punct") continue;
|
|
2589
|
+
if (token.v === open) depth++;
|
|
2590
|
+
else if (token.v === close) {
|
|
2591
|
+
if (depth === 0) return true;
|
|
2592
|
+
depth--;
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
return false;
|
|
2596
|
+
};
|
|
2597
|
+
const type = parseUnion();
|
|
2598
|
+
if (type === null || pos !== tokens.length) return null;
|
|
2599
|
+
return type;
|
|
2600
|
+
}
|
|
2601
|
+
function findJsDocComments(script, scan) {
|
|
2602
|
+
const out = [];
|
|
2603
|
+
let from = 0;
|
|
2604
|
+
for (; ; ) {
|
|
2605
|
+
const start = scan.indexOf("/*", from);
|
|
2606
|
+
if (start === -1) break;
|
|
2607
|
+
const close = scan.indexOf("*/", start + 2);
|
|
2608
|
+
if (close === -1) break;
|
|
2609
|
+
from = close + 2;
|
|
2610
|
+
if (script[start + 2] === "*") out.push({ start, end: close + 2, text: script.slice(start, close + 2) });
|
|
2611
|
+
}
|
|
2612
|
+
return out;
|
|
2613
|
+
}
|
|
2614
|
+
function readJsDocTagType(comment, tag) {
|
|
2615
|
+
return readBracedType(comment, tag)?.type.trim() ?? null;
|
|
2616
|
+
}
|
|
2617
|
+
function readBracedType(comment, tag) {
|
|
2618
|
+
const tagMatch = new RegExp(`@${tag}\\s*\\{`).exec(comment);
|
|
2619
|
+
if (!tagMatch) return null;
|
|
2620
|
+
const open = tagMatch.index + tagMatch[0].length - 1;
|
|
2621
|
+
let depth = 0;
|
|
2622
|
+
for (let i = open; i < comment.length; i++) {
|
|
2623
|
+
const ch = comment[i];
|
|
2624
|
+
if (ch === "{") depth++;
|
|
2625
|
+
else if (ch === "}") {
|
|
2626
|
+
depth--;
|
|
2627
|
+
if (depth === 0) {
|
|
2628
|
+
const type = comment.slice(open + 1, i).replace(/\n\s*\*(?!\/)/g, "\n ");
|
|
2629
|
+
return { type, end: i + 1 };
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
return null;
|
|
2634
|
+
}
|
|
2635
|
+
function readJsDocTypeBefore(content, propIndex) {
|
|
2636
|
+
let end = propIndex;
|
|
2637
|
+
while (end > 0 && /\s/.test(content[end - 1])) end--;
|
|
2638
|
+
if (!content.startsWith("*/", end - 2)) return void 0;
|
|
2639
|
+
const start = content.lastIndexOf("/*", end - 2);
|
|
2640
|
+
if (start === -1 || content[start + 2] !== "*") return void 0;
|
|
2641
|
+
return readBracedType(content.slice(start, end), "type")?.type.trim();
|
|
2642
|
+
}
|
|
2643
|
+
function collectJsDocTypedefs(script, scan) {
|
|
2644
|
+
const typedefs = /* @__PURE__ */ new Map();
|
|
2645
|
+
for (const { text: comment } of findJsDocComments(script, scan)) {
|
|
2646
|
+
const braced = readBracedType(comment, "typedef");
|
|
2647
|
+
if (braced === null) continue;
|
|
2648
|
+
const name = /^\s*([$A-Za-z_][$\w]*)/.exec(comment.slice(braced.end));
|
|
2649
|
+
const type = parseJsDocType(braced.type);
|
|
2650
|
+
if (name && type !== null) typedefs.set(name[1], type);
|
|
2651
|
+
}
|
|
2652
|
+
return typedefs;
|
|
2653
|
+
}
|
|
2654
|
+
function flattenJsDocType(type, typedefs, depth = 0) {
|
|
2655
|
+
if (type.kind === "union") return type.members.flatMap((member) => flattenJsDocType(member, typedefs, depth));
|
|
2656
|
+
if (type.kind === "name" && depth < MAX_RESOLVE_DEPTH) {
|
|
2657
|
+
const resolved = typedefs.get(type.name);
|
|
2658
|
+
if (resolved !== void 0) return flattenJsDocType(resolved, typedefs, depth + 1);
|
|
2659
|
+
}
|
|
2660
|
+
return [type];
|
|
2661
|
+
}
|
|
2662
|
+
function jsDocTypeHint(type, typedefs = /* @__PURE__ */ new Map()) {
|
|
2663
|
+
const hints = /* @__PURE__ */ new Set();
|
|
2664
|
+
for (const member of flattenJsDocType(type, typedefs)) {
|
|
2665
|
+
if (member.kind === "array") hints.add("array");
|
|
2666
|
+
else if (member.kind === "object") hints.add("object");
|
|
2667
|
+
else if (member.kind === "name") {
|
|
2668
|
+
const lower2 = member.name.toLowerCase();
|
|
2669
|
+
if (lower2 === "string" || lower2 === "number" || lower2 === "boolean" || lower2 === "object") hints.add(lower2);
|
|
2670
|
+
else if (lower2 === "null" || lower2 === "undefined") hints.add("null");
|
|
2671
|
+
else if (lower2 === "array" || lower2 === "readonlyarray") hints.add("array");
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
return hints.size === 0 ? void 0 : [...hints].sort().join("|");
|
|
2675
|
+
}
|
|
2676
|
+
function jsDocShape(type, typedefs) {
|
|
2677
|
+
const elements = [];
|
|
2678
|
+
const fields = [];
|
|
2679
|
+
for (const member of flattenJsDocType(type, typedefs)) {
|
|
2680
|
+
if (member.kind === "array") elements.push(member.element);
|
|
2681
|
+
else if (member.kind === "object") {
|
|
2682
|
+
for (const field of member.fields) {
|
|
2683
|
+
if (!fields.some((f) => f.name === field.name)) fields.push(field);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
const element2 = elements.length === 0 ? null : elements.length === 1 ? elements[0] : { kind: "union", members: elements };
|
|
2688
|
+
return { element: element2, fields };
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2398
2691
|
// src/service/stateAnalyzer.ts
|
|
2399
2692
|
var RESERVED_STREAMS_KEYS = /* @__PURE__ */ new Set(["$stream", "$streams"]);
|
|
2400
2693
|
var RESERVED_COMMAND_TOKENS_KEY = "$commandTokens";
|
|
@@ -2412,6 +2705,7 @@ function analyzeStatePaths(scriptContent) {
|
|
|
2412
2705
|
const pendingListKeys = [];
|
|
2413
2706
|
const recursionSpec = specFromRecursionValue(topLevelProps.find((p) => p.name === RESERVED_RECURSION_KEY));
|
|
2414
2707
|
const effectiveDescriptors = effectiveTopLevelDescriptors(topLevelProps);
|
|
2708
|
+
const typedefs = scriptContent.includes("@typedef") ? collectJsDocTypedefs(scriptContent, maskCommentsAndStrings(scriptContent)) : /* @__PURE__ */ new Map();
|
|
2415
2709
|
for (const prop of topLevelProps) {
|
|
2416
2710
|
if (prop.name.startsWith("$")) {
|
|
2417
2711
|
collectReservedKeyPaths(prop, paths, pendingStreamValues, pendingListKeys);
|
|
@@ -2427,15 +2721,17 @@ function analyzeStatePaths(scriptContent) {
|
|
|
2427
2721
|
}
|
|
2428
2722
|
if (prop.kind === "getter") {
|
|
2429
2723
|
if (!paths.some((p) => p.path === prop.name)) {
|
|
2430
|
-
|
|
2724
|
+
const recursive = hasRecursionWildcard(prop.name);
|
|
2725
|
+
const settable = !recursive && effective !== "data" && effective.set;
|
|
2726
|
+
paths.push({ path: prop.name, kind: recursive ? "recursive" : "computed", ...settable ? { settable } : {} });
|
|
2431
2727
|
}
|
|
2432
2728
|
continue;
|
|
2433
2729
|
}
|
|
2434
|
-
pushDataPropertyPaths(prop, paths);
|
|
2730
|
+
pushDataPropertyPaths(prop, paths, typedefs);
|
|
2435
2731
|
}
|
|
2436
2732
|
for (const streamValue of pendingStreamValues) {
|
|
2437
2733
|
if (paths.some((p) => p.path === streamValue.name && p.kind !== "eventToken")) continue;
|
|
2438
|
-
pushDataPropertyPaths(streamValue, paths);
|
|
2734
|
+
pushDataPropertyPaths(streamValue, paths, typedefs);
|
|
2439
2735
|
}
|
|
2440
2736
|
for (const listKeyEntry of pendingListKeys) {
|
|
2441
2737
|
pushListKeyPaths(listKeyEntry, paths);
|
|
@@ -3165,17 +3461,37 @@ function effectiveTopLevelDescriptors(props) {
|
|
|
3165
3461
|
}
|
|
3166
3462
|
return effective;
|
|
3167
3463
|
}
|
|
3168
|
-
function pushDataPropertyPaths(prop, paths) {
|
|
3169
|
-
pushDataPropertyPathsAt(prop.name, prop, paths, 0);
|
|
3464
|
+
function pushDataPropertyPaths(prop, paths, typedefs) {
|
|
3465
|
+
pushDataPropertyPathsAt(prop.name, prop, paths, 0, typedefs);
|
|
3170
3466
|
}
|
|
3171
|
-
function pushDataPropertyPathsAt(path, prop, paths, depth) {
|
|
3467
|
+
function pushDataPropertyPathsAt(path, prop, paths, depth, typedefs) {
|
|
3172
3468
|
paths.push({ path, kind: "data", typeHint: prop.typeHint, rawInitial: prop.value?.trim() });
|
|
3469
|
+
pushLiteralStructurePaths(path, prop, paths, depth, typedefs);
|
|
3470
|
+
if (prop.declaredType !== void 0) pushDeclaredShapePaths(path, prop.declaredType, paths, depth, typedefs);
|
|
3471
|
+
}
|
|
3472
|
+
function pushDeclaredShapePaths(path, type, paths, depth, typedefs) {
|
|
3473
|
+
const shape = jsDocShape(type, typedefs);
|
|
3474
|
+
if (shape.element !== null) {
|
|
3475
|
+
if (!hasPath(paths, `${path}.*`)) paths.push({ path: `${path}.*`, kind: "list" });
|
|
3476
|
+
if (!hasPath(paths, `${path}.length`)) paths.push({ path: `${path}.length`, kind: "data", typeHint: "number" });
|
|
3477
|
+
if (depth < MAX_OBJECT_NEST_DEPTH) pushDeclaredShapePaths(`${path}.*`, shape.element, paths, depth + 1, typedefs);
|
|
3478
|
+
}
|
|
3479
|
+
if (depth >= MAX_OBJECT_NEST_DEPTH) return;
|
|
3480
|
+
for (const field of shape.fields) {
|
|
3481
|
+
const fieldPath = `${path}.${field.name}`;
|
|
3482
|
+
if (!hasPath(paths, fieldPath)) {
|
|
3483
|
+
paths.push(withHint({ path: fieldPath, kind: "data" }, jsDocTypeHint(field.type, typedefs)));
|
|
3484
|
+
}
|
|
3485
|
+
pushDeclaredShapePaths(fieldPath, field.type, paths, depth + 1, typedefs);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
function pushLiteralStructurePaths(path, prop, paths, depth, typedefs) {
|
|
3173
3489
|
if (prop.value && isArrayLiteral(prop.value)) {
|
|
3174
3490
|
paths.push({ path: `${path}.*`, kind: "list" });
|
|
3175
3491
|
paths.push({ path: `${path}.length`, kind: "data", typeHint: "number" });
|
|
3176
3492
|
if (depth >= MAX_OBJECT_NEST_DEPTH) return;
|
|
3177
3493
|
for (const childProp of extractArrayElementDataProperties(prop.value)) {
|
|
3178
|
-
pushDataPropertyPathsAt(`${path}.*.${childProp.name}`, childProp, paths, depth + 1);
|
|
3494
|
+
pushDataPropertyPathsAt(`${path}.*.${childProp.name}`, childProp, paths, depth + 1, typedefs);
|
|
3179
3495
|
}
|
|
3180
3496
|
return;
|
|
3181
3497
|
}
|
|
@@ -3184,7 +3500,7 @@ function pushDataPropertyPathsAt(path, prop, paths, depth) {
|
|
|
3184
3500
|
const childProps = parseTopLevelProperties(extractObjectContent(prop.value));
|
|
3185
3501
|
for (const childProp of childProps) {
|
|
3186
3502
|
if (childProp.kind !== "data") continue;
|
|
3187
|
-
pushDataPropertyPathsAt(`${path}.${childProp.name}`, childProp, paths, depth + 1);
|
|
3503
|
+
pushDataPropertyPathsAt(`${path}.${childProp.name}`, childProp, paths, depth + 1, typedefs);
|
|
3188
3504
|
}
|
|
3189
3505
|
}
|
|
3190
3506
|
}
|
|
@@ -3295,13 +3611,16 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
|
|
|
3295
3611
|
if (propName !== void 0) {
|
|
3296
3612
|
const valueStartIndex = match.index + match[0].length;
|
|
3297
3613
|
const value = extractFullValue(objectContent, scan, valueStartIndex);
|
|
3298
|
-
const
|
|
3614
|
+
const jsdocText = readJsDocTypeBefore(objectContent, match.index);
|
|
3615
|
+
const declaredType = jsdocText === void 0 ? null : parseJsDocType(jsdocText);
|
|
3616
|
+
const jsdocType = declaredType !== null ? jsDocTypeHint(declaredType) : jsdocText === void 0 ? void 0 : normalizeJsDocType(jsdocText);
|
|
3299
3617
|
const typeHint = jsdocType ?? inferTypeHint(value);
|
|
3300
3618
|
props.push({
|
|
3301
3619
|
name: propName,
|
|
3302
3620
|
kind: "data",
|
|
3303
3621
|
value,
|
|
3304
3622
|
typeHint,
|
|
3623
|
+
...declaredType !== null ? { declaredType } : {},
|
|
3305
3624
|
nameStart: nameSpan[0],
|
|
3306
3625
|
nameEnd: nameSpan[1],
|
|
3307
3626
|
valueStart: valueStartIndex
|
|
@@ -3422,13 +3741,6 @@ function extractArrayElementDataProperties(value) {
|
|
|
3422
3741
|
const objectContent = extractBracedContent(trimmed, scan, first);
|
|
3423
3742
|
return parseTopLevelProperties(objectContent).filter((prop) => prop.kind === "data");
|
|
3424
3743
|
}
|
|
3425
|
-
function extractJsDocType(content, propIndex) {
|
|
3426
|
-
const before = content.slice(Math.max(0, propIndex - 200), propIndex);
|
|
3427
|
-
const jsdocMatch = before.match(/\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*$/);
|
|
3428
|
-
if (!jsdocMatch) return void 0;
|
|
3429
|
-
const typeExpr = jsdocMatch[1].trim();
|
|
3430
|
-
return normalizeJsDocType(typeExpr);
|
|
3431
|
-
}
|
|
3432
3744
|
function normalizeJsDocType(typeExpr) {
|
|
3433
3745
|
const parts = typeExpr.split("|").map((p) => p.trim());
|
|
3434
3746
|
const normalized = parts.map((p) => {
|
|
@@ -10169,6 +10481,10 @@ function resolveLocale(locale2) {
|
|
|
10169
10481
|
if (locale2 === void 0 || locale2 === "" || /^ja\b|^ja[-_]/i.test(locale2) || locale2.toLowerCase() === "ja") return "ja";
|
|
10170
10482
|
return "en";
|
|
10171
10483
|
}
|
|
10484
|
+
function shortSeed(raw) {
|
|
10485
|
+
const flat = raw.replace(/\s+/g, " ");
|
|
10486
|
+
return flat.length <= 32 ? flat : `${flat.slice(0, 29)}\u2026`;
|
|
10487
|
+
}
|
|
10172
10488
|
var JA_EXPECTED_LABEL = {
|
|
10173
10489
|
array: "\u914D\u5217\u578B\u306E\u30D1\u30B9",
|
|
10174
10490
|
boolean: "\u30D6\u30FC\u30EA\u30A2\u30F3\u578B",
|
|
@@ -10248,7 +10564,11 @@ var ja = {
|
|
|
10248
10564
|
didYouMean: (c) => `\u3002\u3082\u3057\u304B\u3057\u3066: "${c}"`,
|
|
10249
10565
|
none: () => `\u306A\u3057`,
|
|
10250
10566
|
triggerSeededTruthy: (path) => `trigger \u30D0\u30A4\u30F3\u30C9\u5148 "${path}" \u304C true \u3067\u30B7\u30FC\u30C9\u3055\u308C\u3066\u3044\u307E\u3059\u3002trigger \u306F\u30A8\u30C3\u30B8\u691C\u51FA\u306A\u3057\uFF08truthy \u66F8\u304D\u8FBC\u307F\u3067\u5373\u767A\u706B\u30FBmanual \u3082\u30D0\u30A4\u30D1\u30B9\uFF09\u306E\u305F\u3081\u3001\u30D0\u30A4\u30F3\u30C9\u6642\u306B\u5373\u767A\u706B\u3057\u307E\u3059\u3002false \u3067\u30B7\u30FC\u30C9\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
10251
|
-
storageSeedClobber: (path, raw) => `<wcs-storage> \u306E value \u30D0\u30A4\u30F3\u30C9\u5148 "${path}" \u304C ${raw} \u3067\u30B7\u30FC\u30C9\u3055\u308C\u3066\u3044\u307E\u3059\u3002\u521D\u671F\u66F8\u304D\u623B\u3057\u304C\u4FDD\u5B58\u5024\u3092\u4E0A\u66F8\u304D\u3057\u307E\u3059 \u2014
|
|
10567
|
+
storageSeedClobber: (path, raw) => `<wcs-storage> \u306E value \u30D0\u30A4\u30F3\u30C9\u5148 "${path}" \u304C ${raw} \u3067\u30B7\u30FC\u30C9\u3055\u308C\u3066\u3044\u307E\u3059\u3002\u8AAD\u307F\u8FBC\u307F\u306E\u305F\u3073\u306B\u521D\u671F\u66F8\u304D\u623B\u3057\u304C\u4FDD\u5B58\u5024\u3092\u4E0A\u66F8\u304D\u3057\u307E\u3059 \u2014 \u30D0\u30A4\u30F3\u30C9\u306B #init=element \u3092\u4ED8\u3051\u3066\uFF08\`value#init=element: ${path}\`\uFF09\u4FDD\u5B58\u5024\u3092\u52DD\u305F\u305B\u3001\u30B9\u30ED\u30C3\u30C8\u306F null\uFF08\u7A7A\u306E\u30AD\u30FC\u304C\u8AAD\u3080\u5024\uFF09\u3067\u30B7\u30FC\u30C9\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
10568
|
+
storageInitSeed: (path, raw) => `<wcs-storage> \u306E value \u30D0\u30A4\u30F3\u30C9\u5148 "${path}" \u304C ${shortSeed(raw)} \u3067\u30B7\u30FC\u30C9\u3055\u308C\u3066\u3044\u307E\u3059\u304C\u3001#init=element \u306F\u8981\u7D20\u306E\u5024\u3092\u3053\u306E\u30B9\u30ED\u30C3\u30C8\u3078\u5F15\u304D\u8FBC\u307F\u307E\u3059\u3002\u521D\u56DE\uFF08\u7A7A\u306E\u30AD\u30FC\uFF09\u306F null \u306A\u306E\u3067\u3001\u30B7\u30FC\u30C9\u306F null \u306B\u7F6E\u304D\u63DB\u308F\u308A\u307E\u3059 \u2014 null \u3067\u30B7\u30FC\u30C9\u3057\u3066\u8AAD\u3080\u5074\u3067\u65E2\u5B9A\u5024\u3092\u88DC\u3046\uFF08\`this.${path} ?? \u2026\`\uFF09\u304B\u3001null \u3092\u7121\u8996\u3059\u308B setter \u3092\u6301\u3064\u30A2\u30AF\u30BB\u30B5\u30DA\u30A2\u3092\u675F\u306D\u3066\u304F\u3060\u3055\u3044`,
|
|
10569
|
+
storagePairClobber: (path) => `<wcs-storage> \u306E value \u3092 #init=element \u306A\u3057\u3067\u30A2\u30AF\u30BB\u30B5\u30DA\u30A2 "${path}" \u306B\u675F\u306D\u3066\u3044\u307E\u3059\u3002state \u306E\u5074\u304C\u5148\u306B\u66F8\u304F\u306E\u3067\u3001\u8AAD\u307F\u8FBC\u307F\u306E\u305F\u3073\u306B getter \u306E\u6700\u521D\u306E\u5024\u304C\u4FDD\u5B58\u5024\u306E\u4E0A\u306B\u4FDD\u5B58\u3055\u308C\u3001setter \u306F\u4FDD\u5B58\u5024\u3092\u53D7\u3051\u53D6\u308C\u307E\u305B\u3093 \u2014 #init=element \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\uFF08\`value#init=element: ${path}\`\uFF09`,
|
|
10570
|
+
inputNestedWrite: (tag, input, path, example) => `<${tag}> \u306E\u5165\u529B "${input}" \u306B "${path}" \u3092\u675F\u306D\u3066\u3044\u307E\u3059\u304C\u3001\u30DA\u30FC\u30B8\u306F\u305D\u306E\u4E0B\uFF08"${example}"\uFF09\u3078\u66F8\u304D\u8FBC\u3093\u3067\u3044\u307E\u3059\u3002\u675F\u7E1B\u306F "${path}" \u81EA\u8EAB\u3078\u306E\u4EE3\u5165\u3067\u3057\u304B\u5F53\u3066\u76F4\u3055\u308C\u306A\u3044\u306E\u3067\u3001\u4E0B\u3078\u306E\u66F8\u304D\u8FBC\u307F\u306F <${tag}> \u306B\u5C4A\u304D\u307E\u305B\u3093 \u2014 \u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u30D1\u30B9\u3067\u8AAD\u3093\u3067\u65B0\u3057\u3044\u5024\u3092\u8FD4\u3059 getter\uFF08\`this["${example}"]\`\u30FB\`$getAll\`\uFF09\u3092\u675F\u306D\u308B\u304B\u3001\u4E0B\u3078\u66F8\u304B\u305A\u306B "${path}" \u3092\u5DEE\u3057\u66FF\u3048\u3066\u304F\u3060\u3055\u3044`,
|
|
10571
|
+
inputNestedWriteOneShot: (tag, input, path, example) => `<${tag}> \u306E\u5165\u529B "${input}" \u306B "${path}" \u3092\u675F\u306D\u3066\u3044\u307E\u3059\u304C\u3001\u30DA\u30FC\u30B8\u306F\u305D\u306E\u4E0B\uFF08"${example}"\uFF09\u3078\u66F8\u304D\u8FBC\u3093\u3067\u3044\u307E\u3059\u3002\u675F\u7E1B\u306F "${path}" \u81EA\u8EAB\u3078\u306E\u4EE3\u5165\u3067\u3057\u304B\u5F53\u3066\u76F4\u3055\u308C\u305A\u3001<${tag}> \u306F\u8981\u6C42\u306E\u305F\u3073\u306B "${input}" \u3092 null \u306B\u623B\u3059\u306E\u3067\u3001\u6B21\u306E\u8981\u6C42\u306F "${input}" \u306A\u3057\u3067\u9001\u3089\u308C\u307E\u3059 \u2014 \u8981\u6C42\u3092\u59CB\u3081\u308B\u30CF\u30F3\u30C9\u30E9\u3067\u65B0\u3057\u3044\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u4F5C\u3063\u3066\u4EE3\u5165\u3057\uFF08\`this.submitBody = { \u2026 }\`\uFF09\u3001\u305D\u308C\u3092\u675F\u306D\u3066\u304F\u3060\u3055\u3044`,
|
|
10252
10572
|
devtoolsAfterState: () => `@wcstack/devtools/auto \u306F @wcstack/state/auto \u3088\u308A\u5148\u306B\u8AAD\u307F\u8FBC\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u5F8C\u3060\u3068\u914D\u7DDA\u53F0\u5E33\u304C\u30E9\u30A4\u30D6\u3067 captured \u3055\u308C\u307E\u305B\u3093\uFF09`,
|
|
10253
10573
|
baseHrefMissing: () => `@wcstack/router \u3092\u4F7F\u3046 SPA \u306B\u306F <head> \u5185\u306E <base href="/"> \u304C\u5FC5\u8981\u3067\u3059\uFF08\u7121\u3044\u3068\u30C7\u30A3\u30FC\u30D7\u30EA\u30F3\u30AF\u3067 basename \u304C\u8AA4\u5C0E\u51FA\u3055\u308C\u307E\u3059\uFF09`,
|
|
10254
10574
|
signalsDualEntry: () => `@wcstack/signals \u3068 @wcstack/signals/dom \u304C\u540C\u4E00\u30DA\u30FC\u30B8\u304B\u3089 import \u3055\u308C\u3066\u3044\u307E\u3059\u3002CDN \u3067\u306F\u5404\u30A8\u30F3\u30C8\u30EA\u304C\u81EA\u5DF1\u5B8C\u7D50\u30D0\u30F3\u30C9\u30EB\u306E\u305F\u3081\u30EA\u30A2\u30AF\u30C6\u30A3\u30D6\u30B3\u30A2\u304C\u4E8C\u91CD\u5316\u3057\u3001\u5883\u754C\u3067\u53CD\u5FDC\u304C\u58CA\u308C\u307E\u3059 \u2014 \u3059\u3079\u3066 /dom \u30A8\u30F3\u30C8\u30EA\u304B\u3089 import \u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
@@ -10434,7 +10754,11 @@ var en = {
|
|
|
10434
10754
|
didYouMean: (c) => `. Did you mean "${c}"?`,
|
|
10435
10755
|
none: () => `none`,
|
|
10436
10756
|
triggerSeededTruthy: (path) => `The trigger-bound slot "${path}" is seeded with true. trigger has no edge detection (any truthy write fires, and it bypasses manual), so it fires immediately at bind. Seed it with false`,
|
|
10437
|
-
storageSeedClobber: (path, raw) => `The <wcs-storage> value-bound slot "${path}" is seeded with ${raw}. The initial write-back overwrites the persisted value \u2014
|
|
10757
|
+
storageSeedClobber: (path, raw) => `The <wcs-storage> value-bound slot "${path}" is seeded with ${raw}. The initial write-back overwrites the persisted value on every load \u2014 add #init=element to the binding (\`value#init=element: ${path}\`) so the stored value wins, and seed the slot with null (what an empty key loads as)`,
|
|
10758
|
+
storageInitSeed: (path, raw) => `The <wcs-storage> value-bound slot "${path}" is seeded with ${shortSeed(raw)}, but #init=element pulls the element's value into it. On a first visit (an empty key) that is null, so the seed is replaced by null \u2014 seed it with null and supply the default where you read it (\`this.${path} ?? \u2026\`), or bind an accessor pair whose setter ignores null`,
|
|
10759
|
+
storagePairClobber: (path) => `The <wcs-storage> value is bound to the accessor pair "${path}" without #init=element. The state's side goes first, so on every load the getter's starting value is saved over the stored one, and the setter never receives it \u2014 add #init=element (\`value#init=element: ${path}\`)`,
|
|
10760
|
+
inputNestedWrite: (tag, input, path, example) => `"${path}" is bound to the input "${input}" of <${tag}>, but the page writes below it ("${example}"). A binding is re-applied only when "${path}" itself is assigned, so those writes never reach <${tag}> \u2014 bind a getter that reads the fields by path (\`this["${example}"]\`, \`$getAll\`) and returns a new value, or replace "${path}" instead of writing below it`,
|
|
10761
|
+
inputNestedWriteOneShot: (tag, input, path, example) => `"${path}" is bound to the input "${input}" of <${tag}>, but the page writes below it ("${example}"). A binding is re-applied only when "${path}" itself is assigned, and <${tag}> resets "${input}" to null after every request, so the next request goes without it \u2014 build a new object in the handler that starts the request (\`this.submitBody = { \u2026 }\`) and bind that`,
|
|
10438
10762
|
devtoolsAfterState: () => `Load @wcstack/devtools/auto BEFORE @wcstack/state/auto (otherwise the wiring ledger is not captured live)`,
|
|
10439
10763
|
baseHrefMissing: () => `An SPA using @wcstack/router needs <base href="/"> in <head> (without it, deep links misderive the basename)`,
|
|
10440
10764
|
signalsDualEntry: () => `Both @wcstack/signals and @wcstack/signals/dom are imported on this page. On a CDN each entry is a self-contained bundle, so the reactive core is duplicated and reactivity breaks at the seam \u2014 import everything from the single /dom entry`,
|
|
@@ -11571,18 +11895,24 @@ function validateStateTypes(html, stateTagName = "wcs-state", locale2) {
|
|
|
11571
11895
|
}
|
|
11572
11896
|
return diagnostics;
|
|
11573
11897
|
}
|
|
11898
|
+
var PROPERTY_AFTER_COMMENT = /^\s*(?:"([^"]+)"|'([^']+)'|(\w+))\s*:\s*/;
|
|
11574
11899
|
function findJsDocTypedProperties(script) {
|
|
11575
11900
|
const results = [];
|
|
11576
|
-
const
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
const
|
|
11580
|
-
|
|
11581
|
-
const
|
|
11901
|
+
const scan = maskCommentsAndStrings(script);
|
|
11902
|
+
const typedefs = script.includes("@typedef") ? collectJsDocTypedefs(script, scan) : /* @__PURE__ */ new Map();
|
|
11903
|
+
for (const comment of findJsDocComments(script, scan)) {
|
|
11904
|
+
const typeText = readJsDocTagType(comment.text, "type");
|
|
11905
|
+
if (typeText === null) continue;
|
|
11906
|
+
const match = PROPERTY_AFTER_COMMENT.exec(script.slice(comment.end));
|
|
11907
|
+
if (!match) continue;
|
|
11908
|
+
const rawType = typeText.replace(/\s+/g, " ");
|
|
11909
|
+
const name = match[1] ?? match[2] ?? match[3];
|
|
11910
|
+
const valueStart = comment.end + match[0].length;
|
|
11582
11911
|
const valueText = extractValue(script, valueStart);
|
|
11583
11912
|
const valueType = inferValueType(valueText);
|
|
11584
11913
|
if (valueType) {
|
|
11585
|
-
const declaredTypes = rawType
|
|
11914
|
+
const declaredTypes = declaredTypesOf(rawType, typedefs);
|
|
11915
|
+
if (declaredTypes === null) continue;
|
|
11586
11916
|
results.push({
|
|
11587
11917
|
name,
|
|
11588
11918
|
rawType,
|
|
@@ -11595,6 +11925,20 @@ function findJsDocTypedProperties(script) {
|
|
|
11595
11925
|
}
|
|
11596
11926
|
return results;
|
|
11597
11927
|
}
|
|
11928
|
+
var ANY_TYPES = /* @__PURE__ */ new Set(["any", "unknown", "*"]);
|
|
11929
|
+
function declaredTypesOf(rawType, typedefs) {
|
|
11930
|
+
if (rawType.split("|").some((t) => ANY_TYPES.has(t.trim().toLowerCase()))) return null;
|
|
11931
|
+
const parsed = parseJsDocType(rawType);
|
|
11932
|
+
if (parsed === null) return rawType.split("|").map((t) => normalizeType(t.trim()));
|
|
11933
|
+
const out = [];
|
|
11934
|
+
for (const member of flattenJsDocType(parsed, typedefs)) {
|
|
11935
|
+
if (member.kind === "unknown") return null;
|
|
11936
|
+
if (member.kind === "array") out.push("array");
|
|
11937
|
+
else if (member.kind === "object") out.push("object");
|
|
11938
|
+
else if (member.kind === "name") out.push(normalizeType(member.name));
|
|
11939
|
+
}
|
|
11940
|
+
return out;
|
|
11941
|
+
}
|
|
11598
11942
|
function extractValue(script, start) {
|
|
11599
11943
|
let depth = 0;
|
|
11600
11944
|
let inString = null;
|
|
@@ -13615,7 +13959,8 @@ function validateBindingAgainstContract(tagName, contract, parsed, property, sta
|
|
|
13615
13959
|
}
|
|
13616
13960
|
}
|
|
13617
13961
|
if (tagName === "wcs-storage" && property === "value" && !hasManual && parsed.path && !/(?:^|,)init=(?:element|auto)\b/.test(modifiers)) {
|
|
13618
|
-
const
|
|
13962
|
+
const paths = getPaths();
|
|
13963
|
+
const cand = findDataSlot(paths, parsed.path);
|
|
13619
13964
|
if (cand?.rawInitial !== void 0 && EMPTYISH_SEEDS.has(normalizeSeed(cand.rawInitial))) {
|
|
13620
13965
|
diagnostics.push({
|
|
13621
13966
|
code: WcsDiagnosticCode.StorageSeedClobber,
|
|
@@ -13626,9 +13971,37 @@ function validateBindingAgainstContract(tagName, contract, parsed, property, sta
|
|
|
13626
13971
|
statePath: parsed.path,
|
|
13627
13972
|
message: msgs.storageSeedClobber(parsed.path, cand.rawInitial)
|
|
13628
13973
|
});
|
|
13974
|
+
} else if (cand === void 0 && paths.some((c) => c.kind === "computed" && c.settable && c.path === parsed.path)) {
|
|
13975
|
+
diagnostics.push({
|
|
13976
|
+
code: WcsDiagnosticCode.StorageSeedClobber,
|
|
13977
|
+
start,
|
|
13978
|
+
end,
|
|
13979
|
+
severity: "warning",
|
|
13980
|
+
tag: tagName,
|
|
13981
|
+
statePath: parsed.path,
|
|
13982
|
+
message: msgs.storagePairClobber(parsed.path)
|
|
13983
|
+
});
|
|
13984
|
+
}
|
|
13985
|
+
}
|
|
13986
|
+
if (tagName === "wcs-storage" && property === "value" && parsed.path && /(?:^|,)init=element\b/.test(modifiers)) {
|
|
13987
|
+
const cand = findDataSlot(getPaths(), parsed.path);
|
|
13988
|
+
if (cand?.rawInitial !== void 0 && isNonNullLiteralSeed(cand.rawInitial)) {
|
|
13989
|
+
diagnostics.push({
|
|
13990
|
+
code: WcsDiagnosticCode.StorageInitSeed,
|
|
13991
|
+
start,
|
|
13992
|
+
end,
|
|
13993
|
+
severity: "warning",
|
|
13994
|
+
tag: tagName,
|
|
13995
|
+
statePath: parsed.path,
|
|
13996
|
+
message: msgs.storageInitSeed(parsed.path, cand.rawInitial)
|
|
13997
|
+
});
|
|
13629
13998
|
}
|
|
13630
13999
|
}
|
|
13631
14000
|
}
|
|
14001
|
+
function isNonNullLiteralSeed(raw) {
|
|
14002
|
+
const v = raw.trim();
|
|
14003
|
+
return /^(?:["'`[{]|-?\d)/.test(v) || v === "true" || v === "false";
|
|
14004
|
+
}
|
|
13632
14005
|
function findDataSlot(paths, path) {
|
|
13633
14006
|
return paths.find((c) => c.kind === "data" && c.path === path);
|
|
13634
14007
|
}
|
|
@@ -13765,10 +14138,10 @@ function validateDocumentEnv(html, locale2) {
|
|
|
13765
14138
|
const msgs = getMessages(locale2);
|
|
13766
14139
|
const scanText = blankHtmlComments(html);
|
|
13767
14140
|
const autos = findWcstackAutoScripts(scanText);
|
|
13768
|
-
const stateIndex = autos.findIndex((a) => a.
|
|
14141
|
+
const stateIndex = autos.findIndex((a) => a.pkgs.includes("state"));
|
|
13769
14142
|
if (stateIndex !== -1) {
|
|
13770
14143
|
for (const later of autos.slice(stateIndex + 1)) {
|
|
13771
|
-
if (later.
|
|
14144
|
+
if (!later.pkgs.includes("devtools")) continue;
|
|
13772
14145
|
diagnostics.push({
|
|
13773
14146
|
code: WcsDiagnosticCode.ScriptOrder,
|
|
13774
14147
|
start: later.start,
|
|
@@ -13778,7 +14151,7 @@ function validateDocumentEnv(html, locale2) {
|
|
|
13778
14151
|
});
|
|
13779
14152
|
}
|
|
13780
14153
|
}
|
|
13781
|
-
const router = autos.find((a) => a.
|
|
14154
|
+
const router = autos.find((a) => a.pkgs.includes("router") && (!a.bundle || /<wcs-router\b/i.test(scanText)));
|
|
13782
14155
|
if (router && !/<base\b[^>]*\bhref\s*=/i.test(scanText)) {
|
|
13783
14156
|
diagnostics.push({
|
|
13784
14157
|
code: WcsDiagnosticCode.BaseHrefMissing,
|
|
@@ -13803,6 +14176,9 @@ function validateDocumentEnv(html, locale2) {
|
|
|
13803
14176
|
}
|
|
13804
14177
|
return diagnostics;
|
|
13805
14178
|
}
|
|
14179
|
+
var SCOPED_AUTO = /@wcstack\/([a-z0-9-]+)(?:@[^/"'\s]+)?\/(?:auto\b|dist\/(?:split\/)?auto(?:\.min)?\.js\b)/;
|
|
14180
|
+
var BUNDLE_AUTO = /(?:^|\/)wcstack(?:@[^/"'\s]+)?\/(?:auto\b|dist\/auto\.min\.js\b)/;
|
|
14181
|
+
var BUNDLE_PACKAGES = ["state", "router", "fetch", "storage", "autoloader"];
|
|
13806
14182
|
function findWcstackAutoScripts(html) {
|
|
13807
14183
|
const out = [];
|
|
13808
14184
|
const scriptRegex = /<script\b(?:"[^"]*"|'[^']*'|[^>"'])*>/gi;
|
|
@@ -13810,10 +14186,12 @@ function findWcstackAutoScripts(html) {
|
|
|
13810
14186
|
while ((match = scriptRegex.exec(html)) !== null) {
|
|
13811
14187
|
const src = extractSrc(match[0]);
|
|
13812
14188
|
if (!src) continue;
|
|
13813
|
-
const pkgMatch =
|
|
13814
|
-
|
|
14189
|
+
const pkgMatch = SCOPED_AUTO.exec(src.value);
|
|
14190
|
+
const bundle = pkgMatch === null && BUNDLE_AUTO.test(src.value);
|
|
14191
|
+
if (pkgMatch === null && !bundle) continue;
|
|
13815
14192
|
out.push({
|
|
13816
|
-
|
|
14193
|
+
pkgs: bundle ? BUNDLE_PACKAGES : [pkgMatch[1]],
|
|
14194
|
+
bundle,
|
|
13817
14195
|
start: match.index + src.offsetInTag,
|
|
13818
14196
|
end: match.index + src.offsetInTag + src.value.length
|
|
13819
14197
|
});
|
|
@@ -15271,15 +15649,65 @@ function validateGetterUntrackedReads(script, scriptStart, nestedWriteRoots, loc
|
|
|
15271
15649
|
}
|
|
15272
15650
|
return out;
|
|
15273
15651
|
}
|
|
15652
|
+
var NESTED_WRITE_INPUTS = {
|
|
15653
|
+
"wcs-storage": { inputs: ["value"], exemptWhenManual: true },
|
|
15654
|
+
"wcs-fetch": { inputs: ["body"], exemptWhenManual: false, oneShot: true }
|
|
15655
|
+
};
|
|
15656
|
+
var MANUAL_ATTRIBUTE = /(?:^|\s)manual(?:\s|=|$)/i;
|
|
15657
|
+
function validateInputNestedWrites(html, stateTagName, bindAttrName, nestedWriteRoots, locale2) {
|
|
15658
|
+
const tags = findBuiltinTagOccurrences(html).filter((occ) => {
|
|
15659
|
+
const target = NESTED_WRITE_INPUTS[occ.tagName];
|
|
15660
|
+
return target !== void 0 && !(target.exemptWhenManual && MANUAL_ATTRIBUTE.test(occ.attrsText));
|
|
15661
|
+
}).map((occ) => ({ tagName: occ.tagName, start: occ.tagStart, end: occ.attrsStart + occ.attrsText.length }));
|
|
15662
|
+
if (tags.length === 0) return [];
|
|
15663
|
+
const msgs = getMessages(locale2);
|
|
15664
|
+
const out = [];
|
|
15665
|
+
const index = buildReferenceIndex(html, { bindAttribute: bindAttrName, stateTagName });
|
|
15666
|
+
for (const occ of index.occurrences) {
|
|
15667
|
+
if (occ.kind !== "path" || occ.source !== "attribute" || occ.bindingType !== "prop" || occ.propName === null) continue;
|
|
15668
|
+
if (occ.path.startsWith(".")) continue;
|
|
15669
|
+
const at2 = occ.exprRange.start;
|
|
15670
|
+
const tag = tags.find((t) => t.start <= at2 && at2 <= t.end);
|
|
15671
|
+
if (tag === void 0) continue;
|
|
15672
|
+
const input = occ.propName.startsWith(".") ? occ.propName.slice(1) : occ.propName;
|
|
15673
|
+
if (!NESTED_WRITE_INPUTS[tag.tagName].inputs.includes(input)) continue;
|
|
15674
|
+
const example = nestedWriteRoots().get(occ.path);
|
|
15675
|
+
if (example === void 0) continue;
|
|
15676
|
+
const message = NESTED_WRITE_INPUTS[tag.tagName].oneShot ? msgs.inputNestedWriteOneShot(tag.tagName, input, occ.path, example) : msgs.inputNestedWrite(tag.tagName, input, occ.path, example);
|
|
15677
|
+
out.push({
|
|
15678
|
+
code: WcsDiagnosticCode.InputNestedWrite,
|
|
15679
|
+
start: occ.pathRange.start,
|
|
15680
|
+
end: occ.pathRange.end,
|
|
15681
|
+
severity: "warning",
|
|
15682
|
+
tag: tag.tagName,
|
|
15683
|
+
statePath: occ.path,
|
|
15684
|
+
message
|
|
15685
|
+
});
|
|
15686
|
+
}
|
|
15687
|
+
return out;
|
|
15688
|
+
}
|
|
15274
15689
|
var TWO_WAY_PROPS = /* @__PURE__ */ new Set(["value", "checked"]);
|
|
15275
15690
|
var BRACKET_WRITE = new RegExp(`${ROOT_BRACKET}${ASSIGN_TAIL}`, "g");
|
|
15276
15691
|
var PRE_BRACKET_INCDEC2 = new RegExp(`${PRE_INCDEC}${ROOT_BRACKET}`, "g");
|
|
15692
|
+
var TEMPLATE_BRACKET = String.raw`\bthis\s*(?:\?\.)?\s*\[\s*` + "`([^`]*)`" + String.raw`\s*\]`;
|
|
15693
|
+
var TEMPLATE_BRACKET_WRITE = new RegExp(`${TEMPLATE_BRACKET}${ASSIGN_TAIL}`, "g");
|
|
15694
|
+
var PRE_TEMPLATE_BRACKET_INCDEC = new RegExp(`${PRE_INCDEC}${TEMPLATE_BRACKET}`, "g");
|
|
15695
|
+
var TEMPLATE_KEY_PATH = /^[A-Za-z_][\w]*(?:\.(?:\*|[\w]+))*$/;
|
|
15696
|
+
function templateKeyPath(raw) {
|
|
15697
|
+
if (raw.includes("`")) return null;
|
|
15698
|
+
const path = raw.replace(/\$\{[^{}]*\}/g, "*");
|
|
15699
|
+
return TEMPLATE_KEY_PATH.test(path) ? path : null;
|
|
15700
|
+
}
|
|
15277
15701
|
function collectNestedWriteRoots(html, stateTagName, bindAttrName, blocks) {
|
|
15278
|
-
const roots = /* @__PURE__ */ new
|
|
15702
|
+
const roots = /* @__PURE__ */ new Map();
|
|
15279
15703
|
const addPrefixes = (path, inclusive) => {
|
|
15280
15704
|
const segments = path.split(".");
|
|
15281
15705
|
const last = inclusive ? segments.length : segments.length - 1;
|
|
15282
|
-
|
|
15706
|
+
const example = inclusive ? `${path}.*` : path;
|
|
15707
|
+
for (let i = 1; i <= last; i++) {
|
|
15708
|
+
const prefix = segments.slice(0, i).join(".");
|
|
15709
|
+
if (!roots.has(prefix)) roots.set(prefix, example);
|
|
15710
|
+
}
|
|
15283
15711
|
};
|
|
15284
15712
|
const tags = findBuiltinTagOccurrences(html).map((occ) => ({
|
|
15285
15713
|
contract: BUILTIN_TAGS[occ.tagName],
|
|
@@ -15288,23 +15716,29 @@ function collectNestedWriteRoots(html, stateTagName, bindAttrName, blocks) {
|
|
|
15288
15716
|
}));
|
|
15289
15717
|
const index = buildReferenceIndex(html, { bindAttribute: bindAttrName, stateTagName });
|
|
15290
15718
|
for (const occ of index.occurrences) {
|
|
15291
|
-
if (occ.kind !== "path" || occ.
|
|
15719
|
+
if (occ.kind !== "path" || occ.source !== "attribute") continue;
|
|
15720
|
+
let path = occ.path;
|
|
15721
|
+
if (path.startsWith(".")) {
|
|
15722
|
+
const list = getRowShorthandForPath(html, occ.pathRange.start, bindAttrName) === null ? null : getResolvedForListPath(html, occ.pathRange.start, bindAttrName);
|
|
15723
|
+
if (list === null) continue;
|
|
15724
|
+
path = path === "." ? `${list}.*` : `${list}.*.${path.slice(1)}`;
|
|
15725
|
+
}
|
|
15292
15726
|
if (occ.bindingType === "spread") {
|
|
15293
|
-
addPrefixes(
|
|
15727
|
+
addPrefixes(path, true);
|
|
15294
15728
|
continue;
|
|
15295
15729
|
}
|
|
15296
15730
|
if (occ.bindingType === "radio" || occ.bindingType === "checkbox") {
|
|
15297
|
-
addPrefixes(
|
|
15731
|
+
addPrefixes(path, false);
|
|
15298
15732
|
continue;
|
|
15299
15733
|
}
|
|
15300
15734
|
if (occ.bindingType !== "prop" || occ.propName === null) continue;
|
|
15301
15735
|
if (TWO_WAY_PROPS.has(occ.propName)) {
|
|
15302
|
-
addPrefixes(
|
|
15736
|
+
addPrefixes(path, false);
|
|
15303
15737
|
continue;
|
|
15304
15738
|
}
|
|
15305
15739
|
const at2 = occ.exprRange.start;
|
|
15306
15740
|
const tag = tags.find((t) => t.start <= at2 && at2 <= t.end);
|
|
15307
|
-
if (tag?.contract?.hasWcBindable && tag.contract.properties.includes(occ.propName)) addPrefixes(
|
|
15741
|
+
if (tag?.contract?.hasWcBindable && tag.contract.properties.includes(occ.propName)) addPrefixes(path, false);
|
|
15308
15742
|
}
|
|
15309
15743
|
for (const block of blocks) {
|
|
15310
15744
|
if (block.mountPath !== null) addPrefixes(block.mountPath, true);
|
|
@@ -15317,6 +15751,15 @@ function collectNestedWriteRoots(html, stateTagName, bindAttrName, blocks) {
|
|
|
15317
15751
|
addPrefixes(block.content.slice(keyStart, keyStart + match[1].length), false);
|
|
15318
15752
|
}
|
|
15319
15753
|
}
|
|
15754
|
+
for (const regex of [TEMPLATE_BRACKET_WRITE, PRE_TEMPLATE_BRACKET_INCDEC]) {
|
|
15755
|
+
regex.lastIndex = 0;
|
|
15756
|
+
let match;
|
|
15757
|
+
while ((match = regex.exec(scan)) !== null) {
|
|
15758
|
+
const keyStart = match.index + match[0].indexOf("`") + 1;
|
|
15759
|
+
const path = templateKeyPath(block.content.slice(keyStart, keyStart + match[1].length));
|
|
15760
|
+
if (path !== null) addPrefixes(path, false);
|
|
15761
|
+
}
|
|
15762
|
+
}
|
|
15320
15763
|
API_CALL.lastIndex = 0;
|
|
15321
15764
|
let call;
|
|
15322
15765
|
while ((call = API_CALL.exec(scan)) !== null) {
|
|
@@ -15432,6 +15875,7 @@ function validateSemantics(html, stateTagName = "wcs-state", locale2, bindAttrNa
|
|
|
15432
15875
|
out.push(...validateGetterCycles(block.content, block.contentStart, locale2));
|
|
15433
15876
|
out.push(...validateGetterUntrackedReads(block.content, block.contentStart, getNestedWriteRoots, locale2));
|
|
15434
15877
|
}
|
|
15878
|
+
out.push(...validateInputNestedWrites(html, stateTagName, bindAttrName, getNestedWriteRoots, locale2));
|
|
15435
15879
|
out.push(...validateUpdatedCallbackDemand(html, stateTagName, bindAttrName, locale2));
|
|
15436
15880
|
return out;
|
|
15437
15881
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/lint",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Static-contract validator CLI (wcs-validate) for wcstack data-wcs bindings and wcstack.manifest.json sidecars. Thin npm wrapper around the wcstack-intellisense validator core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|