@wcstack/lint 4.20.0 → 4.22.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 +455 -87
- 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",
|
|
@@ -265,6 +270,14 @@ var WcsDiagnosticCode = {
|
|
|
265
270
|
// 元の値を返し、双方向の入力はそこへ戻る — 何も知らせない(4.17 から diagnostics の後付けが警告する)。setter・getter
|
|
266
271
|
// の読み書きを追えない(`this[key]`・`fn(this)`・知らないメソッド)なら黙る。warning。
|
|
267
272
|
SetterUnobserved: "wcs/setter-unobserved",
|
|
273
|
+
// 1 つのアクセサを複数のパスに宣言するキー(`get "users.*.full,employees.*.full"()`、4.22)の書き方の誤り:
|
|
274
|
+
// カンマの前後の空白・空の項目・再帰のキー(`**`)。ランタイムはカンマで分けた間をそのままパスにするので、
|
|
275
|
+
// 空白入りのパスは誰も読まないパスになる(diagnostics の後付けは同じコードで初期化を失敗させる)。error。
|
|
276
|
+
AccessorListSyntax: "wcs/accessor-list-syntax",
|
|
277
|
+
// 複数のリストに宣言したアクセサの本体が、そのうち 1 つのリストの行を絶対パス(`this["users.*.first"]`)で
|
|
278
|
+
// 読み書きしている。ほかのリストの行ではそのパスに行が無く、読みは undefined、書きは例外になる。本体は
|
|
279
|
+
// 行からの相対パス(`this[".first"]`)で書く(diagnostics の後付けは同じコードで警告する)。error。
|
|
280
|
+
AccessorListPath: "wcs/accessor-list-path",
|
|
268
281
|
// `$renderedCallback`(3.x の旧名 `$updatedCallback`)が、どのバインディングにも現れないパスを判定に使っている。
|
|
269
282
|
// 同コールバックは **binding 駆動**(live binding が適用された path しか報告しない)
|
|
270
283
|
// なので、その分岐は一度も実行されない。表示要素が購読の実体になる事故
|
|
@@ -360,8 +373,15 @@ var WcsDiagnosticCode = {
|
|
|
360
373
|
DelegatedCurrentTarget: "wcs/delegated-current-target",
|
|
361
374
|
// `<form data-wcs="onsubmit: login">` の `#prevent` 忘れ(ハンドラも preventDefault を呼ばない)。ブラウザが
|
|
362
375
|
// フォームも送る — ページが読み直されるか、router があれば GET が欄(パスワードも)を URL と履歴に載せる
|
|
363
|
-
// (docs/seam-apps.md、router-auth)。
|
|
376
|
+
// (docs/seam-apps.md、router-auth)。error(4.21 から — 4.20 までは warning で、`--errors-only` に隠れた: 継ぎ目アプリ
|
|
377
|
+
// ledger-repair)。action 付きのフォームと、読めないハンドラでは黙る。
|
|
364
378
|
SubmitWithoutPrevent: "wcs/submit-without-prevent",
|
|
379
|
+
// `localStorage` / `sessionStorage` / `document.cookie` を、1 回しか評価されないモジュールのトップレベル(関数の外)で読む。
|
|
380
|
+
// `<wcs-guard-handler>` のモジュールは 1 回だけ評価され、export した関数が遷移のたびに走る(router の README)ので、ガードは
|
|
381
|
+
// 読み込みの時点のセッションで決め続ける — ログインしても守られたページはすべて /login へ戻され、何も言わない(継ぎ目アプリ
|
|
382
|
+
// ledger-repair)。ガードは error、`<wcs-state>` のモジュール(インライン・`src=`)は warning(state は読み込みの時点の値を
|
|
383
|
+
// 持ち続ける — 意図した種もありうる)。関数の中(export した関数・そこから呼ぶ補助関数・getter・メソッド)の読みは黙る。
|
|
384
|
+
SessionReadAtModuleTop: "wcs/session-read-at-module-top",
|
|
365
385
|
// 4.0 で外れた API の旧名(`this.$trackDependency` → `$dependOn`、`$untrackDependency` → `$untracked`)。
|
|
366
386
|
// ランタイムは読んだ時点で同じ code(#1701)で throw するので error。3.x(3.2〜3.3)では「動くが 4.0 で
|
|
367
387
|
// 外れる」info だった。フィルタの旧名(`uc` など)は 4.0 のランタイムと同じく `wcs/filter-unknown` で、
|
|
@@ -432,7 +452,8 @@ var WcsDiagnosticCode = {
|
|
|
432
452
|
// wcstack を自分で読み込むページが、あるパッケージのタグ(`<wcs-upload>`・`<wcs-upload-header>`)を書くのに、その
|
|
433
453
|
// パッケージのスクリプトを読み込んでいない。要素は定義されず、束縛は待ち続け、コンソールにも何も出ない(継ぎ目アプリ
|
|
434
454
|
// homeroom — 保存が「送信中 0%」で止まった)。パッケージごとに 1 回、最初のタグに。読めないローカルのスクリプトがある
|
|
435
|
-
// ページ・autoloader の `@components/` が覆うタグ・wcstack を自分で読み込まないページ(断片・バンドラ)では黙る。
|
|
455
|
+
// ページ・autoloader の `@components/` が覆うタグ・wcstack を自分で読み込まないページ(断片・バンドラ)では黙る。error
|
|
456
|
+
// (4.21 から — 4.20 までは warning で、`--errors-only` に隠れた: 継ぎ目アプリ ledger-repair)。
|
|
436
457
|
TagPackageMissing: "wcs/tag-package-missing",
|
|
437
458
|
// `<wcs-router>` の無いページの、内部のパス(`to="/…"`)へ飛ぶ `<wcs-link>`。リンクは接続で
|
|
438
459
|
// `[@wcstack/router] wcs-link is not connected to a router.` を投げ、ホストは `display: none` のまま `<a>` を作らない
|
|
@@ -1223,7 +1244,7 @@ var SENTENCES = {
|
|
|
1223
1244
|
[
|
|
1224
1245
|
1402
|
|
1225
1246
|
/* WildcardRelative */
|
|
1226
|
-
]: (p) => `"${p}" is relative: it needs an enclosing "for" template`,
|
|
1247
|
+
]: (p) => `"${p}" is relative: it needs an enclosing "for" template (in script, a row: a row accessor, or a method called from a row)`,
|
|
1227
1248
|
[
|
|
1228
1249
|
1403
|
|
1229
1250
|
/* WildcardOtherList */
|
|
@@ -2543,7 +2564,7 @@ function getWcsManifest() {
|
|
|
2543
2564
|
}
|
|
2544
2565
|
|
|
2545
2566
|
// ../state/package.json
|
|
2546
|
-
var version = "4.
|
|
2567
|
+
var version = "4.22.0";
|
|
2547
2568
|
|
|
2548
2569
|
// src/service/wcsManifest.ts
|
|
2549
2570
|
var ENGINE_VERSION = version;
|
|
@@ -2568,7 +2589,72 @@ var STRUCTURAL_DIRECTIVES = [...STRUCTURAL_BINDING_TYPE_SET2].map((name) => ({
|
|
|
2568
2589
|
...STRUCTURAL_DIRECTIVE_INFO[name]
|
|
2569
2590
|
}));
|
|
2570
2591
|
|
|
2592
|
+
// src/service/indexPath.ts
|
|
2593
|
+
var INDEX_SEGMENT = /^\d/;
|
|
2594
|
+
function isIndexSegment(segment) {
|
|
2595
|
+
return INDEX_SEGMENT.test(segment);
|
|
2596
|
+
}
|
|
2597
|
+
function hasIndexSegment(path) {
|
|
2598
|
+
return path.split(".").some((segment) => INDEX_SEGMENT.test(segment));
|
|
2599
|
+
}
|
|
2600
|
+
function toWildcardForm(path) {
|
|
2601
|
+
if (!hasIndexSegment(path)) return path;
|
|
2602
|
+
return path.split(".").map((segment) => INDEX_SEGMENT.test(segment) ? "*" : segment).join(".");
|
|
2603
|
+
}
|
|
2604
|
+
function candidateKeyOf(path, has) {
|
|
2605
|
+
return has(path) ? path : toWildcardForm(path);
|
|
2606
|
+
}
|
|
2607
|
+
var UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype"]);
|
|
2608
|
+
function hasUnsafeSegment(path) {
|
|
2609
|
+
return path.split(".").some((segment) => UNSAFE_SEGMENTS.has(segment));
|
|
2610
|
+
}
|
|
2611
|
+
var { maxDepth } = getWcsManifest().syntax.indexParam;
|
|
2612
|
+
var MAX_INDEX_PARAM3 = maxDepth;
|
|
2613
|
+
var INDEX_PARAM = new RegExp(`^\\$[1-9]\\d{0,${String(maxDepth).length - 1}}$`);
|
|
2614
|
+
function classifyIndexParam(path) {
|
|
2615
|
+
if (!/^\$\d+$/.test(path)) return null;
|
|
2616
|
+
if (!INDEX_PARAM.test(path)) return { kind: "notIndex" };
|
|
2617
|
+
const n = Number(path.slice(1));
|
|
2618
|
+
return n <= MAX_INDEX_PARAM3 ? { kind: "index", n } : { kind: "range", n };
|
|
2619
|
+
}
|
|
2620
|
+
function isOutOfRangeIndexRead(name) {
|
|
2621
|
+
if (name.length < 2 || name.charCodeAt(0) !== 36) return false;
|
|
2622
|
+
const c = name.charCodeAt(1);
|
|
2623
|
+
if (c < 48 || c > 57) return false;
|
|
2624
|
+
return !INDEX_PARAM.test(name) || Number(name.slice(1)) > MAX_INDEX_PARAM3;
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2571
2627
|
// src/service/suggestion.ts
|
|
2628
|
+
function pathTree(candidates) {
|
|
2629
|
+
const tree = /* @__PURE__ */ new Map();
|
|
2630
|
+
for (const c of candidates) {
|
|
2631
|
+
let parent = "";
|
|
2632
|
+
for (const segment of c.path.split(".")) {
|
|
2633
|
+
let names2 = tree.get(parent);
|
|
2634
|
+
if (names2 === void 0) tree.set(parent, names2 = /* @__PURE__ */ new Set());
|
|
2635
|
+
names2.add(segment);
|
|
2636
|
+
parent = parent === "" ? segment : `${parent}.${segment}`;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
return tree;
|
|
2640
|
+
}
|
|
2641
|
+
function missingSegment(path, tree) {
|
|
2642
|
+
let parent = "";
|
|
2643
|
+
for (const segment of (hasIndexSegment(path) ? toWildcardForm(path) : path).split(".")) {
|
|
2644
|
+
const names2 = tree.get(parent);
|
|
2645
|
+
if (names2?.has(segment)) {
|
|
2646
|
+
parent = parent === "" ? segment : `${parent}.${segment}`;
|
|
2647
|
+
continue;
|
|
2648
|
+
}
|
|
2649
|
+
return { segment, parent, names: [...names2 ?? []].filter((name) => name !== "*" && !name.startsWith("$")) };
|
|
2650
|
+
}
|
|
2651
|
+
return null;
|
|
2652
|
+
}
|
|
2653
|
+
function rowFieldSuggestion(path, candidates, msgs) {
|
|
2654
|
+
const missing = missingSegment(path, pathTree(candidates));
|
|
2655
|
+
if (missing === null || !missing.parent.split(".").includes("*")) return "";
|
|
2656
|
+
return suggestion(missing.segment, missing.names, msgs);
|
|
2657
|
+
}
|
|
2572
2658
|
function suggestion(input, candidates, msgs) {
|
|
2573
2659
|
let best = null;
|
|
2574
2660
|
let bestDistance = 3;
|
|
@@ -9027,8 +9113,30 @@ function analyzeStatePaths(scriptContent, location) {
|
|
|
9027
9113
|
}
|
|
9028
9114
|
collectRowShapesFromAssignments(scriptContent, paths);
|
|
9029
9115
|
collectGetterResultShapes(scriptContent, root.start, topLevelProps, effectiveDescriptors, paths);
|
|
9116
|
+
markRowsChangedInPlace(scriptContent, paths);
|
|
9030
9117
|
return paths;
|
|
9031
9118
|
}
|
|
9119
|
+
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;
|
|
9120
|
+
var ROWS_IN_PLACE_ASSIGN = /\bthis\s*(?:\?\.|\.)\s*([\w$]+)\s*(?:\?\.)?\s*\[(?!\s*["'])[^[\]]+\]\s*=(?!=)/dg;
|
|
9121
|
+
function markRowsChangedInPlace(scriptContent, paths) {
|
|
9122
|
+
if (!/\b(?:push|unshift|splice|fill)\s*\(|\]\s*=(?!=)/.test(scriptContent)) return;
|
|
9123
|
+
const masked = maskCommentsAndStrings(scriptContent);
|
|
9124
|
+
const changed = /* @__PURE__ */ new Set();
|
|
9125
|
+
ROWS_IN_PLACE_CALL.lastIndex = 0;
|
|
9126
|
+
let m;
|
|
9127
|
+
while ((m = ROWS_IN_PLACE_CALL.exec(masked)) !== null) {
|
|
9128
|
+
if (m[1] !== void 0) changed.add(m[1]);
|
|
9129
|
+
else if (m.indices?.[3] !== void 0) changed.add(scriptContent.slice(m.indices[3][0], m.indices[3][1]));
|
|
9130
|
+
}
|
|
9131
|
+
ROWS_IN_PLACE_ASSIGN.lastIndex = 0;
|
|
9132
|
+
while ((m = ROWS_IN_PLACE_ASSIGN.exec(masked)) !== null) changed.add(m[1]);
|
|
9133
|
+
for (const list of changed) {
|
|
9134
|
+
const rows = paths.find((p) => p.path === `${list}.*` && p.kind === "list");
|
|
9135
|
+
if (rows === void 0 || rows.openKeys === true) continue;
|
|
9136
|
+
const fields = paths.some((p) => p.path.startsWith(`${list}.*.`) && (p.kind === "data" || p.kind === "list"));
|
|
9137
|
+
if (!fields) rows.openKeys = true;
|
|
9138
|
+
}
|
|
9139
|
+
}
|
|
9032
9140
|
function specFromRecursionValue(prop) {
|
|
9033
9141
|
if (!prop || prop.kind !== "data" || !prop.value || !isObjectLiteral(prop.value)) return null;
|
|
9034
9142
|
const entries = parseTopLevelProperties(extractObjectContent(prop.value)).filter((e) => e.kind === "data");
|
|
@@ -9198,6 +9306,13 @@ function analyzeDeclarationSpans(scriptContent) {
|
|
|
9198
9306
|
}
|
|
9199
9307
|
return out;
|
|
9200
9308
|
}
|
|
9309
|
+
function accessorRow(callable) {
|
|
9310
|
+
if (callable.kind !== "getter") return null;
|
|
9311
|
+
const segments = callable.name.split(".");
|
|
9312
|
+
let last = -1;
|
|
9313
|
+
for (let i = 0; i < segments.length; i++) if (segments[i] === "*" || segments[i] === "**") last = i;
|
|
9314
|
+
return last < 0 ? null : segments.slice(0, last + 1).join(".");
|
|
9315
|
+
}
|
|
9201
9316
|
function analyzeCallableBodies(scriptContent) {
|
|
9202
9317
|
const root = locateDefaultExportObject(scriptContent);
|
|
9203
9318
|
if (!root) return [];
|
|
@@ -9212,7 +9327,8 @@ function analyzeCallableBodies(scriptContent) {
|
|
|
9212
9327
|
end: root.start + prop.nameEnd,
|
|
9213
9328
|
body: prop.value ?? "",
|
|
9214
9329
|
bodyStart: root.start + (prop.valueStart ?? 0),
|
|
9215
|
-
accessor: prop.accessor
|
|
9330
|
+
accessor: prop.accessor,
|
|
9331
|
+
...prop.listed !== void 0 ? { listed: { ...prop.listed, start: root.start + prop.listed.start, end: root.start + prop.listed.end } } : {}
|
|
9216
9332
|
});
|
|
9217
9333
|
}
|
|
9218
9334
|
return out;
|
|
@@ -10136,6 +10252,19 @@ function inferJsonTypeHint(value) {
|
|
|
10136
10252
|
if (typeof value === "object") return "object";
|
|
10137
10253
|
return void 0;
|
|
10138
10254
|
}
|
|
10255
|
+
function listedPaths(key, keyStart) {
|
|
10256
|
+
const out = [];
|
|
10257
|
+
let at2 = 0;
|
|
10258
|
+
for (const part of key.split(",")) {
|
|
10259
|
+
const name = part.trim();
|
|
10260
|
+
if (name !== "") {
|
|
10261
|
+
const start = keyStart + at2 + (part.length - part.trimStart().length);
|
|
10262
|
+
out.push({ name, start, end: start + name.length });
|
|
10263
|
+
}
|
|
10264
|
+
at2 += part.length + 1;
|
|
10265
|
+
}
|
|
10266
|
+
return out;
|
|
10267
|
+
}
|
|
10139
10268
|
function locateDefaultExportObject(script) {
|
|
10140
10269
|
const scan = maskCommentsAndStrings(script);
|
|
10141
10270
|
const match = scan.match(/export\s+default\s+(?:defineState\s*\(\s*)?(\{)/);
|
|
@@ -10212,16 +10341,20 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
|
|
|
10212
10341
|
const accessor = match[0].startsWith("set") ? "set" : "get";
|
|
10213
10342
|
const returnsText = accessor === "get" ? readJsDocReturnsBefore(objectContent, match.index) : void 0;
|
|
10214
10343
|
const declaredType = returnsText === void 0 ? null : parseJsDocType(returnsText);
|
|
10215
|
-
|
|
10216
|
-
name: accessorName,
|
|
10344
|
+
const entry = {
|
|
10217
10345
|
kind: "getter",
|
|
10218
10346
|
accessor,
|
|
10219
10347
|
value: body,
|
|
10220
10348
|
valueStart: bodyStart,
|
|
10221
|
-
nameStart: nameSpan[0],
|
|
10222
|
-
nameEnd: nameSpan[1],
|
|
10223
10349
|
...declaredType !== null ? { declaredType } : {}
|
|
10224
|
-
}
|
|
10350
|
+
};
|
|
10351
|
+
const paths = accessorName.includes(",") ? listedPaths(accessorName, nameSpan[0]) : [];
|
|
10352
|
+
if (paths.length > 0) {
|
|
10353
|
+
const listed = { paths: paths.map((p) => p.name), key: accessorName, start: nameSpan[0], end: nameSpan[1] };
|
|
10354
|
+
for (const p of paths) props.push({ name: p.name, ...entry, nameStart: p.start, nameEnd: p.end, listed });
|
|
10355
|
+
continue;
|
|
10356
|
+
}
|
|
10357
|
+
props.push({ name: accessorName, ...entry, nameStart: nameSpan[0], nameEnd: nameSpan[1] });
|
|
10225
10358
|
continue;
|
|
10226
10359
|
}
|
|
10227
10360
|
const methodName = nameAt(4) ?? nameAt(5) ?? nameAt(6);
|
|
@@ -10520,41 +10653,6 @@ function withHint(candidate, typeHint) {
|
|
|
10520
10653
|
return typeHint === void 0 ? candidate : { ...candidate, typeHint };
|
|
10521
10654
|
}
|
|
10522
10655
|
|
|
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
10656
|
// src/service/statePathResolver.ts
|
|
10559
10657
|
function isUnresolvedPath(path, scopes) {
|
|
10560
10658
|
if (scopes.opaquePaths.length > 0) {
|
|
@@ -11082,7 +11180,20 @@ function collectGetterReads(body, options = {}) {
|
|
|
11082
11180
|
} finally {
|
|
11083
11181
|
collecting = {};
|
|
11084
11182
|
}
|
|
11085
|
-
|
|
11183
|
+
const row = options.row;
|
|
11184
|
+
return row == null ? out : out.map((read) => atRow(read, row));
|
|
11185
|
+
}
|
|
11186
|
+
var underRow = (path, row) => path === "." ? row : row + path;
|
|
11187
|
+
var ROW_APIS = /* @__PURE__ */ new Set(["$getAll", "$dependOn"]);
|
|
11188
|
+
function atRow(read, row) {
|
|
11189
|
+
if (!read.path.startsWith(".") || read.api !== void 0 && !ROW_APIS.has(read.api)) return read;
|
|
11190
|
+
return {
|
|
11191
|
+
...read,
|
|
11192
|
+
path: underRow(read.path, row),
|
|
11193
|
+
chain: read.chain === null ? null : [underRow(read.chain[0], row), ...read.chain.slice(1)],
|
|
11194
|
+
...read.indexed !== void 0 ? { indexed: read.indexed.map((list) => underRow(list, row)) } : {},
|
|
11195
|
+
relative: read.path
|
|
11196
|
+
};
|
|
11086
11197
|
}
|
|
11087
11198
|
function unwrapWrapper(program) {
|
|
11088
11199
|
if (program.type !== "Program" || program.body.length !== 1) return null;
|
|
@@ -11346,6 +11457,7 @@ function visitCall(node, scope, out) {
|
|
|
11346
11457
|
form: TRACK_APIS.has(api) ? "track" : "api",
|
|
11347
11458
|
callee: false,
|
|
11348
11459
|
written: false,
|
|
11460
|
+
api,
|
|
11349
11461
|
...scope.nested ? { nested: true } : {},
|
|
11350
11462
|
start: node.start - PREFIX.length,
|
|
11351
11463
|
end: node.end - PREFIX.length
|
|
@@ -11364,6 +11476,7 @@ function visitCall(node, scope, out) {
|
|
|
11364
11476
|
form: "api-write",
|
|
11365
11477
|
callee: false,
|
|
11366
11478
|
written: false,
|
|
11479
|
+
api,
|
|
11367
11480
|
...scope.nested ? { nested: true } : {},
|
|
11368
11481
|
start: first.start - PREFIX.length,
|
|
11369
11482
|
end: first.end - PREFIX.length
|
|
@@ -11825,6 +11938,11 @@ var ja = {
|
|
|
11825
11938
|
setterCycleSelf: (p) => `"${p}" \u306E setter \u304C\u81EA\u5206\u306E\u30D1\u30B9 "${p}" \u306B\u66F8\u3044\u3066\u3044\u307E\u3059\u3002setter \u306E\u30D1\u30B9\u306F\u30A2\u30AF\u30BB\u30B5\u305D\u306E\u3082\u306E\u306A\u306E\u3067\u3001\u66F8\u3051\u3070 setter \u304C\u307E\u305F\u547C\u3070\u308C\u3001\u30B9\u30BF\u30C3\u30AF\u304C\u6EA2\u308C\u308B\u307E\u3067\u7D9A\u304D\u307E\u3059\u3002\u5024\u306F getter \u304C\u8AAD\u3080\u30C7\u30FC\u30BF\u306E\u30D1\u30B9\uFF08_${p.split(".").pop()} \u306A\u3069\uFF09\u306B\u7F6E\u3044\u3066\u304F\u3060\u3055\u3044`,
|
|
11826
11939
|
setterCycle: (cycle) => `setter \u304C\u4E92\u3044\u306B\u66F8\u304D\u5408\u3063\u3066\u3044\u307E\u3059: ${cycle}\u3002\u6761\u4EF6\u3067\u6B62\u307E\u3089\u306A\u3051\u308C\u3070\u3001\u4E92\u3044\u3092\u547C\u3073\u7D9A\u3051\u3066\u30B9\u30BF\u30C3\u30AF\u304C\u6EA2\u308C\u307E\u3059\u3002\u5024\u306F getter \u304C\u8AAD\u3080\u30C7\u30FC\u30BF\u306E\u30D1\u30B9\u306B\u7F6E\u3044\u3066\u304F\u3060\u3055\u3044`,
|
|
11827
11940
|
setterUnobserved: (p, w) => `"${p}" \u306E setter \u306F ${w} \u3092\u66F8\u304D\u307E\u3059\u304C\u3001getter "${p}" \u306F\u305D\u306E\u3069\u308C\u3082\u8AAD\u307F\u307E\u305B\u3093\u3002\u66F8\u3044\u305F\u5F8C\u3082 getter \u306F\u5143\u306E\u5024\u3092\u8FD4\u3057\u3001"${p}" \u306B\u675F\u306D\u305F\u53CC\u65B9\u5411\u306E\u5165\u529B\u306F\u305D\u3053\u3078\u623B\u308A\u307E\u3059\u3002getter \u304C\u8AAD\u3080\u5024\u3092\u66F8\u304F\u304B\u3001setter \u304C\u66F8\u304F\u5024\u3092 getter \u3067\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044`,
|
|
11941
|
+
relativePathOf: (r, a) => `\uFF08\u30A2\u30AF\u30BB\u30B5 "${a}" \u306E\u4E2D\u306E "${r}"\uFF09`,
|
|
11942
|
+
relativeNoRow: (r, a) => `"${r}" \u306F\u884C\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u3059\u304C\u3001\u30A2\u30AF\u30BB\u30B5 "${a}" \u306F\u30EA\u30B9\u30C8\u306E\u884C\u306E\u3082\u306E\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u30AD\u30FC\u306B "*" \u304C\u3042\u308A\u307E\u305B\u3093\uFF09\u3002\u884C\u304C\u7121\u3044\u306E\u3067\u3001\u8A55\u4FA1\u306E\u305F\u3073\u306B\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\uFF08#1402\uFF09\u3002\u30D5\u30EB\u30D1\u30B9\u3067\u66F8\u304F\u304B\u3001\u884C\u306E\u30A2\u30AF\u30BB\u30B5\uFF08get "<\u30EA\u30B9\u30C8>.*.<\u540D\u524D>"()\uFF09\u306B\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
11943
|
+
relativeApiPath: (r, api) => `"${r}" \u306F\u884C\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u3059\u304C\u3001${api} \u306F\u884C\u3092\u6DFB\u5B57\u306E\u5F15\u6570\u3067\u53D7\u3051\u53D6\u308A\u3001\u547C\u3070\u308C\u305F\u884C\u304B\u3089\u306F\u53D6\u308A\u307E\u305B\u3093\u3002\u76F8\u5BFE\u30D1\u30B9\u306F\u3053\u3053\u3067\u306F\u5C55\u958B\u3055\u308C\u305A\u3001\u547C\u3073\u51FA\u3057\u306F\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\u3002\u30D5\u30EB\u30D1\u30B9\u3067\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08"<\u30EA\u30B9\u30C8>.*${r === "." ? "" : r}"\uFF09`,
|
|
11944
|
+
accessorListSyntax: (k, why) => `\u30A2\u30AF\u30BB\u30B5\u306E\u30AD\u30FC "${k}" \u306F\u8907\u6570\u306E\u30D1\u30B9\u306E\u4E26\u3073\u3067\u3059\u304C\u3001${why === "space" ? "\u30AB\u30F3\u30DE\u306E\u524D\u5F8C\u306B\u7A7A\u767D\u304C\u3042\u308A\u307E\u3059" : why === "empty" ? "\u7A7A\u306E\u9805\u76EE\u304C\u3042\u308A\u307E\u3059" : '\u518D\u5E30\u306E\u30D1\u30B9\uFF08"**"\uFF09\u306F\u4E26\u3079\u3089\u308C\u307E\u305B\u3093'}\u3002\u30D1\u30B9\u306F\u30AB\u30F3\u30DE\u3060\u3051\u3067\u533A\u5207\u308A\u307E\u3059\uFF08get "users.*.fullname,employees.*.fullname"()\uFF09${why === "recursive" ? "" : "\u3002\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u30AB\u30F3\u30DE\u306E\u9593\u3092\u305D\u306E\u307E\u307E\u30D1\u30B9\u306B\u3059\u308B\u306E\u3067\u3001\u3053\u306E\u307E\u307E\u3067\u306F\u8AB0\u3082\u8AAD\u307E\u306A\u3044\u30D1\u30B9\u304C\u5BA3\u8A00\u3055\u308C\u307E\u3059"}`,
|
|
11945
|
+
accessorListPath: (p, list, other, rel) => `"${p}" \u306F "${list}" \u306E\u884C\u306E\u30D1\u30B9\u3067\u3059\u304C\u3001\u3053\u306E\u30A2\u30AF\u30BB\u30B5\u306F "${other}" \u306B\u3082\u5BA3\u8A00\u3055\u308C\u3066\u3044\u307E\u3059\u3002\u305D\u3061\u3089\u306E\u884C\u3067\u306F\u3053\u306E\u30D1\u30B9\u306B\u884C\u304C\u7121\u304F\u3001\u8AAD\u307F\u306F undefined\u3001\u66F8\u304D\u306F\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\u3002\u884C\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u66F8\u3044\u3066\u304F\u3060\u3055\u3044: this["${rel}"]`,
|
|
11828
11946
|
nestedWritePathMissing: (p) => `\u30D1\u30B9 "${p}" \u306F\u72B6\u614B\u5B9A\u7FA9\u306B\u5B58\u5728\u3057\u307E\u305B\u3093\u3002\u66F8\u304D\u8FBC\u307F\u306F\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u306B\u65B0\u3057\u3044\u30AD\u30FC\u3092\u4F5C\u308B\u3060\u3051\u3067\u3001\u5BA3\u8A00\u3057\u305F\u30D1\u30B9\u306E\u675F\u7E1B\u306B\u306F\u5C4A\u304D\u307E\u305B\u3093`,
|
|
11829
11947
|
readPathMissing: (p, top) => top ? `"${p}" \u306F state \u304C\u5BA3\u8A00\u3057\u3066\u3044\u306A\u3044\u30AD\u30FC\u3067\u3059\u3002\u8AAD\u3093\u3060\u6642\u70B9\u3067\u4F8B\u5916\u306B\u306A\u308A\u307E\u3059\uFF08#301\uFF09` : `\u30D1\u30B9 "${p}" \u306F\u72B6\u614B\u5B9A\u7FA9\u306B\u5B58\u5728\u3057\u307E\u305B\u3093\u3002\u8AAD\u307F\u306F undefined \u306B\u306A\u308A\u3001\u305D\u3053\u304B\u3089\u8A08\u7B97\u3057\u305F\u5024\u306F\u9ED9\u3063\u3066\u9055\u3044\u307E\u3059`,
|
|
11830
11948
|
stateSrcUnread: (src) => `"${src}" \u3092\u8AAD\u3081\u306A\u3044\u306E\u3067\u3001\u3053\u306E state \u306E\u30D1\u30B9\u3082\u30B9\u30AF\u30EA\u30D7\u30C8\u306E\u898F\u5247\u3082\u691C\u67FB\u3057\u3066\u3044\u307E\u305B\u3093\u3002src \u306F\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u8AAD\u307F\u307E\u3059\uFF08URL \u306F\u8AAD\u307E\u305A\u3001/ \u304B\u3089\u59CB\u307E\u308B\u30D1\u30B9\u306F wcs-validate --root=<\u30B5\u30A4\u30C8\u306E\u30EB\u30FC\u30C8> \u306E\u3068\u304D\u3060\u3051\u305D\u306E\u4E0B\u3067\u8AAD\u307F\u307E\u3059\uFF09\u3002\u30B5\u30FC\u30D0\u30FC\u3068\u540C\u3058\u4E26\u3073\u306B\u7F6E\u3044\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u3001\u3053\u306E\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u306E\u76F8\u5BFE\u30D1\u30B9\u3067\u6307\u3059\u304B\u3001--root \u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044`,
|
|
@@ -11834,6 +11952,10 @@ var ja = {
|
|
|
11834
11952
|
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
11953
|
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
11954
|
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`,
|
|
11955
|
+
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`,
|
|
11956
|
+
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`,
|
|
11957
|
+
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`,
|
|
11958
|
+
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
11959
|
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
11960
|
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
11961
|
handlerFilterNotAllowed: (prop) => `\u30A4\u30D9\u30F3\u30C8\u30CF\u30F3\u30C9\u30E9 "${prop}" \u306B\u30D5\u30A3\u30EB\u30BF\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
|
|
@@ -12053,6 +12175,11 @@ var en = {
|
|
|
12053
12175
|
setterCycleSelf: (p) => `The setter of "${p}" writes its own path "${p}". A setter's path is the accessor itself: writing it calls the setter again, until the stack overflows. Store the value under a data path the getter reads (such as _${p.split(".").pop()})`,
|
|
12054
12176
|
setterCycle: (cycle) => `Setters write each other: ${cycle}. Unless a condition stops them, they call each other until the stack overflows. Store the values under data paths the getters read`,
|
|
12055
12177
|
setterUnobserved: (p, w) => `The setter of "${p}" writes ${w}, none of which the getter "${p}" reads. After a write the getter returns its old value, and a two-way input bound to "${p}" goes back to it. Write what the getter reads, or read what the setter writes in the getter`,
|
|
12178
|
+
relativePathOf: (r, a) => ` ("${r}" in the accessor "${a}")`,
|
|
12179
|
+
relativeNoRow: (r, a) => `"${r}" is relative to a row, but the accessor "${a}" is not one of a list's rows (its key has no "*"). With no row it throws each time it is evaluated (#1402). Write the full path, or make it a row accessor (get "<list>.*.<name>"())`,
|
|
12180
|
+
relativeApiPath: (r, api) => `"${r}" is relative to a row, but ${api} takes its rows from its indexes argument, not from the row it is called at. A relative path is not expanded there, and the call throws. Write the full path ("<list>.*${r === "." ? "" : r}")`,
|
|
12181
|
+
accessorListSyntax: (k, why) => `The accessor key "${k}" lists several paths, but ${why === "space" ? "has a space beside a comma" : why === "empty" ? "has an empty entry" : 'a recursive path ("**") cannot be listed'}. Separate the paths with "," alone (get "users.*.fullname,employees.*.fullname"())${why === "recursive" ? "" : ": the runtime takes what is between the commas as it is, so this declares a path nothing reads"}`,
|
|
12182
|
+
accessorListPath: (p, list, other, rel) => `"${p}" is a path of the rows of "${list}", and this accessor is also declared for "${other}": at its rows that path has no row, so a read gives undefined and a write throws. Write it relative to the row: this["${rel}"]`,
|
|
12056
12183
|
nestedWritePathMissing: (p) => `Path "${p}" does not exist in the state definition. The write creates a new key in the object and reaches no binding of a declared path`,
|
|
12057
12184
|
readPathMissing: (p, top) => top ? `"${p}" is not a key the state declares. Reading it throws (#301)` : `Path "${p}" does not exist in the state definition. The read gives undefined, and what is computed from it is wrong without a word`,
|
|
12058
12185
|
stateSrcUnread: (src) => `"${src}" cannot be read, so this state's paths and script rules are not checked. A src is read relative to this file (a URL is not read, and a path from / only under wcs-validate --root=<the site's root>): point it at the file laid out as on the server, relative to this file, or pass --root`,
|
|
@@ -12062,6 +12189,10 @@ var en = {
|
|
|
12062
12189
|
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
12190
|
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
12191
|
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`,
|
|
12192
|
+
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`,
|
|
12193
|
+
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`,
|
|
12194
|
+
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`,
|
|
12195
|
+
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
12196
|
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
12197
|
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
12198
|
handlerFilterNotAllowed: (prop) => `Filters cannot be applied to event handler "${prop}"`,
|
|
@@ -12638,7 +12769,7 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
|
|
|
12638
12769
|
start: bindingStart + leadingSpace,
|
|
12639
12770
|
end: bindingStart + leadingSpace + propNoMod.length,
|
|
12640
12771
|
message: msgs.submitWithoutPrevent(handler),
|
|
12641
|
-
severity: "
|
|
12772
|
+
severity: "error"
|
|
12642
12773
|
});
|
|
12643
12774
|
}
|
|
12644
12775
|
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 +12891,12 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
|
|
|
12760
12891
|
if (verdict) {
|
|
12761
12892
|
const pathOffset = binding.indexOf(parsed.path);
|
|
12762
12893
|
const pathStart = bindingStart + pathOffset;
|
|
12894
|
+
const near = verdict.code === WcsDiagnosticCode.BindingPathMissing || verdict.code === WcsDiagnosticCode.PathNonexistent ? rowFieldSuggestion(checkPath, scopedPaths, msgs) : "";
|
|
12763
12895
|
diagnostics.push({
|
|
12764
12896
|
code: verdict.code,
|
|
12765
12897
|
start: pathStart,
|
|
12766
12898
|
end: pathStart + pathTrimmed.length,
|
|
12767
|
-
message: `${verdict.message}${pathTrimmed.startsWith(".") ? msgs.expansionSuffix(checkPath) : ""}`,
|
|
12899
|
+
message: `${verdict.message}${pathTrimmed.startsWith(".") ? msgs.expansionSuffix(checkPath) : ""}${near}`,
|
|
12768
12900
|
severity: verdict.severity
|
|
12769
12901
|
});
|
|
12770
12902
|
} else if (writesBack(attr, propNoMod, parsed.property)) {
|
|
@@ -13471,6 +13603,7 @@ function findDestructiveCalls(script, baseOffset, msgs, out) {
|
|
|
13471
13603
|
}
|
|
13472
13604
|
}
|
|
13473
13605
|
function findIndexAssigns(script, baseOffset, msgs, out) {
|
|
13606
|
+
let paths = null;
|
|
13474
13607
|
for (const pattern of [DOT_INDEX_ASSIGN, BRACKET_INDEX_ASSIGN, PRE_DOT_INDEX, PRE_BRACKET_INDEX]) {
|
|
13475
13608
|
for (const match of execAllMasked(pattern, script)) {
|
|
13476
13609
|
const [root, chain] = match.groups;
|
|
@@ -13478,17 +13611,30 @@ function findIndexAssigns(script, baseOffset, msgs, out) {
|
|
|
13478
13611
|
if (isApiRoot(root)) continue;
|
|
13479
13612
|
const suggestedPath = root + chainToDotted(chain);
|
|
13480
13613
|
const start = baseOffset + match.index;
|
|
13614
|
+
const last = LAST_SUB.exec(chain);
|
|
13615
|
+
const target = root + chainToDotted(last === null ? chain : chain.slice(0, last.index));
|
|
13616
|
+
const numeric2 = last !== null && /^\s*\d+\s*$/.test(last[1]);
|
|
13617
|
+
const kind = containerKind(target, paths ??= analyzeStatePaths(script));
|
|
13481
13618
|
out.push({
|
|
13482
13619
|
code: WcsDiagnosticCode.ArrayIndexAssign,
|
|
13483
13620
|
start,
|
|
13484
13621
|
end: start + match.length,
|
|
13485
|
-
message: msgs.arrayIndexAssign(suggestedPath),
|
|
13622
|
+
message: kind === "array" || kind === "unknown" && numeric2 ? msgs.arrayIndexAssign(suggestedPath) : msgs.objectKeyAssign(target, toAccessor(target), suggestedPath),
|
|
13486
13623
|
severity: "error",
|
|
13487
13624
|
statePath: suggestedPath
|
|
13488
13625
|
});
|
|
13489
13626
|
}
|
|
13490
13627
|
}
|
|
13491
13628
|
}
|
|
13629
|
+
var LAST_SUB = /(?:\?\.)?\s*\[([^[\]]+)\]\s*$/;
|
|
13630
|
+
function containerKind(target, paths) {
|
|
13631
|
+
const path = target.split(".").map((s) => /^<.*>$/.test(s) || /^\d+$/.test(s) ? "*" : s).join(".");
|
|
13632
|
+
if (paths.some((p) => p.path === `${path}.*`)) return "array";
|
|
13633
|
+
const hints = (paths.find((p) => p.path === path)?.typeHint ?? "").split("|");
|
|
13634
|
+
if (hints.includes("array")) return "array";
|
|
13635
|
+
if (hints.includes("object") || paths.some((p) => p.path.startsWith(`${path}.`))) return "object";
|
|
13636
|
+
return "unknown";
|
|
13637
|
+
}
|
|
13492
13638
|
|
|
13493
13639
|
// src/service/templateSyntax.ts
|
|
13494
13640
|
var MUSTACHE = /\{\{\s*((?:(?!<[A-Za-z/!?])[\s\S])+?)\s*\}\}/dg;
|
|
@@ -13662,6 +13808,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
13662
13808
|
const defaultPaths = allPaths;
|
|
13663
13809
|
const pathSet = new Set(defaultPaths.map((p) => p.path));
|
|
13664
13810
|
const filterNameSet = new Set(BUILTIN_FILTERS.map((f) => f.name));
|
|
13811
|
+
const nearRowField = (code, path) => code === WcsDiagnosticCode.BindingPathMissing || code === WcsDiagnosticCode.PathNonexistent ? rowFieldSuggestion(path, defaultPaths, msgs) : "";
|
|
13665
13812
|
const mustaches = findAllMustacheSyntax(html);
|
|
13666
13813
|
const comments = findAllCommentBindings(html);
|
|
13667
13814
|
for (const item of [...mustaches, ...comments]) {
|
|
@@ -13774,7 +13921,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
13774
13921
|
code: verdict.code,
|
|
13775
13922
|
start: item.exprStart,
|
|
13776
13923
|
end: item.exprStart + pathPart.length,
|
|
13777
|
-
message: verdict.message + msgs.expansionSuffix(expandedPath),
|
|
13924
|
+
message: verdict.message + msgs.expansionSuffix(expandedPath) + nearRowField(verdict.code, expandedPath),
|
|
13778
13925
|
severity: verdict.severity
|
|
13779
13926
|
});
|
|
13780
13927
|
}
|
|
@@ -13786,7 +13933,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
13786
13933
|
code: verdict.code,
|
|
13787
13934
|
start: item.exprStart,
|
|
13788
13935
|
end: item.exprStart + pathPart.length,
|
|
13789
|
-
message: verdict.message,
|
|
13936
|
+
message: verdict.message + nearRowField(verdict.code, pathPart),
|
|
13790
13937
|
severity: verdict.severity
|
|
13791
13938
|
});
|
|
13792
13939
|
}
|
|
@@ -15822,7 +15969,7 @@ function collectGetterReadsByName(html, stateTagName) {
|
|
|
15822
15969
|
const prefix = block.mountPath === null || block.mountPath === "" ? "" : `${block.mountPath}.`;
|
|
15823
15970
|
for (const callable of analyzeCallableBodies(block.content)) {
|
|
15824
15971
|
if (callable.kind !== "getter" || callable.accessor === "set") continue;
|
|
15825
|
-
const reads = collectGetterReads(callable.body) ?? [];
|
|
15972
|
+
const reads = collectGetterReads(callable.body, { row: accessorRow(callable) }) ?? [];
|
|
15826
15973
|
out.set(prefix + callable.name, reads.map((r) => prefix + r.path));
|
|
15827
15974
|
}
|
|
15828
15975
|
}
|
|
@@ -16349,7 +16496,7 @@ function validatePackageLoads(html, locale2, fileReader) {
|
|
|
16349
16496
|
code: WcsDiagnosticCode.TagPackageMissing,
|
|
16350
16497
|
start: at2.start,
|
|
16351
16498
|
end: at2.end,
|
|
16352
|
-
severity: "
|
|
16499
|
+
severity: "error",
|
|
16353
16500
|
tag: at2.tags[0],
|
|
16354
16501
|
message: msgs.tagPackageMissing(at2.tags, `@wcstack/${pkg}`, `https://esm.run/@wcstack/${pkg}${version3 === null ? "" : `@${version3}`}/auto`)
|
|
16355
16502
|
});
|
|
@@ -16631,10 +16778,10 @@ var NO_MOUNTS = /* @__PURE__ */ new Set();
|
|
|
16631
16778
|
function assignVolumes(elements, html) {
|
|
16632
16779
|
const chainOf = createTemplateChain(html);
|
|
16633
16780
|
const innermost = (chain) => chain.length > 0 ? chain[chain.length - 1] : -1;
|
|
16634
|
-
const
|
|
16781
|
+
const treeOf = (root) => innermost(chainOf(root.tagStart));
|
|
16635
16782
|
const rootTrees = /* @__PURE__ */ new Set();
|
|
16636
16783
|
for (const element2 of elements) {
|
|
16637
|
-
if (element2.mountPath === null && !element2.bindComponent) rootTrees.add(
|
|
16784
|
+
if (element2.mountPath === null && !element2.bindComponent) rootTrees.add(treeOf(element2));
|
|
16638
16785
|
}
|
|
16639
16786
|
const volumes = /* @__PURE__ */ new Map();
|
|
16640
16787
|
for (const element2 of elements) {
|
|
@@ -16651,7 +16798,7 @@ function assignVolumes(elements, html) {
|
|
|
16651
16798
|
if (list === void 0) volumes.set(tree, [element2]);
|
|
16652
16799
|
else list.push(element2);
|
|
16653
16800
|
}
|
|
16654
|
-
return { treeOf
|
|
16801
|
+
return { treeOf, volumes };
|
|
16655
16802
|
}
|
|
16656
16803
|
function validateEntry(entry, pathSet, paths, scopes, msgs) {
|
|
16657
16804
|
const { key } = entry;
|
|
@@ -17867,6 +18014,7 @@ function validateIndexArity(script, scriptStart, locale2) {
|
|
|
17867
18014
|
if (parsed.args.length < 2) continue;
|
|
17868
18015
|
const path = literalString2(parsed.args[0]);
|
|
17869
18016
|
if (path === null) continue;
|
|
18017
|
+
if (path.startsWith(".")) continue;
|
|
17870
18018
|
if (hasRecursionWildcard(path)) continue;
|
|
17871
18019
|
const actual = literalArrayLength(parsed.args[1]);
|
|
17872
18020
|
if (actual === null) continue;
|
|
@@ -17895,7 +18043,7 @@ function validateGetterCycles(script, scriptStart, locale2) {
|
|
|
17895
18043
|
for (const getter of getters) {
|
|
17896
18044
|
if (getter.accessor === "set") continue;
|
|
17897
18045
|
const targets = /* @__PURE__ */ new Set();
|
|
17898
|
-
for (const read of collectGetterReads(getter.body) ?? []) {
|
|
18046
|
+
for (const read of collectGetterReads(getter.body, { row: accessorRow(getter) }) ?? []) {
|
|
17899
18047
|
if (declared.has(read.path)) targets.add(read.path);
|
|
17900
18048
|
}
|
|
17901
18049
|
edges.set(getter.name, [...targets]);
|
|
@@ -18447,13 +18595,17 @@ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bind
|
|
|
18447
18595
|
if (blocks.length === 0) return [];
|
|
18448
18596
|
const msgs = getMessages(locale2);
|
|
18449
18597
|
const out = [];
|
|
18598
|
+
let hidden = null;
|
|
18450
18599
|
let receivers = null;
|
|
18451
18600
|
let markupEmits = null;
|
|
18601
|
+
let eventEmits = null;
|
|
18452
18602
|
const bindings = () => {
|
|
18453
18603
|
if (receivers !== null) return;
|
|
18454
18604
|
receivers = /* @__PURE__ */ new Set();
|
|
18455
18605
|
markupEmits = /* @__PURE__ */ new Map();
|
|
18606
|
+
eventEmits = /* @__PURE__ */ new Set();
|
|
18456
18607
|
for (const o of buildReferenceIndex(html, { bindAttribute: bindAttrName, stateTagName }).occurrences) {
|
|
18608
|
+
if (o.kind === "eventToken") eventEmits.add(o.path);
|
|
18457
18609
|
if (!o.path.startsWith("$command.")) continue;
|
|
18458
18610
|
const name = o.path.slice("$command.".length);
|
|
18459
18611
|
const prop = o.propName ?? "";
|
|
@@ -18499,6 +18651,23 @@ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bind
|
|
|
18499
18651
|
});
|
|
18500
18652
|
}
|
|
18501
18653
|
}
|
|
18654
|
+
const events = paths.filter((p) => p.kind === "eventToken").map((p) => p.path);
|
|
18655
|
+
if (block.mountPath === null && events.length > 0) {
|
|
18656
|
+
bindings();
|
|
18657
|
+
const unbound = events.filter((name) => !eventEmits.has(name));
|
|
18658
|
+
if (unbound.length > 0 && !(hidden ??= hidesEmitters(html, blocks))) {
|
|
18659
|
+
const handlers = new Set(analyzeOnHandlerSources(block.content).map((h) => h.name));
|
|
18660
|
+
for (const at2 of declaredNames(block.content, unbound)) {
|
|
18661
|
+
out.push({
|
|
18662
|
+
code: WcsDiagnosticCode.EventTokenUnbound,
|
|
18663
|
+
start: block.contentStart + at2.start,
|
|
18664
|
+
end: block.contentStart + at2.end,
|
|
18665
|
+
message: msgs.eventTokenUnbound(at2.name, handlers.has(at2.name)),
|
|
18666
|
+
severity: "warning"
|
|
18667
|
+
});
|
|
18668
|
+
}
|
|
18669
|
+
}
|
|
18670
|
+
}
|
|
18502
18671
|
const keys = [...new Set(paths.map((p) => p.path.split(".")[0]).filter((key) => key !== "" && !key.startsWith("$")))];
|
|
18503
18672
|
const reported = /* @__PURE__ */ new Set();
|
|
18504
18673
|
for (const pattern of [THIS_WRITE, PRE_THIS_WRITE]) {
|
|
@@ -18523,6 +18692,33 @@ function validateScriptStateUses(html, stateTagName = "wcs-state", locale2, bind
|
|
|
18523
18692
|
}
|
|
18524
18693
|
return out;
|
|
18525
18694
|
}
|
|
18695
|
+
function declaredNames(script, names2) {
|
|
18696
|
+
const decl = findTopLevelDeclaration(script, "$eventTokens");
|
|
18697
|
+
if (decl === null || decl.value === void 0 || decl.valueStart === void 0 || literalKind(decl.value) !== "array") return [];
|
|
18698
|
+
const out = [];
|
|
18699
|
+
for (const element2 of arrayElements(blankComments(decl.value))) {
|
|
18700
|
+
if (literalKind(element2.text) !== "string") continue;
|
|
18701
|
+
const name = element2.text.slice(1, -1);
|
|
18702
|
+
if (!names2.includes(name) || out.some((o) => o.name === name)) continue;
|
|
18703
|
+
const start = decl.valueStart + element2.start + 1;
|
|
18704
|
+
out.push({ name, start, end: start + name.length });
|
|
18705
|
+
}
|
|
18706
|
+
return out;
|
|
18707
|
+
}
|
|
18708
|
+
var LAYOUT_SRC = /<wcs-layout\b(?:"[^"]*"|'[^']*'|[^>"'])*?\ssrc\s*=/i;
|
|
18709
|
+
var SCRIPT = /(<script\b(?:"[^"]*"|'[^']*'|[^>"'])*>)([\s\S]*?)<\/script\s*>/gi;
|
|
18710
|
+
function hidesEmitters(html, blocks) {
|
|
18711
|
+
const text3 = html.replace(/<!--[\s\S]*?-->/g, (c) => " ".repeat(c.length));
|
|
18712
|
+
if (LAYOUT_SRC.test(text3)) return true;
|
|
18713
|
+
SCRIPT.lastIndex = 0;
|
|
18714
|
+
let m;
|
|
18715
|
+
while ((m = SCRIPT.exec(text3)) !== null) {
|
|
18716
|
+
const contentStart = m.index + m[1].length;
|
|
18717
|
+
if (blocks.some((b) => b.contentStart === contentStart)) continue;
|
|
18718
|
+
if (m[2].includes("eventToken.")) return true;
|
|
18719
|
+
}
|
|
18720
|
+
return false;
|
|
18721
|
+
}
|
|
18526
18722
|
|
|
18527
18723
|
// src/service/scriptReadValidator.ts
|
|
18528
18724
|
function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileReader, applicationSchema, bindAttribute = "data-wcs") {
|
|
@@ -18565,8 +18761,9 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18565
18761
|
});
|
|
18566
18762
|
}
|
|
18567
18763
|
}
|
|
18764
|
+
const saidInListed = /* @__PURE__ */ new Set();
|
|
18568
18765
|
for (const callable of analyzeCallableBodies(block.content)) {
|
|
18569
|
-
for (const read of collectGetterReads(callable.body, { templates: true, writes: true }) ?? []) {
|
|
18766
|
+
for (const read of collectGetterReads(callable.body, { templates: true, writes: true, row: accessorRow(callable) }) ?? []) {
|
|
18570
18767
|
const write = read.written || read.form === "write" || read.form === "api-write";
|
|
18571
18768
|
if (write && read.form !== "api-write" && !read.path.includes(".")) continue;
|
|
18572
18769
|
if (read.path.split(".").some((s) => s === "" || s.startsWith("$")) || hasRecursionWildcard(read.path)) continue;
|
|
@@ -18574,17 +18771,22 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18574
18771
|
if (read.indexed !== void 0 && !read.indexed.every((list) => isList(prefix + list, candidates, candidateSet))) continue;
|
|
18575
18772
|
if (pathExistsInCandidates(path, candidates, candidateSet)) continue;
|
|
18576
18773
|
if (applicationSchema !== void 0 ? resolveIndexedSchemaPath(applicationSchema, path).kind !== "nonexistent" : isUnresolvedPath(path, index.scopes)) continue;
|
|
18577
|
-
const near =
|
|
18774
|
+
const near = missingSegment(path, tree ??= pathTree(candidates));
|
|
18578
18775
|
if (near === null) continue;
|
|
18579
18776
|
const said = suggestion(near.segment, near.names, msgs);
|
|
18580
18777
|
if (said === "") continue;
|
|
18581
18778
|
const at2 = block.contentStart + callable.bodyStart;
|
|
18779
|
+
if (callable.listed !== void 0) {
|
|
18780
|
+
const place = `${write}:${at2 + read.start}`;
|
|
18781
|
+
if (saidInListed.has(place)) continue;
|
|
18782
|
+
saidInListed.add(place);
|
|
18783
|
+
}
|
|
18582
18784
|
const member = read.form === "member" || read.form === "write";
|
|
18583
18785
|
out.push({
|
|
18584
18786
|
code: write ? WcsDiagnosticCode.WritePathMissing : WcsDiagnosticCode.ReadPathMissing,
|
|
18585
18787
|
start: at2 + read.start,
|
|
18586
18788
|
end: member ? at2 + read.start + statePart(callable.body.slice(read.start, read.end)) : at2 + read.end,
|
|
18587
|
-
message: (write ? msgs.nestedWritePathMissing(read.path) : msgs.readPathMissing(read.path, !read.path.includes("."))) + said,
|
|
18789
|
+
message: (write ? msgs.nestedWritePathMissing(read.path) : msgs.readPathMissing(read.path, !read.path.includes("."))) + (read.relative === void 0 ? "" : msgs.relativePathOf(read.relative, callable.name)) + said,
|
|
18588
18790
|
// a stateSchema says the path is not there, as for a binding's `wcs/path-nonexistent` (a write stays a
|
|
18589
18791
|
// warning, as the top-level one: a key the state adds on purpose is not a mistake)
|
|
18590
18792
|
severity: !write && applicationSchema !== void 0 ? "error" : "warning"
|
|
@@ -18601,31 +18803,6 @@ var THIS_PART = /^this\s*(?:\?\.\s*|\.\s*)(?:[A-Za-z_$][\w$]*)|^this\s*(?:\?\.)?
|
|
|
18601
18803
|
function statePart(text3) {
|
|
18602
18804
|
return THIS_PART.exec(text3)?.[0].length ?? text3.length;
|
|
18603
18805
|
}
|
|
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
18806
|
|
|
18630
18807
|
// src/service/scriptWriteValidator.ts
|
|
18631
18808
|
var OPTIONS = { writes: true, templates: true, resolveWrites: true, untracked: true, opaque: true };
|
|
@@ -18633,7 +18810,7 @@ function isWrite(read) {
|
|
|
18633
18810
|
return read.form === "write" || read.form === "api-write" || read.written && read.form !== "opaque";
|
|
18634
18811
|
}
|
|
18635
18812
|
function bodyOf(callable) {
|
|
18636
|
-
const found = collectGetterReads(callable.body, OPTIONS);
|
|
18813
|
+
const found = collectGetterReads(callable.body, { ...OPTIONS, row: accessorRow(callable) });
|
|
18637
18814
|
if (found === null) return { callable, writes: [], reads: [], calls: [], opaque: true };
|
|
18638
18815
|
const writes = [];
|
|
18639
18816
|
const reads = [];
|
|
@@ -18641,7 +18818,7 @@ function bodyOf(callable) {
|
|
|
18641
18818
|
let opaque2 = false;
|
|
18642
18819
|
for (const read of found) {
|
|
18643
18820
|
const at2 = { start: callable.bodyStart + read.start, end: callable.bodyStart + read.end, nested: read.nested === true };
|
|
18644
|
-
if (read.form === "opaque") {
|
|
18821
|
+
if (read.form === "opaque" || read.path.startsWith(".")) {
|
|
18645
18822
|
opaque2 = true;
|
|
18646
18823
|
continue;
|
|
18647
18824
|
}
|
|
@@ -18745,6 +18922,8 @@ function validateScriptWrites(html, stateTagName = "wcs-state", locale2) {
|
|
|
18745
18922
|
function getterWrites(state, msgs, at2) {
|
|
18746
18923
|
const out = [];
|
|
18747
18924
|
for (const [name, getter] of state.getters) {
|
|
18925
|
+
const listed = getter.callable.listed;
|
|
18926
|
+
if (listed !== void 0 && listed.paths[0] !== name) continue;
|
|
18748
18927
|
for (const w of getter.writes) {
|
|
18749
18928
|
if (w.state !== true || w.nested) continue;
|
|
18750
18929
|
out.push({ code: WcsDiagnosticCode.GetterWrite, ...at2(w.start, w.end), message: msgs.getterWrite(w.path, name), severity: "error" });
|
|
@@ -18764,9 +18943,12 @@ function readonlyWrites(state, msgs, at2) {
|
|
|
18764
18943
|
if (readonly.size === 0) return [];
|
|
18765
18944
|
const out = [];
|
|
18766
18945
|
for (const body of [...state.methods.values(), ...state.setters.values()]) {
|
|
18946
|
+
const listed = body.callable.listed;
|
|
18947
|
+
const again = listed !== void 0 && listed.paths[0] !== body.callable.name;
|
|
18767
18948
|
for (const w of body.writes) {
|
|
18768
18949
|
const path = toWildcardForm(w.path);
|
|
18769
18950
|
if (w.state !== true || hasRecursionWildcard(path) || !readonly.has(path)) continue;
|
|
18951
|
+
if (again && out.some((d) => d.start === at2(w.start, w.end).start)) continue;
|
|
18770
18952
|
out.push({ code: WcsDiagnosticCode.PathReadonly, ...at2(w.start, w.end), message: msgs.pathReadonlyWrite(path), severity: "error" });
|
|
18771
18953
|
}
|
|
18772
18954
|
}
|
|
@@ -18825,6 +19007,190 @@ function unobservedSetters(state, msgs, at2) {
|
|
|
18825
19007
|
return out;
|
|
18826
19008
|
}
|
|
18827
19009
|
|
|
19010
|
+
// src/service/accessorListValidator.ts
|
|
19011
|
+
var OPTIONS2 = { templates: true, writes: true, resolveWrites: true, untracked: true };
|
|
19012
|
+
var INDEXED_APIS = /* @__PURE__ */ new Set(["$resolve", "$setAll", "$update"]);
|
|
19013
|
+
function rowOfPath(path) {
|
|
19014
|
+
const at2 = path.lastIndexOf("*");
|
|
19015
|
+
return at2 < 0 ? null : path.slice(0, at2 + 1);
|
|
19016
|
+
}
|
|
19017
|
+
function hasRow(row, needed) {
|
|
19018
|
+
return row !== null && (row === needed || row.startsWith(`${needed}.`));
|
|
19019
|
+
}
|
|
19020
|
+
function validateAccessorLists(html, stateTagName = "wcs-state", locale2) {
|
|
19021
|
+
const blocks = parseLoadedScriptBlocks(html, stateTagName).filter((block) => hasDefaultExportObject(block.content));
|
|
19022
|
+
if (blocks.length === 0) return [];
|
|
19023
|
+
const msgs = getMessages(locale2);
|
|
19024
|
+
const out = [];
|
|
19025
|
+
for (const block of blocks) {
|
|
19026
|
+
const at2 = (start, end) => ({ start: block.contentStart + start, end: block.contentStart + end });
|
|
19027
|
+
const keys = /* @__PURE__ */ new Set();
|
|
19028
|
+
for (const callable of analyzeCallableBodies(block.content)) {
|
|
19029
|
+
const listed = callable.listed;
|
|
19030
|
+
if (listed !== void 0 && !keys.has(listed.start)) {
|
|
19031
|
+
keys.add(listed.start);
|
|
19032
|
+
const why = listSyntax(listed.key, listed.paths);
|
|
19033
|
+
if (why !== null) {
|
|
19034
|
+
out.push({
|
|
19035
|
+
code: WcsDiagnosticCode.AccessorListSyntax,
|
|
19036
|
+
...at2(listed.start, listed.end),
|
|
19037
|
+
message: msgs.accessorListSyntax(listed.key, why),
|
|
19038
|
+
severity: "error"
|
|
19039
|
+
});
|
|
19040
|
+
}
|
|
19041
|
+
}
|
|
19042
|
+
if (listed !== void 0 && listed.paths[0] !== callable.name) continue;
|
|
19043
|
+
const reads = collectGetterReads(callable.body, OPTIONS2);
|
|
19044
|
+
if (reads === null) continue;
|
|
19045
|
+
const rows = (listed?.paths ?? [callable.name]).map((name) => accessorRow({ name, kind: callable.kind }));
|
|
19046
|
+
for (const read of reads) {
|
|
19047
|
+
if (read.form === "opaque") continue;
|
|
19048
|
+
const place = at2(callable.bodyStart + read.start, callable.bodyStart + read.end);
|
|
19049
|
+
if (read.path.startsWith(".") && read.api !== void 0 && INDEXED_APIS.has(read.api)) {
|
|
19050
|
+
out.push({ code: WcsDiagnosticCode.WildcardRank, ...place, message: msgs.relativeApiPath(read.path, read.api), severity: "error" });
|
|
19051
|
+
continue;
|
|
19052
|
+
}
|
|
19053
|
+
if (callable.kind !== "getter" || read.nested === true) continue;
|
|
19054
|
+
if (read.path.startsWith(".")) {
|
|
19055
|
+
if (rows.every((row) => row === null)) {
|
|
19056
|
+
out.push({ code: WcsDiagnosticCode.WildcardRank, ...place, message: msgs.relativeNoRow(read.path, describe(callable)), severity: "error" });
|
|
19057
|
+
}
|
|
19058
|
+
continue;
|
|
19059
|
+
}
|
|
19060
|
+
if (listed === void 0 || read.form === "api" || read.form === "api-write" || read.form === "track") continue;
|
|
19061
|
+
if (hasRecursionWildcard(read.path)) continue;
|
|
19062
|
+
const needed = rowOfPath(read.path);
|
|
19063
|
+
if (needed === null) continue;
|
|
19064
|
+
const home = rows.findIndex((row) => hasRow(row, needed));
|
|
19065
|
+
const away = rows.findIndex((row) => !hasRow(row, needed));
|
|
19066
|
+
if (home < 0 || away < 0) continue;
|
|
19067
|
+
const rest = read.path.slice(rows[home].length);
|
|
19068
|
+
out.push({
|
|
19069
|
+
code: WcsDiagnosticCode.AccessorListPath,
|
|
19070
|
+
...place,
|
|
19071
|
+
message: msgs.accessorListPath(read.path, needed.slice(0, -2), listed.paths[away], rest === "" ? "." : rest),
|
|
19072
|
+
severity: "error"
|
|
19073
|
+
});
|
|
19074
|
+
}
|
|
19075
|
+
}
|
|
19076
|
+
}
|
|
19077
|
+
return out;
|
|
19078
|
+
}
|
|
19079
|
+
function listSyntax(key, paths) {
|
|
19080
|
+
if (/\s/.test(key)) return "space";
|
|
19081
|
+
if (key.split(",").some((part) => part === "")) return "empty";
|
|
19082
|
+
return paths.some(hasRecursionWildcard) ? "recursive" : null;
|
|
19083
|
+
}
|
|
19084
|
+
function describe(callable) {
|
|
19085
|
+
return callable.listed?.key ?? callable.name;
|
|
19086
|
+
}
|
|
19087
|
+
|
|
19088
|
+
// src/service/moduleTopReadValidator.ts
|
|
19089
|
+
var GUARD_TAG = "wcs-guard-handler";
|
|
19090
|
+
var STORAGES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
19091
|
+
var GLOBALS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
19092
|
+
var STORAGE_WRITES = /* @__PURE__ */ new Set(["setItem", "removeItem", "clear"]);
|
|
19093
|
+
function validateModuleTopReads(html, stateTagName = "wcs-state", locale2) {
|
|
19094
|
+
const msgs = getMessages(locale2);
|
|
19095
|
+
const out = [];
|
|
19096
|
+
const check = (blocks, guard) => {
|
|
19097
|
+
for (const block of blocks) {
|
|
19098
|
+
for (const read of findTopLevelReads(block.content)) {
|
|
19099
|
+
out.push({
|
|
19100
|
+
code: WcsDiagnosticCode.SessionReadAtModuleTop,
|
|
19101
|
+
start: block.contentStart + read.start,
|
|
19102
|
+
end: block.contentStart + read.end,
|
|
19103
|
+
message: guard ? msgs.guardReadsAtModuleTop(read.text) : msgs.stateReadsAtModuleTop(read.text),
|
|
19104
|
+
severity: guard ? "error" : "warning"
|
|
19105
|
+
});
|
|
19106
|
+
}
|
|
19107
|
+
}
|
|
19108
|
+
};
|
|
19109
|
+
if (html.includes(GUARD_TAG)) check(parseWcsScriptBlocks(html, GUARD_TAG), true);
|
|
19110
|
+
check(parseLoadedScriptBlocks(html, stateTagName), false);
|
|
19111
|
+
return out;
|
|
19112
|
+
}
|
|
19113
|
+
function findTopLevelReads(source) {
|
|
19114
|
+
if (!/localStorage|sessionStorage|cookie/.test(source)) return [];
|
|
19115
|
+
let program;
|
|
19116
|
+
try {
|
|
19117
|
+
program = parse3(source, { ecmaVersion: "latest", sourceType: "module", allowHashBang: true });
|
|
19118
|
+
} catch {
|
|
19119
|
+
return [];
|
|
19120
|
+
}
|
|
19121
|
+
const out = [];
|
|
19122
|
+
const visit2 = (node, assigned) => {
|
|
19123
|
+
switch (node.type) {
|
|
19124
|
+
// run when called (a getter, a setter and a method are function expressions under their property)
|
|
19125
|
+
case "FunctionDeclaration":
|
|
19126
|
+
case "FunctionExpression":
|
|
19127
|
+
case "ArrowFunctionExpression":
|
|
19128
|
+
case "ClassDeclaration":
|
|
19129
|
+
case "ClassExpression":
|
|
19130
|
+
return;
|
|
19131
|
+
case "AssignmentExpression":
|
|
19132
|
+
visit2(node.left, node.operator === "=");
|
|
19133
|
+
visit2(node.right, false);
|
|
19134
|
+
return;
|
|
19135
|
+
case "CallExpression": {
|
|
19136
|
+
const callee = node.callee;
|
|
19137
|
+
if (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") {
|
|
19138
|
+
visit2(callee.body, false);
|
|
19139
|
+
for (const arg of node.arguments) visit2(arg, false);
|
|
19140
|
+
return;
|
|
19141
|
+
}
|
|
19142
|
+
break;
|
|
19143
|
+
}
|
|
19144
|
+
case "MemberExpression": {
|
|
19145
|
+
const read = readOf(node, assigned, source);
|
|
19146
|
+
if (read !== null) {
|
|
19147
|
+
out.push(read);
|
|
19148
|
+
return;
|
|
19149
|
+
}
|
|
19150
|
+
break;
|
|
19151
|
+
}
|
|
19152
|
+
default:
|
|
19153
|
+
break;
|
|
19154
|
+
}
|
|
19155
|
+
for (const child of children(node)) visit2(child, false);
|
|
19156
|
+
};
|
|
19157
|
+
visit2(program, false);
|
|
19158
|
+
return out;
|
|
19159
|
+
}
|
|
19160
|
+
function readOf(node, assigned, source) {
|
|
19161
|
+
const object = node.object;
|
|
19162
|
+
const prop = propertyName(node);
|
|
19163
|
+
if (isGlobal(object, STORAGES)) {
|
|
19164
|
+
if (assigned || prop !== null && STORAGE_WRITES.has(prop)) return null;
|
|
19165
|
+
return { start: node.start, end: node.end, text: source.slice(node.start, node.end) };
|
|
19166
|
+
}
|
|
19167
|
+
if (prop === "cookie" && !assigned && isGlobal(object, /* @__PURE__ */ new Set(["document"]))) {
|
|
19168
|
+
return { start: node.start, end: node.end, text: source.slice(node.start, node.end) };
|
|
19169
|
+
}
|
|
19170
|
+
return null;
|
|
19171
|
+
}
|
|
19172
|
+
function isGlobal(node, names2) {
|
|
19173
|
+
if (node.type === "Identifier") return names2.has(node.name);
|
|
19174
|
+
if (node.type !== "MemberExpression" || node.computed) return false;
|
|
19175
|
+
const object = node.object;
|
|
19176
|
+
return object.type === "Identifier" && GLOBALS.has(object.name) && node.property.type === "Identifier" && names2.has(node.property.name);
|
|
19177
|
+
}
|
|
19178
|
+
function propertyName(node) {
|
|
19179
|
+
if (!node.computed) return node.property.type === "Identifier" ? node.property.name : null;
|
|
19180
|
+
return node.property.type === "Literal" && typeof node.property.value === "string" ? node.property.value : null;
|
|
19181
|
+
}
|
|
19182
|
+
function children(node) {
|
|
19183
|
+
const out = [];
|
|
19184
|
+
for (const value of Object.values(node)) {
|
|
19185
|
+
if (Array.isArray(value)) {
|
|
19186
|
+
for (const v of value) if (v !== null && typeof v === "object" && typeof v.type === "string") out.push(v);
|
|
19187
|
+
} else if (value !== null && typeof value === "object" && typeof value.type === "string") {
|
|
19188
|
+
out.push(value);
|
|
19189
|
+
}
|
|
19190
|
+
}
|
|
19191
|
+
return out;
|
|
19192
|
+
}
|
|
19193
|
+
|
|
18828
19194
|
// src/service/stateSourceValidator.ts
|
|
18829
19195
|
function validateStateSources(html, stateTagName = "wcs-state", locale2, fileReader) {
|
|
18830
19196
|
if (fileReader === void 0) return [];
|
|
@@ -19417,7 +19783,9 @@ function validateText(text3, options, applicationSchema) {
|
|
|
19417
19783
|
out.push(...validateScriptStateUses(text3, stateTagName, locale2, bindAttribute));
|
|
19418
19784
|
out.push(...validateScriptReads(text3, stateTagName, locale2, fileReader, applicationSchema, bindAttribute));
|
|
19419
19785
|
out.push(...validateScriptWrites(text3, stateTagName, locale2));
|
|
19786
|
+
out.push(...validateAccessorLists(text3, stateTagName, locale2));
|
|
19420
19787
|
out.push(...validateArrayMutations(text3, stateTagName, locale2));
|
|
19788
|
+
out.push(...validateModuleTopReads(text3, stateTagName, locale2));
|
|
19421
19789
|
out.push(...validateWatchDeclarations(text3, stateTagName, locale2, fileReader));
|
|
19422
19790
|
out.push(...validateScanDeclarations(text3, stateTagName, locale2));
|
|
19423
19791
|
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.22.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": {
|