@wcstack/state 1.28.0 → 1.30.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/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +180 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/parser.d.ts +42 -1
- package/dist/parser.esm.js +103 -23
- package/package.json +1 -1
package/dist/parser.d.ts
CHANGED
|
@@ -68,7 +68,48 @@ type ParseBindTextResult = IParsedBinding;
|
|
|
68
68
|
|
|
69
69
|
declare function parseBindTextsForElement(bindText: string): ParseBindTextResult[];
|
|
70
70
|
|
|
71
|
+
declare function parseBindTextForEmbeddedNode(bindText: string): ParseBindTextResult;
|
|
72
|
+
|
|
71
73
|
declare function getPathInfo(path: string): IPathInfo;
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
/**
|
|
76
|
+
* parser.ts — `data-wcs` バインディング構文の正本パーサを tooling 向けに公開する
|
|
77
|
+
* サブパスエントリ(`@wcstack/state/parser`)。
|
|
78
|
+
*
|
|
79
|
+
* `./manifest` と同じ「実装が唯一の正本」パターン(docs/static-wiring-dx-design.md D2)。
|
|
80
|
+
* vscode-wcs の正規表現パーサ・devtools の declaredScan 簡易パーサという複製実装を
|
|
81
|
+
* 段階的にこの正本へ寄せるための土台。
|
|
82
|
+
*
|
|
83
|
+
* 契約:
|
|
84
|
+
* - DOM 非依存・純関数(bindText 文字列 → ParseBindTextResult[])。Node でそのまま動く
|
|
85
|
+
* (__tests__/parser.test.ts が node 環境で検証する)。
|
|
86
|
+
* - **位置情報は持たず、不正構文は raiseError で throw する**。エラー耐性と診断 range の
|
|
87
|
+
* 生成は消費側(vscode-wcs の positional ラッパー)の責務(同 D3)— ランタイムの
|
|
88
|
+
* サイズと責務をここで増やさない。
|
|
89
|
+
* - `getPathInfo` はパス文字列の解析済みビュー(セグメント・ワイルドカード位置・親パス
|
|
90
|
+
* チェーン)を返す純関数。静的依存グラフの親チェーン展開はこの情報から機械的に再現できる。
|
|
91
|
+
* 同一パス → 同一インスタンスの保証は**このエントリのモジュールインスタンス内**でのみ
|
|
92
|
+
* 成立する(`.` エントリは別バンドル=別キャッシュ。ランタイムの PathInfo と identity
|
|
93
|
+
* 比較してはならない)。キャッシュは無制限(evict なし)— 言語サーバー等の長時間
|
|
94
|
+
* プロセスでは入力パス種数に単調比例してメモリが増える点に留意。
|
|
95
|
+
* - `ParseBindTextResult.uuid` はランタイム内部(構造テンプレートのハイドレーション台帳)
|
|
96
|
+
* 用のフィールドで、このパーサの戻り値では常に undefined。
|
|
97
|
+
*
|
|
98
|
+
* 公開面は意図的に最小(公開=恒久契約)。`expandSpread` は live Element と
|
|
99
|
+
* CustomElementRegistry を要するためここには含めない — ブラウザ内の消費者
|
|
100
|
+
* (devtools の declared 正本化)は state 自身が pull API で答える。
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* このエントリの内部キャッシュ(PathInfo intern・propPart/statePart のパース結果・フィルタ関数クロージャ)を全て捨てる。
|
|
105
|
+
*
|
|
106
|
+
* 言語サーバー等の**長時間プロセス専用**。編集中の中間パス(`user.n` 等)が
|
|
107
|
+
* 無制限キャッシュに恒久 intern されてメモリが単調増加するため、ドキュメント
|
|
108
|
+
* クローズ等の区切りで呼ぶ。クリア後の getPathInfo は同一パスに**新しい**
|
|
109
|
+
* インスタンスを返す — 「同一パス → 同一参照」の保証はクリアを跨がない。
|
|
110
|
+
* ランタイム(`.` エントリ)にはこの API は無く、呼ばれることもない。
|
|
111
|
+
*/
|
|
112
|
+
declare function clearParserCaches(): void;
|
|
113
|
+
|
|
114
|
+
export { clearParserCaches, getPathInfo, parseBindTextForEmbeddedNode, parseBindTextsForElement };
|
|
74
115
|
export type { BindingType, IFilterInfo, IPathInfo, ParseBindTextResult };
|
package/dist/parser.esm.js
CHANGED
|
@@ -36,6 +36,16 @@ for (let i = 0; i < MAX_WILDCARD_DEPTH; i++) {
|
|
|
36
36
|
Object.freeze(tmpIndexByIndexName);
|
|
37
37
|
|
|
38
38
|
const _cache = new Map();
|
|
39
|
+
/**
|
|
40
|
+
* **tooling 専用**(`@wcstack/state/parser` の clearParserCaches からのみ呼ぶ)。
|
|
41
|
+
* ランタイム文脈で呼んではならない — PathInfo のインスタンス同一性は正規化キー
|
|
42
|
+
* (依存グラフ・アドレス比較)の前提であり、クリアすると同一パスの新旧インスタンスが
|
|
43
|
+
* 併存して identity 比較が黙って壊れる。言語サーバー等の長時間プロセスが、編集中の
|
|
44
|
+
* 中間パス(`user.n` 等)の恒久 intern によるメモリ単調増加を断つための出口。
|
|
45
|
+
*/
|
|
46
|
+
function clearPathInfoCacheForTooling() {
|
|
47
|
+
_cache.clear();
|
|
48
|
+
}
|
|
39
49
|
let id = 0;
|
|
40
50
|
function getPathInfo(path) {
|
|
41
51
|
let pathInfo = _cache.get(path);
|
|
@@ -138,22 +148,6 @@ class PathInfo {
|
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
function raiseError(message) {
|
|
142
|
-
throw new Error(`[@wcstack/state] ${message}`);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const STRUCTURAL_BINDING_TYPE_SET = new Set([
|
|
146
|
-
"if",
|
|
147
|
-
"elseif",
|
|
148
|
-
"else",
|
|
149
|
-
"for",
|
|
150
|
-
]);
|
|
151
|
-
|
|
152
|
-
const _config = {
|
|
153
|
-
locale: 'en'};
|
|
154
|
-
// backward compatible export (read-only usage)
|
|
155
|
-
const config = _config;
|
|
156
|
-
|
|
157
151
|
/**
|
|
158
152
|
* errorGuidance.ts — エラーメッセージへの self-fix 誘導(GTM 2-5 /
|
|
159
153
|
* docs/static-wiring-dx-design.md §3)。
|
|
@@ -217,12 +211,31 @@ function didYouMean(input, candidates) {
|
|
|
217
211
|
/**
|
|
218
212
|
* lint への誘導(誘導付きメッセージ共通の一文)。
|
|
219
213
|
* **lint が実際にそのケースを検出するサイトにだけ付ける** — 検出しないケースに
|
|
220
|
-
* 付けると「エラー → lint 実行 → clean
|
|
221
|
-
*
|
|
222
|
-
*
|
|
214
|
+
* 付けると「エラー → lint 実行 → clean」の空振りで検証ループの信頼を毀損する。
|
|
215
|
+
* 現在 lint 未検出のため付けないもの: DCC 宣言・watch の空キー / Object.prototype
|
|
216
|
+
* 継承名 / ワイルドカード深度超過。
|
|
217
|
+
* なお hint 付きサイト内でも被覆は部分的でありうる(例: `$watch: ident` の実体が
|
|
218
|
+
* 非オブジェクトだった場合、ランタイムは評価後の値で raise するが lint は宣言 shape
|
|
219
|
+
* から断定できず沈黙する)。サイト粒度の hint ではこの残余は構造的に避けられない。
|
|
223
220
|
*/
|
|
224
221
|
const LINT_HINT = " Validate statically: npx @wcstack/lint <file>.";
|
|
225
222
|
|
|
223
|
+
function raiseError(message) {
|
|
224
|
+
throw new Error(`[@wcstack/state] ${message}`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const STRUCTURAL_BINDING_TYPE_SET = new Set([
|
|
228
|
+
"if",
|
|
229
|
+
"elseif",
|
|
230
|
+
"else",
|
|
231
|
+
"for",
|
|
232
|
+
]);
|
|
233
|
+
|
|
234
|
+
const _config = {
|
|
235
|
+
locale: 'en'};
|
|
236
|
+
// backward compatible export (read-only usage)
|
|
237
|
+
const config = _config;
|
|
238
|
+
|
|
226
239
|
/**
|
|
227
240
|
* errorMessages.ts
|
|
228
241
|
*
|
|
@@ -1218,6 +1231,10 @@ function parseFilterArgs(argsText) {
|
|
|
1218
1231
|
}
|
|
1219
1232
|
|
|
1220
1233
|
const filterFnByKey = new Map();
|
|
1234
|
+
/** tooling 専用(parser.ts の clearParserCaches からのみ呼ぶ)。 */
|
|
1235
|
+
function clearFilterFnCacheForTooling() {
|
|
1236
|
+
filterFnByKey.clear();
|
|
1237
|
+
}
|
|
1221
1238
|
// format: filterName(arg1,arg2) or filterName
|
|
1222
1239
|
function parseFilters(filterTextList, filterIOType) {
|
|
1223
1240
|
const builtinFilters = builtinFiltersByFilterIOType[filterIOType];
|
|
@@ -1269,6 +1286,10 @@ function parseFilters(filterTextList, filterIOType) {
|
|
|
1269
1286
|
const trimFn = (s) => s.trim();
|
|
1270
1287
|
|
|
1271
1288
|
const cacheFilterInfos$1 = new Map();
|
|
1289
|
+
/** tooling 専用(parser.ts の clearParserCaches からのみ呼ぶ)。 */
|
|
1290
|
+
function clearPropPartCacheForTooling() {
|
|
1291
|
+
cacheFilterInfos$1.clear();
|
|
1292
|
+
}
|
|
1272
1293
|
// format: propName#moodifier1,modifier2
|
|
1273
1294
|
// propName-format: path.to.property (e.g., textContent, style.color, not include :)
|
|
1274
1295
|
// special path:
|
|
@@ -1311,6 +1332,10 @@ function parsePropPart(propPart) {
|
|
|
1311
1332
|
}
|
|
1312
1333
|
|
|
1313
1334
|
const cacheFilterInfos = new Map();
|
|
1335
|
+
/** tooling 専用(parser.ts の clearParserCaches からのみ呼ぶ)。 */
|
|
1336
|
+
function clearStatePartCacheForTooling() {
|
|
1337
|
+
cacheFilterInfos.clear();
|
|
1338
|
+
}
|
|
1314
1339
|
// format: statePath@stateName|filter|filter
|
|
1315
1340
|
// statePath-format: path.to.property (e.g., user.name.first, users.*.name, users.0.name, not include @)
|
|
1316
1341
|
// stateName: optional, default is 'default'
|
|
@@ -1441,12 +1466,67 @@ function parseBindTextsForElement(bindText) {
|
|
|
1441
1466
|
if (results.length > 1) {
|
|
1442
1467
|
const isIncludeSingleBinding = results.some(r => STRUCTURAL_BINDING_TYPE_SET.has(r.bindingType));
|
|
1443
1468
|
if (isIncludeSingleBinding) {
|
|
1444
|
-
//
|
|
1445
|
-
//
|
|
1446
|
-
raiseError(`[wcs/template-syntax] Invalid bindText: "${bindText}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">)
|
|
1469
|
+
// lint 側の単独バインディング検査(bindingValidator の structuralMustBeSingle)が
|
|
1470
|
+
// 同じケースを検出するため誘導を付ける(三面同語彙)。
|
|
1471
|
+
raiseError(`[wcs/template-syntax] Invalid bindText: "${bindText}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).${LINT_HINT}`);
|
|
1447
1472
|
}
|
|
1448
1473
|
}
|
|
1449
1474
|
return results;
|
|
1450
1475
|
}
|
|
1451
1476
|
|
|
1452
|
-
|
|
1477
|
+
function parseBindTextForEmbeddedNode(bindText) {
|
|
1478
|
+
const stateResult = parseStatePart(bindText);
|
|
1479
|
+
return {
|
|
1480
|
+
propName: 'textContent',
|
|
1481
|
+
propSegments: ['textContent'],
|
|
1482
|
+
propModifiers: [],
|
|
1483
|
+
inFilters: [],
|
|
1484
|
+
...stateResult,
|
|
1485
|
+
bindingType: 'text',
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* parser.ts — `data-wcs` バインディング構文の正本パーサを tooling 向けに公開する
|
|
1491
|
+
* サブパスエントリ(`@wcstack/state/parser`)。
|
|
1492
|
+
*
|
|
1493
|
+
* `./manifest` と同じ「実装が唯一の正本」パターン(docs/static-wiring-dx-design.md D2)。
|
|
1494
|
+
* vscode-wcs の正規表現パーサ・devtools の declaredScan 簡易パーサという複製実装を
|
|
1495
|
+
* 段階的にこの正本へ寄せるための土台。
|
|
1496
|
+
*
|
|
1497
|
+
* 契約:
|
|
1498
|
+
* - DOM 非依存・純関数(bindText 文字列 → ParseBindTextResult[])。Node でそのまま動く
|
|
1499
|
+
* (__tests__/parser.test.ts が node 環境で検証する)。
|
|
1500
|
+
* - **位置情報は持たず、不正構文は raiseError で throw する**。エラー耐性と診断 range の
|
|
1501
|
+
* 生成は消費側(vscode-wcs の positional ラッパー)の責務(同 D3)— ランタイムの
|
|
1502
|
+
* サイズと責務をここで増やさない。
|
|
1503
|
+
* - `getPathInfo` はパス文字列の解析済みビュー(セグメント・ワイルドカード位置・親パス
|
|
1504
|
+
* チェーン)を返す純関数。静的依存グラフの親チェーン展開はこの情報から機械的に再現できる。
|
|
1505
|
+
* 同一パス → 同一インスタンスの保証は**このエントリのモジュールインスタンス内**でのみ
|
|
1506
|
+
* 成立する(`.` エントリは別バンドル=別キャッシュ。ランタイムの PathInfo と identity
|
|
1507
|
+
* 比較してはならない)。キャッシュは無制限(evict なし)— 言語サーバー等の長時間
|
|
1508
|
+
* プロセスでは入力パス種数に単調比例してメモリが増える点に留意。
|
|
1509
|
+
* - `ParseBindTextResult.uuid` はランタイム内部(構造テンプレートのハイドレーション台帳)
|
|
1510
|
+
* 用のフィールドで、このパーサの戻り値では常に undefined。
|
|
1511
|
+
*
|
|
1512
|
+
* 公開面は意図的に最小(公開=恒久契約)。`expandSpread` は live Element と
|
|
1513
|
+
* CustomElementRegistry を要するためここには含めない — ブラウザ内の消費者
|
|
1514
|
+
* (devtools の declared 正本化)は state 自身が pull API で答える。
|
|
1515
|
+
*/
|
|
1516
|
+
/**
|
|
1517
|
+
* このエントリの内部キャッシュ(PathInfo intern・propPart/statePart のパース結果・フィルタ関数クロージャ)を全て捨てる。
|
|
1518
|
+
*
|
|
1519
|
+
* 言語サーバー等の**長時間プロセス専用**。編集中の中間パス(`user.n` 等)が
|
|
1520
|
+
* 無制限キャッシュに恒久 intern されてメモリが単調増加するため、ドキュメント
|
|
1521
|
+
* クローズ等の区切りで呼ぶ。クリア後の getPathInfo は同一パスに**新しい**
|
|
1522
|
+
* インスタンスを返す — 「同一パス → 同一参照」の保証はクリアを跨がない。
|
|
1523
|
+
* ランタイム(`.` エントリ)にはこの API は無く、呼ばれることもない。
|
|
1524
|
+
*/
|
|
1525
|
+
function clearParserCaches() {
|
|
1526
|
+
clearPathInfoCacheForTooling();
|
|
1527
|
+
clearPropPartCacheForTooling();
|
|
1528
|
+
clearStatePartCacheForTooling();
|
|
1529
|
+
clearFilterFnCacheForTooling();
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
export { clearParserCaches, getPathInfo, parseBindTextForEmbeddedNode, parseBindTextsForElement };
|
package/package.json
CHANGED