@wcstack/lint 4.7.0 → 4.9.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/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/cli.cjs +164 -29
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -66,7 +66,7 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
66
66
|
|
|
67
67
|
## state の契約を宣言する(`stateSchema`)
|
|
68
68
|
|
|
69
|
-
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count` は実行時には存在するかもしれないからです。`[]`
|
|
69
|
+
契約が無いと、validator が解決できないパスは **warning**(`wcs/binding-path-missing`)に留まります: インラインスクリプトが静的に読めなくても `count` は実行時には存在するかもしれないからです。`[]` で始まるリストの行のフィールドは、行を足す・置き換える代入式の行リテラルから読みます。4.9 から、`map` で行を作り直す代入 — `this.rows = [...this.items].map((c) => ({ id: c.id, label: c.name }))`・`.filter(…).map((c) => { return { … }; })` — も、そうする getter と同じく読み、`{}` を種にしたキーへ代入したオブジェクトリテラルのキーも読みます(`this.fieldErrors = { date: "…" }` で `fieldErrors.date`。リテラルの中の spread は追いません)。外から届くリスト(`<wcs-fetch>` や `<wcs-storage>` が埋めるまで `null`)にはそのリテラルが無いので、プロパティの直前の JSDoc `@type` で形を宣言してください(`/** @type {{ id: number, name: string }[] | null} */ catalog: null`)。同じスクリプトの `@typedef` で行の型に名前を付け、`@type {Product[] | null}` と書いてもかまいません。HTML と同じ(または上の)ディレクトリに `application` sidecar を置くと、同じ typo が **error** になります:
|
|
70
70
|
|
|
71
71
|
```json
|
|
72
72
|
{
|
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ A framework app (React, Vue) that uses the `<wcs-*>` elements has neither: its p
|
|
|
66
66
|
|
|
67
67
|
## Declaring a state contract (`stateSchema`)
|
|
68
68
|
|
|
69
|
-
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**:
|
|
69
|
+
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. Since 4.9 it also reads an assignment that rebuilds the rows with `map` — `this.rows = [...this.items].map((c) => ({ id: c.id, label: c.name }))`, `.filter(…).map((c) => { return { … }; })` — the way it reads a getter that does, and the keys of an object literal assigned to a key seeded `{}` (`this.fieldErrors = { date: "…" }` gives `fieldErrors.date`; a spread inside the literal is not followed). 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**:
|
|
70
70
|
|
|
71
71
|
```json
|
|
72
72
|
{
|
package/dist/cli.cjs
CHANGED
|
@@ -144,6 +144,9 @@ var WcsDiagnosticCode = {
|
|
|
144
144
|
// (state README「依存追跡の境界」規則 1)。ランタイムは素のアクセスと区別できないので
|
|
145
145
|
// 静的にしか検出できない。対象はオブジェクトリテラル初期値のルートだけ(配列は `items`
|
|
146
146
|
// の依存で足りる — 行の置換は `items` 自体を書き換え、in-place 変異は array-mutation が止める)。
|
|
147
|
+
// 読んだパスをページの束縛(組み込みタグの spread・書き戻す束縛・要素の出力)が書くなら error(その書き込みは
|
|
148
|
+
// getter に届かないと断定できる — 継ぎ目アプリ family-ledger)、スクリプトの書き込みだけなら warning(ルートも
|
|
149
|
+
// 置き換えるなら壊れない)。時刻・`location` を読む getter も同じ code(warning)。
|
|
147
150
|
GetterUntrackedRead: "wcs/getter-untracked-read",
|
|
148
151
|
OnHandlerThis: "wcs/on-handler-this",
|
|
149
152
|
// --- <wcs-state> script: $watch declaration ---
|
|
@@ -786,7 +789,7 @@ var SENTENCES = {
|
|
|
786
789
|
[
|
|
787
790
|
29
|
|
788
791
|
/* FilterValueNotDate */
|
|
789
|
-
]: (fn, v) => `filter ${fn} requires a date value (a Date), not ${was(v)}${typeof v === "string" || typeof v === "number" ? " \u2014 make the Date where it is read: a getter returning new Date(\u2026)" : ""}`,
|
|
792
|
+
]: (fn, v) => `filter ${fn} requires a date value (a Date), not ${was(v)}${typeof v === "string" || typeof v === "number" ? " \u2014 make the Date where it is read: a getter returning new Date(\u2026)" : ""}${typeof v === "string" && /^\d{4}-\d\d-\d\d$/.test(v) ? `. A date-only string is a day, not a moment: new Date(${JSON.stringify(v)}) is midnight UTC, the day before west of Greenwich \u2014 new Date(y, m - 1, d) is that day where the page is` : ""}`,
|
|
790
793
|
[
|
|
791
794
|
52
|
|
792
795
|
/* FilterStyleInvalid */
|
|
@@ -2598,7 +2601,7 @@ function tokenize(text3) {
|
|
|
2598
2601
|
i += 2;
|
|
2599
2602
|
continue;
|
|
2600
2603
|
}
|
|
2601
|
-
if ("{}[]<>()
|
|
2604
|
+
if ("{}[]<>()|&,;:?!*.=".includes(ch)) {
|
|
2602
2605
|
tokens.push({ t: "punct", v: ch });
|
|
2603
2606
|
i++;
|
|
2604
2607
|
continue;
|
|
@@ -2647,6 +2650,7 @@ function parseJsDocType(text3) {
|
|
|
2647
2650
|
const member = parsePostfix();
|
|
2648
2651
|
if (member === null) return null;
|
|
2649
2652
|
members.push(member);
|
|
2653
|
+
if (expect("&")) continue;
|
|
2650
2654
|
if (!expect("|")) break;
|
|
2651
2655
|
}
|
|
2652
2656
|
if (isPunct("=>")) {
|
|
@@ -2810,12 +2814,21 @@ function readBracedType(comment, tag) {
|
|
|
2810
2814
|
return null;
|
|
2811
2815
|
}
|
|
2812
2816
|
function readJsDocTypeBefore(content, propIndex) {
|
|
2817
|
+
const comment = jsDocCommentBefore(content, propIndex);
|
|
2818
|
+
return comment === void 0 ? void 0 : readBracedType(comment, "type")?.type.trim();
|
|
2819
|
+
}
|
|
2820
|
+
function readJsDocReturnsBefore(content, propIndex) {
|
|
2821
|
+
const comment = jsDocCommentBefore(content, propIndex);
|
|
2822
|
+
if (comment === void 0) return void 0;
|
|
2823
|
+
return (readBracedType(comment, "returns") ?? readBracedType(comment, "return"))?.type.trim();
|
|
2824
|
+
}
|
|
2825
|
+
function jsDocCommentBefore(content, propIndex) {
|
|
2813
2826
|
let end = propIndex;
|
|
2814
2827
|
while (end > 0 && /\s/.test(content[end - 1])) end--;
|
|
2815
2828
|
if (!content.startsWith("*/", end - 2)) return void 0;
|
|
2816
2829
|
const start = content.lastIndexOf("/*", end - 2);
|
|
2817
2830
|
if (start === -1 || content[start + 2] !== "*") return void 0;
|
|
2818
|
-
return
|
|
2831
|
+
return content.slice(start, end);
|
|
2819
2832
|
}
|
|
2820
2833
|
function collectJsDocTypedefs(script, scan) {
|
|
2821
2834
|
const typedefs = /* @__PURE__ */ new Map();
|
|
@@ -2874,10 +2887,10 @@ var RESERVED_WATCH_KEY = "$watch";
|
|
|
2874
2887
|
var RESERVED_SCAN_KEY = "$scan";
|
|
2875
2888
|
var RESERVED_RECURSION_KEY = RECURSION_KEY;
|
|
2876
2889
|
function analyzeStatePaths(scriptContent) {
|
|
2877
|
-
const
|
|
2878
|
-
if (!
|
|
2890
|
+
const root = locateDefaultExportObject(scriptContent);
|
|
2891
|
+
if (!root || !root.content) return [];
|
|
2879
2892
|
const paths = [];
|
|
2880
|
-
const topLevelProps = parseTopLevelProperties(
|
|
2893
|
+
const topLevelProps = parseTopLevelProperties(root.content);
|
|
2881
2894
|
const pendingStreamValues = [];
|
|
2882
2895
|
const pendingListKeys = [];
|
|
2883
2896
|
const recursionSpec = specFromRecursionValue(topLevelProps.find((p) => p.name === RESERVED_RECURSION_KEY));
|
|
@@ -2902,6 +2915,7 @@ function analyzeStatePaths(scriptContent) {
|
|
|
2902
2915
|
const settable = !recursive && effective !== "data" && effective.set;
|
|
2903
2916
|
paths.push({ path: prop.name, kind: recursive ? "recursive" : "computed", ...settable ? { settable } : {} });
|
|
2904
2917
|
}
|
|
2918
|
+
if (prop.declaredType !== void 0) pushDeclaredShapePaths(prop.name, prop.declaredType, paths, 0, typedefs);
|
|
2905
2919
|
continue;
|
|
2906
2920
|
}
|
|
2907
2921
|
pushDataPropertyPaths(prop, paths, typedefs);
|
|
@@ -2923,7 +2937,7 @@ function analyzeStatePaths(scriptContent) {
|
|
|
2923
2937
|
}
|
|
2924
2938
|
}
|
|
2925
2939
|
collectRowShapesFromAssignments(scriptContent, paths);
|
|
2926
|
-
collectGetterResultShapes(topLevelProps, effectiveDescriptors, paths);
|
|
2940
|
+
collectGetterResultShapes(scriptContent, root.start, topLevelProps, effectiveDescriptors, paths);
|
|
2927
2941
|
return paths;
|
|
2928
2942
|
}
|
|
2929
2943
|
function specFromRecursionValue(prop) {
|
|
@@ -3335,23 +3349,45 @@ var ROW_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
|
3335
3349
|
]);
|
|
3336
3350
|
var ROW_PICKING_METHODS = /* @__PURE__ */ new Set(["find", "findLast", "at"]);
|
|
3337
3351
|
var MAX_GETTER_SHAPE_PASSES = 4;
|
|
3338
|
-
function collectGetterResultShapes(props, effective, paths) {
|
|
3352
|
+
function collectGetterResultShapes(script, rootStart, props, effective, paths) {
|
|
3339
3353
|
const getters = /* @__PURE__ */ new Map();
|
|
3340
3354
|
for (const prop of props) {
|
|
3341
3355
|
if (prop.kind !== "getter" || prop.accessor !== "get" || prop.value === void 0) continue;
|
|
3342
3356
|
if (prop.name.startsWith("$") || hasRecursionWildcard(prop.name) || effective.get(prop.name) === "data") continue;
|
|
3343
3357
|
getters.set(prop.name, prop);
|
|
3344
3358
|
}
|
|
3359
|
+
const assignments = collectAssignments(script, rootStart, props);
|
|
3345
3360
|
for (let pass = 0; pass < MAX_GETTER_SHAPE_PASSES; pass++) {
|
|
3346
3361
|
const before = paths.length;
|
|
3347
3362
|
for (const [name, prop] of getters) {
|
|
3348
3363
|
const shape = getterResultShape(prop.value, paths);
|
|
3349
3364
|
if (shape !== null) applyResultShape(name, shape, paths);
|
|
3350
3365
|
}
|
|
3366
|
+
const aliasesByBody = /* @__PURE__ */ new Map();
|
|
3367
|
+
for (const assignment of assignments) {
|
|
3368
|
+
let aliases = /* @__PURE__ */ new Map();
|
|
3369
|
+
if (assignment.body !== null) {
|
|
3370
|
+
aliases = aliasesByBody.get(assignment.body) ?? collectAliases(assignment.body, paths);
|
|
3371
|
+
aliasesByBody.set(assignment.body, aliases);
|
|
3372
|
+
}
|
|
3373
|
+
const shape = expressionShape(assignment.expr, paths, aliases);
|
|
3374
|
+
if (shape !== null) applyAssignedShape(assignment.target, shape, paths);
|
|
3375
|
+
}
|
|
3351
3376
|
if (paths.length === before) break;
|
|
3352
3377
|
}
|
|
3353
3378
|
}
|
|
3354
3379
|
function getterResultShape(body, paths) {
|
|
3380
|
+
const scan = maskCommentsAndStrings(body);
|
|
3381
|
+
const aliases = collectAliases(body, paths);
|
|
3382
|
+
const shapes = [];
|
|
3383
|
+
for (const m of scan.matchAll(/\breturn\b/g)) {
|
|
3384
|
+
const start = m.index + m[0].length;
|
|
3385
|
+
const shape = expressionShape(readExpression(body, scan, start), paths, aliases);
|
|
3386
|
+
if (shape !== null) shapes.push(shape);
|
|
3387
|
+
}
|
|
3388
|
+
return shapes.length === 0 ? null : mergeShapes(shapes);
|
|
3389
|
+
}
|
|
3390
|
+
function collectAliases(body, paths) {
|
|
3355
3391
|
const scan = maskCommentsAndStrings(body);
|
|
3356
3392
|
const aliases = /* @__PURE__ */ new Map();
|
|
3357
3393
|
for (const m of scan.matchAll(/\b(?:const|let|var)\s+([$\w]+)\s*=(?![=>])/g)) {
|
|
@@ -3361,13 +3397,36 @@ function getterResultShape(body, paths) {
|
|
|
3361
3397
|
const shape = expressionShape(readExpression(body, scan, start), paths, aliases);
|
|
3362
3398
|
if (shape !== null) aliases.set(name, shape);
|
|
3363
3399
|
}
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3400
|
+
return aliases;
|
|
3401
|
+
}
|
|
3402
|
+
var PLAIN_ASSIGN = new RegExp(String.raw`\bthis\s*(?:\.\s*([$\w]+)|\[\s*["']([^"']+)["']\s*\])\s*=(?![=>])`, "gd");
|
|
3403
|
+
function collectAssignments(script, rootStart, props) {
|
|
3404
|
+
const scan = maskCommentsAndStrings(script);
|
|
3405
|
+
const bodies = props.filter((p) => (p.kind === "getter" || p.kind === "method") && p.value !== void 0 && p.valueStart !== void 0).map((p) => ({ start: rootStart + p.valueStart, body: p.value }));
|
|
3406
|
+
const out = [];
|
|
3407
|
+
PLAIN_ASSIGN.lastIndex = 0;
|
|
3408
|
+
let match;
|
|
3409
|
+
while ((match = PLAIN_ASSIGN.exec(scan)) !== null) {
|
|
3410
|
+
if (/\.\s*$/.test(scan.slice(Math.max(0, match.index - 8), match.index))) continue;
|
|
3411
|
+
const span = match.indices[1] ?? match.indices[2];
|
|
3412
|
+
const target = script.slice(span[0], span[1]);
|
|
3413
|
+
if (target.startsWith("$") || target.includes("*")) continue;
|
|
3414
|
+
const expr = readExpression(script, scan, match.index + match[0].length);
|
|
3415
|
+
const owner = bodies.find((b) => b.start <= match.index && match.index < b.start + b.body.length);
|
|
3416
|
+
out.push({ target, expr, body: owner?.body ?? null });
|
|
3417
|
+
}
|
|
3418
|
+
return out;
|
|
3419
|
+
}
|
|
3420
|
+
function applyAssignedShape(target, shape, paths) {
|
|
3421
|
+
const declared = paths.find((p) => p.path === target);
|
|
3422
|
+
if (declared === void 0 || declared.kind !== "data") return;
|
|
3423
|
+
if (hasPath(paths, `${target}.*`)) {
|
|
3424
|
+
if (shape.isList) applyResultShape(target, shape, paths);
|
|
3425
|
+
return;
|
|
3426
|
+
}
|
|
3427
|
+
if (!shape.isList && declared.rawInitial !== void 0 && isObjectLiteral(declared.rawInitial)) {
|
|
3428
|
+
applyResultShape(target, shape, paths);
|
|
3369
3429
|
}
|
|
3370
|
-
return shapes.length === 0 ? null : mergeShapes(shapes);
|
|
3371
3430
|
}
|
|
3372
3431
|
function readExpression(text3, scan, start) {
|
|
3373
3432
|
let depth = 0;
|
|
@@ -3422,9 +3481,7 @@ function expressionShape(text3, paths, aliases) {
|
|
|
3422
3481
|
}
|
|
3423
3482
|
} else if (scan.startsWith("(")) {
|
|
3424
3483
|
const inner = extractDelimitedContent(expr, scan, 0, "(", ")");
|
|
3425
|
-
|
|
3426
|
-
if (base === null) return null;
|
|
3427
|
-
shape = base;
|
|
3484
|
+
shape = expressionShape(inner, paths, aliases) ?? OPAQUE;
|
|
3428
3485
|
rest = inner.length + 2;
|
|
3429
3486
|
} else {
|
|
3430
3487
|
const base = readBase(expr, scan, aliases, paths);
|
|
@@ -3773,13 +3830,15 @@ function locateDefaultExportObject(script) {
|
|
|
3773
3830
|
const braceIndex = scan.indexOf(match[1], match.index);
|
|
3774
3831
|
return { content: extractBracedContent(script, scan, braceIndex), start: braceIndex + 1 };
|
|
3775
3832
|
}
|
|
3776
|
-
function extractDefaultExportObject(script) {
|
|
3777
|
-
return locateDefaultExportObject(script)?.content ?? null;
|
|
3778
|
-
}
|
|
3779
3833
|
function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
|
|
3780
3834
|
const props = [];
|
|
3781
3835
|
const scan = maskCommentsAndStrings(objectContent);
|
|
3782
|
-
const
|
|
3836
|
+
const params = String.raw`\((?:[^()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*\)`;
|
|
3837
|
+
const dataKey = allowEmptyDataKeys ? String.raw`(?:"([^"]*)"|'([^']*)'|([$\w]+))` : String.raw`(?:"([^"]+)"|'([^']+)'|([$\w]+))`;
|
|
3838
|
+
const regex = new RegExp(
|
|
3839
|
+
String.raw`(?:(?:get|set)\s+(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params}\s*\{)|(?:(?:async\s+)?(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params}\s*\{)|(?:${dataKey}\s*:\s*)`,
|
|
3840
|
+
"gd"
|
|
3841
|
+
);
|
|
3783
3842
|
let match;
|
|
3784
3843
|
while ((match = regex.exec(scan)) !== null) {
|
|
3785
3844
|
const indices = match.indices;
|
|
@@ -3800,6 +3859,8 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
|
|
|
3800
3859
|
if (accessorName) {
|
|
3801
3860
|
const { body, bodyStart } = skipBody();
|
|
3802
3861
|
const accessor = match[0].startsWith("set") ? "set" : "get";
|
|
3862
|
+
const returnsText = accessor === "get" ? readJsDocReturnsBefore(objectContent, match.index) : void 0;
|
|
3863
|
+
const declaredType = returnsText === void 0 ? null : parseJsDocType(returnsText);
|
|
3803
3864
|
props.push({
|
|
3804
3865
|
name: accessorName,
|
|
3805
3866
|
kind: "getter",
|
|
@@ -3807,7 +3868,8 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
|
|
|
3807
3868
|
value: body,
|
|
3808
3869
|
valueStart: bodyStart,
|
|
3809
3870
|
nameStart: nameSpan[0],
|
|
3810
|
-
nameEnd: nameSpan[1]
|
|
3871
|
+
nameEnd: nameSpan[1],
|
|
3872
|
+
...declaredType !== null ? { declaredType } : {}
|
|
3811
3873
|
});
|
|
3812
3874
|
continue;
|
|
3813
3875
|
}
|
|
@@ -10962,6 +11024,7 @@ var ja = {
|
|
|
10962
11024
|
pathReadonlyTwoWay: (p, prop) => `"${p}" \u306F setter \u306E\u7121\u3044 getter \u3067\u3059\u304C\u3001${prop}: \u306F\u8AAD\u8005\u306E\u5165\u529B\u3092\u66F8\u304D\u623B\u3059\u306E\u3067\u3001\u5165\u529B\u306E\u305F\u3073\u306B\u66F8\u304D\u8FBC\u307F\u304C\u5931\u6557\u3057\u307E\u3059\uFF08"${p}" is a getter without a setter\uFF09\u3002setter \u3092\u8DB3\u3059\uFF08set "${p}"(v) { \u2026 }\uFF09\u304B\u3001#ro \u3067\u4E00\u65B9\u5411\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${prop}#ro: ${p}\uFF09`,
|
|
10963
11025
|
submitWithoutPrevent: (h) => `onsubmit \u306B #prevent \u304C\u7121\u304F\u3001"${h}" \u3082 preventDefault \u3092\u547C\u3073\u307E\u305B\u3093\u3002\u30D6\u30E9\u30A6\u30B6\u306F\u30D5\u30A9\u30FC\u30E0\u3082\u9001\u308B\u306E\u3067\u3001\u30DA\u30FC\u30B8\u304C\u8AAD\u307F\u76F4\u3055\u308C\u308B\u304B\u3001router \u304C\u3042\u308C\u3070 GET \u304C\u6B04\u306E\u5024\uFF08\u30D1\u30B9\u30EF\u30FC\u30C9\u3082\uFF09\u3092 URL \u3068\u5C65\u6B74\u306B\u8F09\u305B\u307E\u3059\u3002onsubmit#prevent: ${h} \u3068\u66F8\u304F\u304B\u3001\u30CF\u30F3\u30C9\u30E9\u3067 event.preventDefault() \u3092\u547C\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
10964
11026
|
getterUntrackedRead: (root, sp) => `\u3053\u3053\u3067\u8FFD\u8DE1\u3055\u308C\u308B\u306E\u306F "${root}" \u3060\u3051\u3067\u3059\u3002"${sp}" \u304C\u5909\u308F\u3063\u3066\u3082\u3053\u306E getter \u306F\u518D\u8A55\u4FA1\u3055\u308C\u307E\u305B\u3093\uFF08\u30D1\u30B9\u8AAD\u307F\u53D6\u308A\u306E\u5148\u306E\u7D20\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u30A2\u30AF\u30BB\u30B9\u306F\u8FFD\u8DE1\u3055\u308C\u306A\u3044\uFF09\u3002this["${sp}"] \u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
11027
|
+
getterUntrackedReadBound: (root, sp, binding, tag, written) => `\u3053\u3053\u3067\u8FFD\u8DE1\u3055\u308C\u308B\u306E\u306F "${root}" \u3060\u3051\u3067\u3059\u304C\u3001<${tag}> \u306E\u675F\u7E1B "${binding}" \u306F "${written}" \u3092\u30D1\u30B9\u3067\u66F8\u304D\u307E\u3059\u3002\u305D\u306E\u66F8\u304D\u8FBC\u307F\u306F\u3053\u306E getter \u306B\u5C4A\u304B\u305A\u3001getter \u306F\u524D\u306B\u8A08\u7B97\u3057\u305F\u5024\u3092\u8FD4\u3057\u7D9A\u3051\u307E\u3059\uFF08\u30D1\u30B9\u8AAD\u307F\u53D6\u308A\u306E\u5148\u306E\u7D20\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u30A2\u30AF\u30BB\u30B9\u306F\u8FFD\u8DE1\u3055\u308C\u306A\u3044\uFF09\u3002this["${sp}"] \u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
10965
11028
|
handlerFilterNotAllowed: (prop) => `\u30A4\u30D9\u30F3\u30C8\u30CF\u30F3\u30C9\u30E9 "${prop}" \u306B\u30D5\u30A3\u30EB\u30BF\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
|
|
10966
11029
|
typeExpectation: (label, expected, resultType) => `"${label}" \u306B\u306F${JA_EXPECTED_LABEL[expected]}\u304C\u5FC5\u8981\u3067\u3059\uFF08\u73FE\u5728\u306E\u578B: ${resultType}\uFF09`,
|
|
10967
11030
|
filterUnknown: (n) => `\u30D5\u30A3\u30EB\u30BF "${n}" \u306F\u7D44\u307F\u8FBC\u307F\u30D5\u30A3\u30EB\u30BF\u306B\u5B58\u5728\u3057\u307E\u305B\u3093`,
|
|
@@ -11172,6 +11235,7 @@ var en = {
|
|
|
11172
11235
|
pathReadonlyTwoWay: (p, prop) => `"${p}" is a getter without a setter, and ${prop}: writes back what the reader enters, so every edit fails ("${p}" is a getter without a setter). Add a setter (set "${p}"(v) { \u2026 }), or bind it one way with #ro (${prop}#ro: ${p})`,
|
|
11173
11236
|
submitWithoutPrevent: (h) => `onsubmit has no #prevent and "${h}" does not call preventDefault, so the browser submits the form too: the page reloads, or with the router a GET puts the fields (a password too) in the URL and the history. Write onsubmit#prevent: ${h}, or call event.preventDefault() in the handler`,
|
|
11174
11237
|
getterUntrackedRead: (root, sp) => `Only "${root}" is tracked here: the getter is not re-evaluated when "${sp}" changes (plain property access after a path read is not tracked). Read this["${sp}"] instead`,
|
|
11238
|
+
getterUntrackedReadBound: (root, sp, binding, tag, written) => `Only "${root}" is tracked here, but the binding "${binding}" on <${tag}> writes "${written}" by path: that write never reaches this getter, which keeps returning the value it last computed (plain property access after a path read is not tracked). Read this["${sp}"] instead`,
|
|
11175
11239
|
handlerFilterNotAllowed: (prop) => `Filters cannot be applied to event handler "${prop}"`,
|
|
11176
11240
|
typeExpectation: (label, expected, resultType) => `"${label}" requires ${EN_EXPECTED_LABEL[expected]} (current type: ${resultType})`,
|
|
11177
11241
|
filterUnknown: (n) => `Filter "${n}" is not a built-in filter`,
|
|
@@ -11681,7 +11745,7 @@ function forEachStateMethod(elements, html, fileReader, spelling, fn) {
|
|
|
11681
11745
|
for (const callable of analyzeCallableBodies(script)) {
|
|
11682
11746
|
if (callable.kind !== "method" || spelling !== null && !callable.body.includes(spelling)) continue;
|
|
11683
11747
|
const head = script.slice(callable.end, callable.bodyStart - 1);
|
|
11684
|
-
const params = /\(([
|
|
11748
|
+
const params = /\(([\s\S]*)\)\s*$/.exec(head);
|
|
11685
11749
|
if (params === null) continue;
|
|
11686
11750
|
fn(volume === null ? callable.name : `${volume}.${callable.name}`, params[1], callable.body);
|
|
11687
11751
|
}
|
|
@@ -12101,7 +12165,8 @@ function openTagBefore(html, valueStart) {
|
|
|
12101
12165
|
return lt2 === -1 ? "" : html.slice(lt2, valueStart);
|
|
12102
12166
|
}
|
|
12103
12167
|
function writesBack(attr, prop, written) {
|
|
12104
|
-
|
|
12168
|
+
const modifiers = written.split("#").slice(1).flatMap((part) => part.split(","));
|
|
12169
|
+
if (modifiers.some((modifier) => modifier.trim() === "ro")) return false;
|
|
12105
12170
|
if (prop === "radio" || prop === "checkbox") return true;
|
|
12106
12171
|
const tag = attr.tagName;
|
|
12107
12172
|
if (tag === void 0 || tag.includes("-")) return false;
|
|
@@ -14044,6 +14109,10 @@ var BUILTIN_TAGS = {
|
|
|
14044
14109
|
"withCredentials": "with-credentials",
|
|
14045
14110
|
"events": "events",
|
|
14046
14111
|
"raw": "raw",
|
|
14112
|
+
"autoReconnect": "auto-reconnect",
|
|
14113
|
+
"reconnectInterval": "reconnect-interval",
|
|
14114
|
+
"maxReconnects": "max-reconnects",
|
|
14115
|
+
"staleAfter": "stale-after",
|
|
14047
14116
|
"manual": "manual",
|
|
14048
14117
|
"trigger": null
|
|
14049
14118
|
},
|
|
@@ -14170,6 +14239,14 @@ var BUILTIN_TAGS = {
|
|
|
14170
14239
|
"abort"
|
|
14171
14240
|
]
|
|
14172
14241
|
},
|
|
14242
|
+
"wcs-upload-header": {
|
|
14243
|
+
"package": "upload",
|
|
14244
|
+
"hasWcBindable": false,
|
|
14245
|
+
"observedAttributes": [],
|
|
14246
|
+
"inputs": {},
|
|
14247
|
+
"properties": [],
|
|
14248
|
+
"commands": []
|
|
14249
|
+
},
|
|
14173
14250
|
"wcs-view-transition": {
|
|
14174
14251
|
"package": "view-transition",
|
|
14175
14252
|
"hasWcBindable": true,
|
|
@@ -14234,6 +14311,7 @@ var BUILTIN_TAGS = {
|
|
|
14234
14311
|
"reconnectInterval": "reconnect-interval",
|
|
14235
14312
|
"maxReconnects": "max-reconnects",
|
|
14236
14313
|
"binaryType": "binary-type",
|
|
14314
|
+
"staleAfter": "stale-after",
|
|
14237
14315
|
"manual": "manual",
|
|
14238
14316
|
"trigger": null,
|
|
14239
14317
|
"send": null
|
|
@@ -16457,7 +16535,7 @@ function validateGetterCycles(script, scriptStart, locale2) {
|
|
|
16457
16535
|
}
|
|
16458
16536
|
return out;
|
|
16459
16537
|
}
|
|
16460
|
-
function validateGetterUntrackedReads(script, scriptStart, nestedWriteRoots, locale2) {
|
|
16538
|
+
function validateGetterUntrackedReads(script, scriptStart, mountPath, nestedWriteRoots, bindingWrites, locale2) {
|
|
16461
16539
|
const getters = analyzeCallableBodies(script).filter((entry) => entry.kind === "getter" && entry.accessor === "get");
|
|
16462
16540
|
if (getters.length === 0) return [];
|
|
16463
16541
|
const objectRoots = /* @__PURE__ */ new Set();
|
|
@@ -16475,18 +16553,66 @@ function validateGetterUntrackedReads(script, scriptStart, nestedWriteRoots, loc
|
|
|
16475
16553
|
if (read.written) continue;
|
|
16476
16554
|
const segments = read.callee ? read.chain.slice(0, -1) : read.chain;
|
|
16477
16555
|
if (segments.length < 2 || !objectRoots.has(segments[0])) continue;
|
|
16478
|
-
|
|
16556
|
+
const prefix = mountPath === null ? [] : mountPath.split(".");
|
|
16557
|
+
const write = boundWriteOf([...prefix, ...segments], prefix.length + read.path.split(".").length, bindingWrites());
|
|
16558
|
+
if (write === void 0 && !nestedWriteRoots().has([...prefix, segments[0]].join("."))) continue;
|
|
16559
|
+
const sp = segments.join(".");
|
|
16479
16560
|
out.push({
|
|
16480
16561
|
code: WcsDiagnosticCode.GetterUntrackedRead,
|
|
16481
16562
|
start: scriptStart + getter.bodyStart + read.start,
|
|
16482
16563
|
end: scriptStart + getter.bodyStart + read.end,
|
|
16483
|
-
message: msgs.getterUntrackedRead(segments[0],
|
|
16484
|
-
severity: "warning"
|
|
16564
|
+
message: write === void 0 ? msgs.getterUntrackedRead(segments[0], sp) : msgs.getterUntrackedReadBound(segments[0], sp, write.binding, write.tag, write.path),
|
|
16565
|
+
severity: write === void 0 ? "warning" : "error"
|
|
16485
16566
|
});
|
|
16486
16567
|
}
|
|
16487
16568
|
}
|
|
16488
16569
|
return out;
|
|
16489
16570
|
}
|
|
16571
|
+
function boundWriteOf(segments, tracked, writes) {
|
|
16572
|
+
return writes.find((write) => {
|
|
16573
|
+
const written = write.path.split(".");
|
|
16574
|
+
if (written.length <= tracked || written.length > segments.length) return false;
|
|
16575
|
+
return written.every((s, i) => s === segments[i] || s === "*" && /^\d+$/.test(segments[i]));
|
|
16576
|
+
});
|
|
16577
|
+
}
|
|
16578
|
+
function collectBindingWrites(html, bindAttrName) {
|
|
16579
|
+
const out = [];
|
|
16580
|
+
const ignored = findIgnoredRanges(html, bindAttrName);
|
|
16581
|
+
for (const attr of findAllBindAttributes(html, bindAttrName)) {
|
|
16582
|
+
if (ignored.some(([start, end]) => attr.valueStart >= start && attr.valueStart < end)) continue;
|
|
16583
|
+
const tag = attr.tagName ?? "";
|
|
16584
|
+
const contract = BUILTIN_TAGS[tag];
|
|
16585
|
+
const outputs = contract?.hasWcBindable === true ? contract.properties : null;
|
|
16586
|
+
const bindings = parseBindTextWithPositions(attr.value);
|
|
16587
|
+
bindings.forEach((binding, index) => {
|
|
16588
|
+
const parsed = binding.parsed;
|
|
16589
|
+
if (parsed === null || binding.pathRange === null) return;
|
|
16590
|
+
let path = parsed.statePathName;
|
|
16591
|
+
if (path.startsWith(".")) {
|
|
16592
|
+
const at2 = attr.valueStart + binding.pathRange.start;
|
|
16593
|
+
const list = getRowShorthandForPath(html, at2, bindAttrName) === null ? null : getResolvedForListPath(html, at2, bindAttrName);
|
|
16594
|
+
if (list === null) return;
|
|
16595
|
+
path = path === "." ? `${list}.*` : `${list}.*.${path.slice(1)}`;
|
|
16596
|
+
}
|
|
16597
|
+
const write = (written) => {
|
|
16598
|
+
out.push({ path: written, binding: binding.exprText, tag });
|
|
16599
|
+
};
|
|
16600
|
+
if (parsed.bindingType === "spread") {
|
|
16601
|
+
if (outputs === null) return;
|
|
16602
|
+
const later = new Set(bindings.slice(index + 1).flatMap((b) => b.parsed?.bindingType === "prop" ? [b.parsed.propName] : []));
|
|
16603
|
+
for (const output of outputs) if (!later.has(output)) write(`${path}.${output}`);
|
|
16604
|
+
return;
|
|
16605
|
+
}
|
|
16606
|
+
if (parsed.propModifiers.includes("ro")) return;
|
|
16607
|
+
if (parsed.bindingType === "radio" || parsed.bindingType === "checkbox") {
|
|
16608
|
+
write(path);
|
|
16609
|
+
} else if (parsed.bindingType === "prop" && (writesBack(attr, parsed.propName, parsed.propName) || outputs?.includes(parsed.propName) === true)) {
|
|
16610
|
+
write(path);
|
|
16611
|
+
}
|
|
16612
|
+
});
|
|
16613
|
+
}
|
|
16614
|
+
return out;
|
|
16615
|
+
}
|
|
16490
16616
|
function validateGetterLocationReads(script, scriptStart, locale2) {
|
|
16491
16617
|
if (!script.includes("location")) return [];
|
|
16492
16618
|
const msgs = getMessages(locale2);
|
|
@@ -16817,12 +16943,21 @@ function validateSemantics(html, stateTagName = "wcs-state", locale2, bindAttrNa
|
|
|
16817
16943
|
const blocks = parseLoadedScriptBlocks(html, stateTagName);
|
|
16818
16944
|
let nestedWriteRoots = null;
|
|
16819
16945
|
const getNestedWriteRoots = () => nestedWriteRoots ??= collectNestedWriteRoots(html, stateTagName, bindAttrName, blocks);
|
|
16946
|
+
let bindingWrites = null;
|
|
16947
|
+
const getBindingWrites = () => bindingWrites ??= collectBindingWrites(html, bindAttrName);
|
|
16820
16948
|
for (const block of blocks) {
|
|
16821
16949
|
out.push(...validateIndexArity(block.content, block.contentStart, locale2));
|
|
16822
16950
|
out.push(...validateNameAliases(block.content, block.contentStart, locale2, block.mountPath));
|
|
16823
16951
|
out.push(...validateIndexParamReads(block.content, block.contentStart, locale2));
|
|
16824
16952
|
out.push(...validateGetterCycles(block.content, block.contentStart, locale2));
|
|
16825
|
-
out.push(...validateGetterUntrackedReads(
|
|
16953
|
+
out.push(...validateGetterUntrackedReads(
|
|
16954
|
+
block.content,
|
|
16955
|
+
block.contentStart,
|
|
16956
|
+
block.mountPath,
|
|
16957
|
+
getNestedWriteRoots,
|
|
16958
|
+
getBindingWrites,
|
|
16959
|
+
locale2
|
|
16960
|
+
));
|
|
16826
16961
|
out.push(...validateGetterLocationReads(block.content, block.contentStart, locale2));
|
|
16827
16962
|
out.push(...validateGetterClockReads(block.content, block.contentStart, locale2));
|
|
16828
16963
|
out.push(...validateOnHandlerThis(block.content, block.contentStart, locale2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/lint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
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": {
|