@wcstack/lint 4.20.0 → 4.21.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 +12 -1
- package/README.md +12 -1
- package/dist/cli.cjs +292 -73
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -101,12 +101,23 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
101
101
|
|
|
102
102
|
## ページの wcstack のスクリプトと lint の版
|
|
103
103
|
|
|
104
|
-
4.11 から、2
|
|
104
|
+
4.11 から、2 つの検査がページの読み込む wcstack のスクリプトを見ます。4.20 から 3 つ目が加わります。4.21 から `wcs/tag-package-missing` は error なので、`--errors-only` でも落ちます(4.20 までは warning で、`--errors-only` に隠れていました)。残りの 2 つは warning なので、`--strict` では落ち、`--errors-only` では落ちません。
|
|
105
105
|
|
|
106
106
|
- **`wcs/tag-package-missing`** — wcstack を自分で読み込むページが、あるパッケージの `wcs-*` のタグ(`<wcs-upload>` やそのヘルパー `<wcs-upload-header>`、`<wcs-state>`・`<wcs-router>` など)を書くのに、そのパッケージのスクリプトを読み込んでいない。要素は定義されず、束縛は待ち続けて何も起きず、コンソールにも何も出ません。パッケージごとに 1 回、最初のタグに、読み込む `/auto` を挙げて報告します。読み込んだと数えるのは、`<script src>`・import map の項目・インラインのスクリプトの import か文字列が `@wcstack/<pkg>`(版・CDN・ローカルのパスを問わない)か一括バンドル `wcstack`(state・router・fetch・storage・autoloader)を名指すものです。ローカルのスクリプト(`./app.js`)は、それが import する相対のモジュールとともに読み、名指すものを数えます。wcstack を自分で読み込まないページ(断片・バンドラのページ)、autoloader がいて `@components/` の import map が覆うタグ、読めないローカルのスクリプトがあるページでは報告しません。
|
|
107
107
|
- **`wcs/link-router-missing`**(4.20 から) — router(か一括バンドル `wcstack`)を読み込むのに `<wcs-router>` の無いページの `<wcs-link to="/…">`。リンクは接続した時点で `[@wcstack/router] wcs-link is not connected to a router.` を投げ、隠れたまま(`display: none`)になります。router の無いページ — サーバーが描き、アイランドを置いたページ — では `<a href>` と書くか、`<wcs-router>` を置いてください。ページに 1 回、最初のそうしたリンクに報告します。見るのは `wcs/tag-package-missing` と同じページ(wcstack を自分で読み込むページ)だけです: 断片 — ルートの中身・router のページが取り込むレイアウトのファイル — は wcstack のスクリプトを読み込まないので報告せず、HTML コメントの外のどこかで `wcs-router` を名指すページ(`<template>` の中の `<wcs-router>`・それを作るスクリプトも)、router が無くても描かれる URL やクエリ(`?page=2`)の `to` も報告しません。
|
|
108
108
|
- **`wcs/lint-version-behind`** — ページの URL が、この lint より新しい minor を固定している: `@wcstack/state@4.11.0` を `@wcstack/lint@4.10.1` で検査する。lint が持つのは自分の版の規則なので(`@wcstack/state` と lockstep で出ます)、新しい minor で加わったものは検査されず、新しい minor の正しい書き方を error にもします(4.2.0 の lint は 4.10 の `datetime(ja-JP,short,Asia/Tokyo)` を `wcs/filter-arity` にします)。ページに 1 回、いちばん新しい固定に、`@wcstack/lint` をその版に上げるよう言います — `package.json` の lint はページが固定する版に揃えてください。版の無い URL・major だけの固定(`@4`)・lint の方が新しいときは報告しません。
|
|
109
109
|
|
|
110
|
+
## ページを直す保守担当に言うこと
|
|
111
|
+
|
|
112
|
+
4.21 から、継ぎ目アプリ ledger-repair — 目録の誤りを 10 件入れた家計簿を、外の保守担当がコンソール・この lint・DevTools のオーバーレイ・文書で直した — から:
|
|
113
|
+
|
|
114
|
+
- **`wcs/submit-without-prevent` と `wcs/tag-package-missing` は error です。** 報告するところでは必ず不具合です — フォームも自分を送る(router があれば GET がパスワードを URL に載せる)、要素がけっして定義されない — が、warning だったので `--errors-only` に隠れていました。`wcs/binding-path-missing` は warning のままです: `stateSchema` が無いと、値が外から届くこともあるためです。
|
|
115
|
+
- **`wcs/session-read-at-module-top`** — `<wcs-guard-handler>` のモジュール(error)や `<wcs-state>` のモジュール(インライン・`src=`。warning)のトップレベルでの `localStorage` / `sessionStorage` / `document.cookie` の読み。router はガードのモジュールを 1 回だけ評価し、export した関数を遷移のたびに走らせるので、関数の外でセッションを読むガードは、ページを読み込んだ時点のセッションを持ち続けます: ログインの後も、守られたページはすべて /login へ戻り、何も知らせませんでした。関数の中で読んでください。関数の中(そこから呼ぶ補助関数・getter・メソッド)の読みは報告しません。
|
|
116
|
+
- **`wcs/event-token-unbound`**(warning) — `wcs/command-token-unbound` の逆: `$eventTokens` に宣言したのに、ページのどの `eventToken.<メンバー>: <名前>` 束縛も出さない名前。`$on` のハンドラは走りません(ページは束縛を外して `deleteFetch.status` を watch していましたが、2 回目の 204 ではそれは変わりません)。lint の見ない束縛が出しうるページ — `<wcs-layout src>` のあるページ、`eventToken.` の束縛を書くスクリプトのあるページ — では報告しません。
|
|
117
|
+
- 行に無いフィールドの近くに行のフィールドがあれば名指します — `パス ".amountLabl" は状態定義に存在しません(展開: rows.*.amountLabl)。もしかして: "amountLabel"`。行の形はどこから読んだものでもかまいません: データのリスト・getter の map のリテラル・JSDoc の型。
|
|
118
|
+
- 配列と分からない値(`budgetErrors: {}` と `this.budgetErrors[id] = …`)への `wcs/array-index-assign` は、「配列の添字」ではなくオブジェクトのキーへの代入として言います。
|
|
119
|
+
- スクリプトがその場で変えるリスト(`this.budgetRows.splice(0, n, ...rows)` — `wcs/array-mutation` が報告する)の行は、リテラルや JSDoc の型からフィールドが読めなければ検査しません。4.20 までは、そうした行のフィールドがどれも `wcs/binding-path-missing` の誤報で、本物の打ち間違いと同じ code でした。
|
|
120
|
+
|
|
110
121
|
## 生成 → 検証 → 修正ループでの利用
|
|
111
122
|
|
|
112
123
|
安定した diagnostic code・`source:line:col` range・exit code 契約により、CI のゲートにも AI コード生成フローにもそのまま組み込めます: HTML を生成 → `npx @wcstack/lint --errors-only` → 診断を読んで修正 → exit code `0` になるまで再実行。このゲートが覆うのは `data-wcs` のページです: 出力が `not read:` や `nothing to check:` で終わるときは、そのファイルは検査されていません。
|
package/README.md
CHANGED
|
@@ -101,12 +101,23 @@ Without a contract, a path the validator cannot resolve is only a **warning** (`
|
|
|
101
101
|
|
|
102
102
|
## The page's wcstack scripts and the lint's version
|
|
103
103
|
|
|
104
|
-
Since 4.11, two
|
|
104
|
+
Since 4.11, two findings look at the wcstack scripts a page loads, and since 4.20 a third. Since 4.21, `wcs/tag-package-missing` is an error, so `--errors-only` fails on it too (up to 4.20 it was a warning, which `--errors-only` hid); the other two are warnings: `--strict` fails on them, `--errors-only` does not.
|
|
105
105
|
|
|
106
106
|
- **`wcs/tag-package-missing`** — a `wcs-*` tag of a wcstack package (`<wcs-upload>`, or its helper `<wcs-upload-header>`; `<wcs-state>`, `<wcs-router>` …) on a page that loads wcstack itself but no script of that package. The element is never defined, its bindings wait and nothing happens, and the console says nothing. Reported once per package, at its first tag, with the `/auto` to load. A script counts when a `<script src>`, an import map entry, or an import or a string in an inline script names `@wcstack/<pkg>` (any version, any CDN, a local path) or the `wcstack` bundle (state, router, fetch, storage, autoloader); a local script (`./app.js`) is read, with the relative modules it imports, for what it names. Not reported on a page that names no wcstack script itself (a fragment, a bundler's page), for a tag an `@components/` import map entry covers while the autoloader is there, or when a local script cannot be read.
|
|
107
107
|
- **`wcs/link-router-missing`** (since 4.20) — a `<wcs-link to="/…">` on a page that loads the router (or the `wcstack` bundle) but has no `<wcs-router>`: the link throws `[@wcstack/router] wcs-link is not connected to a router.` when it connects, and stays hidden (`display: none`). On a page without the router — a page a server renders, with islands in it — write `<a href>`, or add the `<wcs-router>`. Reported once per page, at the first such link, where `wcs/tag-package-missing` would look (a page that loads wcstack itself): a fragment — a route's content, a layout file the router page includes — loads no wcstack script and is not reported, nor is a page that names `wcs-router` anywhere outside an HTML comment (a `<wcs-router>`, in a `<template>` too, or a script that makes one), nor a `to` that is a URL or a query (`?page=2`), which renders without the router.
|
|
108
108
|
- **`wcs/lint-version-behind`** — a URL on the page pins a newer minor than this lint: `@wcstack/state@4.11.0` checked with `@wcstack/lint@4.10.1`. The lint carries the rules of its own version (it is released with `@wcstack/state`, in lockstep), so it does not check what the newer minor added, and it can report the newer minor's correct syntax as an error (4.2.0's lint gives `wcs/filter-arity` for 4.10's `datetime(ja-JP,short,Asia/Tokyo)`). Said once per page, at the newest pin: upgrade `@wcstack/lint` to that version — keep the lint in `package.json` at the version the page pins. A URL without a version, a major-only pin (`@4`) and a lint newer than the page are not reported.
|
|
109
109
|
|
|
110
|
+
## What a maintainer fixing a page is told
|
|
111
|
+
|
|
112
|
+
Since 4.21, from the ledger-repair seam app — a maintainer fixing a household-budget app with ten catalogued mistakes put in, with the console, this lint, the DevTools overlay and the documents:
|
|
113
|
+
|
|
114
|
+
- **`wcs/submit-without-prevent` and `wcs/tag-package-missing` are errors.** Where they are reported they are always bugs — a form that also submits itself (with the router, a GET that puts the password in the URL), an element that is never defined — and as warnings `--errors-only` hid them. `wcs/binding-path-missing` stays a warning: without a `stateSchema` the value may arrive from outside.
|
|
115
|
+
- **`wcs/session-read-at-module-top`** — a `localStorage` / `sessionStorage` / `document.cookie` read at the top level of a `<wcs-guard-handler>`'s module (an error) or of a `<wcs-state>`'s module, inline or `src=` (a warning). The router evaluates a guard's module once and runs its exported function on every navigation, so a guard that reads the session outside the function keeps the session there was when the page loaded: after the login, every guarded page went back to /login, and nothing said so. Read it inside the function; a read inside any function (a helper it calls, a getter, a method) is not reported.
|
|
116
|
+
- **`wcs/event-token-unbound`** (warning) — the mirror of `wcs/command-token-unbound`: a name `$eventTokens` declares that no `eventToken.<member>: <name>` binding on the page emits, so its `$on` handler never runs (the page had removed the binding and watched `deleteFetch.status`, which a second 204 does not change). Not reported where a binding the lint does not see can emit it: a page with a `<wcs-layout src>`, or a script that writes `eventToken.` bindings.
|
|
117
|
+
- A row field the rows lack, beside a near one they have, is named — `Path ".amountLabl" does not exist in the state definition (expanded: rows.*.amountLabl). Did you mean "amountLabel"?` — wherever the rows were read from: a data list, a getter's mapped literal, a JSDoc type.
|
|
118
|
+
- `wcs/array-index-assign` on a value not known to be an array (`budgetErrors: {}` with `this.budgetErrors[id] = …`) says it assigns an object's key, not "an array index".
|
|
119
|
+
- The rows of a list the script changes in place (`this.budgetRows.splice(0, n, ...rows)`, reported as `wcs/array-mutation`) are not checked when no literal or JSDoc type gives their fields. Up to 4.20 each such row field was a false `wcs/binding-path-missing`, the same code as a real typo.
|
|
120
|
+
|
|
110
121
|
## Use in generate–validate–fix loops
|
|
111
122
|
|
|
112
123
|
Stable diagnostic codes, `source:line:col` ranges, and the exit-code contract make this CLI a drop-in gate for CI and for AI code-generation flows: generate HTML → `npx @wcstack/lint --errors-only` → read the diagnostics, fix, and re-run until exit code `0`. The gate covers `data-wcs` pages: when the output ends with `not read:` or `nothing to check:`, those files were not checked.
|
package/dist/cli.cjs
CHANGED
|
@@ -223,6 +223,11 @@ var WcsDiagnosticCode = {
|
|
|
223
223
|
// `command.<method>:` 束縛にも結ばれていない。emit は誰にも届かず、ランタイムは何も言わない(7GUIs の評価)。warning
|
|
224
224
|
// (ページの外 — 別ファイルのルートのテンプレート — で束ねる形は見えない)。
|
|
225
225
|
CommandTokenUnbound: "wcs/command-token-unbound",
|
|
226
|
+
// `$eventTokens` に宣言したのに、ドキュメントのどの `eventToken.<member>: <name>` 束縛も出さないトークン(command-token-unbound
|
|
227
|
+
// の逆)。どの要素も発火させないので `$on` のハンドラは走らず、ランタイムは何も言わない(継ぎ目アプリ ledger-repair — 束縛と
|
|
228
|
+
// ハンドラを外して `deleteFetch.status` を見た)。warning。ファイルから読むレイアウト(`<wcs-layout src>`)や、state の
|
|
229
|
+
// モジュールのほかに `eventToken.` の束縛を書くスクリプトがあるページは、見えない束縛が出しうるので黙る。root の state だけ。
|
|
230
|
+
EventTokenUnbound: "wcs/event-token-unbound",
|
|
226
231
|
// state が宣言していないトップレベルのキーへの書き込み(`this.selectedID = …` と `selectedId`)。新しいキーができる
|
|
227
232
|
// だけで、宣言したキーの束縛は変わらない。ランタイムは何も言わない。近い名前(打ち間違い)があるときだけ、warning。
|
|
228
233
|
WritePathMissing: "wcs/write-path-missing",
|
|
@@ -360,8 +365,15 @@ var WcsDiagnosticCode = {
|
|
|
360
365
|
DelegatedCurrentTarget: "wcs/delegated-current-target",
|
|
361
366
|
// `<form data-wcs="onsubmit: login">` の `#prevent` 忘れ(ハンドラも preventDefault を呼ばない)。ブラウザが
|
|
362
367
|
// フォームも送る — ページが読み直されるか、router があれば GET が欄(パスワードも)を URL と履歴に載せる
|
|
363
|
-
// (docs/seam-apps.md、router-auth)。
|
|
368
|
+
// (docs/seam-apps.md、router-auth)。error(4.21 から — 4.20 までは warning で、`--errors-only` に隠れた: 継ぎ目アプリ
|
|
369
|
+
// ledger-repair)。action 付きのフォームと、読めないハンドラでは黙る。
|
|
364
370
|
SubmitWithoutPrevent: "wcs/submit-without-prevent",
|
|
371
|
+
// `localStorage` / `sessionStorage` / `document.cookie` を、1 回しか評価されないモジュールのトップレベル(関数の外)で読む。
|
|
372
|
+
// `<wcs-guard-handler>` のモジュールは 1 回だけ評価され、export した関数が遷移のたびに走る(router の README)ので、ガードは
|
|
373
|
+
// 読み込みの時点のセッションで決め続ける — ログインしても守られたページはすべて /login へ戻され、何も言わない(継ぎ目アプリ
|
|
374
|
+
// ledger-repair)。ガードは error、`<wcs-state>` のモジュール(インライン・`src=`)は warning(state は読み込みの時点の値を
|
|
375
|
+
// 持ち続ける — 意図した種もありうる)。関数の中(export した関数・そこから呼ぶ補助関数・getter・メソッド)の読みは黙る。
|
|
376
|
+
SessionReadAtModuleTop: "wcs/session-read-at-module-top",
|
|
365
377
|
// 4.0 で外れた API の旧名(`this.$trackDependency` → `$dependOn`、`$untrackDependency` → `$untracked`)。
|
|
366
378
|
// ランタイムは読んだ時点で同じ code(#1701)で throw するので error。3.x(3.2〜3.3)では「動くが 4.0 で
|
|
367
379
|
// 外れる」info だった。フィルタの旧名(`uc` など)は 4.0 のランタイムと同じく `wcs/filter-unknown` で、
|
|
@@ -432,7 +444,8 @@ var WcsDiagnosticCode = {
|
|
|
432
444
|
// wcstack を自分で読み込むページが、あるパッケージのタグ(`<wcs-upload>`・`<wcs-upload-header>`)を書くのに、その
|
|
433
445
|
// パッケージのスクリプトを読み込んでいない。要素は定義されず、束縛は待ち続け、コンソールにも何も出ない(継ぎ目アプリ
|
|
434
446
|
// homeroom — 保存が「送信中 0%」で止まった)。パッケージごとに 1 回、最初のタグに。読めないローカルのスクリプトがある
|
|
435
|
-
// ページ・autoloader の `@components/` が覆うタグ・wcstack を自分で読み込まないページ(断片・バンドラ)では黙る。
|
|
447
|
+
// ページ・autoloader の `@components/` が覆うタグ・wcstack を自分で読み込まないページ(断片・バンドラ)では黙る。error
|
|
448
|
+
// (4.21 から — 4.20 までは warning で、`--errors-only` に隠れた: 継ぎ目アプリ ledger-repair)。
|
|
436
449
|
TagPackageMissing: "wcs/tag-package-missing",
|
|
437
450
|
// `<wcs-router>` の無いページの、内部のパス(`to="/…"`)へ飛ぶ `<wcs-link>`。リンクは接続で
|
|
438
451
|
// `[@wcstack/router] wcs-link is not connected to a router.` を投げ、ホストは `display: none` のまま `<a>` を作らない
|
|
@@ -2543,7 +2556,7 @@ function getWcsManifest() {
|
|
|
2543
2556
|
}
|
|
2544
2557
|
|
|
2545
2558
|
// ../state/package.json
|
|
2546
|
-
var version = "4.
|
|
2559
|
+
var version = "4.21.0";
|
|
2547
2560
|
|
|
2548
2561
|
// src/service/wcsManifest.ts
|
|
2549
2562
|
var ENGINE_VERSION = version;
|
|
@@ -2568,7 +2581,72 @@ var STRUCTURAL_DIRECTIVES = [...STRUCTURAL_BINDING_TYPE_SET2].map((name) => ({
|
|
|
2568
2581
|
...STRUCTURAL_DIRECTIVE_INFO[name]
|
|
2569
2582
|
}));
|
|
2570
2583
|
|
|
2584
|
+
// src/service/indexPath.ts
|
|
2585
|
+
var INDEX_SEGMENT = /^\d/;
|
|
2586
|
+
function isIndexSegment(segment) {
|
|
2587
|
+
return INDEX_SEGMENT.test(segment);
|
|
2588
|
+
}
|
|
2589
|
+
function hasIndexSegment(path) {
|
|
2590
|
+
return path.split(".").some((segment) => INDEX_SEGMENT.test(segment));
|
|
2591
|
+
}
|
|
2592
|
+
function toWildcardForm(path) {
|
|
2593
|
+
if (!hasIndexSegment(path)) return path;
|
|
2594
|
+
return path.split(".").map((segment) => INDEX_SEGMENT.test(segment) ? "*" : segment).join(".");
|
|
2595
|
+
}
|
|
2596
|
+
function candidateKeyOf(path, has) {
|
|
2597
|
+
return has(path) ? path : toWildcardForm(path);
|
|
2598
|
+
}
|
|
2599
|
+
var UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype"]);
|
|
2600
|
+
function hasUnsafeSegment(path) {
|
|
2601
|
+
return path.split(".").some((segment) => UNSAFE_SEGMENTS.has(segment));
|
|
2602
|
+
}
|
|
2603
|
+
var { maxDepth } = getWcsManifest().syntax.indexParam;
|
|
2604
|
+
var MAX_INDEX_PARAM3 = maxDepth;
|
|
2605
|
+
var INDEX_PARAM = new RegExp(`^\\$[1-9]\\d{0,${String(maxDepth).length - 1}}$`);
|
|
2606
|
+
function classifyIndexParam(path) {
|
|
2607
|
+
if (!/^\$\d+$/.test(path)) return null;
|
|
2608
|
+
if (!INDEX_PARAM.test(path)) return { kind: "notIndex" };
|
|
2609
|
+
const n = Number(path.slice(1));
|
|
2610
|
+
return n <= MAX_INDEX_PARAM3 ? { kind: "index", n } : { kind: "range", n };
|
|
2611
|
+
}
|
|
2612
|
+
function isOutOfRangeIndexRead(name) {
|
|
2613
|
+
if (name.length < 2 || name.charCodeAt(0) !== 36) return false;
|
|
2614
|
+
const c = name.charCodeAt(1);
|
|
2615
|
+
if (c < 48 || c > 57) return false;
|
|
2616
|
+
return !INDEX_PARAM.test(name) || Number(name.slice(1)) > MAX_INDEX_PARAM3;
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2571
2619
|
// src/service/suggestion.ts
|
|
2620
|
+
function pathTree(candidates) {
|
|
2621
|
+
const tree = /* @__PURE__ */ new Map();
|
|
2622
|
+
for (const c of candidates) {
|
|
2623
|
+
let parent = "";
|
|
2624
|
+
for (const segment of c.path.split(".")) {
|
|
2625
|
+
let names2 = tree.get(parent);
|
|
2626
|
+
if (names2 === void 0) tree.set(parent, names2 = /* @__PURE__ */ new Set());
|
|
2627
|
+
names2.add(segment);
|
|
2628
|
+
parent = parent === "" ? segment : `${parent}.${segment}`;
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
return tree;
|
|
2632
|
+
}
|
|
2633
|
+
function missingSegment(path, tree) {
|
|
2634
|
+
let parent = "";
|
|
2635
|
+
for (const segment of (hasIndexSegment(path) ? toWildcardForm(path) : path).split(".")) {
|
|
2636
|
+
const names2 = tree.get(parent);
|
|
2637
|
+
if (names2?.has(segment)) {
|
|
2638
|
+
parent = parent === "" ? segment : `${parent}.${segment}`;
|
|
2639
|
+
continue;
|
|
2640
|
+
}
|
|
2641
|
+
return { segment, parent, names: [...names2 ?? []].filter((name) => name !== "*" && !name.startsWith("$")) };
|
|
2642
|
+
}
|
|
2643
|
+
return null;
|
|
2644
|
+
}
|
|
2645
|
+
function rowFieldSuggestion(path, candidates, msgs) {
|
|
2646
|
+
const missing = missingSegment(path, pathTree(candidates));
|
|
2647
|
+
if (missing === null || !missing.parent.split(".").includes("*")) return "";
|
|
2648
|
+
return suggestion(missing.segment, missing.names, msgs);
|
|
2649
|
+
}
|
|
2572
2650
|
function suggestion(input, candidates, msgs) {
|
|
2573
2651
|
let best = null;
|
|
2574
2652
|
let bestDistance = 3;
|
|
@@ -9027,8 +9105,30 @@ function analyzeStatePaths(scriptContent, location) {
|
|
|
9027
9105
|
}
|
|
9028
9106
|
collectRowShapesFromAssignments(scriptContent, paths);
|
|
9029
9107
|
collectGetterResultShapes(scriptContent, root.start, topLevelProps, effectiveDescriptors, paths);
|
|
9108
|
+
markRowsChangedInPlace(scriptContent, paths);
|
|
9030
9109
|
return paths;
|
|
9031
9110
|
}
|
|
9111
|
+
var ROWS_IN_PLACE_CALL = /\bthis\s*(?:\?\.|\.)\s*([\w$]+)\s*\??\.\s*(?:push|unshift|splice|fill)\s*\(|\bthis\s*(?:\?\.)?\s*\[\s*(["'])([^"']*)\2\s*\]\s*\??\.\s*(?:push|unshift|splice|fill)\s*\(/dg;
|
|
9112
|
+
var ROWS_IN_PLACE_ASSIGN = /\bthis\s*(?:\?\.|\.)\s*([\w$]+)\s*(?:\?\.)?\s*\[(?!\s*["'])[^[\]]+\]\s*=(?!=)/dg;
|
|
9113
|
+
function markRowsChangedInPlace(scriptContent, paths) {
|
|
9114
|
+
if (!/\b(?:push|unshift|splice|fill)\s*\(|\]\s*=(?!=)/.test(scriptContent)) return;
|
|
9115
|
+
const masked = maskCommentsAndStrings(scriptContent);
|
|
9116
|
+
const changed = /* @__PURE__ */ new Set();
|
|
9117
|
+
ROWS_IN_PLACE_CALL.lastIndex = 0;
|
|
9118
|
+
let m;
|
|
9119
|
+
while ((m = ROWS_IN_PLACE_CALL.exec(masked)) !== null) {
|
|
9120
|
+
if (m[1] !== void 0) changed.add(m[1]);
|
|
9121
|
+
else if (m.indices?.[3] !== void 0) changed.add(scriptContent.slice(m.indices[3][0], m.indices[3][1]));
|
|
9122
|
+
}
|
|
9123
|
+
ROWS_IN_PLACE_ASSIGN.lastIndex = 0;
|
|
9124
|
+
while ((m = ROWS_IN_PLACE_ASSIGN.exec(masked)) !== null) changed.add(m[1]);
|
|
9125
|
+
for (const list of changed) {
|
|
9126
|
+
const rows = paths.find((p) => p.path === `${list}.*` && p.kind === "list");
|
|
9127
|
+
if (rows === void 0 || rows.openKeys === true) continue;
|
|
9128
|
+
const fields = paths.some((p) => p.path.startsWith(`${list}.*.`) && (p.kind === "data" || p.kind === "list"));
|
|
9129
|
+
if (!fields) rows.openKeys = true;
|
|
9130
|
+
}
|
|
9131
|
+
}
|
|
9032
9132
|
function specFromRecursionValue(prop) {
|
|
9033
9133
|
if (!prop || prop.kind !== "data" || !prop.value || !isObjectLiteral(prop.value)) return null;
|
|
9034
9134
|
const entries = parseTopLevelProperties(extractObjectContent(prop.value)).filter((e) => e.kind === "data");
|
|
@@ -10520,41 +10620,6 @@ function withHint(candidate, typeHint) {
|
|
|
10520
10620
|
return typeHint === void 0 ? candidate : { ...candidate, typeHint };
|
|
10521
10621
|
}
|
|
10522
10622
|
|
|
10523
|
-
// src/service/indexPath.ts
|
|
10524
|
-
var INDEX_SEGMENT = /^\d/;
|
|
10525
|
-
function isIndexSegment(segment) {
|
|
10526
|
-
return INDEX_SEGMENT.test(segment);
|
|
10527
|
-
}
|
|
10528
|
-
function hasIndexSegment(path) {
|
|
10529
|
-
return path.split(".").some((segment) => INDEX_SEGMENT.test(segment));
|
|
10530
|
-
}
|
|
10531
|
-
function toWildcardForm(path) {
|
|
10532
|
-
if (!hasIndexSegment(path)) return path;
|
|
10533
|
-
return path.split(".").map((segment) => INDEX_SEGMENT.test(segment) ? "*" : segment).join(".");
|
|
10534
|
-
}
|
|
10535
|
-
function candidateKeyOf(path, has) {
|
|
10536
|
-
return has(path) ? path : toWildcardForm(path);
|
|
10537
|
-
}
|
|
10538
|
-
var UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype"]);
|
|
10539
|
-
function hasUnsafeSegment(path) {
|
|
10540
|
-
return path.split(".").some((segment) => UNSAFE_SEGMENTS.has(segment));
|
|
10541
|
-
}
|
|
10542
|
-
var { maxDepth } = getWcsManifest().syntax.indexParam;
|
|
10543
|
-
var MAX_INDEX_PARAM3 = maxDepth;
|
|
10544
|
-
var INDEX_PARAM = new RegExp(`^\\$[1-9]\\d{0,${String(maxDepth).length - 1}}$`);
|
|
10545
|
-
function classifyIndexParam(path) {
|
|
10546
|
-
if (!/^\$\d+$/.test(path)) return null;
|
|
10547
|
-
if (!INDEX_PARAM.test(path)) return { kind: "notIndex" };
|
|
10548
|
-
const n = Number(path.slice(1));
|
|
10549
|
-
return n <= MAX_INDEX_PARAM3 ? { kind: "index", n } : { kind: "range", n };
|
|
10550
|
-
}
|
|
10551
|
-
function isOutOfRangeIndexRead(name) {
|
|
10552
|
-
if (name.length < 2 || name.charCodeAt(0) !== 36) return false;
|
|
10553
|
-
const c = name.charCodeAt(1);
|
|
10554
|
-
if (c < 48 || c > 57) return false;
|
|
10555
|
-
return !INDEX_PARAM.test(name) || Number(name.slice(1)) > MAX_INDEX_PARAM3;
|
|
10556
|
-
}
|
|
10557
|
-
|
|
10558
10623
|
// src/service/statePathResolver.ts
|
|
10559
10624
|
function isUnresolvedPath(path, scopes) {
|
|
10560
10625
|
if (scopes.opaquePaths.length > 0) {
|
|
@@ -11834,6 +11899,10 @@ var ja = {
|
|
|
11834
11899
|
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`,
|
|
11835
11900
|
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`,
|
|
11836
11901
|
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`,
|
|
11902
|
+
guardReadsAtModuleTop: (r) => `\u30AC\u30FC\u30C9\u306E\u30E2\u30B8\u30E5\u30FC\u30EB\u304C\u3001export \u3059\u308B\u95A2\u6570\u306E\u5916\uFF08\u30C8\u30C3\u30D7\u30EC\u30D9\u30EB\uFF09\u3067 ${r} \u3092\u8AAD\u3093\u3067\u3044\u307E\u3059\u3002\u30E2\u30B8\u30E5\u30FC\u30EB\u306F\u30DA\u30FC\u30B8\u306E\u8AAD\u307F\u8FBC\u307F\u3067 1 \u56DE\u3060\u3051\u8A55\u4FA1\u3055\u308C\u308B\u306E\u3067\u3001\u30AC\u30FC\u30C9\u306F\u305D\u306E\u3068\u304D\u8AAD\u3093\u3060\u5024\u3092\u6301\u3061\u7D9A\u3051\u3001\u9077\u79FB\u306E\u305F\u3073\u306B\u305D\u306E\u5024\u3067\u6C7A\u3081\u307E\u3059\uFF08\u30ED\u30B0\u30A4\u30F3\u3057\u305F\u5F8C\u3082\u30BB\u30C3\u30B7\u30E7\u30F3\u304C\u7121\u3044\u307E\u307E\uFF09\u3002\u9077\u79FB\u306E\u305F\u3073\u306B\u8D70\u308B\u3001export \u3057\u305F\u95A2\u6570\u306E\u4E2D\u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
11903
|
+
stateReadsAtModuleTop: (r) => `state \u306E\u30E2\u30B8\u30E5\u30FC\u30EB\u304C\u30C8\u30C3\u30D7\u30EC\u30D9\u30EB\u3067 ${r} \u3092\u8AAD\u3093\u3067\u3044\u307E\u3059\u3002\u30E2\u30B8\u30E5\u30FC\u30EB\u306F <wcs-state> \u3054\u3068\u306B 1 \u56DE\u3060\u3051\u8A55\u4FA1\u3055\u308C\u308B\u306E\u3067\u3001state \u306F\u30DA\u30FC\u30B8\u306E\u8AAD\u307F\u8FBC\u307F\u306E\u6642\u70B9\u306E\u5024\u3092\u6301\u3061\u7D9A\u3051\u307E\u3059\uFF08\u5F8C\u3067\u5909\u308F\u308B\u30C8\u30FC\u30AF\u30F3\u3084\u30BB\u30C3\u30B7\u30E7\u30F3\u306F\u898B\u3048\u307E\u305B\u3093\uFF09\u3002\u5024\u3092 state \u306B\u7F6E\u304F\uFF08<wcs-storage> \u306B\u675F\u306D\u308B\uFF09\u304B\u3001\u4F7F\u3046\u30E1\u30BD\u30C3\u30C9\u306E\u4E2D\u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
11904
|
+
eventTokenUnbound: (t, handler) => `\u30A4\u30D9\u30F3\u30C8\u30C8\u30FC\u30AF\u30F3 "${t}" \u3092 $eventTokens \u306B\u5BA3\u8A00\u3057\u3066\u3044\u307E\u3059\u304C\u3001\u3053\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306B\u305D\u308C\u3092\u51FA\u3059 eventToken.<\u30E1\u30F3\u30D0\u30FC>: ${t} \u306E\u675F\u7E1B\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u3069\u306E\u8981\u7D20\u3082\u767A\u706B\u3055\u305B\u306A\u3044\u306E\u3067\u3001${handler ? "$on \u306E\u30CF\u30F3\u30C9\u30E9\u306F\u4E00\u5EA6\u3082\u8D70\u308A\u307E\u305B\u3093" : "\u3053\u306E\u30C8\u30FC\u30AF\u30F3\u306F\u4E00\u5EA6\u3082\u767A\u706B\u3057\u307E\u305B\u3093"}\u3002\u767A\u706B\u3055\u305B\u308B\u8981\u7D20\u306B\u675F\u306D\u308B\uFF08eventToken.<\u30E1\u30F3\u30D0\u30FC>: ${t} \u2014 <\u30E1\u30F3\u30D0\u30FC> \u306F\u305D\u306E\u8981\u7D20\u306E wcBindable \u306E\u30D7\u30ED\u30D1\u30C6\u30A3\uFF09\u304B\u3001$eventTokens \u304B\u3089\u5916\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
11905
|
+
objectKeyAssign: (t, acc, sp) => `"${t}" \u306E\u30AD\u30FC\u306B\u305D\u306E\u5834\u3067\u4EE3\u5165\u3057\u3066\u3044\u307E\u3059\u3002state \u306F\u3053\u306E\u66F8\u304D\u8FBC\u307F\u3092\u898B\u306A\u3044\u306E\u3067\u3001\u305D\u308C\u3092\u8AAD\u3080\u675F\u7E1B\u30FBgetter\u30FB$watch \u306F\u5909\u308F\u3089\u305A\u3001\u4F55\u3082\u63CF\u304D\u76F4\u3055\u308C\u307E\u305B\u3093\u3002\u65B0\u3057\u3044\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u4EE3\u5165\u3059\u308B\uFF08${acc} = { ...${acc}, [key]: value }\uFF09\u304B\u3001\u30C9\u30C3\u30C8\u30D1\u30B9\u3067\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08this["${sp}"] = \u2026\uFF09`,
|
|
11837
11906
|
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`,
|
|
11838
11907
|
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`,
|
|
11839
11908
|
handlerFilterNotAllowed: (prop) => `\u30A4\u30D9\u30F3\u30C8\u30CF\u30F3\u30C9\u30E9 "${prop}" \u306B\u30D5\u30A3\u30EB\u30BF\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
|
|
@@ -12062,6 +12131,10 @@ var en = {
|
|
|
12062
12131
|
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`,
|
|
12063
12132
|
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})`,
|
|
12064
12133
|
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`,
|
|
12134
|
+
guardReadsAtModuleTop: (r) => `The guard's module reads ${r} at its top level, outside the function it exports. The module is evaluated once, when the page loads, so the guard keeps the value it read then and decides every navigation with it (after a login, the session is still not there). Read it inside the exported function, which runs on every navigation`,
|
|
12135
|
+
stateReadsAtModuleTop: (r) => `The state's module reads ${r} at its top level. The module is evaluated once per <wcs-state>, so the state keeps the value it read when the page loaded (a token or a session that changes later is not seen). Keep the value in state (bind it with <wcs-storage>), or read it inside the method that uses it`,
|
|
12136
|
+
eventTokenUnbound: (t, handler) => `The event token "${t}" is declared in $eventTokens, but no eventToken.<member>: ${t} binding in this document emits it: no element fires it, so ${handler ? "its $on handler never runs" : "it never fires"}. Bind it on the element whose event should fire it (eventToken.<member>: ${t}, with <member> a wcBindable property of that element), or remove it from $eventTokens`,
|
|
12137
|
+
objectKeyAssign: (t, acc, sp) => `This assigns a key of "${t}" in place. The state does not see the write, so no binding, getter or $watch that reads it changes, and nothing is rendered again. Assign a new object (${acc} = { ...${acc}, [key]: value }), or write the dot path this["${sp}"] = \u2026`,
|
|
12065
12138
|
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`,
|
|
12066
12139
|
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`,
|
|
12067
12140
|
handlerFilterNotAllowed: (prop) => `Filters cannot be applied to event handler "${prop}"`,
|
|
@@ -12638,7 +12711,7 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
|
|
|
12638
12711
|
start: bindingStart + leadingSpace,
|
|
12639
12712
|
end: bindingStart + leadingSpace + propNoMod.length,
|
|
12640
12713
|
message: msgs.submitWithoutPrevent(handler),
|
|
12641
|
-
severity: "
|
|
12714
|
+
severity: "error"
|
|
12642
12715
|
});
|
|
12643
12716
|
}
|
|
12644
12717
|
if (DELEGATED_EVENTS.has(eventName) && !modifiers.includes(DIRECT_MODIFIER) && attr.tagName !== void 0 && !(attr.tagName.includes("-") && CUSTOM_ELEMENT_OWN_EVENTS.has(eventName)) && /^[A-Za-z_][\w$]*(?:\.[A-Za-z_][\w$]*)*$/.test(handler) && getCurrentTargetHandlers().has(handler)) {
|
|
@@ -12760,11 +12833,12 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
|
|
|
12760
12833
|
if (verdict) {
|
|
12761
12834
|
const pathOffset = binding.indexOf(parsed.path);
|
|
12762
12835
|
const pathStart = bindingStart + pathOffset;
|
|
12836
|
+
const near = verdict.code === WcsDiagnosticCode.BindingPathMissing || verdict.code === WcsDiagnosticCode.PathNonexistent ? rowFieldSuggestion(checkPath, scopedPaths, msgs) : "";
|
|
12763
12837
|
diagnostics.push({
|
|
12764
12838
|
code: verdict.code,
|
|
12765
12839
|
start: pathStart,
|
|
12766
12840
|
end: pathStart + pathTrimmed.length,
|
|
12767
|
-
message: `${verdict.message}${pathTrimmed.startsWith(".") ? msgs.expansionSuffix(checkPath) : ""}`,
|
|
12841
|
+
message: `${verdict.message}${pathTrimmed.startsWith(".") ? msgs.expansionSuffix(checkPath) : ""}${near}`,
|
|
12768
12842
|
severity: verdict.severity
|
|
12769
12843
|
});
|
|
12770
12844
|
} else if (writesBack(attr, propNoMod, parsed.property)) {
|
|
@@ -13471,6 +13545,7 @@ function findDestructiveCalls(script, baseOffset, msgs, out) {
|
|
|
13471
13545
|
}
|
|
13472
13546
|
}
|
|
13473
13547
|
function findIndexAssigns(script, baseOffset, msgs, out) {
|
|
13548
|
+
let paths = null;
|
|
13474
13549
|
for (const pattern of [DOT_INDEX_ASSIGN, BRACKET_INDEX_ASSIGN, PRE_DOT_INDEX, PRE_BRACKET_INDEX]) {
|
|
13475
13550
|
for (const match of execAllMasked(pattern, script)) {
|
|
13476
13551
|
const [root, chain] = match.groups;
|
|
@@ -13478,17 +13553,30 @@ function findIndexAssigns(script, baseOffset, msgs, out) {
|
|
|
13478
13553
|
if (isApiRoot(root)) continue;
|
|
13479
13554
|
const suggestedPath = root + chainToDotted(chain);
|
|
13480
13555
|
const start = baseOffset + match.index;
|
|
13556
|
+
const last = LAST_SUB.exec(chain);
|
|
13557
|
+
const target = root + chainToDotted(last === null ? chain : chain.slice(0, last.index));
|
|
13558
|
+
const numeric2 = last !== null && /^\s*\d+\s*$/.test(last[1]);
|
|
13559
|
+
const kind = containerKind(target, paths ??= analyzeStatePaths(script));
|
|
13481
13560
|
out.push({
|
|
13482
13561
|
code: WcsDiagnosticCode.ArrayIndexAssign,
|
|
13483
13562
|
start,
|
|
13484
13563
|
end: start + match.length,
|
|
13485
|
-
message: msgs.arrayIndexAssign(suggestedPath),
|
|
13564
|
+
message: kind === "array" || kind === "unknown" && numeric2 ? msgs.arrayIndexAssign(suggestedPath) : msgs.objectKeyAssign(target, toAccessor(target), suggestedPath),
|
|
13486
13565
|
severity: "error",
|
|
13487
13566
|
statePath: suggestedPath
|
|
13488
13567
|
});
|
|
13489
13568
|
}
|
|
13490
13569
|
}
|
|
13491
13570
|
}
|
|
13571
|
+
var LAST_SUB = /(?:\?\.)?\s*\[([^[\]]+)\]\s*$/;
|
|
13572
|
+
function containerKind(target, paths) {
|
|
13573
|
+
const path = target.split(".").map((s) => /^<.*>$/.test(s) || /^\d+$/.test(s) ? "*" : s).join(".");
|
|
13574
|
+
if (paths.some((p) => p.path === `${path}.*`)) return "array";
|
|
13575
|
+
const hints = (paths.find((p) => p.path === path)?.typeHint ?? "").split("|");
|
|
13576
|
+
if (hints.includes("array")) return "array";
|
|
13577
|
+
if (hints.includes("object") || paths.some((p) => p.path.startsWith(`${path}.`))) return "object";
|
|
13578
|
+
return "unknown";
|
|
13579
|
+
}
|
|
13492
13580
|
|
|
13493
13581
|
// src/service/templateSyntax.ts
|
|
13494
13582
|
var MUSTACHE = /\{\{\s*((?:(?!<[A-Za-z/!?])[\s\S])+?)\s*\}\}/dg;
|
|
@@ -13662,6 +13750,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
13662
13750
|
const defaultPaths = allPaths;
|
|
13663
13751
|
const pathSet = new Set(defaultPaths.map((p) => p.path));
|
|
13664
13752
|
const filterNameSet = new Set(BUILTIN_FILTERS.map((f) => f.name));
|
|
13753
|
+
const nearRowField = (code, path) => code === WcsDiagnosticCode.BindingPathMissing || code === WcsDiagnosticCode.PathNonexistent ? rowFieldSuggestion(path, defaultPaths, msgs) : "";
|
|
13665
13754
|
const mustaches = findAllMustacheSyntax(html);
|
|
13666
13755
|
const comments = findAllCommentBindings(html);
|
|
13667
13756
|
for (const item of [...mustaches, ...comments]) {
|
|
@@ -13774,7 +13863,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
13774
13863
|
code: verdict.code,
|
|
13775
13864
|
start: item.exprStart,
|
|
13776
13865
|
end: item.exprStart + pathPart.length,
|
|
13777
|
-
message: verdict.message + msgs.expansionSuffix(expandedPath),
|
|
13866
|
+
message: verdict.message + msgs.expansionSuffix(expandedPath) + nearRowField(verdict.code, expandedPath),
|
|
13778
13867
|
severity: verdict.severity
|
|
13779
13868
|
});
|
|
13780
13869
|
}
|
|
@@ -13786,7 +13875,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
13786
13875
|
code: verdict.code,
|
|
13787
13876
|
start: item.exprStart,
|
|
13788
13877
|
end: item.exprStart + pathPart.length,
|
|
13789
|
-
message: verdict.message,
|
|
13878
|
+
message: verdict.message + nearRowField(verdict.code, pathPart),
|
|
13790
13879
|
severity: verdict.severity
|
|
13791
13880
|
});
|
|
13792
13881
|
}
|
|
@@ -16349,7 +16438,7 @@ function validatePackageLoads(html, locale2, fileReader) {
|
|
|
16349
16438
|
code: WcsDiagnosticCode.TagPackageMissing,
|
|
16350
16439
|
start: at2.start,
|
|
16351
16440
|
end: at2.end,
|
|
16352
|
-
severity: "
|
|
16441
|
+
severity: "error",
|
|
16353
16442
|
tag: at2.tags[0],
|
|
16354
16443
|
message: msgs.tagPackageMissing(at2.tags, `@wcstack/${pkg}`, `https://esm.run/@wcstack/${pkg}${version3 === null ? "" : `@${version3}`}/auto`)
|
|
16355
16444
|
});
|
|
@@ -16631,10 +16720,10 @@ var NO_MOUNTS = /* @__PURE__ */ new Set();
|
|
|
16631
16720
|
function assignVolumes(elements, html) {
|
|
16632
16721
|
const chainOf = createTemplateChain(html);
|
|
16633
16722
|
const innermost = (chain) => chain.length > 0 ? chain[chain.length - 1] : -1;
|
|
16634
|
-
const
|
|
16723
|
+
const treeOf = (root) => innermost(chainOf(root.tagStart));
|
|
16635
16724
|
const rootTrees = /* @__PURE__ */ new Set();
|
|
16636
16725
|
for (const element2 of elements) {
|
|
16637
|
-
if (element2.mountPath === null && !element2.bindComponent) rootTrees.add(
|
|
16726
|
+
if (element2.mountPath === null && !element2.bindComponent) rootTrees.add(treeOf(element2));
|
|
16638
16727
|
}
|
|
16639
16728
|
const volumes = /* @__PURE__ */ new Map();
|
|
16640
16729
|
for (const element2 of elements) {
|
|
@@ -16651,7 +16740,7 @@ function assignVolumes(elements, html) {
|
|
|
16651
16740
|
if (list === void 0) volumes.set(tree, [element2]);
|
|
16652
16741
|
else list.push(element2);
|
|
16653
16742
|
}
|
|
16654
|
-
return { treeOf
|
|
16743
|
+
return { treeOf, volumes };
|
|
16655
16744
|
}
|
|
16656
16745
|
function validateEntry(entry, pathSet, paths, scopes, msgs) {
|
|
16657
16746
|
const { key } = entry;
|
|
@@ -18447,13 +18536,17 @@ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bind
|
|
|
18447
18536
|
if (blocks.length === 0) return [];
|
|
18448
18537
|
const msgs = getMessages(locale2);
|
|
18449
18538
|
const out = [];
|
|
18539
|
+
let hidden = null;
|
|
18450
18540
|
let receivers = null;
|
|
18451
18541
|
let markupEmits = null;
|
|
18542
|
+
let eventEmits = null;
|
|
18452
18543
|
const bindings = () => {
|
|
18453
18544
|
if (receivers !== null) return;
|
|
18454
18545
|
receivers = /* @__PURE__ */ new Set();
|
|
18455
18546
|
markupEmits = /* @__PURE__ */ new Map();
|
|
18547
|
+
eventEmits = /* @__PURE__ */ new Set();
|
|
18456
18548
|
for (const o of buildReferenceIndex(html, { bindAttribute: bindAttrName, stateTagName }).occurrences) {
|
|
18549
|
+
if (o.kind === "eventToken") eventEmits.add(o.path);
|
|
18457
18550
|
if (!o.path.startsWith("$command.")) continue;
|
|
18458
18551
|
const name = o.path.slice("$command.".length);
|
|
18459
18552
|
const prop = o.propName ?? "";
|
|
@@ -18499,6 +18592,23 @@ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bind
|
|
|
18499
18592
|
});
|
|
18500
18593
|
}
|
|
18501
18594
|
}
|
|
18595
|
+
const events = paths.filter((p) => p.kind === "eventToken").map((p) => p.path);
|
|
18596
|
+
if (block.mountPath === null && events.length > 0) {
|
|
18597
|
+
bindings();
|
|
18598
|
+
const unbound = events.filter((name) => !eventEmits.has(name));
|
|
18599
|
+
if (unbound.length > 0 && !(hidden ??= hidesEmitters(html, blocks))) {
|
|
18600
|
+
const handlers = new Set(analyzeOnHandlerSources(block.content).map((h) => h.name));
|
|
18601
|
+
for (const at2 of declaredNames(block.content, unbound)) {
|
|
18602
|
+
out.push({
|
|
18603
|
+
code: WcsDiagnosticCode.EventTokenUnbound,
|
|
18604
|
+
start: block.contentStart + at2.start,
|
|
18605
|
+
end: block.contentStart + at2.end,
|
|
18606
|
+
message: msgs.eventTokenUnbound(at2.name, handlers.has(at2.name)),
|
|
18607
|
+
severity: "warning"
|
|
18608
|
+
});
|
|
18609
|
+
}
|
|
18610
|
+
}
|
|
18611
|
+
}
|
|
18502
18612
|
const keys = [...new Set(paths.map((p) => p.path.split(".")[0]).filter((key) => key !== "" && !key.startsWith("$")))];
|
|
18503
18613
|
const reported = /* @__PURE__ */ new Set();
|
|
18504
18614
|
for (const pattern of [THIS_WRITE, PRE_THIS_WRITE]) {
|
|
@@ -18523,6 +18633,33 @@ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bind
|
|
|
18523
18633
|
}
|
|
18524
18634
|
return out;
|
|
18525
18635
|
}
|
|
18636
|
+
function declaredNames(script, names2) {
|
|
18637
|
+
const decl = findTopLevelDeclaration(script, "$eventTokens");
|
|
18638
|
+
if (decl === null || decl.value === void 0 || decl.valueStart === void 0 || literalKind(decl.value) !== "array") return [];
|
|
18639
|
+
const out = [];
|
|
18640
|
+
for (const element2 of arrayElements(blankComments(decl.value))) {
|
|
18641
|
+
if (literalKind(element2.text) !== "string") continue;
|
|
18642
|
+
const name = element2.text.slice(1, -1);
|
|
18643
|
+
if (!names2.includes(name) || out.some((o) => o.name === name)) continue;
|
|
18644
|
+
const start = decl.valueStart + element2.start + 1;
|
|
18645
|
+
out.push({ name, start, end: start + name.length });
|
|
18646
|
+
}
|
|
18647
|
+
return out;
|
|
18648
|
+
}
|
|
18649
|
+
var LAYOUT_SRC = /<wcs-layout\b(?:"[^"]*"|'[^']*'|[^>"'])*?\ssrc\s*=/i;
|
|
18650
|
+
var SCRIPT = /(<script\b(?:"[^"]*"|'[^']*'|[^>"'])*>)([\s\S]*?)<\/script\s*>/gi;
|
|
18651
|
+
function hidesEmitters(html, blocks) {
|
|
18652
|
+
const text3 = html.replace(/<!--[\s\S]*?-->/g, (c) => " ".repeat(c.length));
|
|
18653
|
+
if (LAYOUT_SRC.test(text3)) return true;
|
|
18654
|
+
SCRIPT.lastIndex = 0;
|
|
18655
|
+
let m;
|
|
18656
|
+
while ((m = SCRIPT.exec(text3)) !== null) {
|
|
18657
|
+
const contentStart = m.index + m[1].length;
|
|
18658
|
+
if (blocks.some((b) => b.contentStart === contentStart)) continue;
|
|
18659
|
+
if (m[2].includes("eventToken.")) return true;
|
|
18660
|
+
}
|
|
18661
|
+
return false;
|
|
18662
|
+
}
|
|
18526
18663
|
|
|
18527
18664
|
// src/service/scriptReadValidator.ts
|
|
18528
18665
|
function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileReader, applicationSchema, bindAttribute = "data-wcs") {
|
|
@@ -18574,7 +18711,7 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18574
18711
|
if (read.indexed !== void 0 && !read.indexed.every((list) => isList(prefix + list, candidates, candidateSet))) continue;
|
|
18575
18712
|
if (pathExistsInCandidates(path, candidates, candidateSet)) continue;
|
|
18576
18713
|
if (applicationSchema !== void 0 ? resolveIndexedSchemaPath(applicationSchema, path).kind !== "nonexistent" : isUnresolvedPath(path, index.scopes)) continue;
|
|
18577
|
-
const near =
|
|
18714
|
+
const near = missingSegment(path, tree ??= pathTree(candidates));
|
|
18578
18715
|
if (near === null) continue;
|
|
18579
18716
|
const said = suggestion(near.segment, near.names, msgs);
|
|
18580
18717
|
if (said === "") continue;
|
|
@@ -18601,31 +18738,6 @@ var THIS_PART = /^this\s*(?:\?\.\s*|\.\s*)(?:[A-Za-z_$][\w$]*)|^this\s*(?:\?\.)?
|
|
|
18601
18738
|
function statePart(text3) {
|
|
18602
18739
|
return THIS_PART.exec(text3)?.[0].length ?? text3.length;
|
|
18603
18740
|
}
|
|
18604
|
-
function treeOf(candidates) {
|
|
18605
|
-
const tree = /* @__PURE__ */ new Map();
|
|
18606
|
-
for (const c of candidates) {
|
|
18607
|
-
let parent = "";
|
|
18608
|
-
for (const segment of c.path.split(".")) {
|
|
18609
|
-
let names2 = tree.get(parent);
|
|
18610
|
-
if (names2 === void 0) tree.set(parent, names2 = /* @__PURE__ */ new Set());
|
|
18611
|
-
names2.add(segment);
|
|
18612
|
-
parent = parent === "" ? segment : `${parent}.${segment}`;
|
|
18613
|
-
}
|
|
18614
|
-
}
|
|
18615
|
-
return tree;
|
|
18616
|
-
}
|
|
18617
|
-
function nearName(path, tree) {
|
|
18618
|
-
let parent = "";
|
|
18619
|
-
for (const segment of (hasIndexSegment(path) ? toWildcardForm(path) : path).split(".")) {
|
|
18620
|
-
const names2 = tree.get(parent);
|
|
18621
|
-
if (names2?.has(segment)) {
|
|
18622
|
-
parent = parent === "" ? segment : `${parent}.${segment}`;
|
|
18623
|
-
continue;
|
|
18624
|
-
}
|
|
18625
|
-
return { segment, names: [...names2 ?? []].filter((name) => name !== "*" && !name.startsWith("$")) };
|
|
18626
|
-
}
|
|
18627
|
-
return null;
|
|
18628
|
-
}
|
|
18629
18741
|
|
|
18630
18742
|
// src/service/scriptWriteValidator.ts
|
|
18631
18743
|
var OPTIONS = { writes: true, templates: true, resolveWrites: true, untracked: true, opaque: true };
|
|
@@ -18825,6 +18937,112 @@ function unobservedSetters(state, msgs, at2) {
|
|
|
18825
18937
|
return out;
|
|
18826
18938
|
}
|
|
18827
18939
|
|
|
18940
|
+
// src/service/moduleTopReadValidator.ts
|
|
18941
|
+
var GUARD_TAG = "wcs-guard-handler";
|
|
18942
|
+
var STORAGES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
18943
|
+
var GLOBALS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
18944
|
+
var STORAGE_WRITES = /* @__PURE__ */ new Set(["setItem", "removeItem", "clear"]);
|
|
18945
|
+
function validateModuleTopReads(html, stateTagName = "wcs-state", locale2) {
|
|
18946
|
+
const msgs = getMessages(locale2);
|
|
18947
|
+
const out = [];
|
|
18948
|
+
const check = (blocks, guard) => {
|
|
18949
|
+
for (const block of blocks) {
|
|
18950
|
+
for (const read of findTopLevelReads(block.content)) {
|
|
18951
|
+
out.push({
|
|
18952
|
+
code: WcsDiagnosticCode.SessionReadAtModuleTop,
|
|
18953
|
+
start: block.contentStart + read.start,
|
|
18954
|
+
end: block.contentStart + read.end,
|
|
18955
|
+
message: guard ? msgs.guardReadsAtModuleTop(read.text) : msgs.stateReadsAtModuleTop(read.text),
|
|
18956
|
+
severity: guard ? "error" : "warning"
|
|
18957
|
+
});
|
|
18958
|
+
}
|
|
18959
|
+
}
|
|
18960
|
+
};
|
|
18961
|
+
if (html.includes(GUARD_TAG)) check(parseWcsScriptBlocks(html, GUARD_TAG), true);
|
|
18962
|
+
check(parseLoadedScriptBlocks(html, stateTagName), false);
|
|
18963
|
+
return out;
|
|
18964
|
+
}
|
|
18965
|
+
function findTopLevelReads(source) {
|
|
18966
|
+
if (!/localStorage|sessionStorage|cookie/.test(source)) return [];
|
|
18967
|
+
let program;
|
|
18968
|
+
try {
|
|
18969
|
+
program = parse3(source, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true });
|
|
18970
|
+
} catch {
|
|
18971
|
+
return [];
|
|
18972
|
+
}
|
|
18973
|
+
const out = [];
|
|
18974
|
+
const visit2 = (node, assigned) => {
|
|
18975
|
+
switch (node.type) {
|
|
18976
|
+
// run when called (a getter, a setter and a method are function expressions under their property)
|
|
18977
|
+
case "FunctionDeclaration":
|
|
18978
|
+
case "FunctionExpression":
|
|
18979
|
+
case "ArrowFunctionExpression":
|
|
18980
|
+
case "ClassDeclaration":
|
|
18981
|
+
case "ClassExpression":
|
|
18982
|
+
return;
|
|
18983
|
+
case "AssignmentExpression":
|
|
18984
|
+
visit2(node.left, node.operator === "=");
|
|
18985
|
+
visit2(node.right, false);
|
|
18986
|
+
return;
|
|
18987
|
+
case "CallExpression": {
|
|
18988
|
+
const callee = node.callee;
|
|
18989
|
+
if (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") {
|
|
18990
|
+
visit2(callee.body, false);
|
|
18991
|
+
for (const arg of node.arguments) visit2(arg, false);
|
|
18992
|
+
return;
|
|
18993
|
+
}
|
|
18994
|
+
break;
|
|
18995
|
+
}
|
|
18996
|
+
case "MemberExpression": {
|
|
18997
|
+
const read = readOf(node, assigned, source);
|
|
18998
|
+
if (read !== null) {
|
|
18999
|
+
out.push(read);
|
|
19000
|
+
return;
|
|
19001
|
+
}
|
|
19002
|
+
break;
|
|
19003
|
+
}
|
|
19004
|
+
default:
|
|
19005
|
+
break;
|
|
19006
|
+
}
|
|
19007
|
+
for (const child of children(node)) visit2(child, false);
|
|
19008
|
+
};
|
|
19009
|
+
visit2(program, false);
|
|
19010
|
+
return out;
|
|
19011
|
+
}
|
|
19012
|
+
function readOf(node, assigned, source) {
|
|
19013
|
+
const object = node.object;
|
|
19014
|
+
const prop = propertyName(node);
|
|
19015
|
+
if (isGlobal(object, STORAGES)) {
|
|
19016
|
+
if (assigned || prop !== null && STORAGE_WRITES.has(prop)) return null;
|
|
19017
|
+
return { start: node.start, end: node.end, text: source.slice(node.start, node.end) };
|
|
19018
|
+
}
|
|
19019
|
+
if (prop === "cookie" && !assigned && isGlobal(object, /* @__PURE__ */ new Set(["document"]))) {
|
|
19020
|
+
return { start: node.start, end: node.end, text: source.slice(node.start, node.end) };
|
|
19021
|
+
}
|
|
19022
|
+
return null;
|
|
19023
|
+
}
|
|
19024
|
+
function isGlobal(node, names2) {
|
|
19025
|
+
if (node.type === "Identifier") return names2.has(node.name);
|
|
19026
|
+
if (node.type !== "MemberExpression" || node.computed) return false;
|
|
19027
|
+
const object = node.object;
|
|
19028
|
+
return object.type === "Identifier" && GLOBALS.has(object.name) && node.property.type === "Identifier" && names2.has(node.property.name);
|
|
19029
|
+
}
|
|
19030
|
+
function propertyName(node) {
|
|
19031
|
+
if (!node.computed) return node.property.type === "Identifier" ? node.property.name : null;
|
|
19032
|
+
return node.property.type === "Literal" && typeof node.property.value === "string" ? node.property.value : null;
|
|
19033
|
+
}
|
|
19034
|
+
function children(node) {
|
|
19035
|
+
const out = [];
|
|
19036
|
+
for (const value of Object.values(node)) {
|
|
19037
|
+
if (Array.isArray(value)) {
|
|
19038
|
+
for (const v of value) if (v !== null && typeof v === "object" && typeof v.type === "string") out.push(v);
|
|
19039
|
+
} else if (value !== null && typeof value === "object" && typeof value.type === "string") {
|
|
19040
|
+
out.push(value);
|
|
19041
|
+
}
|
|
19042
|
+
}
|
|
19043
|
+
return out;
|
|
19044
|
+
}
|
|
19045
|
+
|
|
18828
19046
|
// src/service/stateSourceValidator.ts
|
|
18829
19047
|
function validateStateSources(html, stateTagName = "wcs-state", locale2, fileReader) {
|
|
18830
19048
|
if (fileReader === void 0) return [];
|
|
@@ -19418,6 +19636,7 @@ function validateText(text3, options, applicationSchema) {
|
|
|
19418
19636
|
out.push(...validateScriptReads(text3, stateTagName, locale2, fileReader, applicationSchema, bindAttribute));
|
|
19419
19637
|
out.push(...validateScriptWrites(text3, stateTagName, locale2));
|
|
19420
19638
|
out.push(...validateArrayMutations(text3, stateTagName, locale2));
|
|
19639
|
+
out.push(...validateModuleTopReads(text3, stateTagName, locale2));
|
|
19421
19640
|
out.push(...validateWatchDeclarations(text3, stateTagName, locale2, fileReader));
|
|
19422
19641
|
out.push(...validateScanDeclarations(text3, stateTagName, locale2));
|
|
19423
19642
|
out.push(...validateRecursion(text3, stateTagName, locale2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/lint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.21.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": {
|