@wcstack/lint 4.22.0 → 4.23.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 -0
- package/README.md +12 -0
- package/dist/cli.cjs +405 -16
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -118,6 +118,18 @@ nothing to check: index.html — no data-wcs binding, <wcs-*> tag or wcstack scr
|
|
|
118
118
|
- 配列と分からない値(`budgetErrors: {}` と `this.budgetErrors[id] = …`)への `wcs/array-index-assign` は、「配列の添字」ではなくオブジェクトのキーへの代入として言います。
|
|
119
119
|
- スクリプトがその場で変えるリスト(`this.budgetRows.splice(0, n, ...rows)` — `wcs/array-mutation` が報告する)の行は、リテラルや JSDoc の型からフィールドが読めなければ検査しません。4.20 までは、そうした行のフィールドがどれも `wcs/binding-path-missing` の誤報で、本物の打ち間違いと同じ code でした。
|
|
120
120
|
|
|
121
|
+
## 入力の重いフォームに言うこと
|
|
122
|
+
|
|
123
|
+
4.23 から、継ぎ目アプリ ekiden-entry — 駅伝の申し込みウィザード。IME・オートフィル・行の中の入力・フォーム連携のカスタム要素と、入力の重いページ — から。そのページで lint は、仕込んだ誤り 21 件に何も言わず、読めない state について偽の warning を 91 件出していました:
|
|
124
|
+
|
|
125
|
+
- **値を読めないキーの下は「分からない」で、「存在しない」ではありません。** `const init = emptyEntry()` の `team: init.team`、`errs: emptyErrs()`、条件式、`[1, 2].map(…)`、`[newRunner()]` の行: そうしたキーの下のパスは検査せず、キーの上の `wcs/path-dynamic-unknown`(info)が 1 回だけそう言います — その下に束ねたパスの数(キーの `for:` の行の `.name` も数えます)と、検査させる方法(キーの JSDoc の `@type` か `stateSchema`)付きで。4.22 までは、そのパスが 1 件ずつ `wcs/binding-path-missing` の誤報で、本物の打ち間違いと同じ code でした。オブジェクトリテラルを束縛する `const` のメンバー(`team: DEFAULTS.team`。モジュールの中のものも import したものも)は読み、その下のパスを検査します。
|
|
126
|
+
- **`wcs/radio-name-shared`**(warning) — `for:` の行の中の、`name` をリテラルで書いた、行の値を束ねたラジオ(`<input type="radio" name="sex" data-wcs="radio: .sex">`)。どの行のラジオも同じ name になるので、ブラウザは全部の行を 1 つのグループにします: ページ全体で 1 つしか選ばれた状態にならず、表示は最初の描画から行ごとの値と食い違います。行ごとに違う name を束ねる(`attr.name: .<行のフィールド>`)か、name を外してください — `radio:` は name が無くても、同じパスに束ねたラジオを選択に合わせます。name を束ねてあるとき、行のものでないパス(`value: .id; radio: selectedId` — 行をまたぐ 1 つの選択)、行ごとに `<form>` があるときは報告しません。
|
|
127
|
+
- **`wcs/number-written-as-string`**(warning) — 書き戻すときに変換しない双方向の `value:` が、state が数値で持つパスを指す: `count: 0` と `<input type="number" data-wcs="value: count">`(JSDoc の `@type {number}`・`stateSchema`・行のフィールド `value: .qty` も)。要素の `value` は文字列なので、5 と入力した後の state は `"5"` で、`count + 1` は `"51"` になります。`valueAsNumber: count` か、左辺の入力フィルタ `value|number: count`(`|int`・`|float`)と書いてください。
|
|
128
|
+
- **`wcs/two-way-output-filter`**(warning) — 双方向の `value:` / `valueAsNumber:` の出力フィルタ(`value: code|upper`・`value: price|locale`)。打つ欄では、フィルタが 1 打鍵ごとに state の値を整形して欄へ書き直します: 入力中の欄が書き換わり(キャレットは末尾へ飛び、IME の変換は途切れます)、state が受け取るのも欄の整形済みの文字です — 出力フィルタは書き戻しで元に戻りません。整形した文字は別の要素に表示する、欄の確定で書き戻して setter で整形する(`value#onchange:`)、または一方向にしてください(`value#ro:`)。確定した値を書き戻す束縛(`#onchange`・`<select>`・スライダー)は、出力を元に戻す入力フィルタが無いときだけ報告します: `value#onchange|number: price|toFixed(2)` は報告しません。要素の書いた文字をそのまま返すフィルタ(`string`・`nullIfEmpty`・`coalesce(…)`・`defaults('')`)も報告しません。
|
|
129
|
+
- **`attr.*` に束ねた boolean**(`wcs/binding-type-expectation`)には、起きることを言います: ランタイムは `String(value)` — `"true"` / `"false"` — を書き、属性を外すのは `null` / `undefined` だけです。その語が属性の値であるもの — ARIA の状態(`attr.aria-invalid: flag|truthy`)・`contenteditable`・`draggable`・`spellcheck` — は、もう報告しません(`"attr.aria-invalid" には文字列型が必要です` は誤報でした)。ネイティブ要素の論理属性(`attr.disabled: flag`)には、`disabled="false"` でも無効のままであることと、代わりに束ねるプロパティ(`disabled: flag`)を言います。ほかの属性(`attr.data-open: flag`)には、文字として書かれて外れないことと、false の間は外す `|defaults(null)`・文字が意図のときの `|string` を言います。
|
|
130
|
+
|
|
131
|
+
新しい 3 つの規則は warning です: `--strict` では失敗し、`--errors-only` には出ません。
|
|
132
|
+
|
|
121
133
|
## 生成 → 検証 → 修正ループでの利用
|
|
122
134
|
|
|
123
135
|
安定した 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
|
@@ -118,6 +118,18 @@ Since 4.21, from the ledger-repair seam app — a maintainer fixing a household-
|
|
|
118
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
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
120
|
|
|
121
|
+
## What a data-entry form is told
|
|
122
|
+
|
|
123
|
+
Since 4.23, from the ekiden-entry seam app — an entry wizard for a relay race, heavy on input: an IME, autofill, rows of inputs, form-associated custom elements. On its page the lint had said nothing about 21 mistakes made on purpose, and had given 91 false warnings about a state it could not read:
|
|
124
|
+
|
|
125
|
+
- **A key whose value the lint cannot read is unknown, not missing.** `team: init.team` beside `const init = emptyEntry()`, `errs: emptyErrs()`, a conditional, `[1, 2].map(…)`, the rows of `[newRunner()]`: the paths under such a key are not checked, and one `wcs/path-dynamic-unknown` info at the key says so — with the number of paths bound under it (a row's `.name` under the key's `for:` is one) and what has them checked: a JSDoc `@type` on the key, or a `stateSchema`. Up to 4.22 each of those paths was a false `wcs/binding-path-missing`, the same code as a real typo. A member of a `const` bound to an object literal (`team: DEFAULTS.team`, in the module or imported) is read, and the paths under it are checked.
|
|
126
|
+
- **`wcs/radio-name-shared`** (warning) — radios in a `for:` row with a literal `name` and a binding of the row's (`<input type="radio" name="sex" data-wcs="radio: .sex">`). Every row's radios get the same name, so the browser makes one group of all the rows: only one radio on the whole page stays checked, and the page disagrees with the rows' values from the first render. Bind a name that differs per row (`attr.name: .<a row field>`), or drop the name — `radio:` keeps the radios bound to one path in step without it. Not reported when the name is bound, when the bound path is not the row's (`value: .id; radio: selectedId` — one choice over the rows), or when each row holds its own `<form>`.
|
|
127
|
+
- **`wcs/number-written-as-string`** (warning) — a two-way `value:` with no conversion on the way in, bound to a path the state holds as a number: `<input type="number" data-wcs="value: count">` with `count: 0` (a JSDoc `@type {number}`, a `stateSchema` and a row field `value: .qty` count too). An element's `value` is a string, so after the user enters 5 the state has `"5"` and `count + 1` is `"51"`. Write `valueAsNumber: count`, or an input filter on the left side: `value|number: count` (`|int`, `|float`).
|
|
128
|
+
- **`wcs/two-way-output-filter`** (warning) — an output filter on a two-way `value:` / `valueAsNumber:` (`value: code|upper`, `value: price|locale`). In a field the user types in, the filter formats what the state holds on every keystroke: the field is rewritten while the user types — the caret jumps to the end, an IME composition is cut — and the state receives the field's formatted text, since an output filter is not undone on the way back. Show the formatted text in another element, write back when the field is committed and format in a setter (`value#onchange:`), or make the binding one-way (`value#ro:`). A binding that writes back a committed value (`#onchange`, a `<select>`, a slider) is reported only when no input filter undoes the output: `value#onchange|number: price|toFixed(2)` is not. Nor are the filters that give back what the element wrote: `string`, `nullIfEmpty`, `coalesce(…)`, `defaults('')`.
|
|
129
|
+
- **A boolean given to `attr.*`** (`wcs/binding-type-expectation`) is told what happens to it: the runtime writes `String(value)` — `"true"` / `"false"` — and only `null` / `undefined` remove an attribute. Where those words are the attribute's values — the ARIA states (`attr.aria-invalid: flag|truthy`), `contenteditable`, `draggable`, `spellcheck` — nothing is reported any more (it was a false warning: `"attr.aria-invalid" requires a string`). A boolean attribute of a native element (`attr.disabled: flag`) is told that `disabled="false"` still disables, with the property to bind instead (`disabled: flag`). Any other attribute (`attr.data-open: flag`) is told that it is written as the text and never removed, with `|defaults(null)` to remove it while false and `|string` where the text is meant.
|
|
130
|
+
|
|
131
|
+
The three new rules are warnings: `--strict` fails on them, `--errors-only` does not print them.
|
|
132
|
+
|
|
121
133
|
## Use in generate–validate–fix loops
|
|
122
134
|
|
|
123
135
|
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
|
@@ -432,6 +432,25 @@ var WcsDiagnosticCode = {
|
|
|
432
432
|
// 置き、文と一緒に挿入される。スクリーンリーダーは読み上げない(読み上げるのは、ページにある間に文が変わったとき)。
|
|
433
433
|
// 挿入で読み上げられる `role="alert"` は対象外。継ぎ目アプリ city-library(view transition ありの Chromium で 0/10)。warning。
|
|
434
434
|
LiveRegionInserted: "wcs/live-region-inserted",
|
|
435
|
+
// --- フォームの入力(要素の束縛が、利用者の入力に対して何をするか。service/formInputValidator.ts) ---
|
|
436
|
+
// `for:` の行の中の、`name` をリテラルで書いたラジオ(`<input type="radio" name="sex" data-wcs="radio: .sex">`)。
|
|
437
|
+
// どの行のラジオも同じ name になるので、ブラウザは全部の行を 1 つのグループにする: ページ全体で 1 つしか選ばれた
|
|
438
|
+
// 状態にならず、表示は最初の描画から行ごとの値と食い違う。ランタイムは何も言わない(ブラウザの規則 — 継ぎ目アプリ
|
|
439
|
+
// ekiden-entry)。name を束ねてあるとき(`attr.name:`)・行のものでないパス(`radio: selectedId` — 行をまたぐ 1 つの
|
|
440
|
+
// グループが意図)・行ごとに `<form>` があるときは黙る。warning。
|
|
441
|
+
RadioNameShared: "wcs/radio-name-shared",
|
|
442
|
+
// 書き戻すときに変換しない双方向の `value:` が、state が数値で持つパス(種・JSDoc の `@type`・stateSchema)を指す。
|
|
443
|
+
// 要素の `value` は文字列なので、5 と入力した後の state は `"5"` で、`count + 1` は `"51"` になる。ランタイムは何も
|
|
444
|
+
// 言わない(ekiden-entry — 弁当 1 個と 2 個が 12 個になった)。数値にする入力フィルタ(`value|number:`)・
|
|
445
|
+
// `valueAsNumber:`・`#ro`・アクセサペア(setter が変換しうる)では黙る。warning。
|
|
446
|
+
NumberWrittenAsString: "wcs/number-written-as-string",
|
|
447
|
+
// 双方向の `value:` / `valueAsNumber:` に付けた出力フィルタ(`value: code|upper`・`value: price|locale`)。フィルタは
|
|
448
|
+
// 要素が書き戻すたび(既定では 1 打鍵ごと)に state の値を整形して欄へ書き直す: キャレットは末尾へ飛び、IME の変換は
|
|
449
|
+
// 途切れ、state が受け取るのは整形済みの文字(出力フィルタは書き戻しで元に戻らない)。確定した値を書き戻す束縛
|
|
450
|
+
// (`#onchange`・スライダー・`<select>`)は入力中に書き換わらないので、入力フィルタ(作者が用意した戻り道 —
|
|
451
|
+
// `value#onchange|number: price|toFixed(2)`)が無いときだけ報告する。要素の書いた文字をそのまま返すフィルタ
|
|
452
|
+
// (`string`・`nullIfEmpty`・`coalesce(…)`・`defaults('')`)と `#ro` では黙る。warning。
|
|
453
|
+
TwoWayOutputFilter: "wcs/two-way-output-filter",
|
|
435
454
|
// --- document-level load configuration ---
|
|
436
455
|
// @wcstack/state/auto より後に @wcstack/devtools/auto が読まれている。info: 4.0 は後から付いた DevTools に
|
|
437
456
|
// 既存の束縛を送り直すので、欠けるのは付く前のタイムラインだけ。
|
|
@@ -1997,7 +2016,7 @@ var config = {
|
|
|
1997
2016
|
locale: typeof document !== "undefined" ? document.documentElement?.lang || "en" : "en",
|
|
1998
2017
|
enableContractAnalyzer: false
|
|
1999
2018
|
};
|
|
2000
|
-
var FEATURE_NAMES = ["formats", "diagnostics", "temporal", "list-keys", "scopes", "recursion", "ssr", "devtools", "native-commands", "release"];
|
|
2019
|
+
var FEATURE_NAMES = ["formats", "diagnostics", "temporal", "list-keys", "scopes", "recursion", "ssr", "devtools", "native-commands", "release", "forms"];
|
|
2001
2020
|
var NATIVE_COMMANDS = {
|
|
2002
2021
|
"*": ["focus", "blur", "click", "scrollIntoView", "showPopover", "hidePopover", "togglePopover"],
|
|
2003
2022
|
"dialog": ["show", "showModal", "close", "requestClose"],
|
|
@@ -2564,7 +2583,7 @@ function getWcsManifest() {
|
|
|
2564
2583
|
}
|
|
2565
2584
|
|
|
2566
2585
|
// ../state/package.json
|
|
2567
|
-
var version = "4.
|
|
2586
|
+
var version = "4.23.0";
|
|
2568
2587
|
|
|
2569
2588
|
// src/service/wcsManifest.ts
|
|
2570
2589
|
var ENGINE_VERSION = version;
|
|
@@ -10017,7 +10036,8 @@ function pushDataPropertyPathsAt(path, prop, paths, depth, typedefs, scope) {
|
|
|
10017
10036
|
let candidate;
|
|
10018
10037
|
let unread = null;
|
|
10019
10038
|
if (followed === null) {
|
|
10020
|
-
|
|
10039
|
+
const opaque2 = prop.value !== void 0 && prop.declaredType === void 0 && isUnreadExpression(prop.value) ? { opaque: unreadExpression(prop.value, scope) } : {};
|
|
10040
|
+
candidate = { path, kind: "data", typeHint: prop.typeHint, rawInitial: prop.value?.trim(), ...opaque2 };
|
|
10021
10041
|
paths.push(candidate);
|
|
10022
10042
|
unread = pushLiteralStructurePaths(path, prop, paths, depth, typedefs, scope);
|
|
10023
10043
|
} else {
|
|
@@ -10131,6 +10151,45 @@ function isReadableLiteral(text3) {
|
|
|
10131
10151
|
const v = text3.trim();
|
|
10132
10152
|
return /^[[{"'`]/.test(v) || /^-?\.?\d/.test(v) || WORD_LITERALS.has(v) || /^(?:async\s+)?function\b/.test(v) || /^(?:async\s*)?(?:\([^()]*\)|[$\w]+)\s*=>/.test(v);
|
|
10133
10153
|
}
|
|
10154
|
+
function isUnreadExpression(value) {
|
|
10155
|
+
const v = value.trim();
|
|
10156
|
+
if (!isReadableLiteral(v)) return true;
|
|
10157
|
+
const open = v[0];
|
|
10158
|
+
if (open !== "[" && open !== "{") return false;
|
|
10159
|
+
const scan = maskCommentsAndStrings(v);
|
|
10160
|
+
const inner = extractDelimitedContent(v, scan, 0, open, open === "[" ? "]" : "}");
|
|
10161
|
+
const rest = scan.slice(inner.length + 2).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, " ").trimStart();
|
|
10162
|
+
return /^(?:\?\.|\.|\[|\()/.test(rest);
|
|
10163
|
+
}
|
|
10164
|
+
var MAX_UNREAD_TEXT = 40;
|
|
10165
|
+
function unreadExpression(value, scope) {
|
|
10166
|
+
const flat = value.trim().replace(/^(?:\/\*[\s\S]*?\*\/\s*|\/\/[^\n]*\n\s*)+/, "").replace(/\s+/g, " ");
|
|
10167
|
+
const name = flat.length <= MAX_UNREAD_TEXT ? flat : `${flat.slice(0, MAX_UNREAD_TEXT - 1)}\u2026`;
|
|
10168
|
+
const root = /^(?:\.\.\.|(?:new|await)\s+)*([$A-Za-z_][$\w]*)/.exec(flat)?.[1];
|
|
10169
|
+
const from = root === void 0 || scope === void 0 ? void 0 : scope.importOf(root);
|
|
10170
|
+
return { name, ...from !== void 0 ? { from } : {} };
|
|
10171
|
+
}
|
|
10172
|
+
function firstArrayElement(value) {
|
|
10173
|
+
const trimmed = value.trim();
|
|
10174
|
+
const scan = maskCommentsAndStrings(trimmed).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, (c) => " ".repeat(c.length));
|
|
10175
|
+
const element2 = (end) => {
|
|
10176
|
+
const from = 1 + (scan.slice(1, end).length - scan.slice(1, end).trimStart().length);
|
|
10177
|
+
return scan.slice(from, end).trim() === "" ? null : trimmed.slice(from, end).trim();
|
|
10178
|
+
};
|
|
10179
|
+
let depth = 0;
|
|
10180
|
+
for (let i = 1; i < scan.length; i++) {
|
|
10181
|
+
const ch = scan[i];
|
|
10182
|
+
if (ch === "{" || ch === "[" || ch === "(") {
|
|
10183
|
+
depth++;
|
|
10184
|
+
} else if (ch === "}" || ch === "]" || ch === ")") {
|
|
10185
|
+
if (depth === 0) return element2(i);
|
|
10186
|
+
depth--;
|
|
10187
|
+
} else if (ch === "," && depth === 0) {
|
|
10188
|
+
return element2(i);
|
|
10189
|
+
}
|
|
10190
|
+
}
|
|
10191
|
+
return null;
|
|
10192
|
+
}
|
|
10134
10193
|
function followValue(prop, scope) {
|
|
10135
10194
|
const type = parseTypeImport(prop.jsdocText);
|
|
10136
10195
|
let current2;
|
|
@@ -10144,12 +10203,20 @@ function followValue(prop, scope) {
|
|
|
10144
10203
|
if (prop.value === void 0) return null;
|
|
10145
10204
|
const written = prop.value.trim();
|
|
10146
10205
|
const text3 = unwrapFreeze(written);
|
|
10147
|
-
if (!isFollowableName(text3, scope))
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10206
|
+
if (!isFollowableName(text3, scope)) {
|
|
10207
|
+
const member = followMember(text3, scope);
|
|
10208
|
+
if (member === void 0) return text3 === written ? null : { value: { text: text3, scope } };
|
|
10209
|
+
name = text3;
|
|
10210
|
+
from = member.from;
|
|
10211
|
+
if (member.value === null) return { value: null, name, from };
|
|
10212
|
+
current2 = member.value;
|
|
10213
|
+
} else {
|
|
10214
|
+
name = text3;
|
|
10215
|
+
from = scope.importOf(text3);
|
|
10216
|
+
const resolved = scope.resolveName(text3);
|
|
10217
|
+
if (resolved === null) return { value: null, name, from };
|
|
10218
|
+
current2 = resolved;
|
|
10219
|
+
}
|
|
10153
10220
|
}
|
|
10154
10221
|
for (let hops = 0; hops < 8; hops++) {
|
|
10155
10222
|
const inner = unwrapFreeze(current2.text);
|
|
@@ -10160,6 +10227,38 @@ function followValue(prop, scope) {
|
|
|
10160
10227
|
}
|
|
10161
10228
|
return { value: null, name, from };
|
|
10162
10229
|
}
|
|
10230
|
+
function followMember(text3, scope) {
|
|
10231
|
+
const m = /^([$A-Za-z_][$\w]*)((?:\s*\.\s*[$A-Za-z_][$\w]*)+)$/.exec(text3);
|
|
10232
|
+
if (m === null || WORD_LITERALS.has(m[1])) return void 0;
|
|
10233
|
+
const root = m[1];
|
|
10234
|
+
let keys = m[2].split(".").map((key) => key.trim()).filter((key) => key !== "");
|
|
10235
|
+
let current2;
|
|
10236
|
+
if (scope.isNamespaceMember(`${root}.${keys[0]}`)) {
|
|
10237
|
+
current2 = scope.resolveName(`${root}.${keys[0]}`);
|
|
10238
|
+
keys = keys.slice(1);
|
|
10239
|
+
} else {
|
|
10240
|
+
current2 = scope.resolveName(root);
|
|
10241
|
+
if (current2 === null) return void 0;
|
|
10242
|
+
}
|
|
10243
|
+
const from = scope.importOf(root);
|
|
10244
|
+
const unread = { value: null, ...from !== void 0 ? { from } : {} };
|
|
10245
|
+
for (const key of keys) {
|
|
10246
|
+
let literal2 = current2;
|
|
10247
|
+
for (let hops = 0; literal2 !== null && hops < MAX_SPREAD_HOPS; hops++) {
|
|
10248
|
+
const inner = unwrapFreeze(literal2.text);
|
|
10249
|
+
if (isObjectLiteral(inner)) {
|
|
10250
|
+
literal2 = { text: inner, scope: literal2.scope };
|
|
10251
|
+
break;
|
|
10252
|
+
}
|
|
10253
|
+
literal2 = isFollowableName(inner, literal2.scope) ? literal2.scope.resolveName(inner) : null;
|
|
10254
|
+
}
|
|
10255
|
+
if (literal2 === null || !isObjectLiteral(literal2.text)) return unread;
|
|
10256
|
+
const found = objectLiteralKeys(extractObjectContent(literal2.text), literal2.scope, true).keys.find((k) => k.prop.name === key);
|
|
10257
|
+
if (found === void 0 || found.prop.value === void 0) return unread;
|
|
10258
|
+
current2 = { text: found.prop.value, scope: found.scope ?? literal2.scope };
|
|
10259
|
+
}
|
|
10260
|
+
return { value: current2, ...from !== void 0 ? { from } : {} };
|
|
10261
|
+
}
|
|
10163
10262
|
function pushDeclaredShapePaths(path, type, paths, depth, typedefs) {
|
|
10164
10263
|
const shape = jsDocShape(type, typedefs);
|
|
10165
10264
|
if (shape.index !== void 0) {
|
|
@@ -10187,7 +10286,11 @@ function pushLiteralStructurePaths(path, prop, paths, depth, typedefs, scope) {
|
|
|
10187
10286
|
paths.push({ path: `${path}.length`, kind: "data", typeHint: "number" });
|
|
10188
10287
|
if (depth >= MAX_OBJECT_NEST_DEPTH) return null;
|
|
10189
10288
|
const first = firstRowObjectContent(prop.value);
|
|
10190
|
-
if (first === null)
|
|
10289
|
+
if (first === null) {
|
|
10290
|
+
const element2 = prop.declaredType === void 0 ? firstArrayElement(prop.value) : null;
|
|
10291
|
+
if (element2 !== null && !isReadableLiteral(element2)) row.opaque = unreadExpression(element2, scope);
|
|
10292
|
+
return null;
|
|
10293
|
+
}
|
|
10191
10294
|
const { keys, unread } = objectLiteralKeys(first, scope, false);
|
|
10192
10295
|
for (const key of keys) {
|
|
10193
10296
|
pushDataPropertyPathsAt(`${path}.*.${key.prop.name}`, key.prop, paths, depth + 1, typedefs, key.scope);
|
|
@@ -11960,6 +12063,11 @@ var ja = {
|
|
|
11960
12063
|
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`,
|
|
11961
12064
|
handlerFilterNotAllowed: (prop) => `\u30A4\u30D9\u30F3\u30C8\u30CF\u30F3\u30C9\u30E9 "${prop}" \u306B\u30D5\u30A3\u30EB\u30BF\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093`,
|
|
11962
12065
|
typeExpectation: (label, expected, resultType) => `"${label}" \u306B\u306F${JA_EXPECTED_LABEL[expected]}\u304C\u5FC5\u8981\u3067\u3059\uFF08\u73FE\u5728\u306E\u578B: ${resultType}\uFF09`,
|
|
12066
|
+
attrBooleanPresence: (a, p, rhs) => `"attr.${a}" \u306B boolean \u3092\u675F\u306D\u3066\u3044\u307E\u3059\u3002attr.* \u306F String(value) \u3092\u66F8\u304F\u306E\u3067\u3001false \u306E\u3068\u304D ${a}="false" \u306B\u306A\u308A\u307E\u3059\u3002\u8AD6\u7406\u5C5E\u6027\u306F\u5024\u306B\u95A2\u4FC2\u306A\u304F\u3001\u5728\u308B\u3060\u3051\u3067\u52B9\u304D\u307E\u3059: ${a}="false" \u3067\u3082 ${a} \u306E\u307E\u307E\u3067\u3059\uFF08\u5C5E\u6027\u3092\u5916\u3059\u306E\u306F null / undefined \u3060\u3051\uFF09\u3002\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u675F\u306D\u3066\u304F\u3060\u3055\u3044: ${p}: ${rhs}`,
|
|
12067
|
+
attrBooleanText: (a, rhs) => `"attr.${a}" \u306B boolean \u3092\u675F\u306D\u3066\u3044\u307E\u3059\u3002attr.* \u306F String(value) \u3092\u66F8\u304F\u306E\u3067\u3001\u5C5E\u6027\u306F "true" \u304B "false" \u306B\u306A\u308A\u3001\u5916\u308C\u308B\u3053\u3068\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u5916\u3059\u306E\u306F null / undefined \u3060\u3051\uFF09\u3002\u5C5E\u6027\u306E\u6709\u7121\u3092\u898B\u308B\u5074\uFF08CSS \u306E [${a}]\u30FBhasAttribute()\uFF09\u306B\u306F\u3001\u3069\u3061\u3089\u3067\u3082\u5728\u308A\u307E\u3059\u3002false \u306E\u9593\u306F\u5916\u3059\u306A\u3089 attr.${a}: ${rhs}|defaults(null)\u3001\u6587\u5B57\u306E "true" / "false" \u304C\u610F\u56F3\u306A\u3089 attr.${a}: ${rhs}|string \u3068\u66F8\u3044\u3066\u304F\u3060\u3055\u3044`,
|
|
12068
|
+
radioNameShared: (name, binding) => `\u884C\u3054\u3068\u306E\u30E9\u30B8\u30AA\u304C\u3059\u3079\u3066 name="${name}" \u306B\u306A\u308B\u306E\u3067\u3001\u30D6\u30E9\u30A6\u30B6\u306F\u5168\u90E8\u306E\u884C\u306E\u30E9\u30B8\u30AA\u3092 1 \u3064\u306E\u30B0\u30EB\u30FC\u30D7\u306B\u3057\u307E\u3059\u3002\u30DA\u30FC\u30B8\u5168\u4F53\u3067 1 \u3064\u3057\u304B\u9078\u3070\u308C\u305F\u72B6\u614B\u306B\u306A\u3089\u305A\u3001\u8868\u793A\u306F\u6700\u521D\u306E\u63CF\u753B\u304B\u3089\u884C\u3054\u3068\u306E\u5024\u3068\u98DF\u3044\u9055\u3044\u307E\u3059\uFF08\u4F55\u3082\u77E5\u3089\u305B\u307E\u305B\u3093\uFF09\u3002${binding === "radio" ? "\u884C\u3054\u3068\u306B\u9055\u3046 name \u3092\u675F\u306D\u308B\uFF08attr.name: .<\u884C\u3054\u3068\u306B\u9055\u3046\u30D5\u30A3\u30FC\u30EB\u30C9>\uFF09\u304B\u3001name \u3092\u5916\u3057\u3066\u304F\u3060\u3055\u3044\uFF08radio: \u306F name \u304C\u7121\u304F\u3066\u3082\u3001\u540C\u3058\u30D1\u30B9\u306B\u675F\u306D\u305F\u30E9\u30B8\u30AA\u3092\u9078\u629E\u306B\u5408\u308F\u305B\u307E\u3059\uFF09" : "\u884C\u3054\u3068\u306B\u9055\u3046 name \u3092\u675F\u306D\u3066\u304F\u3060\u3055\u3044\uFF08attr.name: .<\u884C\u3054\u3068\u306B\u9055\u3046\u30D5\u30A3\u30FC\u30EB\u30C9>\uFF09\u3002\u884C\u3092\u307E\u305F\u3044\u3067 1 \u3064\u3092\u9078\u3070\u305B\u308B\u306A\u3089\u3001\u5168\u90E8\u3092 1 \u3064\u306E\u30D1\u30B9\u306B\u675F\u306D\u307E\u3059\uFF08value: .<\u884C\u306E id>; radio: <\u30D1\u30B9>\uFF09"}`,
|
|
12069
|
+
numberWrittenAsString: (path, left, asNumber) => `"${path}" \u306F state \u3067\u306F\u6570\u5024\u3067\u3059\u304C\u3001value: \u304C\u66F8\u304D\u623B\u3059\u306E\u306F\u8981\u7D20\u306E\u6301\u3064\u6587\u5B57\u5217\u3067\u3059\u30025 \u3068\u5165\u529B\u3057\u305F\u5F8C\u306E state \u306F "5" \u3067\u3001"5" + 1 \u306F "51" \u306B\u306A\u308A\u307E\u3059\uFF08\u4F55\u3082\u77E5\u3089\u305B\u307E\u305B\u3093\uFF09\u3002\u66F8\u304D\u623B\u3059\u3068\u304D\u306B\u6570\u5024\u306B\u3057\u3066\u304F\u3060\u3055\u3044: ${asNumber ? `valueAsNumber: ${path}\u3001\u307E\u305F\u306F` : ""}\u5DE6\u8FBA\u306E\u5165\u529B\u30D5\u30A3\u30EB\u30BF ${left}|number: ${path}\uFF08|int\u30FB|float \u3082\uFF09`,
|
|
12070
|
+
twoWayOutputFilter: (prop, filters, left, rhs, keystroke) => keystroke ? `${prop}: \u306F\u53CC\u65B9\u5411\u3067 1 \u6253\u9375\u3054\u3068\u306B\u66F8\u304D\u623B\u3057\u3001\u51FA\u529B\u30D5\u30A3\u30EB\u30BF "${filters}" \u306F\u305D\u306E\u305F\u3073\u306B state \u306E\u5024\u3092\u6574\u5F62\u3057\u3066\u6B04\u3078\u66F8\u304D\u76F4\u3057\u307E\u3059\u3002\u5165\u529B\u4E2D\u306E\u6B04\u304C\u66F8\u304D\u63DB\u308F\u308A\uFF08\u30AD\u30E3\u30EC\u30C3\u30C8\u306F\u672B\u5C3E\u3078\u98DB\u3073\u3001IME \u306E\u5909\u63DB\u306F\u9014\u5207\u308C\u307E\u3059\uFF09\u3001state \u304C\u53D7\u3051\u53D6\u308B\u306E\u3082\u6B04\u306E\u6574\u5F62\u6E08\u307F\u306E\u6587\u5B57\u3067\u3059\uFF08\u51FA\u529B\u30D5\u30A3\u30EB\u30BF\u306F\u66F8\u304D\u623B\u3057\u3067\u5143\u306B\u623B\u308A\u307E\u305B\u3093\uFF09\u3002\u6574\u5F62\u3057\u305F\u6587\u5B57\u306F\u5225\u306E\u8981\u7D20\u306B\u8868\u793A\u3059\u308B\u3001\u6B04\u306E\u78BA\u5B9A\u3067\u66F8\u304D\u623B\u3057\u3066 setter \u3067\u6574\u5F62\u3059\u308B\uFF08${prop}#onchange:\uFF09\u3001\u307E\u305F\u306F\u4E00\u65B9\u5411\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${prop}#ro: ${rhs}\uFF09` : `${prop}: \u306F\u53CC\u65B9\u5411\u3067\u3059\u304C\u3001\u51FA\u529B\u30D5\u30A3\u30EB\u30BF "${filters}" \u306F\u66F8\u304D\u623B\u3057\u3067\u5143\u306B\u623B\u308A\u307E\u305B\u3093\u3002\u8981\u7D20\u304C\u66F8\u304D\u623B\u3059\u306E\u306F\u8868\u793A\u3057\u3066\u3044\u308B\u6574\u5F62\u6E08\u307F\u306E\u5024\u3067\u3001\u6B21\u306F\u305D\u306E\u5024\u306B\u30D5\u30A3\u30EB\u30BF\u304C\u639B\u304B\u308A\u307E\u3059\u3002\u5DE6\u8FBA\u306E\u5165\u529B\u30D5\u30A3\u30EB\u30BF\u3067\u5143\u306B\u623B\u3059\uFF08${left}|<\u30D5\u30A3\u30EB\u30BF>: \u2026\uFF09\u3001\u6574\u5F62\u3057\u305F\u5024\u306F\u5225\u306E\u8981\u7D20\u306B\u8868\u793A\u3059\u308B\u3001\u307E\u305F\u306F\u4E00\u65B9\u5411\u306B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08${prop}#ro: ${rhs}\uFF09`,
|
|
11963
12071
|
filterUnknown: (n) => `\u30D5\u30A3\u30EB\u30BF "${n}" \u306F\u7D44\u307F\u8FBC\u307F\u30D5\u30A3\u30EB\u30BF\u306B\u5B58\u5728\u3057\u307E\u305B\u3093`,
|
|
11964
12072
|
filterRemoved: (n, c) => `\u30D5\u30A3\u30EB\u30BF "${n}" \u306F 4.0 \u3067\u5916\u308C\u307E\u3057\u305F\uFF08"${c}" \u306E 3.x \u306E\u65E7\u540D\uFF09\u3002"${c}" \u3068\u66F8\u3044\u3066\u304F\u3060\u3055\u3044`,
|
|
11965
12073
|
substrRemoved: (rewrite) => `\u30D5\u30A3\u30EB\u30BF "substr" \u306F 4.0 \u3067\u5916\u308C\u307E\u3057\u305F\u3002slice(start, start + length) \u3068\u66F8\u3044\u3066\u304F\u3060\u3055\u3044 \u2014 slice \u306E\u7B2C 2 \u5F15\u6570\u306F\u9577\u3055\u3067\u306F\u306A\u304F\u7D42\u308F\u308A\u306E\u4F4D\u7F6E\u3067\u3059${rewrite === null ? "" : `\uFF08\u3053\u3053\u3067\u306F ${rewrite}\uFF09`}`,
|
|
@@ -12197,6 +12305,11 @@ var en = {
|
|
|
12197
12305
|
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`,
|
|
12198
12306
|
handlerFilterNotAllowed: (prop) => `Filters cannot be applied to event handler "${prop}"`,
|
|
12199
12307
|
typeExpectation: (label, expected, resultType) => `"${label}" requires ${EN_EXPECTED_LABEL[expected]} (current type: ${resultType})`,
|
|
12308
|
+
attrBooleanPresence: (a, p, rhs) => `"attr.${a}" is given a boolean. attr.* writes String(value), so false is written as ${a}="false" \u2014 and a boolean attribute is on whenever it is present, whatever its value: ${a}="false" still means ${a} (only null / undefined remove an attribute). Bind the property instead: ${p}: ${rhs}`,
|
|
12309
|
+
attrBooleanText: (a, rhs) => `"attr.${a}" is given a boolean. attr.* writes String(value), so the attribute is "true" or "false" and is never removed (only null / undefined remove it): whatever tests its presence \u2014 [${a}] in CSS, hasAttribute() \u2014 finds it either way. To remove it while false, write attr.${a}: ${rhs}|defaults(null); if the text "true" / "false" is what is meant, say so: attr.${a}: ${rhs}|string`,
|
|
12310
|
+
radioNameShared: (name, binding) => `Every row's radios get name="${name}", so the browser makes one group of all the rows: only one radio on the whole page stays checked, and the page disagrees with the rows' values from the first render \u2014 nothing says so. ${binding === "radio" ? "Bind a name that differs per row (attr.name: .<a row field>), or drop the name: radio: keeps the radios bound to one path in step without it" : "Bind a name that differs per row (attr.name: .<a row field>) \u2014 or, for one choice over all the rows, bind them all to one path: value: .<the row's id>; radio: <path>"}`,
|
|
12311
|
+
numberWrittenAsString: (path, left, asNumber) => `"${path}" is a number in the state, but value: writes back what the element holds, a string: after the user enters 5 the state has "5", and "5" + 1 is "51" \u2014 nothing says so. Convert it on the way in: ${asNumber ? `valueAsNumber: ${path}, or ` : ""}an input filter on the left side, ${left}|number: ${path} (also |int, |float)`,
|
|
12312
|
+
twoWayOutputFilter: (prop, filters, left, rhs, keystroke) => keystroke ? `${prop}: is two-way and writes back on every keystroke, and the output filter "${filters}" formats what the state holds each time: the field is rewritten while the user types \u2014 the caret jumps to the end, an IME composition is cut \u2014 and what the state receives is the field's formatted text (an output filter is not undone on the way back). Show the formatted text in another element, write back when the field is committed and format in a setter (${prop}#onchange:), or make the binding one-way: ${prop}#ro: ${rhs}` : `${prop}: is two-way, and nothing undoes the output filter "${filters}" on the way back: the element writes back the formatted value it shows, and the filter is then applied to that. Undo it with an input filter on the left side (${left}|<filter>: \u2026), show the formatted value in another element, or make the binding one-way: ${prop}#ro: ${rhs}`,
|
|
12200
12313
|
filterUnknown: (n) => `Filter "${n}" is not a built-in filter`,
|
|
12201
12314
|
filterRemoved: (n, c) => `Filter "${n}" was removed in 4.0 (it was the 3.x old name of "${c}") \u2014 write "${c}"`,
|
|
12202
12315
|
substrRemoved: (rewrite) => `Filter "substr" was removed in 4.0 \u2014 write slice(start, start + length): slice takes the end index, not a length${rewrite === null ? "" : ` (here: ${rewrite})`}`,
|
|
@@ -12614,6 +12727,63 @@ function removedFilterMessage(name, args, msgs) {
|
|
|
12614
12727
|
return canonical === null ? null : msgs.filterRemoved(name, canonical);
|
|
12615
12728
|
}
|
|
12616
12729
|
|
|
12730
|
+
// src/service/attributeValues.ts
|
|
12731
|
+
var ARIA_TRUE_FALSE = /* @__PURE__ */ new Set([
|
|
12732
|
+
"aria-atomic",
|
|
12733
|
+
"aria-busy",
|
|
12734
|
+
"aria-checked",
|
|
12735
|
+
"aria-current",
|
|
12736
|
+
"aria-disabled",
|
|
12737
|
+
"aria-expanded",
|
|
12738
|
+
"aria-grabbed",
|
|
12739
|
+
"aria-haspopup",
|
|
12740
|
+
"aria-hidden",
|
|
12741
|
+
"aria-invalid",
|
|
12742
|
+
"aria-modal",
|
|
12743
|
+
"aria-multiline",
|
|
12744
|
+
"aria-multiselectable",
|
|
12745
|
+
"aria-pressed",
|
|
12746
|
+
"aria-readonly",
|
|
12747
|
+
"aria-required",
|
|
12748
|
+
"aria-selected"
|
|
12749
|
+
]);
|
|
12750
|
+
var ENUMERATED_TRUE_FALSE = /* @__PURE__ */ new Set(["contenteditable", "draggable", "spellcheck", "writingsuggestions"]);
|
|
12751
|
+
var BOOLEAN_ATTRIBUTE_PROPERTY = {
|
|
12752
|
+
allowfullscreen: "allowFullscreen",
|
|
12753
|
+
async: "async",
|
|
12754
|
+
autofocus: "autofocus",
|
|
12755
|
+
autoplay: "autoplay",
|
|
12756
|
+
checked: "checked",
|
|
12757
|
+
controls: "controls",
|
|
12758
|
+
default: "default",
|
|
12759
|
+
defer: "defer",
|
|
12760
|
+
disabled: "disabled",
|
|
12761
|
+
formnovalidate: "formNoValidate",
|
|
12762
|
+
hidden: "hidden",
|
|
12763
|
+
inert: "inert",
|
|
12764
|
+
ismap: "isMap",
|
|
12765
|
+
loop: "loop",
|
|
12766
|
+
multiple: "multiple",
|
|
12767
|
+
muted: "muted",
|
|
12768
|
+
nomodule: "noModule",
|
|
12769
|
+
novalidate: "noValidate",
|
|
12770
|
+
open: "open",
|
|
12771
|
+
playsinline: "playsInline",
|
|
12772
|
+
readonly: "readOnly",
|
|
12773
|
+
required: "required",
|
|
12774
|
+
reversed: "reversed",
|
|
12775
|
+
selected: "selected"
|
|
12776
|
+
};
|
|
12777
|
+
function booleanAttributeText(name, tag) {
|
|
12778
|
+
const attribute = name.toLowerCase();
|
|
12779
|
+
if (ARIA_TRUE_FALSE.has(attribute) || ENUMERATED_TRUE_FALSE.has(attribute)) return { kind: "value" };
|
|
12780
|
+
const native = tag !== void 0 && !tag.includes("-");
|
|
12781
|
+
if (native && Object.hasOwn(BOOLEAN_ATTRIBUTE_PROPERTY, attribute)) {
|
|
12782
|
+
return { kind: "presence", property: BOOLEAN_ATTRIBUTE_PROPERTY[attribute] };
|
|
12783
|
+
}
|
|
12784
|
+
return { kind: "text" };
|
|
12785
|
+
}
|
|
12786
|
+
|
|
12617
12787
|
// src/service/bindingValidator.ts
|
|
12618
12788
|
var filterMap = new Map(BUILTIN_FILTERS.map((f) => [f.name, f]));
|
|
12619
12789
|
var DIRECT_MODIFIER = "direct";
|
|
@@ -13044,7 +13214,19 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
|
|
|
13044
13214
|
const resultType = resolveResultType(typePath, parsed.filters, scopedPaths);
|
|
13045
13215
|
if (resultType !== null) {
|
|
13046
13216
|
const typeReq = getExpectedType(parsed.property);
|
|
13047
|
-
|
|
13217
|
+
const attrBoolean = typeReq !== null && propNoMod.startsWith("attr.") && isBooleanType(resultType) ? booleanAttrMessage(propNoMod.slice("attr.".length), attr.tagName, binding, parsed, msgs) : void 0;
|
|
13218
|
+
if (attrBoolean !== void 0) {
|
|
13219
|
+
if (attrBoolean !== null) {
|
|
13220
|
+
const pathStart = bindingStart + binding.indexOf(parsed.path);
|
|
13221
|
+
diagnostics.push({
|
|
13222
|
+
code: WcsDiagnosticCode.BindingTypeExpectation,
|
|
13223
|
+
start: pathStart,
|
|
13224
|
+
end: pathStart + pathTrimmed.length,
|
|
13225
|
+
message: attrBoolean,
|
|
13226
|
+
severity: "warning"
|
|
13227
|
+
});
|
|
13228
|
+
}
|
|
13229
|
+
} else if (typeReq && resultType !== typeReq.expected) {
|
|
13048
13230
|
const pathOffset = binding.indexOf(parsed.path);
|
|
13049
13231
|
const pathStart = bindingStart + pathOffset;
|
|
13050
13232
|
const schemaDefinite = typeReq.expected === "array" && parsed.filters.length === 0 && applicationSchema !== void 0 && scopedPaths.some((p) => p.path === typePath && p.fromSchema === true);
|
|
@@ -13125,7 +13307,14 @@ function findAllBindAttributes(html, attrName) {
|
|
|
13125
13307
|
const valueEnd = html.indexOf(quote, valueStart);
|
|
13126
13308
|
if (valueEnd === -1 || valueEnd > tag.end) continue;
|
|
13127
13309
|
const inputType = tag.tagName === "input" ? extractAttribute(attrsText, "type") ?? void 0 : void 0;
|
|
13128
|
-
attrs.push({
|
|
13310
|
+
attrs.push({
|
|
13311
|
+
value: html.slice(valueStart, valueEnd),
|
|
13312
|
+
valueStart,
|
|
13313
|
+
tagName: tag.tagName,
|
|
13314
|
+
...inputType !== void 0 ? { inputType } : {},
|
|
13315
|
+
attrsStart: tag.start,
|
|
13316
|
+
attrsEnd: tag.end
|
|
13317
|
+
});
|
|
13129
13318
|
regex.lastIndex = valueEnd - tag.start;
|
|
13130
13319
|
}
|
|
13131
13320
|
}
|
|
@@ -13306,6 +13495,18 @@ function getExpectedType(property) {
|
|
|
13306
13495
|
}
|
|
13307
13496
|
return null;
|
|
13308
13497
|
}
|
|
13498
|
+
function isBooleanType(type) {
|
|
13499
|
+
const parts = type.split("|");
|
|
13500
|
+
return parts.includes("boolean") && parts.every((part) => part === "boolean" || part === "null");
|
|
13501
|
+
}
|
|
13502
|
+
function booleanAttrMessage(name, tag, binding, parsed, msgs) {
|
|
13503
|
+
const last = parsed.filters[parsed.filters.length - 1];
|
|
13504
|
+
if (last !== void 0 && last.name === "defaults" && last.args.length === 1 && last.args[0] === "null") return null;
|
|
13505
|
+
const written = booleanAttributeText(name, tag);
|
|
13506
|
+
if (written.kind === "value") return null;
|
|
13507
|
+
const rhs = binding.slice(indexOfOutsideQuotes2(binding, ":") + 1).trim();
|
|
13508
|
+
return written.kind === "presence" ? msgs.attrBooleanPresence(name, written.property, rhs) : msgs.attrBooleanText(name, rhs);
|
|
13509
|
+
}
|
|
13309
13510
|
function validateFilterChainTypes(path, filters, statePaths, bindingStart, msgs) {
|
|
13310
13511
|
const diagnostics = [];
|
|
13311
13512
|
const pathInfo = statePaths.find((p) => p.path === path);
|
|
@@ -16053,6 +16254,187 @@ function closingTagStart(html, from, name) {
|
|
|
16053
16254
|
return html.length;
|
|
16054
16255
|
}
|
|
16055
16256
|
|
|
16257
|
+
// src/service/formInputValidator.ts
|
|
16258
|
+
var filterMap2 = new Map(BUILTIN_FILTERS.map((f) => [f.name, f]));
|
|
16259
|
+
var NOT_ENTERED = /* @__PURE__ */ new Set(["checkbox", "radio", "hidden", "button", "submit", "reset", "image", "file"]);
|
|
16260
|
+
var NOT_TYPED = /* @__PURE__ */ new Set(["range", "color", "date", "datetime-local", "month", "week", "time"]);
|
|
16261
|
+
var AS_NUMBER = /* @__PURE__ */ new Set(["number", "range", "date", "datetime-local", "month", "week", "time"]);
|
|
16262
|
+
function validateFormInputs(html, bindAttribute = "data-wcs", stateTagName = "wcs-state", locale2, fileReader, applicationSchema) {
|
|
16263
|
+
const attrs = findAllBindAttributes(html, bindAttribute).filter((attr) => attr.tagName === "input" || attr.tagName === "textarea" || attr.tagName === "select");
|
|
16264
|
+
if (attrs.length === 0) return [];
|
|
16265
|
+
const msgs = getMessages(locale2);
|
|
16266
|
+
const out = [];
|
|
16267
|
+
let types2 = null;
|
|
16268
|
+
const getTypes = () => {
|
|
16269
|
+
if (types2 === null) {
|
|
16270
|
+
const index = getStatePathIndex(html, stateTagName, fileReader);
|
|
16271
|
+
const candidates = mergeSchemaCandidates(index.paths, applicationSchema);
|
|
16272
|
+
const set = new Set(candidates.map((p) => p.path));
|
|
16273
|
+
types2 = {
|
|
16274
|
+
candidates,
|
|
16275
|
+
has: (path) => set.has(path),
|
|
16276
|
+
computed: new Set(index.paths.filter((p) => p.kind === "computed").map((p) => p.path))
|
|
16277
|
+
};
|
|
16278
|
+
}
|
|
16279
|
+
return types2;
|
|
16280
|
+
};
|
|
16281
|
+
const saidRadio = /* @__PURE__ */ new Set();
|
|
16282
|
+
for (const attr of attrs) {
|
|
16283
|
+
const bindings = splitBindingExpressions(attr.value);
|
|
16284
|
+
const parsed = bindings.map(parseBindingExpression);
|
|
16285
|
+
const type = (attr.inputType ?? "text").toLowerCase();
|
|
16286
|
+
if (attr.tagName === "input" && type === "radio") {
|
|
16287
|
+
const shared = sharedRadioName(html, attr, parsed, bindAttribute);
|
|
16288
|
+
if (shared !== null && !saidRadio.has(shared.key)) {
|
|
16289
|
+
saidRadio.add(shared.key);
|
|
16290
|
+
out.push({
|
|
16291
|
+
code: WcsDiagnosticCode.RadioNameShared,
|
|
16292
|
+
start: shared.start,
|
|
16293
|
+
end: shared.end,
|
|
16294
|
+
message: msgs.radioNameShared(shared.name, shared.binding),
|
|
16295
|
+
severity: "warning"
|
|
16296
|
+
});
|
|
16297
|
+
}
|
|
16298
|
+
continue;
|
|
16299
|
+
}
|
|
16300
|
+
if (attr.tagName === "input" && NOT_ENTERED.has(type)) continue;
|
|
16301
|
+
const typed = attr.tagName === "textarea" || attr.tagName === "input" && !NOT_TYPED.has(type);
|
|
16302
|
+
let pos = 0;
|
|
16303
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
16304
|
+
const binding = bindings[i];
|
|
16305
|
+
const bindingStart = attr.valueStart + pos;
|
|
16306
|
+
pos += binding.length + 1;
|
|
16307
|
+
const p = parsed[i];
|
|
16308
|
+
if (p.path === null) continue;
|
|
16309
|
+
const name = propertyName(p.property);
|
|
16310
|
+
if (name !== "value" && name !== "valueAsNumber") continue;
|
|
16311
|
+
if (!writesBack(attr, name, p.property)) continue;
|
|
16312
|
+
const path = p.path.trim();
|
|
16313
|
+
const colon = indexOfOutsideQuotes2(binding, ":");
|
|
16314
|
+
const left = binding.slice(0, colon).trim();
|
|
16315
|
+
const rhs = binding.slice(colon + 1).trim();
|
|
16316
|
+
const harmful = p.filters.find((filter) => !givesBackWhatWasWritten(filter, p));
|
|
16317
|
+
const keystroke = typed && writeBackEvent(p.property) === "input";
|
|
16318
|
+
if (harmful !== void 0 && (keystroke || p.inputFilters.length === 0)) {
|
|
16319
|
+
if (p.filters.some((filter) => !filterMap2.has(filter.name))) continue;
|
|
16320
|
+
out.push({
|
|
16321
|
+
code: WcsDiagnosticCode.TwoWayOutputFilter,
|
|
16322
|
+
start: bindingStart + harmful.offset,
|
|
16323
|
+
end: bindingStart + harmful.offset + harmful.name.length,
|
|
16324
|
+
message: msgs.twoWayOutputFilter(name, `|${binding.slice(p.filters[0].offset).trim()}`, left, rhs, keystroke),
|
|
16325
|
+
severity: "warning"
|
|
16326
|
+
});
|
|
16327
|
+
continue;
|
|
16328
|
+
}
|
|
16329
|
+
if (name !== "value" || inputGivesNumber(p) !== false) continue;
|
|
16330
|
+
const statePath = expandRowPath(path, html, attr.valueStart, bindAttribute);
|
|
16331
|
+
if (statePath === null) continue;
|
|
16332
|
+
const t = getTypes();
|
|
16333
|
+
const key = candidateKeyOf(statePath, t.has);
|
|
16334
|
+
const candidate = t.candidates.find((c) => c.path === key);
|
|
16335
|
+
if (candidate === void 0 || candidate.kind !== "data" || t.computed.has(key) || !isNumberType(candidate.typeHint)) continue;
|
|
16336
|
+
const pathStart = bindingStart + binding.indexOf(p.path, colon + 1);
|
|
16337
|
+
out.push({
|
|
16338
|
+
code: WcsDiagnosticCode.NumberWrittenAsString,
|
|
16339
|
+
start: pathStart,
|
|
16340
|
+
end: pathStart + path.length,
|
|
16341
|
+
message: msgs.numberWrittenAsString(path, left, attr.tagName === "input" && AS_NUMBER.has(type)) + (path.startsWith(".") ? msgs.expansionSuffix(statePath) : ""),
|
|
16342
|
+
severity: "warning",
|
|
16343
|
+
statePath
|
|
16344
|
+
});
|
|
16345
|
+
}
|
|
16346
|
+
}
|
|
16347
|
+
return out;
|
|
16348
|
+
}
|
|
16349
|
+
function propertyName(property) {
|
|
16350
|
+
const name = property.replace(/#.*$/, "").trim();
|
|
16351
|
+
return name.startsWith(".") ? name.slice(1) : name;
|
|
16352
|
+
}
|
|
16353
|
+
function writeBackEvent(property) {
|
|
16354
|
+
const hash = property.indexOf("#");
|
|
16355
|
+
if (hash === -1) return "input";
|
|
16356
|
+
const named = property.slice(hash + 1).split(",").map((m) => m.trim()).find((m) => /^on\w+$/.test(m));
|
|
16357
|
+
return named === void 0 ? "input" : named.slice(2);
|
|
16358
|
+
}
|
|
16359
|
+
function isNumberType(typeHint) {
|
|
16360
|
+
if (typeHint === void 0) return false;
|
|
16361
|
+
const parts = typeHint.split("|");
|
|
16362
|
+
return parts.includes("number") && parts.every((part) => part === "number" || part === "null");
|
|
16363
|
+
}
|
|
16364
|
+
function inputGivesNumber(p) {
|
|
16365
|
+
let current2 = "string";
|
|
16366
|
+
for (const filter of p.inputFilters) {
|
|
16367
|
+
const info = filterMap2.get(filter.name);
|
|
16368
|
+
if (info === void 0) return null;
|
|
16369
|
+
if (info.resultType !== "passthrough") current2 = info.resultType;
|
|
16370
|
+
}
|
|
16371
|
+
return current2 === "number";
|
|
16372
|
+
}
|
|
16373
|
+
function isEmptyArgument(args) {
|
|
16374
|
+
return args.length === 1 && (args[0] === "" || args[0] === "''" || args[0] === '""');
|
|
16375
|
+
}
|
|
16376
|
+
function givesBackWhatWasWritten(filter, p) {
|
|
16377
|
+
switch (filter.name) {
|
|
16378
|
+
case "string":
|
|
16379
|
+
case "nullIfEmpty":
|
|
16380
|
+
return true;
|
|
16381
|
+
case "coalesce":
|
|
16382
|
+
return isEmptyArgument(filter.args) || !p.inputFilters.some((input) => input.name === "nullIfEmpty");
|
|
16383
|
+
case "defaults":
|
|
16384
|
+
return isEmptyArgument(filter.args);
|
|
16385
|
+
default:
|
|
16386
|
+
return false;
|
|
16387
|
+
}
|
|
16388
|
+
}
|
|
16389
|
+
function expandRowPath(path, html, offset2, bindAttribute) {
|
|
16390
|
+
if (!path.startsWith(".")) return path;
|
|
16391
|
+
if (getRowShorthandForPath(html, offset2, bindAttribute) === null) return null;
|
|
16392
|
+
const list = getResolvedForListPath(html, offset2, bindAttribute);
|
|
16393
|
+
if (list === null || list.startsWith(".")) return null;
|
|
16394
|
+
return path === "." ? `${list}.*` : `${list}.*.${path.slice(1)}`;
|
|
16395
|
+
}
|
|
16396
|
+
function writtenAttributes(html, from, to) {
|
|
16397
|
+
const out = [];
|
|
16398
|
+
const attribute = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>`=]+)))?/g;
|
|
16399
|
+
const text3 = html.slice(from, to);
|
|
16400
|
+
let match;
|
|
16401
|
+
while ((match = attribute.exec(text3)) !== null) {
|
|
16402
|
+
out.push({
|
|
16403
|
+
name: match[1].toLowerCase(),
|
|
16404
|
+
value: match[2] ?? match[3] ?? match[4] ?? null,
|
|
16405
|
+
start: from + match.index,
|
|
16406
|
+
end: from + match.index + match[0].length
|
|
16407
|
+
});
|
|
16408
|
+
}
|
|
16409
|
+
return out;
|
|
16410
|
+
}
|
|
16411
|
+
function sharedRadioName(html, attr, parsed, bindAttribute) {
|
|
16412
|
+
if (attr.attrsStart === void 0 || attr.attrsEnd === void 0) return null;
|
|
16413
|
+
const names2 = parsed.map((p) => propertyName(p.property));
|
|
16414
|
+
if (names2.includes("attr.name") || names2.includes("name")) return null;
|
|
16415
|
+
const at2 = names2.findIndex((name) => name === "radio" || name === "checked");
|
|
16416
|
+
if (at2 === -1) return null;
|
|
16417
|
+
const path = parsed[at2].path?.trim() ?? "";
|
|
16418
|
+
const wildcards = countWildcardSegments(path);
|
|
16419
|
+
if (!path.startsWith(".") && wildcards === 0) return null;
|
|
16420
|
+
const literal2 = writtenAttributes(html, attr.attrsStart, attr.attrsEnd).find((a) => a.name === "name");
|
|
16421
|
+
if (literal2 === void 0 || literal2.value === null || literal2.value.trim() === "") return null;
|
|
16422
|
+
const fors = getEnclosingFors(html, attr.valueStart, bindAttribute);
|
|
16423
|
+
if (fors.length === 0) return null;
|
|
16424
|
+
const level = path.startsWith(".") || wildcards > fors.length ? fors.length - 1 : wildcards - 1;
|
|
16425
|
+
const loop = fors[level];
|
|
16426
|
+
const row = html.slice(loop.anchor, attr.attrsStart).toLowerCase();
|
|
16427
|
+
const form = row.lastIndexOf("<form");
|
|
16428
|
+
if (form !== -1 && /^<form[\s>]/.test(row.slice(form)) && row.indexOf("</form", form) === -1) return null;
|
|
16429
|
+
return {
|
|
16430
|
+
name: literal2.value,
|
|
16431
|
+
binding: names2[at2],
|
|
16432
|
+
start: literal2.start,
|
|
16433
|
+
end: literal2.end,
|
|
16434
|
+
key: `${loop.anchor}\0${literal2.value}`
|
|
16435
|
+
};
|
|
16436
|
+
}
|
|
16437
|
+
|
|
16056
16438
|
// src/service/documentEnvValidator.ts
|
|
16057
16439
|
function validateDocumentEnv(html, locale2) {
|
|
16058
16440
|
const diagnostics = [];
|
|
@@ -18748,8 +19130,8 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18748
19130
|
const spans = opaque2.length === 0 ? [] : analyzeDeclarationSpans(block.content);
|
|
18749
19131
|
for (const candidate of opaque2) {
|
|
18750
19132
|
const path = prefix + candidate.path;
|
|
18751
|
-
bound ??= buildReferenceIndex(html, { bindAttribute, stateTagName }).occurrences.filter((o) => o.kind === "path").map((o) =>
|
|
18752
|
-
const count = bound.filter((b) => b.startsWith(`${path}.`)).length;
|
|
19133
|
+
bound ??= buildReferenceIndex(html, { bindAttribute, stateTagName }).occurrences.filter((o) => o.kind === "path").map((o) => rowPathOf(o.path, html, o.pathRange.start, bindAttribute)).map((path2) => hasIndexSegment(path2) ? toWildcardForm(path2) : path2);
|
|
19134
|
+
const count = bound.filter((b) => b.startsWith(`${path}.`) && !pathExistsInCandidates(b, candidates, candidateSet)).length;
|
|
18753
19135
|
const span = spans.find((s) => candidate.path === s.name || candidate.path.startsWith(`${s.name}.`));
|
|
18754
19136
|
if (count === 0 || span === void 0) continue;
|
|
18755
19137
|
out.push({
|
|
@@ -18796,6 +19178,12 @@ function validateScriptReads(html, stateTagName = "wcs-state", locale2, fileRead
|
|
|
18796
19178
|
}
|
|
18797
19179
|
return out;
|
|
18798
19180
|
}
|
|
19181
|
+
function rowPathOf(path, html, offset2, bindAttribute) {
|
|
19182
|
+
if (!path.startsWith(".")) return path;
|
|
19183
|
+
const list = getResolvedForListPath(html, offset2, bindAttribute);
|
|
19184
|
+
if (list === null || list.startsWith(".")) return path;
|
|
19185
|
+
return path === "." ? `${list}.*` : `${list}.*.${path.slice(1)}`;
|
|
19186
|
+
}
|
|
18799
19187
|
function isList(path, candidates, candidateSet) {
|
|
18800
19188
|
return candidateSet.has(`${path}.*`) || candidates.some((c) => c.path === path && c.kind === "list");
|
|
18801
19189
|
}
|
|
@@ -19159,7 +19547,7 @@ function findTopLevelReads(source) {
|
|
|
19159
19547
|
}
|
|
19160
19548
|
function readOf(node, assigned, source) {
|
|
19161
19549
|
const object = node.object;
|
|
19162
|
-
const prop =
|
|
19550
|
+
const prop = propertyName2(node);
|
|
19163
19551
|
if (isGlobal(object, STORAGES)) {
|
|
19164
19552
|
if (assigned || prop !== null && STORAGE_WRITES.has(prop)) return null;
|
|
19165
19553
|
return { start: node.start, end: node.end, text: source.slice(node.start, node.end) };
|
|
@@ -19175,7 +19563,7 @@ function isGlobal(node, names2) {
|
|
|
19175
19563
|
const object = node.object;
|
|
19176
19564
|
return object.type === "Identifier" && GLOBALS.has(object.name) && node.property.type === "Identifier" && names2.has(node.property.name);
|
|
19177
19565
|
}
|
|
19178
|
-
function
|
|
19566
|
+
function propertyName2(node) {
|
|
19179
19567
|
if (!node.computed) return node.property.type === "Identifier" ? node.property.name : null;
|
|
19180
19568
|
return node.property.type === "Literal" && typeof node.property.value === "string" ? node.property.value : null;
|
|
19181
19569
|
}
|
|
@@ -19777,6 +20165,7 @@ function validateText(text3, options, applicationSchema) {
|
|
|
19777
20165
|
out.push(...validateIoNodes(text3, bindAttribute, stateTagName, locale2, fileReader));
|
|
19778
20166
|
out.push(...validateAriaAttributes(text3, bindAttribute, locale2));
|
|
19779
20167
|
out.push(...validateLiveRegions(text3, bindAttribute, stateTagName, locale2));
|
|
20168
|
+
out.push(...validateFormInputs(text3, bindAttribute, stateTagName, locale2, fileReader, applicationSchema));
|
|
19780
20169
|
out.push(...validateDocumentEnv(text3, locale2));
|
|
19781
20170
|
out.push(...validatePackageLoads(text3, locale2, fileReader));
|
|
19782
20171
|
out.push(...validateSemantics(text3, stateTagName, locale2, bindAttribute));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/lint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.23.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": {
|