@wcstack/lint 3.2.0 → 3.3.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.
Files changed (2) hide show
  1. package/dist/cli.cjs +2271 -2012
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -163,7 +163,7 @@ var WcsDiagnosticCode = {
163
163
  // 依存する wcs/recursion-context は runtime 専用(静的側は出さない)。
164
164
  //
165
165
  // `**` を解釈しない場所へ `**` が渡った(data-wcs / mustache / $watch キー / $listKeys
166
- // キー / $resolve / $postUpdate / $trackDependency / 代入)、または `$recursion` 宣言が
166
+ // キー / $resolve / $postUpdate / $dependOn(旧名 $trackDependency) / 代入)、または `$recursion` 宣言が
167
167
  // 無いのに `**` を使った。runtime は PathInfo の不変条件として raiseError するか
168
168
  //(API 経由)、getter を黙って無視する(宣言なしの `**` getter)。
169
169
  RecursionUnsupported: "wcs/recursion-unsupported",
@@ -207,6 +207,19 @@ var WcsDiagnosticCode = {
207
207
  // 3.x の間だけ残る旧名(フィルタ `uc` → `upper`、`$trackDependency` → `$dependOn` …)を書いた(info)。
208
208
  // 動くが 4.0 で外れるので正式名を提案する(@wcstack/state 3.2・要件 B12 / 3.x 計画 D39)
209
209
  NameAlias: "wcs/name-alias",
210
+ // 旧名の宣言キーを `this.` 越しに**読んだ**(`this.$streams`)。宣言と違い旧名のままでは
211
+ // 3.x でも動かない — 正規化(@wcstack/state declarationAliases.ts)が正式名へ写したあと
212
+ // 旧名の自前プロパティを delete するので、読み出しは例外も出さずに undefined になる。
213
+ // `wcs/name-alias`(「動くが 4.0 で外れる」)とは別の事実なので code を分ける: 移行中に
214
+ // name-alias を抑制したチームが、この「今日すでに壊れている」まで一緒に消さないため。
215
+ // severity は検出経路で変わる — AST で断定できたら warning、読めない形(class 構文など)の
216
+ // 正規表現フォールバックは info(誤検出しうる経路を warning にしない)。
217
+ DeclarationAliasRead: "wcs/declaration-alias-read",
218
+ // 旧名と正式名の宣言キーを**両方**書いた(`$streams` と `$stream` 等)。どちらが効くのか
219
+ // 書き手に見えないので、ランタイム(@wcstack/state declarationAliases.ts)は正規化の時点で
220
+ // 名指しで raiseError する = ページ初期化ごと止まるので error。3.2 への移行中
221
+ //(新名を足して旧名を消し忘れる)にちょうど起きる形。
222
+ DeclarationAlias: "wcs/declaration-alias",
210
223
  // wcBindable 無宣言タグ(wcs-fetch-header 等のヘルパー)への spread。
211
224
  // ランタイム(expandSpread)は raiseError で落とす。
212
225
  SpreadNoBindable: "wcs/spread-no-bindable",
@@ -240,488 +253,1319 @@ function sortDiagnostics(diagnostics) {
240
253
  return [...diagnostics].sort((a, b) => a.start - b.start || severityRank[a.severity] - severityRank[b.severity] || (a.code < b.code ? -1 : a.code > b.code ? 1 : 0));
241
254
  }
242
255
 
243
- // ../state/dist/manifest.esm.js
244
- var _config = {
245
- bindAttributeName: "data-wcs",
246
- tagNames: {
247
- state: "wcs-state"
248
- },
249
- locale: "en"
250
- };
251
- var config = _config;
256
+ // ../state/dist/parser.esm.js
257
+ var DELIMITER = ".";
258
+ var WILDCARD = "*";
259
+ var MAX_WILDCARD_DEPTH = 128;
260
+ var MAX_PATH_SEGMENTS = 512;
261
+ var BINDING_SEPARATOR = ";";
262
+ var PROP_VALUE_SEPARATOR = ":";
263
+ var MODIFIER_SEPARATOR = "#";
264
+ var FILTER_SEPARATOR = "|";
265
+ var ELSE_KEYWORD = "else";
266
+ var SPREAD_PROP = "...";
267
+ var EVENT_PROP_PREFIX = "on";
268
+ var EVENT_TOKEN_NAMESPACE = "eventToken";
269
+ var VOLUME_INJECTION_PROP = "state";
270
+ var COMMAND_NAMESPACE = "command";
271
+ var CLASS_NAMESPACE = "class";
272
+ var ATTR_NAMESPACE = "attr";
273
+ var STYLE_NAMESPACE = "style";
274
+ var INDEX_PARAM_PREFIX = "$";
275
+ var tmpIndexByIndexName = {};
276
+ for (let i = 0; i < MAX_WILDCARD_DEPTH; i++) {
277
+ tmpIndexByIndexName[`${INDEX_PARAM_PREFIX}${i + 1}`] = i;
278
+ }
279
+ Object.freeze(tmpIndexByIndexName);
280
+ var RECURSION_WILDCARD = "**";
252
281
  function raiseError(message) {
253
282
  throw new Error(`[@wcstack/state] ${message}`);
254
283
  }
255
- function optionsRequired(fnName) {
256
- raiseError(`filter ${fnName} requires at least one option`);
257
- }
258
- function optionMustBeNumber(fnName) {
259
- raiseError(`filter ${fnName} requires a number as option`);
260
- }
261
- function valueMustBeNumber(fnName) {
262
- raiseError(`filter ${fnName} requires a number value`);
263
- }
264
- function valueMustBeBoolean(fnName) {
265
- raiseError(`filter ${fnName} requires a boolean value`);
266
- }
267
- function valueMustBeDate(fnName) {
268
- raiseError(`filter ${fnName} requires a date value`);
269
- }
270
- function valueMustBeArray(fnName) {
271
- raiseError(`filter ${fnName} requires an array value`);
272
- }
273
- var builtinFilterAliases = {
274
- inc: "add",
275
- dec: "sub",
276
- fix: "toFixed",
277
- uc: "upper",
278
- lc: "lower",
279
- cap: "capitalize",
280
- rep: "repeat",
281
- rev: "reverse",
282
- pad: "padStart",
283
- null: "nullIfEmpty"
284
- };
285
- function validateNumberString(value) {
286
- if (!value || isNaN(Number(value))) {
287
- return false;
288
- }
289
- return true;
284
+ var _cache = /* @__PURE__ */ new Map();
285
+ function clearPathInfoCacheForTooling() {
286
+ _cache.clear();
290
287
  }
291
- var eq = (options, literals) => {
292
- const opt = options?.[0] ?? optionsRequired("eq");
293
- const literal2 = literals !== void 0 && literals.length > 0 ? literals[0] : opt;
294
- return (value) => {
295
- if (typeof value === "number") {
296
- if (!validateNumberString(opt)) {
297
- optionMustBeNumber("eq");
298
- }
299
- return value === Number(opt);
300
- }
301
- if (typeof value === "string") {
302
- return value === opt;
303
- }
304
- return value === literal2;
305
- };
306
- };
307
- var ne = (options, literals) => {
308
- const opt = options?.[0] ?? optionsRequired("ne");
309
- const literal2 = literals !== void 0 && literals.length > 0 ? literals[0] : opt;
310
- return (value) => {
311
- if (typeof value === "number") {
312
- if (!validateNumberString(opt)) {
313
- optionMustBeNumber("ne");
314
- }
315
- return value !== Number(opt);
316
- }
317
- if (typeof value === "string") {
318
- return value !== opt;
319
- }
320
- return value !== literal2;
321
- };
322
- };
323
- var not = (_options) => {
324
- return (value) => {
325
- if (typeof value !== "boolean") {
326
- valueMustBeBoolean("not");
327
- }
328
- return !value;
329
- };
330
- };
331
- var lt = (options) => {
332
- const opt = options?.[0] ?? optionsRequired("lt");
333
- if (!validateNumberString(opt)) {
334
- optionMustBeNumber("lt");
335
- }
336
- return (value) => {
337
- if (typeof value !== "number") {
338
- valueMustBeNumber("lt");
339
- }
340
- return value < Number(opt);
341
- };
342
- };
343
- var le = (options) => {
344
- const opt = options?.[0] ?? optionsRequired("le");
345
- if (!validateNumberString(opt)) {
346
- optionMustBeNumber("le");
288
+ var id = 0;
289
+ function getPathInfo(path) {
290
+ let pathInfo = _cache.get(path);
291
+ if (typeof pathInfo !== "undefined") {
292
+ return pathInfo;
347
293
  }
348
- return (value) => {
349
- if (typeof value !== "number") {
350
- valueMustBeNumber("le");
351
- }
352
- return value <= Number(opt);
353
- };
354
- };
355
- var gt = (options) => {
356
- const opt = options?.[0] ?? optionsRequired("gt");
357
- if (!validateNumberString(opt)) {
358
- optionMustBeNumber("gt");
294
+ if (path.indexOf(RECURSION_WILDCARD) !== -1) {
295
+ raiseError(`[wcs/recursion-unsupported] "${path}" uses "${RECURSION_WILDCARD}", which is not accepted here. It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll \u2014 and only when the state declares a $recursion anchor.`);
359
296
  }
360
- return (value) => {
361
- if (typeof value !== "number") {
362
- valueMustBeNumber("gt");
363
- }
364
- return value > Number(opt);
365
- };
366
- };
367
- var ge = (options) => {
368
- const opt = options?.[0] ?? optionsRequired("ge");
369
- if (!validateNumberString(opt)) {
370
- optionMustBeNumber("ge");
297
+ const segmentCount = countSegments(path);
298
+ if (segmentCount > MAX_PATH_SEGMENTS) {
299
+ raiseError(`[wcs/binding-syntax] "${path}" has ${segmentCount} path segments \u2014 the limit is ${MAX_PATH_SEGMENTS}. Every prefix of a path is interned, so the cost grows with the square of the depth.`);
371
300
  }
372
- return (value) => {
373
- if (typeof value !== "number") {
374
- valueMustBeNumber("ge");
301
+ pathInfo = Object.freeze(new PathInfo(path));
302
+ _cache.set(path, pathInfo);
303
+ return pathInfo;
304
+ }
305
+ function countSegments(path) {
306
+ let count = 1;
307
+ for (let i = 0; i < path.length; i++) {
308
+ if (path[i] === DELIMITER) {
309
+ count++;
375
310
  }
376
- return value >= Number(opt);
377
- };
378
- };
379
- var inc = (options) => {
380
- const opt = options?.[0] ?? optionsRequired("add");
381
- if (!validateNumberString(opt)) {
382
- optionMustBeNumber("add");
383
311
  }
384
- return (value) => {
385
- if (typeof value !== "number") {
386
- valueMustBeNumber("add");
312
+ return count;
313
+ }
314
+ var PathInfo = class {
315
+ id = ++id;
316
+ path;
317
+ segments;
318
+ lastSegment;
319
+ cumulativePaths;
320
+ cumulativePathSet;
321
+ cumulativePathInfos;
322
+ cumulativePathInfoSet;
323
+ parentPath;
324
+ wildcardPaths;
325
+ wildcardPathSet;
326
+ indexByWildcardPath;
327
+ wildcardPathInfos;
328
+ wildcardPathInfoSet;
329
+ wildcardParentPaths;
330
+ wildcardParentPathSet;
331
+ wildcardParentPathInfos;
332
+ wildcardParentPathInfoSet;
333
+ wildcardPositions;
334
+ lastWildcardPath;
335
+ lastWildcardInfo;
336
+ wildcardCount;
337
+ parentPathInfo;
338
+ constructor(path) {
339
+ const getPattern = (_path) => {
340
+ return path === _path ? this : getPathInfo(_path);
341
+ };
342
+ const segments = path.split(".");
343
+ const cumulativePaths = [];
344
+ const cumulativePathInfos = [];
345
+ const wildcardPaths = [];
346
+ const indexByWildcardPath = {};
347
+ const wildcardPathInfos = [];
348
+ const wildcardParentPaths = [];
349
+ const wildcardParentPathInfos = [];
350
+ const wildcardPositions = [];
351
+ let currentPatternPath = "", prevPatternPath = "";
352
+ let wildcardCount = 0;
353
+ for (let i = 0; i < segments.length; i++) {
354
+ currentPatternPath += segments[i];
355
+ if (segments[i] === WILDCARD) {
356
+ wildcardPaths.push(currentPatternPath);
357
+ indexByWildcardPath[currentPatternPath] = wildcardCount;
358
+ wildcardPathInfos.push(getPattern(currentPatternPath));
359
+ wildcardParentPaths.push(prevPatternPath);
360
+ wildcardParentPathInfos.push(getPattern(prevPatternPath));
361
+ wildcardPositions.push(i);
362
+ wildcardCount++;
363
+ }
364
+ cumulativePaths.push(currentPatternPath);
365
+ cumulativePathInfos.push(getPattern(currentPatternPath));
366
+ prevPatternPath = currentPatternPath;
367
+ currentPatternPath += ".";
387
368
  }
388
- return value + Number(opt);
389
- };
390
- };
391
- var dec = (options) => {
392
- const opt = options?.[0] ?? optionsRequired("sub");
393
- if (!validateNumberString(opt)) {
394
- optionMustBeNumber("sub");
369
+ const lastWildcardPath = wildcardPaths.length > 0 ? wildcardPaths[wildcardPaths.length - 1] : null;
370
+ const parentPath = cumulativePaths.length > 1 ? cumulativePaths[cumulativePaths.length - 2] : null;
371
+ this.path = path;
372
+ this.segments = segments;
373
+ this.lastSegment = segments[segments.length - 1];
374
+ this.cumulativePaths = cumulativePaths;
375
+ this.cumulativePathSet = new Set(cumulativePaths);
376
+ this.cumulativePathInfos = cumulativePathInfos;
377
+ this.cumulativePathInfoSet = new Set(cumulativePathInfos);
378
+ this.wildcardPaths = wildcardPaths;
379
+ this.wildcardPathSet = new Set(wildcardPaths);
380
+ this.indexByWildcardPath = indexByWildcardPath;
381
+ this.wildcardPathInfos = wildcardPathInfos;
382
+ this.wildcardPathInfoSet = new Set(wildcardPathInfos);
383
+ this.wildcardParentPaths = wildcardParentPaths;
384
+ this.wildcardParentPathSet = new Set(wildcardParentPaths);
385
+ this.wildcardParentPathInfos = wildcardParentPathInfos;
386
+ this.wildcardParentPathInfoSet = new Set(wildcardParentPathInfos);
387
+ this.wildcardPositions = wildcardPositions;
388
+ this.lastWildcardPath = lastWildcardPath;
389
+ this.lastWildcardInfo = lastWildcardPath ? getPattern(lastWildcardPath) : null;
390
+ this.parentPath = parentPath;
391
+ this.parentPathInfo = parentPath ? getPattern(parentPath) : null;
392
+ this.wildcardCount = wildcardCount;
395
393
  }
396
- return (value) => {
397
- if (typeof value !== "number") {
398
- valueMustBeNumber("sub");
399
- }
400
- return value - Number(opt);
401
- };
402
394
  };
403
- var mul = (options) => {
404
- const opt = options?.[0] ?? optionsRequired("mul");
405
- if (!validateNumberString(opt)) {
406
- optionMustBeNumber("mul");
395
+ var LINT_HINT = " Validate statically: npx @wcstack/lint <file>.";
396
+ var STRUCTURAL_BINDING_TYPE_SET = /* @__PURE__ */ new Set([
397
+ "if",
398
+ "elseif",
399
+ "else",
400
+ "for"
401
+ ]);
402
+ var resolvedByKey = /* @__PURE__ */ new Map();
403
+ function clearFilterResolutionCache() {
404
+ resolvedByKey.clear();
405
+ }
406
+ function finalizeArg(text, firstQuoteStart, lastQuoteEnd) {
407
+ const startLimit = firstQuoteStart === -1 ? text.length : firstQuoteStart;
408
+ let start = 0;
409
+ while (start < startLimit && /\s/.test(text[start])) {
410
+ start++;
407
411
  }
408
- return (value) => {
409
- if (typeof value !== "number") {
410
- valueMustBeNumber("mul");
411
- }
412
- return value * Number(opt);
413
- };
414
- };
415
- var div = (options) => {
416
- const opt = options?.[0] ?? optionsRequired("div");
417
- if (!validateNumberString(opt)) {
418
- optionMustBeNumber("div");
412
+ const endLimit = lastQuoteEnd === -1 ? 0 : lastQuoteEnd;
413
+ let end = text.length;
414
+ while (end > endLimit && /\s/.test(text[end - 1])) {
415
+ end--;
419
416
  }
420
- return (value) => {
421
- if (typeof value !== "number") {
422
- valueMustBeNumber("div");
423
- }
424
- return value / Number(opt);
417
+ return text.slice(start, end);
418
+ }
419
+ var NUMBER_LITERAL = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
420
+ function toLiteral(text, quoted) {
421
+ if (quoted)
422
+ return text;
423
+ if (text === "true")
424
+ return true;
425
+ if (text === "false")
426
+ return false;
427
+ if (text === "null")
428
+ return null;
429
+ return NUMBER_LITERAL.test(text) ? Number(text) : text;
430
+ }
431
+ function parseFilterArgsWithLiterals(argsText) {
432
+ const args = [];
433
+ const literals = [];
434
+ let current2 = "";
435
+ let inQuote = null;
436
+ let hasQuote = false;
437
+ let firstQuoteStart = -1;
438
+ let lastQuoteEnd = -1;
439
+ const flush = () => {
440
+ const arg = finalizeArg(current2, firstQuoteStart, lastQuoteEnd);
441
+ args.push(arg);
442
+ literals.push(toLiteral(arg, hasQuote));
443
+ current2 = "";
444
+ hasQuote = false;
445
+ firstQuoteStart = -1;
446
+ lastQuoteEnd = -1;
425
447
  };
426
- };
427
- var mod = (options) => {
428
- const opt = options?.[0] ?? optionsRequired("mod");
429
- if (!validateNumberString(opt)) {
430
- optionMustBeNumber("mod");
431
- }
432
- return (value) => {
433
- if (typeof value !== "number") {
434
- valueMustBeNumber("mod");
448
+ for (let i = 0; i < argsText.length; i++) {
449
+ const char = argsText[i];
450
+ if (inQuote) {
451
+ if (char === inQuote) {
452
+ inQuote = null;
453
+ } else {
454
+ if (firstQuoteStart === -1) {
455
+ firstQuoteStart = current2.length;
456
+ }
457
+ current2 += char;
458
+ lastQuoteEnd = current2.length;
459
+ }
460
+ } else if (char === '"' || char === "'") {
461
+ inQuote = char;
462
+ hasQuote = true;
463
+ } else if (char === ",") {
464
+ flush();
465
+ } else {
466
+ current2 += char;
435
467
  }
436
- return value % Number(opt);
437
- };
438
- };
439
- var abs = (_options) => {
440
- return (value) => {
441
- if (typeof value !== "number") {
442
- valueMustBeNumber("abs");
468
+ }
469
+ if (inQuote !== null) {
470
+ raiseError(`[wcs/binding-syntax] unterminated ${inQuote} quote in the filter arguments "(${argsText})". Close the quote.${LINT_HINT}`);
471
+ }
472
+ const last = finalizeArg(current2, firstQuoteStart, lastQuoteEnd);
473
+ if (last || hasQuote) {
474
+ args.push(last);
475
+ literals.push(toLiteral(last, hasQuote));
476
+ }
477
+ return { args, literals };
478
+ }
479
+ var trimFn = (s) => s.trim();
480
+ var isQuote = (c) => c === "'" || c === '"';
481
+ function indexOfOutsideQuotes(text, char) {
482
+ let quote = null;
483
+ for (let i = 0; i < text.length; i++) {
484
+ const c = text[i];
485
+ if (quote !== null) {
486
+ if (c === quote)
487
+ quote = null;
488
+ } else if (isQuote(c)) {
489
+ quote = c;
490
+ } else if (c === char) {
491
+ return i;
443
492
  }
444
- return Math.abs(value);
445
- };
446
- };
447
- var clamp = (options) => {
448
- const opt1 = options?.[0] ?? optionsRequired("clamp");
449
- if (!validateNumberString(opt1)) {
450
- optionMustBeNumber("clamp");
451
493
  }
452
- const opt2 = options?.[1] ?? optionsRequired("clamp");
453
- if (!validateNumberString(opt2)) {
454
- optionMustBeNumber("clamp");
494
+ return -1;
495
+ }
496
+ function lastIndexOfOutsideQuotes(text, char) {
497
+ let quote = null;
498
+ let found = -1;
499
+ for (let i = 0; i < text.length; i++) {
500
+ const c = text[i];
501
+ if (quote !== null) {
502
+ if (c === quote)
503
+ quote = null;
504
+ } else if (isQuote(c)) {
505
+ quote = c;
506
+ } else if (c === char) {
507
+ found = i;
508
+ }
455
509
  }
456
- const min = Number(opt1);
457
- const max = Number(opt2);
458
- return (value) => {
459
- if (typeof value !== "number") {
460
- valueMustBeNumber("clamp");
510
+ return found;
511
+ }
512
+ function splitOutsideQuotes(text, separator) {
513
+ const parts = [];
514
+ let quote = null;
515
+ let start = 0;
516
+ for (let i = 0; i < text.length; i++) {
517
+ const c = text[i];
518
+ if (quote !== null) {
519
+ if (c === quote)
520
+ quote = null;
521
+ } else if (isQuote(c)) {
522
+ quote = c;
523
+ } else if (c === separator) {
524
+ parts.push(text.slice(start, i));
525
+ start = i + 1;
461
526
  }
462
- return Math.min(Math.max(value, min), max);
463
- };
464
- };
465
- var fix = (options) => {
466
- const opt = options?.[0] ?? "0";
467
- if (!validateNumberString(opt)) {
468
- optionMustBeNumber("toFixed");
469
527
  }
470
- return (value) => {
471
- if (typeof value !== "number") {
472
- valueMustBeNumber("toFixed");
528
+ parts.push(text.slice(start));
529
+ return parts;
530
+ }
531
+ function clearFilterFnCacheForTooling() {
532
+ clearFilterResolutionCache();
533
+ }
534
+ function parseFilters(filterTextList, filterIOType, sourceText) {
535
+ const source = sourceText ?? filterTextList.join("|");
536
+ return filterTextList.map((filterText) => {
537
+ const openParenIndex = indexOfOutsideQuotes(filterText, "(");
538
+ let closeParenIndex = lastIndexOfOutsideQuotes(filterText, ")");
539
+ if (closeParenIndex === -1) {
540
+ closeParenIndex = filterText.lastIndexOf(")");
473
541
  }
474
- return value.toFixed(Number(opt));
475
- };
476
- };
477
- var locale = (options) => {
478
- const explicit = options?.[0];
479
- return (value) => {
480
- if (typeof value !== "number") {
481
- valueMustBeNumber("locale");
542
+ if (openParenIndex !== -1 && closeParenIndex === -1) {
543
+ raiseError(`[wcs/binding-syntax] Invalid filter format: missing closing parenthesis in "${filterText}".${LINT_HINT}`);
482
544
  }
483
- return value.toLocaleString(explicit ?? config.locale);
484
- };
485
- };
486
- var uc = (_options) => {
487
- return (value) => {
488
- return String(value).toUpperCase();
489
- };
490
- };
491
- var lc = (_options) => {
492
- return (value) => {
493
- return String(value).toLowerCase();
494
- };
495
- };
496
- var cap = (_options) => {
497
- return (value) => {
498
- const v = String(value);
499
- if (v.length === 0) {
500
- return v;
545
+ if (closeParenIndex !== -1 && openParenIndex === -1) {
546
+ raiseError(`[wcs/binding-syntax] Invalid filter format: missing opening parenthesis in "${filterText}".${LINT_HINT}`);
501
547
  }
502
- if (v.length === 1) {
503
- return v.toUpperCase();
548
+ if (closeParenIndex !== -1 && closeParenIndex < openParenIndex) {
549
+ raiseError(`[wcs/binding-syntax] Invalid filter format: ")" comes before "(" in "${filterText}".${LINT_HINT}`);
504
550
  }
505
- return v.charAt(0).toUpperCase() + v.slice(1);
506
- };
507
- };
508
- var trim = (_options) => {
509
- return (value) => {
510
- return String(value).trim();
511
- };
512
- };
513
- var slice = (options) => {
514
- const numberedOpts = [];
515
- const opt1 = options?.[0] ?? optionsRequired("slice");
516
- if (!validateNumberString(opt1)) {
517
- optionMustBeNumber("slice");
518
- }
519
- numberedOpts.push(Number(opt1));
520
- const opt2 = options?.[1];
521
- if (typeof opt2 !== "undefined") {
522
- if (!validateNumberString(opt2)) {
523
- optionMustBeNumber("slice");
551
+ if (closeParenIndex !== -1 && filterText.slice(closeParenIndex + 1).trim().length > 0) {
552
+ const trailing = filterText.slice(closeParenIndex + 1).trim();
553
+ raiseError(`[wcs/binding-syntax] "${filterText}": unexpected "${trailing}" after the filter's closing ")" \u2014 separate filters with "|" (write "${filterText.slice(0, closeParenIndex + 1)}|${trailing}").${LINT_HINT}`);
554
+ }
555
+ const filterName = (openParenIndex === -1 ? filterText : filterText.substring(0, openParenIndex)).trim();
556
+ if (filterName.length === 0) {
557
+ raiseError(`[wcs/binding-syntax] an empty filter in "${source}" \u2014 remove the extra "|" or name the filter.${LINT_HINT}`);
558
+ }
559
+ if (filterName.includes(MODIFIER_SEPARATOR)) {
560
+ const [name, modifiers] = filterName.split(MODIFIER_SEPARATOR);
561
+ raiseError(filterIOType === "input" ? `[wcs/binding-syntax] "${filterName}" is not a filter name: a modifier list "${MODIFIER_SEPARATOR}${modifiers}" comes before the input filters, not inside one \u2014 write "<property>${MODIFIER_SEPARATOR}${modifiers}|${name}".${LINT_HINT}` : `[wcs/binding-syntax] "${filterName}" is not a filter name: "${MODIFIER_SEPARATOR}" cannot appear in one. Modifiers belong on the left side of the binding, before the ":" \u2014 write "${name}" here.${LINT_HINT}`);
562
+ }
563
+ if (openParenIndex === -1) {
564
+ return { filterName, args: [], literals: [] };
565
+ }
566
+ const argsText = filterText.substring(openParenIndex + 1, closeParenIndex);
567
+ return { filterName, ...parseFilterArgsWithLiterals(argsText) };
568
+ });
569
+ }
570
+ var cacheFilterInfos$1 = /* @__PURE__ */ new Map();
571
+ function clearPropPartCacheForTooling() {
572
+ cacheFilterInfos$1.clear();
573
+ }
574
+ function parsePropPart(propPart) {
575
+ const pos = indexOfOutsideQuotes(propPart, FILTER_SEPARATOR);
576
+ let propText = "";
577
+ let filterTexts = [];
578
+ let filtersText = "";
579
+ let filters = [];
580
+ if (pos !== -1) {
581
+ propText = propPart.slice(0, pos).trim();
582
+ filtersText = propPart.slice(pos + 1).trim();
583
+ if (cacheFilterInfos$1.has(filtersText)) {
584
+ filters = cacheFilterInfos$1.get(filtersText);
585
+ } else {
586
+ filterTexts = splitOutsideQuotes(filtersText, FILTER_SEPARATOR).map(trimFn);
587
+ filters = parseFilters(filterTexts, "input", propPart);
588
+ cacheFilterInfos$1.set(filtersText, filters);
524
589
  }
525
- numberedOpts.push(Number(opt2));
590
+ } else {
591
+ propText = propPart.trim();
526
592
  }
527
- return (value) => {
528
- return String(value).slice(...numberedOpts);
529
- };
530
- };
531
- var substr = (options) => {
532
- const opt1 = options?.[0] ?? optionsRequired("substr");
533
- if (!validateNumberString(opt1)) {
534
- optionMustBeNumber("substr");
593
+ const modifierParts = propText.split(MODIFIER_SEPARATOR).map(trimFn);
594
+ if (modifierParts.length > 2) {
595
+ raiseError(`[wcs/binding-syntax] "${propText}": a binding takes one modifier list after a single "${MODIFIER_SEPARATOR}" \u2014 write "${modifierParts[0]}${MODIFIER_SEPARATOR}${modifierParts.slice(1).join(",")}".${LINT_HINT}`);
535
596
  }
536
- const opt2 = options?.[1] ?? optionsRequired("substr");
537
- if (!validateNumberString(opt2)) {
538
- optionMustBeNumber("substr");
597
+ const [propName, propModifiersText] = modifierParts;
598
+ const propSegments = propName.split(DELIMITER).map(trimFn);
599
+ const isExplicitProperty = propSegments.length > 1 && propSegments[0] === "";
600
+ if (!isExplicitProperty && (propName.length === 0 || propSegments.some((segment) => segment.length === 0))) {
601
+ raiseError(`[wcs/binding-syntax] "${propPart}": the left side of a binding must name a property \u2014 write "<property>: <path>" (modifiers and input filters come after the name).${LINT_HINT}`);
539
602
  }
540
- return (value) => {
541
- return String(value).substr(Number(opt1), Number(opt2));
603
+ const propModifiers = propModifiersText ? propModifiersText.split(",").map(trimFn) : [];
604
+ return {
605
+ propName,
606
+ propSegments,
607
+ propModifiers,
608
+ inFilters: filters
542
609
  };
543
- };
544
- var pad = (options) => {
545
- const opt1 = options?.[0] ?? optionsRequired("padStart");
546
- if (!validateNumberString(opt1)) {
547
- optionMustBeNumber("padStart");
610
+ }
611
+ var cacheFilterInfos = /* @__PURE__ */ new Map();
612
+ function clearStatePartCacheForTooling() {
613
+ cacheFilterInfos.clear();
614
+ }
615
+ function parseStatePart(statePart) {
616
+ const pos = indexOfOutsideQuotes(statePart, FILTER_SEPARATOR);
617
+ let stateAndPath = "";
618
+ let filterTexts = [];
619
+ let filtersText = "";
620
+ let filters = [];
621
+ if (pos !== -1) {
622
+ stateAndPath = statePart.slice(0, pos).trim();
623
+ filtersText = statePart.slice(pos + 1).trim();
624
+ if (cacheFilterInfos.has(filtersText)) {
625
+ filters = cacheFilterInfos.get(filtersText);
626
+ } else {
627
+ filterTexts = splitOutsideQuotes(filtersText, FILTER_SEPARATOR).map(trimFn);
628
+ filters = parseFilters(filterTexts, "output", statePart);
629
+ cacheFilterInfos.set(filtersText, filters);
630
+ }
631
+ } else {
632
+ stateAndPath = statePart.trim();
548
633
  }
549
- const opt2 = options?.[1] ?? "0";
550
- return (value) => {
551
- return String(value).padStart(Number(opt1), opt2);
552
- };
553
- };
554
- var padEnd = (options) => {
555
- const opt1 = options?.[0] ?? optionsRequired("padEnd");
556
- if (!validateNumberString(opt1)) {
557
- optionMustBeNumber("padEnd");
634
+ if (stateAndPath.indexOf("@") !== -1) {
635
+ raiseError(`"${stateAndPath}": the "@name" selector was removed in v2 \u2014 there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`);
558
636
  }
559
- const opt2 = options?.[1] ?? " ";
560
- return (value) => {
561
- return String(value).padEnd(Number(opt1), opt2);
562
- };
563
- };
564
- var rep = (options) => {
565
- const opt = options?.[0] ?? optionsRequired("repeat");
566
- if (!validateNumberString(opt)) {
567
- optionMustBeNumber("repeat");
637
+ const statePathName = stateAndPath;
638
+ const isLoopRelative = statePathName.startsWith(DELIMITER);
639
+ const body = isLoopRelative ? statePathName.slice(DELIMITER.length) : statePathName;
640
+ const hasEmptySegment = body.length > 0 && body.split(DELIMITER).some((segment) => segment.length === 0);
641
+ if (hasEmptySegment || !isLoopRelative && body.length === 0) {
642
+ raiseError(`[wcs/binding-syntax] "${statePart}": the right side of a binding must name a state path \u2014 write "<property>: <path>" (a path segment cannot be empty; "." alone and a leading "." are the loop-relative shorthand).${LINT_HINT}`);
568
643
  }
569
- return (value) => {
570
- return String(value).repeat(Number(opt));
571
- };
572
- };
573
- var rev = (_options) => {
574
- return (value) => {
575
- return String(value).split("").reverse().join("");
576
- };
577
- };
578
- var int = (_options) => {
579
- return (value) => {
580
- return parseInt(String(value), 10);
581
- };
582
- };
583
- var float = (_options) => {
584
- return (value) => {
585
- return parseFloat(String(value));
586
- };
587
- };
588
- var round = (options) => {
589
- const opt = options?.[0] ?? "0";
590
- if (!validateNumberString(opt)) {
591
- optionMustBeNumber("round");
592
- }
593
- return (value) => {
594
- if (typeof value !== "number") {
595
- valueMustBeNumber("round");
596
- }
597
- const optValue = Math.pow(10, Number(opt));
598
- return Math.round(value * optValue) / optValue;
644
+ const pathInfo = getPathInfo(statePathName);
645
+ return {
646
+ statePathName,
647
+ statePathInfo: pathInfo,
648
+ outFilters: filters
599
649
  };
600
- };
601
- var floor = (options) => {
602
- const opt = options?.[0] ?? "0";
603
- if (!validateNumberString(opt)) {
604
- optionMustBeNumber("floor");
605
- }
606
- return (value) => {
607
- if (typeof value !== "number") {
608
- valueMustBeNumber("floor");
650
+ }
651
+ var KEYWORDS_WITHOUT_MODIFIERS = /* @__PURE__ */ new Set([ELSE_KEYWORD, "if", "elseif", "for", SPREAD_PROP]);
652
+ var EXPLICIT_PROPERTY_REJECTED_HEADS = /* @__PURE__ */ new Set([
653
+ CLASS_NAMESPACE,
654
+ ATTR_NAMESPACE,
655
+ STYLE_NAMESPACE,
656
+ COMMAND_NAMESPACE,
657
+ EVENT_TOKEN_NAMESPACE,
658
+ VOLUME_INJECTION_PROP
659
+ ]);
660
+ function splitBindTexts(bindText) {
661
+ return splitOutsideQuotes(bindText, BINDING_SEPARATOR);
662
+ }
663
+ function parseBindTextsForElement(bindText) {
664
+ const [...bindTexts] = splitBindTexts(bindText).map(trimFn).filter((s) => s.length > 0);
665
+ const results = bindTexts.map((bindText2) => {
666
+ const separatorIndex = indexOfOutsideQuotes(bindText2, PROP_VALUE_SEPARATOR);
667
+ if (separatorIndex === -1) {
668
+ raiseError(`[wcs/binding-syntax] Invalid bindText: "${bindText2}". Missing ':' separator between propPart and statePart.${LINT_HINT}`);
609
669
  }
610
- const optValue = Math.pow(10, Number(opt));
611
- return Math.floor(value * optValue) / optValue;
612
- };
613
- };
614
- var ceil = (options) => {
615
- const opt = options?.[0] ?? "0";
616
- if (!validateNumberString(opt)) {
617
- optionMustBeNumber("ceil");
618
- }
619
- return (value) => {
620
- if (typeof value !== "number") {
621
- valueMustBeNumber("ceil");
670
+ const propPart = bindText2.slice(0, separatorIndex).trim();
671
+ const statePart = bindText2.slice(separatorIndex + 1).trim();
672
+ const keyword = propPart.split(MODIFIER_SEPARATOR)[0].split(FILTER_SEPARATOR)[0].trim();
673
+ if (keyword !== propPart && KEYWORDS_WITHOUT_MODIFIERS.has(keyword)) {
674
+ raiseError(`[wcs/binding-syntax] "${bindText2}": "${keyword}" takes no modifiers or filters on its left side \u2014 write "${keyword}:".${LINT_HINT}`);
622
675
  }
623
- const optValue = Math.pow(10, Number(opt));
624
- return Math.ceil(value * optValue) / optValue;
625
- };
626
- };
627
- var percent = (options) => {
628
- const opt = options?.[0] ?? "0";
629
- if (!validateNumberString(opt)) {
630
- optionMustBeNumber("percent");
631
- }
632
- return (value) => {
633
- if (typeof value !== "number") {
634
- valueMustBeNumber("percent");
676
+ if (propPart === ELSE_KEYWORD) {
677
+ if (statePart.length > 0) {
678
+ raiseError(`[wcs/binding-syntax] "${bindText2}": "else" takes no value \u2014 write "else:".${LINT_HINT}`);
679
+ }
680
+ const pathInfo = getPathInfo("#else");
681
+ return {
682
+ propName: ELSE_KEYWORD,
683
+ propSegments: [ELSE_KEYWORD],
684
+ propModifiers: [],
685
+ statePathName: "#else",
686
+ statePathInfo: pathInfo,
687
+ inFilters: [],
688
+ outFilters: [],
689
+ bindingType: "else"
690
+ };
691
+ } else if (propPart === SPREAD_PROP) {
692
+ if (statePart.length === 0) {
693
+ raiseError(`[wcs/binding-syntax] Invalid spread binding "${bindText2}": spread target path is required.${LINT_HINT}`);
694
+ }
695
+ const stateResult = parseStatePart(statePart);
696
+ if (stateResult.outFilters.length > 0) {
697
+ raiseError(`[wcs/binding-syntax] Invalid spread binding "${bindText2}": filters are not allowed on spread targets.${LINT_HINT}`);
698
+ }
699
+ return {
700
+ propName: SPREAD_PROP,
701
+ propSegments: [SPREAD_PROP],
702
+ propModifiers: [],
703
+ inFilters: [],
704
+ ...stateResult,
705
+ bindingType: "spread"
706
+ };
707
+ } else if (propPart === "if" || propPart === "elseif" || propPart === "for") {
708
+ const stateResult = parseStatePart(statePart);
709
+ return {
710
+ propName: propPart,
711
+ propSegments: [propPart],
712
+ propModifiers: [],
713
+ inFilters: [],
714
+ ...stateResult,
715
+ bindingType: propPart
716
+ };
717
+ } else if (keyword === "radio" || keyword === "checkbox") {
718
+ const stateResult = parseStatePart(statePart);
719
+ const propResult = parsePropPart(propPart);
720
+ return {
721
+ ...propResult,
722
+ ...stateResult,
723
+ bindingType: keyword
724
+ };
725
+ } else {
726
+ const stateResult = parseStatePart(statePart);
727
+ const propResult = parsePropPart(propPart);
728
+ if (propResult.propSegments[0] === "" && propResult.propSegments.length > 1) {
729
+ const propSegments = propResult.propSegments.slice(1);
730
+ if (propSegments.includes("") || EXPLICIT_PROPERTY_REJECTED_HEADS.has(propSegments[0])) {
731
+ raiseError(`[wcs/binding-syntax] "${propPart}": a leading "." binds an element property by name \u2014 write a non-empty property that is not a namespace (${[...EXPLICIT_PROPERTY_REJECTED_HEADS].join(", ")}).${LINT_HINT}`);
732
+ }
733
+ return {
734
+ ...propResult,
735
+ propName: propSegments.join(DELIMITER),
736
+ propSegments,
737
+ ...stateResult,
738
+ bindingType: "prop"
739
+ };
740
+ }
741
+ if (propResult.propSegments[0] === EVENT_TOKEN_NAMESPACE) {
742
+ return {
743
+ ...propResult,
744
+ ...stateResult,
745
+ bindingType: "event"
746
+ };
747
+ }
748
+ if (propResult.propSegments[0].startsWith(EVENT_PROP_PREFIX)) {
749
+ return {
750
+ ...propResult,
751
+ ...stateResult,
752
+ bindingType: "event"
753
+ };
754
+ } else {
755
+ return {
756
+ ...propResult,
757
+ ...stateResult,
758
+ bindingType: "prop"
759
+ };
760
+ }
635
761
  }
636
- return `${(value * 100).toFixed(Number(opt))}%`;
637
- };
638
- };
639
- var unit = (options) => {
640
- const opt = options?.[0] ?? optionsRequired("unit");
641
- return (value) => {
642
- if (value === null || typeof value === "undefined") {
643
- return value;
762
+ });
763
+ if (results.length > 1) {
764
+ const isIncludeSingleBinding = results.some((r) => STRUCTURAL_BINDING_TYPE_SET.has(r.bindingType));
765
+ if (isIncludeSingleBinding) {
766
+ 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}`);
644
767
  }
645
- return String(value) + opt;
768
+ }
769
+ return results;
770
+ }
771
+ function parseBindTextForEmbeddedNode(bindText) {
772
+ const stateResult = parseStatePart(bindText);
773
+ return {
774
+ propName: "textContent",
775
+ propSegments: ["textContent"],
776
+ propModifiers: [],
777
+ inFilters: [],
778
+ ...stateResult,
779
+ bindingType: "text"
646
780
  };
647
- };
648
- var join = (options) => {
649
- const opt = options?.[0] ?? ", ";
650
- return (value) => {
651
- if (!Array.isArray(value)) {
652
- valueMustBeArray("join");
781
+ }
782
+ function clearParserCaches() {
783
+ clearPathInfoCacheForTooling();
784
+ clearPropPartCacheForTooling();
785
+ clearStatePartCacheForTooling();
786
+ clearFilterFnCacheForTooling();
787
+ }
788
+
789
+ // src/language/htmlParse.ts
790
+ function findStartTagRegions(html) {
791
+ const out = [];
792
+ let i = 0;
793
+ while (i < html.length) {
794
+ const lt2 = html.indexOf("<", i);
795
+ if (lt2 === -1) break;
796
+ const next = html[lt2 + 1];
797
+ if (html.startsWith("<!--", lt2)) {
798
+ const close = html.indexOf("-->", lt2 + 4);
799
+ i = close === -1 ? html.length : close + 3;
800
+ continue;
653
801
  }
654
- return value.join(opt);
655
- };
656
- };
657
- var truncate = (options) => {
658
- const opt1 = options?.[0] ?? optionsRequired("truncate");
659
- if (!validateNumberString(opt1)) {
660
- optionMustBeNumber("truncate");
661
- }
662
- const maxLength = Number(opt1);
663
- const suffix = options?.[1] ?? "\u2026";
664
- return (value) => {
665
- const v = String(value);
666
- if (v.length <= maxLength) {
667
- return v;
802
+ if (next === "!" || next === "?" || next === "/") {
803
+ const close = html.indexOf(">", lt2 + 1);
804
+ i = close === -1 ? html.length : close + 1;
805
+ continue;
668
806
  }
669
- return v.slice(0, maxLength) + suffix;
670
- };
671
- };
672
- var date = (options) => {
673
- const explicit = options?.[0];
674
- return (value) => {
675
- if (!(value instanceof Date)) {
676
- valueMustBeDate("date");
807
+ if (next === void 0 || !/[A-Za-z]/.test(next)) {
808
+ i = lt2 + 1;
809
+ continue;
677
810
  }
678
- return value.toLocaleDateString(explicit ?? config.locale);
679
- };
680
- };
681
- var time = (options) => {
682
- const explicit = options?.[0];
683
- return (value) => {
684
- if (!(value instanceof Date)) {
685
- valueMustBeDate("time");
811
+ let n = lt2 + 1;
812
+ while (n < html.length && /[^\s/>]/.test(html[n])) n++;
813
+ const tagName = html.slice(lt2 + 1, n).toLowerCase();
814
+ let j = n;
815
+ let quote = null;
816
+ while (j < html.length) {
817
+ const c = html[j];
818
+ if (quote !== null) {
819
+ if (c === quote) quote = null;
820
+ } else if (c === '"' || c === "'") {
821
+ quote = c;
822
+ } else if (c === ">") {
823
+ break;
824
+ }
825
+ j++;
686
826
  }
687
- return value.toLocaleTimeString(explicit ?? config.locale);
688
- };
689
- };
690
- var datetime = (options) => {
691
- const explicit = options?.[0];
692
- return (value) => {
693
- if (!(value instanceof Date)) {
694
- valueMustBeDate("datetime");
827
+ const gt2 = j < html.length ? j : html.length;
828
+ const selfClosing = html[gt2 - 1] === "/";
829
+ out.push({ tagName, start: n, end: selfClosing ? gt2 - 1 : gt2 });
830
+ i = gt2 + 1;
831
+ if (tagName === "script" || tagName === "style") {
832
+ const close = html.toLowerCase().indexOf(`</${tagName}`, i);
833
+ i = close === -1 ? html.length : close;
695
834
  }
696
- return value.toLocaleString(explicit ?? config.locale);
697
- };
698
- };
699
- var ymd = (options) => {
700
- const opt = options?.[0] ?? "-";
701
- return (value) => {
702
- if (!(value instanceof Date)) {
703
- valueMustBeDate("ymd");
835
+ }
836
+ return out;
837
+ }
838
+ function parseWcsScriptBlocks(html, stateTagName = "wcs-state") {
839
+ const blocks = [];
840
+ let pos = 0;
841
+ const len = html.length;
842
+ while (pos < len) {
843
+ if (html.startsWith("<!--", pos)) {
844
+ const commentEnd = html.indexOf("-->", pos + 4);
845
+ if (commentEnd === -1) break;
846
+ pos = commentEnd + 3;
847
+ continue;
704
848
  }
705
- const year = value.getFullYear().toString();
706
- const month = (value.getMonth() + 1).toString().padStart(2, "0");
707
- const day = value.getDate().toString().padStart(2, "0");
708
- return `${year}${opt}${month}${opt}${day}`;
709
- };
710
- };
711
- var hms = (options) => {
712
- const opt = options?.[0] ?? ":";
713
- return (value) => {
714
- if (!(value instanceof Date)) {
715
- valueMustBeDate("hms");
849
+ const wcsMatch = matchOpenTag(html, pos, stateTagName);
850
+ if (wcsMatch === null) {
851
+ pos++;
852
+ continue;
716
853
  }
717
- const hours = value.getHours().toString().padStart(2, "0");
718
- const minutes = value.getMinutes().toString().padStart(2, "0");
719
- const seconds = value.getSeconds().toString().padStart(2, "0");
720
- return `${hours}${opt}${minutes}${opt}${seconds}`;
721
- };
722
- };
723
- var falsy = (_options) => {
724
- return (value) => !value;
854
+ const mountPath = extractAttribute(wcsMatch.tagContent, "mount");
855
+ pos = wcsMatch.end;
856
+ const wcsCloseIdx = findCloseTag(html, pos, stateTagName);
857
+ const wcsEnd = wcsCloseIdx === -1 ? len : wcsCloseIdx;
858
+ while (pos < wcsEnd) {
859
+ if (html.startsWith("<!--", pos)) {
860
+ const commentEnd = html.indexOf("-->", pos + 4);
861
+ if (commentEnd === -1) break;
862
+ pos = commentEnd + 3;
863
+ continue;
864
+ }
865
+ const scriptMatch = matchOpenTag(html, pos, "script");
866
+ if (scriptMatch === null) {
867
+ pos++;
868
+ continue;
869
+ }
870
+ const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
871
+ if (typeAttr?.toLowerCase() !== "module") {
872
+ pos = scriptMatch.end;
873
+ continue;
874
+ }
875
+ const contentStart = scriptMatch.end;
876
+ const scriptCloseIdx = findCloseTag(html, contentStart, "script");
877
+ if (scriptCloseIdx === -1) {
878
+ pos = contentStart;
879
+ break;
880
+ }
881
+ const contentEnd = scriptCloseIdx;
882
+ blocks.push({
883
+ contentStart,
884
+ contentEnd,
885
+ content: html.slice(contentStart, contentEnd),
886
+ mountPath
887
+ });
888
+ pos = html.indexOf(">", scriptCloseIdx) + 1;
889
+ if (pos === 0) break;
890
+ }
891
+ pos = wcsEnd;
892
+ if (wcsCloseIdx !== -1) {
893
+ const closeEnd = html.indexOf(">", wcsCloseIdx);
894
+ if (closeEnd !== -1) pos = closeEnd + 1;
895
+ }
896
+ }
897
+ return blocks;
898
+ }
899
+ function parseWcsStateElements(html, stateTagName = "wcs-state") {
900
+ const elements = [];
901
+ let pos = 0;
902
+ const len = html.length;
903
+ while (pos < len) {
904
+ if (html.startsWith("<!--", pos)) {
905
+ const commentEnd = html.indexOf("-->", pos + 4);
906
+ if (commentEnd === -1) break;
907
+ pos = commentEnd + 3;
908
+ continue;
909
+ }
910
+ const wcsMatch = matchOpenTag(html, pos, stateTagName);
911
+ if (wcsMatch === null) {
912
+ pos++;
913
+ continue;
914
+ }
915
+ const mountPath = extractAttribute(wcsMatch.tagContent, "mount");
916
+ const bindComponent = parseAttributeNames(wcsMatch.tagContent).has("bind-component");
917
+ const jsonAttr = extractAttribute(wcsMatch.tagContent, "json") ?? void 0;
918
+ const stateAttr = extractAttribute(wcsMatch.tagContent, "state") ?? void 0;
919
+ const srcAttr = extractAttribute(wcsMatch.tagContent, "src") ?? void 0;
920
+ const tagStart = pos;
921
+ const tagEnd = wcsMatch.end;
922
+ pos = wcsMatch.end;
923
+ const scriptBlocks = [];
924
+ const wcsCloseIdx = findCloseTag(html, pos, stateTagName);
925
+ const wcsEnd = wcsCloseIdx === -1 ? len : wcsCloseIdx;
926
+ while (pos < wcsEnd) {
927
+ if (html.startsWith("<!--", pos)) {
928
+ const commentEnd = html.indexOf("-->", pos + 4);
929
+ if (commentEnd === -1) break;
930
+ pos = commentEnd + 3;
931
+ continue;
932
+ }
933
+ const scriptMatch = matchOpenTag(html, pos, "script");
934
+ if (scriptMatch === null) {
935
+ pos++;
936
+ continue;
937
+ }
938
+ const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
939
+ if (typeAttr?.toLowerCase() !== "module") {
940
+ pos = scriptMatch.end;
941
+ continue;
942
+ }
943
+ const contentStart = scriptMatch.end;
944
+ const scriptCloseIdx = findCloseTag(html, contentStart, "script");
945
+ if (scriptCloseIdx === -1) {
946
+ pos = contentStart;
947
+ break;
948
+ }
949
+ scriptBlocks.push({
950
+ contentStart,
951
+ contentEnd: scriptCloseIdx,
952
+ content: html.slice(contentStart, scriptCloseIdx),
953
+ mountPath
954
+ });
955
+ pos = html.indexOf(">", scriptCloseIdx) + 1;
956
+ if (pos === 0) break;
957
+ }
958
+ elements.push({ mountPath, bindComponent, jsonAttr, stateAttr, srcAttr, scriptBlocks, tagStart, tagEnd });
959
+ pos = wcsEnd;
960
+ if (wcsCloseIdx !== -1) {
961
+ const closeEnd = html.indexOf(">", wcsCloseIdx);
962
+ if (closeEnd !== -1) pos = closeEnd + 1;
963
+ }
964
+ }
965
+ return elements;
966
+ }
967
+ function findScriptJsonById(html, id2) {
968
+ let pos = 0;
969
+ const len = html.length;
970
+ while (pos < len) {
971
+ if (html.startsWith("<!--", pos)) {
972
+ const commentEnd = html.indexOf("-->", pos + 4);
973
+ if (commentEnd === -1) break;
974
+ pos = commentEnd + 3;
975
+ continue;
976
+ }
977
+ const scriptMatch = matchOpenTag(html, pos, "script");
978
+ if (scriptMatch === null) {
979
+ pos++;
980
+ continue;
981
+ }
982
+ const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
983
+ const idAttr = extractAttribute(scriptMatch.tagContent, "id");
984
+ if (typeAttr?.toLowerCase() === "application/json" && idAttr === id2) {
985
+ const contentStart = scriptMatch.end;
986
+ const scriptCloseIdx = findCloseTag(html, contentStart, "script");
987
+ if (scriptCloseIdx === -1) return null;
988
+ return html.slice(contentStart, scriptCloseIdx);
989
+ }
990
+ pos = scriptMatch.end;
991
+ }
992
+ return null;
993
+ }
994
+ function matchOpenTag(html, pos, tagName) {
995
+ if (html[pos] !== "<") return null;
996
+ const nameStart = pos + 1;
997
+ const nameEnd = nameStart + tagName.length;
998
+ if (nameEnd > html.length) return null;
999
+ const slice2 = html.slice(nameStart, nameEnd);
1000
+ if (slice2.toLowerCase() !== tagName.toLowerCase()) return null;
1001
+ const charAfter = html[nameEnd];
1002
+ if (charAfter !== ">" && charAfter !== " " && charAfter !== " " && charAfter !== "\n" && charAfter !== "\r" && charAfter !== "/") {
1003
+ return null;
1004
+ }
1005
+ let i = nameEnd;
1006
+ let inSingleQuote = false;
1007
+ let inDoubleQuote = false;
1008
+ while (i < html.length) {
1009
+ const ch = html[i];
1010
+ if (inSingleQuote) {
1011
+ if (ch === "'") inSingleQuote = false;
1012
+ } else if (inDoubleQuote) {
1013
+ if (ch === '"') inDoubleQuote = false;
1014
+ } else if (ch === "'") {
1015
+ inSingleQuote = true;
1016
+ } else if (ch === '"') {
1017
+ inDoubleQuote = true;
1018
+ } else if (ch === ">") {
1019
+ return {
1020
+ start: pos,
1021
+ end: i + 1,
1022
+ tagContent: html.slice(nameEnd, i)
1023
+ };
1024
+ }
1025
+ i++;
1026
+ }
1027
+ return null;
1028
+ }
1029
+ function findCloseTag(html, startPos, tagName) {
1030
+ const pattern = "</" + tagName;
1031
+ const patternLower = pattern.toLowerCase();
1032
+ const htmlLower = html.toLowerCase();
1033
+ let pos = startPos;
1034
+ while (pos < html.length) {
1035
+ const idx = htmlLower.indexOf(patternLower, pos);
1036
+ if (idx === -1) return -1;
1037
+ const afterIdx = idx + pattern.length;
1038
+ if (afterIdx < html.length) {
1039
+ const ch = html[afterIdx];
1040
+ if (ch === ">" || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
1041
+ return idx;
1042
+ }
1043
+ }
1044
+ pos = idx + 1;
1045
+ }
1046
+ return -1;
1047
+ }
1048
+ function parseAttributeNames(tagContent) {
1049
+ const names = /* @__PURE__ */ new Set();
1050
+ const attribute = /([^\s"'<>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'<>`=]+))?/g;
1051
+ let match;
1052
+ while ((match = attribute.exec(tagContent)) !== null) {
1053
+ names.add(match[1].toLowerCase());
1054
+ }
1055
+ return names;
1056
+ }
1057
+ function extractAttribute(tagContent, attrName) {
1058
+ const regex = new RegExp(
1059
+ `(?:^|\\s)${attrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|(\\S+))`,
1060
+ "i"
1061
+ );
1062
+ const match = tagContent.match(regex);
1063
+ if (!match) return null;
1064
+ return match[1] ?? match[2] ?? match[3] ?? null;
1065
+ }
1066
+
1067
+ // src/core/parser/quoteAware.ts
1068
+ var isQuote2 = (c) => c === "'" || c === '"';
1069
+ function indexOfOutsideQuotes2(text, char) {
1070
+ let quote = null;
1071
+ for (let i = 0; i < text.length; i++) {
1072
+ const c = text[i];
1073
+ if (quote !== null) {
1074
+ if (c === quote) quote = null;
1075
+ } else if (isQuote2(c)) {
1076
+ quote = c;
1077
+ } else if (c === char) {
1078
+ return i;
1079
+ }
1080
+ }
1081
+ return -1;
1082
+ }
1083
+ function splitOutsideQuotes2(text, separator) {
1084
+ const parts = [];
1085
+ let quote = null;
1086
+ let start = 0;
1087
+ for (let i = 0; i < text.length; i++) {
1088
+ const c = text[i];
1089
+ if (quote !== null) {
1090
+ if (c === quote) quote = null;
1091
+ } else if (isQuote2(c)) {
1092
+ quote = c;
1093
+ } else if (c === separator) {
1094
+ parts.push(text.slice(start, i));
1095
+ start = i + 1;
1096
+ }
1097
+ }
1098
+ parts.push(text.slice(start));
1099
+ return parts;
1100
+ }
1101
+
1102
+ // ../state/dist/manifest.esm.js
1103
+ var _config = {
1104
+ bindAttributeName: "data-wcs",
1105
+ tagNames: {
1106
+ state: "wcs-state"
1107
+ },
1108
+ locale: "en"
1109
+ };
1110
+ var config = _config;
1111
+ var DELIMITER2 = ".";
1112
+ var WILDCARD2 = "*";
1113
+ var MAX_WILDCARD_DEPTH2 = 128;
1114
+ var BINDING_SEPARATOR2 = ";";
1115
+ var PROP_VALUE_SEPARATOR2 = ":";
1116
+ var MODIFIER_SEPARATOR2 = "#";
1117
+ var FILTER_SEPARATOR2 = "|";
1118
+ var MODIFIER_PREVENT = "prevent";
1119
+ var MODIFIER_STOP = "stop";
1120
+ var MODIFIER_READONLY = "ro";
1121
+ var MODIFIER_FLAGS = Object.freeze([
1122
+ MODIFIER_PREVENT,
1123
+ MODIFIER_STOP,
1124
+ MODIFIER_READONLY
1125
+ ]);
1126
+ var MODIFIER_KEY_INIT = "init";
1127
+ var MODIFIER_KEY_SYNC = "sync";
1128
+ var MODIFIER_KEYS = Object.freeze([
1129
+ MODIFIER_KEY_INIT,
1130
+ MODIFIER_KEY_SYNC
1131
+ ]);
1132
+ var ELSE_KEYWORD2 = "else";
1133
+ var SPREAD_PROP2 = "...";
1134
+ var EVENT_PROP_PREFIX2 = "on";
1135
+ var EVENT_TOKEN_NAMESPACE2 = "eventToken";
1136
+ var COMMAND_NAMESPACE2 = "command";
1137
+ var CLASS_NAMESPACE2 = "class";
1138
+ var ATTR_NAMESPACE2 = "attr";
1139
+ var STYLE_NAMESPACE2 = "style";
1140
+ var INDEX_PARAM_PREFIX2 = "$";
1141
+ var tmpIndexByIndexName2 = {};
1142
+ for (let i = 0; i < MAX_WILDCARD_DEPTH2; i++) {
1143
+ tmpIndexByIndexName2[`${INDEX_PARAM_PREFIX2}${i + 1}`] = i;
1144
+ }
1145
+ Object.freeze(tmpIndexByIndexName2);
1146
+ var STATE_CONNECTED_CALLBACK_NAME = "$connectedCallback";
1147
+ var STATE_DISCONNECTED_CALLBACK_NAME = "$disconnectedCallback";
1148
+ var STATE_RENDERED_CALLBACK_NAME = "$renderedCallback";
1149
+ var STATE_ERROR_CALLBACK_NAME = "$errorCallback";
1150
+ var WEBCOMPONENT_STATE_READY_CALLBACK_NAME = "$stateReadyCallback";
1151
+ var STATE_BINDABLES_NAME = "$bindables";
1152
+ var STATE_COMMANDS_NAME = "$commands";
1153
+ var STATE_COMMAND_TOKENS_NAME = "$commandTokens";
1154
+ var STATE_COMMAND_NAMESPACE_NAME = "$command";
1155
+ var STATE_EVENT_TOKENS_NAME = "$eventTokens";
1156
+ var STATE_ON_NAME = "$on";
1157
+ var STATE_STREAM_NAME = "$stream";
1158
+ var STATE_WATCH_NAME = "$watch";
1159
+ var STATE_SCAN_NAME = "$scan";
1160
+ var STATE_RECURSION_NAME = "$recursion";
1161
+ var STATE_LIST_KEYS_NAME = "$listKeys";
1162
+ var STATE_STREAM_STATUS_NAMESPACE_NAME = "$streamStatus";
1163
+ var STATE_STREAM_ERROR_NAMESPACE_NAME = "$streamError";
1164
+ function raiseError2(message) {
1165
+ throw new Error(`[@wcstack/state] ${message}`);
1166
+ }
1167
+ var DECLARATION_ALIASES = {
1168
+ $updatedCallback: STATE_RENDERED_CALLBACK_NAME,
1169
+ $streams: STATE_STREAM_NAME
1170
+ };
1171
+ function optionsRequired(fnName) {
1172
+ raiseError2(`filter ${fnName} requires at least one option`);
1173
+ }
1174
+ function optionMustBeNumber(fnName) {
1175
+ raiseError2(`filter ${fnName} requires a number as option`);
1176
+ }
1177
+ function valueMustBeNumber(fnName) {
1178
+ raiseError2(`filter ${fnName} requires a number value`);
1179
+ }
1180
+ function valueMustBeDate(fnName) {
1181
+ raiseError2(`filter ${fnName} requires a date value`);
1182
+ }
1183
+ function valueMustBeArray(fnName) {
1184
+ raiseError2(`filter ${fnName} requires an array value`);
1185
+ }
1186
+ var builtinFilterAliases = {
1187
+ inc: "add",
1188
+ dec: "sub",
1189
+ fix: "toFixed",
1190
+ uc: "upper",
1191
+ lc: "lower",
1192
+ cap: "capitalize",
1193
+ rep: "repeat",
1194
+ rev: "reverse",
1195
+ pad: "padStart",
1196
+ null: "nullIfEmpty"
1197
+ };
1198
+ function validateNumberString(value) {
1199
+ if (!value || isNaN(Number(value))) {
1200
+ return false;
1201
+ }
1202
+ return true;
1203
+ }
1204
+ function numberOption(value, fnName) {
1205
+ if (!validateNumberString(value)) {
1206
+ optionMustBeNumber(fnName);
1207
+ }
1208
+ return Number(value);
1209
+ }
1210
+ function requiredNumberOption(options, index, fnName) {
1211
+ return numberOption(options?.[index] ?? optionsRequired(fnName), fnName);
1212
+ }
1213
+ var nullishPassthrough = (factory) => (options) => {
1214
+ const filterFn = factory(options);
1215
+ return (value) => value == null ? value : filterFn(value);
1216
+ };
1217
+ var eq = (options, literals) => {
1218
+ const opt = options?.[0] ?? optionsRequired("eq");
1219
+ const literal2 = literals !== void 0 && literals.length > 0 ? literals[0] : opt;
1220
+ return (value) => {
1221
+ if (typeof value === "number") {
1222
+ if (typeof literal2 !== "string") {
1223
+ return value === literal2;
1224
+ }
1225
+ if (!validateNumberString(opt)) {
1226
+ optionMustBeNumber("eq");
1227
+ }
1228
+ return value === Number(opt);
1229
+ }
1230
+ if (typeof value === "string") {
1231
+ return value === opt;
1232
+ }
1233
+ return value === literal2;
1234
+ };
1235
+ };
1236
+ var ne = (options, literals) => {
1237
+ const opt = options?.[0] ?? optionsRequired("ne");
1238
+ const literal2 = literals !== void 0 && literals.length > 0 ? literals[0] : opt;
1239
+ return (value) => {
1240
+ if (typeof value === "number") {
1241
+ if (typeof literal2 !== "string") {
1242
+ return value !== literal2;
1243
+ }
1244
+ if (!validateNumberString(opt)) {
1245
+ optionMustBeNumber("ne");
1246
+ }
1247
+ return value !== Number(opt);
1248
+ }
1249
+ if (typeof value === "string") {
1250
+ return value !== opt;
1251
+ }
1252
+ return value !== literal2;
1253
+ };
1254
+ };
1255
+ var not = (_options) => {
1256
+ return (value) => !value;
1257
+ };
1258
+ var lt = (options) => {
1259
+ const opt = requiredNumberOption(options, 0, "lt");
1260
+ return (value) => {
1261
+ if (typeof value !== "number") {
1262
+ valueMustBeNumber("lt");
1263
+ }
1264
+ return value < opt;
1265
+ };
1266
+ };
1267
+ var le = (options) => {
1268
+ const opt = requiredNumberOption(options, 0, "le");
1269
+ return (value) => {
1270
+ if (typeof value !== "number") {
1271
+ valueMustBeNumber("le");
1272
+ }
1273
+ return value <= opt;
1274
+ };
1275
+ };
1276
+ var gt = (options) => {
1277
+ const opt = requiredNumberOption(options, 0, "gt");
1278
+ return (value) => {
1279
+ if (typeof value !== "number") {
1280
+ valueMustBeNumber("gt");
1281
+ }
1282
+ return value > opt;
1283
+ };
1284
+ };
1285
+ var ge = (options) => {
1286
+ const opt = requiredNumberOption(options, 0, "ge");
1287
+ return (value) => {
1288
+ if (typeof value !== "number") {
1289
+ valueMustBeNumber("ge");
1290
+ }
1291
+ return value >= opt;
1292
+ };
1293
+ };
1294
+ var inc = (options) => {
1295
+ const opt = requiredNumberOption(options, 0, "add");
1296
+ return (value) => {
1297
+ if (typeof value !== "number") {
1298
+ valueMustBeNumber("add");
1299
+ }
1300
+ return value + opt;
1301
+ };
1302
+ };
1303
+ var dec = (options) => {
1304
+ const opt = requiredNumberOption(options, 0, "sub");
1305
+ return (value) => {
1306
+ if (typeof value !== "number") {
1307
+ valueMustBeNumber("sub");
1308
+ }
1309
+ return value - opt;
1310
+ };
1311
+ };
1312
+ var mul = (options) => {
1313
+ const opt = requiredNumberOption(options, 0, "mul");
1314
+ return (value) => {
1315
+ if (typeof value !== "number") {
1316
+ valueMustBeNumber("mul");
1317
+ }
1318
+ return value * opt;
1319
+ };
1320
+ };
1321
+ var div = (options) => {
1322
+ const opt = requiredNumberOption(options, 0, "div");
1323
+ return (value) => {
1324
+ if (typeof value !== "number") {
1325
+ valueMustBeNumber("div");
1326
+ }
1327
+ return value / opt;
1328
+ };
1329
+ };
1330
+ var mod = (options) => {
1331
+ const opt = requiredNumberOption(options, 0, "mod");
1332
+ return (value) => {
1333
+ if (typeof value !== "number") {
1334
+ valueMustBeNumber("mod");
1335
+ }
1336
+ return value % opt;
1337
+ };
1338
+ };
1339
+ var abs = (_options) => {
1340
+ return (value) => {
1341
+ if (typeof value !== "number") {
1342
+ valueMustBeNumber("abs");
1343
+ }
1344
+ return Math.abs(value);
1345
+ };
1346
+ };
1347
+ var clamp = (options) => {
1348
+ const min = requiredNumberOption(options, 0, "clamp");
1349
+ const max = requiredNumberOption(options, 1, "clamp");
1350
+ return (value) => {
1351
+ if (typeof value !== "number") {
1352
+ valueMustBeNumber("clamp");
1353
+ }
1354
+ return Math.min(Math.max(value, min), max);
1355
+ };
1356
+ };
1357
+ var fix = (options) => {
1358
+ const opt = numberOption(options?.[0] ?? "0", "toFixed");
1359
+ return (value) => {
1360
+ if (typeof value !== "number") {
1361
+ valueMustBeNumber("toFixed");
1362
+ }
1363
+ return value.toFixed(opt);
1364
+ };
1365
+ };
1366
+ var locale = (options) => {
1367
+ const explicit = options?.[0];
1368
+ return (value) => {
1369
+ if (typeof value !== "number") {
1370
+ valueMustBeNumber("locale");
1371
+ }
1372
+ return value.toLocaleString(explicit ?? config.locale);
1373
+ };
1374
+ };
1375
+ var uc = (_options) => {
1376
+ return (value) => {
1377
+ return String(value).toUpperCase();
1378
+ };
1379
+ };
1380
+ var lc = (_options) => {
1381
+ return (value) => {
1382
+ return String(value).toLowerCase();
1383
+ };
1384
+ };
1385
+ var cap = (_options) => {
1386
+ return (value) => {
1387
+ const v = String(value);
1388
+ if (v.length === 0) {
1389
+ return v;
1390
+ }
1391
+ if (v.length === 1) {
1392
+ return v.toUpperCase();
1393
+ }
1394
+ return v.charAt(0).toUpperCase() + v.slice(1);
1395
+ };
1396
+ };
1397
+ var trim = (_options) => {
1398
+ return (value) => {
1399
+ return String(value).trim();
1400
+ };
1401
+ };
1402
+ var slice = (options) => {
1403
+ const numberedOpts = [requiredNumberOption(options, 0, "slice")];
1404
+ const opt2 = options?.[1];
1405
+ if (typeof opt2 !== "undefined") {
1406
+ numberedOpts.push(numberOption(opt2, "slice"));
1407
+ }
1408
+ return (value) => {
1409
+ return String(value).slice(...numberedOpts);
1410
+ };
1411
+ };
1412
+ var substr = (options) => {
1413
+ const opt1 = requiredNumberOption(options, 0, "substr");
1414
+ const opt2 = requiredNumberOption(options, 1, "substr");
1415
+ return (value) => {
1416
+ return String(value).substr(opt1, opt2);
1417
+ };
1418
+ };
1419
+ var pad = (options) => {
1420
+ const opt1 = requiredNumberOption(options, 0, "padStart");
1421
+ const opt2 = options?.[1] ?? "0";
1422
+ return (value) => {
1423
+ return String(value).padStart(opt1, opt2);
1424
+ };
1425
+ };
1426
+ var padEnd = (options) => {
1427
+ const opt1 = requiredNumberOption(options, 0, "padEnd");
1428
+ const opt2 = options?.[1] ?? " ";
1429
+ return (value) => {
1430
+ return String(value).padEnd(opt1, opt2);
1431
+ };
1432
+ };
1433
+ var rep = (options) => {
1434
+ const opt = requiredNumberOption(options, 0, "repeat");
1435
+ return (value) => {
1436
+ return String(value).repeat(opt);
1437
+ };
1438
+ };
1439
+ var rev = (_options) => {
1440
+ return (value) => {
1441
+ return String(value).split("").reverse().join("");
1442
+ };
1443
+ };
1444
+ var int = (_options) => {
1445
+ return (value) => {
1446
+ return parseInt(String(value), 10);
1447
+ };
1448
+ };
1449
+ var float = (_options) => {
1450
+ return (value) => {
1451
+ return parseFloat(String(value));
1452
+ };
1453
+ };
1454
+ var round = (options) => {
1455
+ const optValue = Math.pow(10, numberOption(options?.[0] ?? "0", "round"));
1456
+ return (value) => {
1457
+ if (typeof value !== "number") {
1458
+ valueMustBeNumber("round");
1459
+ }
1460
+ return Math.round(value * optValue) / optValue;
1461
+ };
1462
+ };
1463
+ var floor = (options) => {
1464
+ const optValue = Math.pow(10, numberOption(options?.[0] ?? "0", "floor"));
1465
+ return (value) => {
1466
+ if (typeof value !== "number") {
1467
+ valueMustBeNumber("floor");
1468
+ }
1469
+ return Math.floor(value * optValue) / optValue;
1470
+ };
1471
+ };
1472
+ var ceil = (options) => {
1473
+ const optValue = Math.pow(10, numberOption(options?.[0] ?? "0", "ceil"));
1474
+ return (value) => {
1475
+ if (typeof value !== "number") {
1476
+ valueMustBeNumber("ceil");
1477
+ }
1478
+ return Math.ceil(value * optValue) / optValue;
1479
+ };
1480
+ };
1481
+ var percent = (options) => {
1482
+ const opt = numberOption(options?.[0] ?? "0", "percent");
1483
+ return (value) => {
1484
+ if (typeof value !== "number") {
1485
+ valueMustBeNumber("percent");
1486
+ }
1487
+ return `${(value * 100).toFixed(opt)}%`;
1488
+ };
1489
+ };
1490
+ var unit = (options) => {
1491
+ const opt = options?.[0] ?? optionsRequired("unit");
1492
+ return (value) => {
1493
+ return String(value) + opt;
1494
+ };
1495
+ };
1496
+ var join = (options) => {
1497
+ const opt = options?.[0] ?? ", ";
1498
+ return (value) => {
1499
+ if (!Array.isArray(value)) {
1500
+ valueMustBeArray("join");
1501
+ }
1502
+ return value.join(opt);
1503
+ };
1504
+ };
1505
+ var truncate = (options) => {
1506
+ const maxLength = requiredNumberOption(options, 0, "truncate");
1507
+ const suffix = options?.[1] ?? "\u2026";
1508
+ return (value) => {
1509
+ const v = String(value);
1510
+ if (v.length <= maxLength) {
1511
+ return v;
1512
+ }
1513
+ return v.slice(0, maxLength) + suffix;
1514
+ };
1515
+ };
1516
+ var date = (options) => {
1517
+ const explicit = options?.[0];
1518
+ return (value) => {
1519
+ if (!(value instanceof Date)) {
1520
+ valueMustBeDate("date");
1521
+ }
1522
+ return value.toLocaleDateString(explicit ?? config.locale);
1523
+ };
1524
+ };
1525
+ var time = (options) => {
1526
+ const explicit = options?.[0];
1527
+ return (value) => {
1528
+ if (!(value instanceof Date)) {
1529
+ valueMustBeDate("time");
1530
+ }
1531
+ return value.toLocaleTimeString(explicit ?? config.locale);
1532
+ };
1533
+ };
1534
+ var datetime = (options) => {
1535
+ const explicit = options?.[0];
1536
+ return (value) => {
1537
+ if (!(value instanceof Date)) {
1538
+ valueMustBeDate("datetime");
1539
+ }
1540
+ return value.toLocaleString(explicit ?? config.locale);
1541
+ };
1542
+ };
1543
+ var ymd = (options) => {
1544
+ const opt = options?.[0] ?? "-";
1545
+ return (value) => {
1546
+ if (!(value instanceof Date)) {
1547
+ valueMustBeDate("ymd");
1548
+ }
1549
+ const year = value.getFullYear().toString();
1550
+ const month = (value.getMonth() + 1).toString().padStart(2, "0");
1551
+ const day = value.getDate().toString().padStart(2, "0");
1552
+ return `${year}${opt}${month}${opt}${day}`;
1553
+ };
1554
+ };
1555
+ var hms = (options) => {
1556
+ const opt = options?.[0] ?? ":";
1557
+ return (value) => {
1558
+ if (!(value instanceof Date)) {
1559
+ valueMustBeDate("hms");
1560
+ }
1561
+ const hours = value.getHours().toString().padStart(2, "0");
1562
+ const minutes = value.getMinutes().toString().padStart(2, "0");
1563
+ const seconds = value.getSeconds().toString().padStart(2, "0");
1564
+ return `${hours}${opt}${minutes}${opt}${seconds}`;
1565
+ };
1566
+ };
1567
+ var falsy = (_options) => {
1568
+ return (value) => !value;
725
1569
  };
726
1570
  var truthy = (_options) => {
727
1571
  return (value) => !!value;
@@ -778,17 +1622,18 @@ var builtinFilters = {
778
1622
  "clamp": clamp,
779
1623
  "toFixed": fix,
780
1624
  "locale": locale,
781
- "upper": uc,
782
- "lower": lc,
783
- "capitalize": cap,
784
- "trim": trim,
785
- "slice": slice,
786
- "substr": substr,
787
- "padStart": pad,
788
- "padEnd": padEnd,
789
- "repeat": rep,
790
- "reverse": rev,
791
- "truncate": truncate,
1625
+ // `String(value)` で組み立てる族は、値が無いときに素通しする(要件 B8 — nullishPassthrough を参照)
1626
+ "upper": nullishPassthrough(uc),
1627
+ "lower": nullishPassthrough(lc),
1628
+ "capitalize": nullishPassthrough(cap),
1629
+ "trim": nullishPassthrough(trim),
1630
+ "slice": nullishPassthrough(slice),
1631
+ "substr": nullishPassthrough(substr),
1632
+ "padStart": nullishPassthrough(pad),
1633
+ "padEnd": nullishPassthrough(padEnd),
1634
+ "repeat": nullishPassthrough(rep),
1635
+ "reverse": nullishPassthrough(rev),
1636
+ "truncate": nullishPassthrough(truncate),
792
1637
  "join": join,
793
1638
  "int": int,
794
1639
  "float": float,
@@ -796,7 +1641,7 @@ var builtinFilters = {
796
1641
  "floor": floor,
797
1642
  "ceil": ceil,
798
1643
  "percent": percent,
799
- "unit": unit,
1644
+ "unit": nullishPassthrough(unit),
800
1645
  "date": date,
801
1646
  "time": time,
802
1647
  "datetime": datetime,
@@ -816,7 +1661,9 @@ var builtinFilterMeta = {
816
1661
  // 比較・論理
817
1662
  eq: { description: "\u7B49\u3057\u3044\u304B\u6BD4\u8F03", hasArgs: true, resultType: "boolean", acceptTypes: "any", minArgs: 1, maxArgs: 1, argTypes: ["any"] },
818
1663
  ne: { description: "\u7570\u306A\u308B\u304B\u6BD4\u8F03", hasArgs: true, resultType: "boolean", acceptTypes: "any", minArgs: 1, maxArgs: 1, argTypes: ["any"] },
819
- not: { description: "\u30D6\u30FC\u30EB\u5024\u3092\u53CD\u8EE2", hasArgs: false, resultType: "boolean", acceptTypes: ["boolean"], minArgs: 0, maxArgs: 0 },
1664
+ // `not` は真偽性(truthy / falsy)の反転。`if:` が `Boolean()` で寄せるのと同じ規則で、
1665
+ // `else:` はこのフィルタを足した束縛として組み立てられる(structural/createNotFilter.ts)
1666
+ not: { description: "\u771F\u507D\u6027\u3092\u53CD\u8EE2\uFF08falsy \u2192 true\uFF09", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
820
1667
  lt: { description: "\u3088\u308A\u5C0F\u3055\u3044\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
821
1668
  le: { description: "\u4EE5\u4E0B\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
822
1669
  gt: { description: "\u3088\u308A\u5927\u304D\u3044\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
@@ -838,13 +1685,15 @@ var builtinFilterMeta = {
838
1685
  capitalize: { description: "\u5148\u982D\u6587\u5B57\u3092\u5927\u6587\u5B57\u306B", hasArgs: false, resultType: "string", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 },
839
1686
  trim: { description: "\u524D\u5F8C\u306E\u7A7A\u767D\u3092\u524A\u9664", hasArgs: false, resultType: "string", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 },
840
1687
  slice: { description: "\u90E8\u5206\u6587\u5B57\u5217 (start[,end])", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "number"] },
841
- substr: { description: "\u90E8\u5206\u6587\u5B57\u5217 (pos,len)", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "number"] },
842
- padStart: { description: "\u5148\u982D\u3092\u57CB\u3081\u308B (length[,char])", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "string"] },
843
- padEnd: { description: "\u672B\u5C3E\u3092\u57CB\u3081\u308B (length[,char])", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "string"] },
1688
+ // 長さは省略できない(実装が両方読む)。minArgs: 1 だった頃は補完・lint が `substr(0)` を
1689
+ // 通し、実行時にだけ落ちていた
1690
+ substr: { description: "\u90E8\u5206\u6587\u5B57\u5217 (pos,len)", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 2, maxArgs: 2, argTypes: ["number", "number"] },
1691
+ padStart: { description: "\u5148\u982D\u3092\u57CB\u3081\u308B (length[,char]\u3002char \u306E\u65E2\u5B9A\u306F 0 \u2014 JS \u306E\u65E2\u5B9A\u306F\u7A7A\u767D\u306A\u306E\u3067\u6CE8\u610F)", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "string"] },
1692
+ padEnd: { description: "\u672B\u5C3E\u3092\u57CB\u3081\u308B (length[,char]\u3002char \u306E\u65E2\u5B9A\u306F\u7A7A\u767D \u2014 JS \u3068\u540C\u3058)", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "string"] },
844
1693
  repeat: { description: "\u7E70\u308A\u8FD4\u3057 (count)", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
845
1694
  reverse: { description: "\u6587\u5B57\u9806\u3092\u53CD\u8EE2", hasArgs: false, resultType: "string", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 },
846
- truncate: { description: "\u5207\u308A\u8A70\u3081\u3066\u7701\u7565\u8A18\u53F7 (length[,suffix])", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "string"] },
847
- join: { description: "\u914D\u5217\u3092\u9023\u7D50 ([separator])", hasArgs: true, resultType: "string", acceptTypes: ["array"], minArgs: 0, maxArgs: 1, argTypes: ["string"] },
1695
+ truncate: { description: "\u5207\u308A\u8A70\u3081\u3066\u7701\u7565\u8A18\u53F7 (length[,suffix]\u3002suffix \u306E\u65E2\u5B9A\u306F \u2026 \u2014 U+2026 \u306E 1 \u6587\u5B57)", hasArgs: true, resultType: "string", acceptTypes: ["string"], minArgs: 1, maxArgs: 2, argTypes: ["number", "string"] },
1696
+ join: { description: "\u914D\u5217\u3092\u9023\u7D50 ([separator]\u3002\u65E2\u5B9A\u306F\u30AB\u30F3\u30DE + \u7A7A\u767D)", hasArgs: true, resultType: "string", acceptTypes: ["array"], minArgs: 0, maxArgs: 1, argTypes: ["string"] },
848
1697
  // 数値パース・丸め
849
1698
  int: { description: "\u6574\u6570\u306B\u30D1\u30FC\u30B9", hasArgs: false, resultType: "number", acceptTypes: ["string", "number"], minArgs: 0, maxArgs: 0 },
850
1699
  float: { description: "\u6D6E\u52D5\u5C0F\u6570\u70B9\u6570\u306B\u30D1\u30FC\u30B9", hasArgs: false, resultType: "number", acceptTypes: ["string", "number"], minArgs: 0, maxArgs: 0 },
@@ -856,117 +1705,70 @@ var builtinFilterMeta = {
856
1705
  // それらは既に string を返すため(builtinFilters.ts の unit を参照)
857
1706
  unit: { description: "\u5358\u4F4D\uFF08\u63A5\u5C3E\u8F9E\uFF09\u3092\u4ED8\u52A0", hasArgs: true, resultType: "string", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["string"] },
858
1707
  // 日付・時刻
859
- date: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u4ED8", hasArgs: false, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
860
- time: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u6642\u523B", hasArgs: false, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
861
- datetime: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u6642", hasArgs: false, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
862
- ymd: { description: "YYYY-MM-DD \u5F62\u5F0F", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
863
- hms: { description: "HH:MM:SS \u5F62\u5F0F", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
1708
+ // `locale` と同じくロケールを 1 つ受ける(`date(ja-JP)`)。実装は最初からこれを読んでいたが、
1709
+ // メタデータ側が maxArgs: 0 だったため lint と補完が正しい書き方を誤りとして報告していた
1710
+ date: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u4ED8 ([locale]\u3002\u65E2\u5B9A\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
1711
+ time: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u6642\u523B ([locale]\u3002\u65E2\u5B9A\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
1712
+ datetime: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u6642 ([locale]\u3002\u65E2\u5B9A\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
1713
+ ymd: { description: "YYYY-MM-DD \u5F62\u5F0F ([separator]\u3002\u65E2\u5B9A\u306F -)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
1714
+ hms: { description: "HH:MM:SS \u5F62\u5F0F ([separator]\u3002\u65E2\u5B9A\u306F :)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
864
1715
  // 真偽値・変換
865
1716
  falsy: { description: "\u507D\u5024\u304B\u5224\u5B9A", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
866
1717
  truthy: { description: "\u771F\u5024\u304B\u5224\u5B9A", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
867
1718
  defaults: { description: "\u507D\u5024\u306E\u5834\u5408\u30C7\u30D5\u30A9\u30EB\u30C8\u5024", hasArgs: true, resultType: "passthrough", acceptTypes: "any", minArgs: 1, maxArgs: 1, argTypes: ["any"] },
868
1719
  coalesce: { description: "null / undefined \u306E\u5834\u5408\u30C7\u30D5\u30A9\u30EB\u30C8\u5024", hasArgs: true, resultType: "passthrough", acceptTypes: "any", minArgs: 1, maxArgs: 1, argTypes: ["any"] },
869
- boolean: { description: "\u30D6\u30FC\u30EB\u5024\u306B\u5909\u63DB", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
870
- number: { description: "\u6570\u5024\u306B\u5909\u63DB", hasArgs: false, resultType: "number", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
871
- string: { description: "\u6587\u5B57\u5217\u306B\u5909\u63DB", hasArgs: false, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
872
- nullIfEmpty: { description: "\u7A7A\u6587\u5B57\u5217\u3092null\u306B\u5909\u63DB", hasArgs: false, resultType: "passthrough", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 }
873
- };
874
- var STRUCTURAL_BINDING_TYPE_SET = /* @__PURE__ */ new Set([
875
- "if",
876
- "elseif",
877
- "else",
878
- "for"
879
- ]);
880
- var DELIMITER = ".";
881
- var WILDCARD = "*";
882
- var MAX_WILDCARD_DEPTH = 128;
883
- var BINDING_SEPARATOR = ";";
884
- var PROP_VALUE_SEPARATOR = ":";
885
- var MODIFIER_SEPARATOR = "#";
886
- var FILTER_SEPARATOR = "|";
887
- var MODIFIER_PREVENT = "prevent";
888
- var MODIFIER_STOP = "stop";
889
- var MODIFIER_READONLY = "ro";
890
- var MODIFIER_FLAGS = Object.freeze([
891
- MODIFIER_PREVENT,
892
- MODIFIER_STOP,
893
- MODIFIER_READONLY
894
- ]);
895
- var MODIFIER_KEY_INIT = "init";
896
- var MODIFIER_KEY_SYNC = "sync";
897
- var MODIFIER_KEYS = Object.freeze([
898
- MODIFIER_KEY_INIT,
899
- MODIFIER_KEY_SYNC
900
- ]);
901
- var ELSE_KEYWORD = "else";
902
- var SPREAD_PROP = "...";
903
- var EVENT_PROP_PREFIX = "on";
904
- var EVENT_TOKEN_NAMESPACE = "eventToken";
905
- var COMMAND_NAMESPACE = "command";
906
- var CLASS_NAMESPACE = "class";
907
- var ATTR_NAMESPACE = "attr";
908
- var STYLE_NAMESPACE = "style";
909
- var INDEX_PARAM_PREFIX = "$";
910
- var tmpIndexByIndexName = {};
911
- for (let i = 0; i < MAX_WILDCARD_DEPTH; i++) {
912
- tmpIndexByIndexName[`${INDEX_PARAM_PREFIX}${i + 1}`] = i;
913
- }
914
- Object.freeze(tmpIndexByIndexName);
915
- var STATE_CONNECTED_CALLBACK_NAME = "$connectedCallback";
916
- var STATE_DISCONNECTED_CALLBACK_NAME = "$disconnectedCallback";
917
- var STATE_UPDATED_CALLBACK_NAME = "$renderedCallback";
918
- var STATE_ERROR_CALLBACK_NAME = "$errorCallback";
919
- var WEBCOMPONENT_STATE_READY_CALLBACK_NAME = "$stateReadyCallback";
920
- var STATE_BINDABLES_NAME = "$bindables";
921
- var STATE_COMMANDS_NAME = "$commands";
922
- var STATE_COMMAND_TOKENS_NAME = "$commandTokens";
923
- var STATE_COMMAND_NAMESPACE_NAME = "$command";
924
- var STATE_EVENT_TOKENS_NAME = "$eventTokens";
925
- var STATE_ON_NAME = "$on";
926
- var STATE_STREAMS_NAME = "$stream";
927
- var STATE_WATCH_NAME = "$watch";
928
- var STATE_SCAN_NAME = "$scan";
929
- var STATE_RECURSION_NAME = "$recursion";
930
- var STATE_LIST_KEYS_NAME = "$listKeys";
931
- var STATE_STREAM_STATUS_NAMESPACE_NAME = "$streamStatus";
932
- var STATE_STREAM_ERROR_NAMESPACE_NAME = "$streamError";
933
- var WCS_MANIFEST_VERSION = 1;
1720
+ boolean: { description: "\u30D6\u30FC\u30EB\u5024\u306B\u5909\u63DB", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
1721
+ number: { description: "\u6570\u5024\u306B\u5909\u63DB", hasArgs: false, resultType: "number", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
1722
+ string: { description: "\u6587\u5B57\u5217\u306B\u5909\u63DB", hasArgs: false, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
1723
+ nullIfEmpty: { description: "\u7A7A\u6587\u5B57\u5217\u3092null\u306B\u5909\u63DB", hasArgs: false, resultType: "passthrough", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 }
1724
+ };
1725
+ var STRUCTURAL_BINDING_TYPE_SET2 = /* @__PURE__ */ new Set([
1726
+ "if",
1727
+ "elseif",
1728
+ "else",
1729
+ "for"
1730
+ ]);
1731
+ var WCS_MANIFEST_VERSION = 2;
1732
+ var STATE_API_ALIASES = Object.freeze({
1733
+ $trackDependency: "$dependOn",
1734
+ $untrackDependency: "$untracked"
1735
+ });
934
1736
  function getWcsManifest() {
935
1737
  return {
936
1738
  version: WCS_MANIFEST_VERSION,
937
1739
  syntax: {
938
1740
  bindAttribute: config.bindAttributeName,
939
1741
  tagName: config.tagNames.state,
940
- pathDelimiter: DELIMITER,
941
- wildcard: WILDCARD,
1742
+ pathDelimiter: DELIMITER2,
1743
+ wildcard: WILDCARD2,
942
1744
  delimiters: {
943
- binding: BINDING_SEPARATOR,
944
- propValue: PROP_VALUE_SEPARATOR,
945
- modifier: MODIFIER_SEPARATOR,
946
- filter: FILTER_SEPARATOR
1745
+ binding: BINDING_SEPARATOR2,
1746
+ propValue: PROP_VALUE_SEPARATOR2,
1747
+ modifier: MODIFIER_SEPARATOR2,
1748
+ filter: FILTER_SEPARATOR2
947
1749
  },
948
1750
  // 正本 STRUCTURAL_BINDING_TYPE_SET から導出(手書きの二重定義を排除)。
949
- structuralDirectives: Array.from(STRUCTURAL_BINDING_TYPE_SET),
1751
+ structuralDirectives: Array.from(STRUCTURAL_BINDING_TYPE_SET2),
950
1752
  modifiers: {
951
1753
  flags: MODIFIER_FLAGS,
952
1754
  keyValue: MODIFIER_KEYS,
953
- eventNamePrefix: EVENT_PROP_PREFIX
1755
+ eventNamePrefix: EVENT_PROP_PREFIX2
954
1756
  },
955
1757
  indexParam: {
956
- prefix: INDEX_PARAM_PREFIX,
957
- maxDepth: MAX_WILDCARD_DEPTH
1758
+ prefix: INDEX_PARAM_PREFIX2,
1759
+ maxDepth: MAX_WILDCARD_DEPTH2
958
1760
  },
959
1761
  bindingTypes: {
960
- elseKeyword: ELSE_KEYWORD,
961
- spread: SPREAD_PROP,
962
- eventPropertyPrefix: EVENT_PROP_PREFIX,
963
- explicitPropertyPrefix: DELIMITER,
1762
+ elseKeyword: ELSE_KEYWORD2,
1763
+ spread: SPREAD_PROP2,
1764
+ eventPropertyPrefix: EVENT_PROP_PREFIX2,
1765
+ explicitPropertyPrefix: DELIMITER2,
964
1766
  propNamespaces: {
965
- eventToken: EVENT_TOKEN_NAMESPACE,
966
- command: COMMAND_NAMESPACE,
967
- class: CLASS_NAMESPACE,
968
- attr: ATTR_NAMESPACE,
969
- style: STYLE_NAMESPACE
1767
+ eventToken: EVENT_TOKEN_NAMESPACE2,
1768
+ command: COMMAND_NAMESPACE2,
1769
+ class: CLASS_NAMESPACE2,
1770
+ attr: ATTR_NAMESPACE2,
1771
+ style: STYLE_NAMESPACE2
970
1772
  }
971
1773
  }
972
1774
  },
@@ -974,10 +1776,12 @@ function getWcsManifest() {
974
1776
  filters: Object.keys(outputBuiltinFilters),
975
1777
  filterMeta: builtinFilterMeta,
976
1778
  filterAliases: builtinFilterAliases,
1779
+ declarationAliases: DECLARATION_ALIASES,
1780
+ apiAliases: STATE_API_ALIASES,
977
1781
  reservedLifecycle: [
978
1782
  STATE_CONNECTED_CALLBACK_NAME,
979
1783
  STATE_DISCONNECTED_CALLBACK_NAME,
980
- STATE_UPDATED_CALLBACK_NAME,
1784
+ STATE_RENDERED_CALLBACK_NAME,
981
1785
  STATE_ERROR_CALLBACK_NAME,
982
1786
  WEBCOMPONENT_STATE_READY_CALLBACK_NAME
983
1787
  ],
@@ -988,7 +1792,7 @@ function getWcsManifest() {
988
1792
  STATE_COMMAND_NAMESPACE_NAME,
989
1793
  STATE_EVENT_TOKENS_NAME,
990
1794
  STATE_ON_NAME,
991
- STATE_STREAMS_NAME,
1795
+ STATE_STREAM_NAME,
992
1796
  STATE_WATCH_NAME,
993
1797
  STATE_SCAN_NAME,
994
1798
  STATE_LIST_KEYS_NAME,
@@ -1012,16 +1816,16 @@ var STRUCTURAL_DIRECTIVE_INFO = {
1012
1816
  elseif: { description: "else-if \u6761\u4EF6 (<template>)", insertColon: true },
1013
1817
  else: { description: "else \u30D6\u30ED\u30C3\u30AF (<template>)", insertColon: false }
1014
1818
  };
1015
- var STRUCTURAL_DIRECTIVES = [...STRUCTURAL_BINDING_TYPE_SET].map((name) => ({
1819
+ var STRUCTURAL_DIRECTIVES = [...STRUCTURAL_BINDING_TYPE_SET2].map((name) => ({
1016
1820
  name,
1017
1821
  ...STRUCTURAL_DIRECTIVE_INFO[name]
1018
1822
  }));
1019
1823
 
1020
1824
  // src/service/recursionPaths.ts
1021
- var RECURSION_WILDCARD = "**";
1825
+ var RECURSION_WILDCARD2 = "**";
1022
1826
  var RECURSION_KEY = "$recursion";
1023
1827
  function hasRecursionWildcard(path) {
1024
- return path.indexOf(RECURSION_WILDCARD) !== -1;
1828
+ return path.indexOf(RECURSION_WILDCARD2) !== -1;
1025
1829
  }
1026
1830
  function checkNodePath(path) {
1027
1831
  if (typeof path !== "string" || path.length === 0) return "empty";
@@ -1032,7 +1836,7 @@ function checkNodePath(path) {
1032
1836
  if (path.indexOf("#") !== -1) return "reservedMount";
1033
1837
  for (let i = 0; i < segments.length - 1; i++) {
1034
1838
  if (segments[i] === "*") return "midWildcard";
1035
- if (segments[i] === RECURSION_WILDCARD) return "nestedRecursion";
1839
+ if (segments[i] === RECURSION_WILDCARD2) return "nestedRecursion";
1036
1840
  if (!isNaN(Number(segments[i]))) return "indexSegment";
1037
1841
  }
1038
1842
  return null;
@@ -1041,7 +1845,7 @@ function makeRecursionSpec(anchor, repeat) {
1041
1845
  return Object.freeze({
1042
1846
  anchor,
1043
1847
  repeat,
1044
- recursiveAnchor: anchor.slice(0, anchor.lastIndexOf(".")) + "." + RECURSION_WILDCARD,
1848
+ recursiveAnchor: anchor.slice(0, anchor.lastIndexOf(".")) + "." + RECURSION_WILDCARD2,
1045
1849
  anchorList: anchor.slice(0, anchor.lastIndexOf(".")),
1046
1850
  repeatList: repeat.slice(0, repeat.lastIndexOf("."))
1047
1851
  });
@@ -1117,8 +1921,8 @@ function collectRecursionSpecs(candidates) {
1117
1921
  const out = [];
1118
1922
  for (const candidate of candidates) {
1119
1923
  if (candidate.kind !== "recursionAnchor" || typeof candidate.repeat !== "string") continue;
1120
- if (!candidate.path.endsWith("." + RECURSION_WILDCARD)) continue;
1121
- const anchor = candidate.path.slice(0, candidate.path.length - RECURSION_WILDCARD.length) + "*";
1924
+ if (!candidate.path.endsWith("." + RECURSION_WILDCARD2)) continue;
1925
+ const anchor = candidate.path.slice(0, candidate.path.length - RECURSION_WILDCARD2.length) + "*";
1122
1926
  if (out.some((spec) => spec.anchor === anchor && spec.repeat === candidate.repeat)) continue;
1123
1927
  out.push(makeRecursionSpec(anchor, candidate.repeat));
1124
1928
  }
@@ -1298,6 +2102,26 @@ function analyzeWatchEntries(scriptContent) {
1298
2102
  definitelyNotFunction: entry.kind === "data" && isNonFunctionLiteral(entry.value)
1299
2103
  }));
1300
2104
  }
2105
+ function analyzeWatchHandlerSources(scriptContent) {
2106
+ const root = locateDefaultExportObject(scriptContent);
2107
+ if (!root) return [];
2108
+ const prop = parseTopLevelProperties(root.content).find((p) => p.name === RESERVED_WATCH_KEY);
2109
+ if (!prop || prop.kind !== "data" || !prop.value || !isObjectLiteral(prop.value) || prop.valueStart === void 0) {
2110
+ return [];
2111
+ }
2112
+ const leading = prop.value.length - prop.value.trimStart().length;
2113
+ const innerStart = root.start + prop.valueStart + leading + 1;
2114
+ const out = [];
2115
+ for (const entry of parseTopLevelProperties(extractObjectContent(prop.value))) {
2116
+ if (entry.value === void 0 || entry.valueStart === void 0) continue;
2117
+ out.push({
2118
+ kind: entry.kind === "data" ? "value" : "body",
2119
+ text: entry.value,
2120
+ start: innerStart + entry.valueStart
2121
+ });
2122
+ }
2123
+ return out;
2124
+ }
1301
2125
  function analyzeListKeyEntries(scriptContent) {
1302
2126
  return analyzeObjectEntries(scriptContent, RESERVED_LIST_KEYS_KEY).map((entry) => ({ key: entry.key, start: entry.start, end: entry.end }));
1303
2127
  }
@@ -2164,271 +2988,42 @@ function pushSchemaValuePaths(path, node, paths, defs, depth) {
2164
2988
  const typeHint = schemaTypeHint(nodes);
2165
2989
  paths.push(withHint({ path, kind: "data", fromSchema: true }, typeHint));
2166
2990
  const items = nodes.map((n) => n.items).find((i) => i !== void 0 && i !== null && typeof i === "object");
2167
- const isArray2 = items !== void 0 || (typeHint?.split("|").includes("array") ?? false);
2168
- if (isArray2) {
2169
- const itemNodes = items !== void 0 ? derefSchemaNodes(items, defs) : [];
2170
- paths.push(withHint({ path: `${path}.*`, kind: "list", fromSchema: true }, schemaTypeHint(itemNodes)));
2171
- paths.push({ path: `${path}.length`, kind: "data", typeHint: "number", fromSchema: true });
2172
- if (depth >= MAX_OBJECT_NEST_DEPTH) return;
2173
- const seen = /* @__PURE__ */ new Set();
2174
- for (const n of itemNodes) {
2175
- for (const [childKey, childNode] of Object.entries(n.properties ?? {})) {
2176
- if (seen.has(childKey)) continue;
2177
- seen.add(childKey);
2178
- pushSchemaValuePaths(`${path}.*.${childKey}`, childNode, paths, defs, depth + 1);
2179
- }
2180
- }
2181
- return;
2182
- }
2183
- if (nodes.some((n) => n.properties !== void 0)) {
2184
- collectSchemaObjectPaths(node, path, paths, defs, depth + 1);
2185
- }
2186
- }
2187
- function withHint(candidate, typeHint) {
2188
- return typeHint === void 0 ? candidate : { ...candidate, typeHint };
2189
- }
2190
-
2191
- // src/language/htmlParse.ts
2192
- function parseWcsScriptBlocks(html, stateTagName = "wcs-state") {
2193
- const blocks = [];
2194
- let pos = 0;
2195
- const len = html.length;
2196
- while (pos < len) {
2197
- if (html.startsWith("<!--", pos)) {
2198
- const commentEnd = html.indexOf("-->", pos + 4);
2199
- if (commentEnd === -1) break;
2200
- pos = commentEnd + 3;
2201
- continue;
2202
- }
2203
- const wcsMatch = matchOpenTag(html, pos, stateTagName);
2204
- if (wcsMatch === null) {
2205
- pos++;
2206
- continue;
2207
- }
2208
- const mountPath = extractAttribute(wcsMatch.tagContent, "mount");
2209
- pos = wcsMatch.end;
2210
- const wcsCloseIdx = findCloseTag(html, pos, stateTagName);
2211
- const wcsEnd = wcsCloseIdx === -1 ? len : wcsCloseIdx;
2212
- while (pos < wcsEnd) {
2213
- if (html.startsWith("<!--", pos)) {
2214
- const commentEnd = html.indexOf("-->", pos + 4);
2215
- if (commentEnd === -1) break;
2216
- pos = commentEnd + 3;
2217
- continue;
2218
- }
2219
- const scriptMatch = matchOpenTag(html, pos, "script");
2220
- if (scriptMatch === null) {
2221
- pos++;
2222
- continue;
2223
- }
2224
- const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
2225
- if (typeAttr?.toLowerCase() !== "module") {
2226
- pos = scriptMatch.end;
2227
- continue;
2228
- }
2229
- const contentStart = scriptMatch.end;
2230
- const scriptCloseIdx = findCloseTag(html, contentStart, "script");
2231
- if (scriptCloseIdx === -1) {
2232
- pos = contentStart;
2233
- break;
2234
- }
2235
- const contentEnd = scriptCloseIdx;
2236
- blocks.push({
2237
- contentStart,
2238
- contentEnd,
2239
- content: html.slice(contentStart, contentEnd),
2240
- mountPath
2241
- });
2242
- pos = html.indexOf(">", scriptCloseIdx) + 1;
2243
- if (pos === 0) break;
2244
- }
2245
- pos = wcsEnd;
2246
- if (wcsCloseIdx !== -1) {
2247
- const closeEnd = html.indexOf(">", wcsCloseIdx);
2248
- if (closeEnd !== -1) pos = closeEnd + 1;
2249
- }
2250
- }
2251
- return blocks;
2252
- }
2253
- function parseWcsStateElements(html, stateTagName = "wcs-state") {
2254
- const elements = [];
2255
- let pos = 0;
2256
- const len = html.length;
2257
- while (pos < len) {
2258
- if (html.startsWith("<!--", pos)) {
2259
- const commentEnd = html.indexOf("-->", pos + 4);
2260
- if (commentEnd === -1) break;
2261
- pos = commentEnd + 3;
2262
- continue;
2263
- }
2264
- const wcsMatch = matchOpenTag(html, pos, stateTagName);
2265
- if (wcsMatch === null) {
2266
- pos++;
2267
- continue;
2268
- }
2269
- const mountPath = extractAttribute(wcsMatch.tagContent, "mount");
2270
- const bindComponent = parseAttributeNames(wcsMatch.tagContent).has("bind-component");
2271
- const jsonAttr = extractAttribute(wcsMatch.tagContent, "json") ?? void 0;
2272
- const stateAttr = extractAttribute(wcsMatch.tagContent, "state") ?? void 0;
2273
- const srcAttr = extractAttribute(wcsMatch.tagContent, "src") ?? void 0;
2274
- const tagStart = pos;
2275
- const tagEnd = wcsMatch.end;
2276
- pos = wcsMatch.end;
2277
- const scriptBlocks = [];
2278
- const wcsCloseIdx = findCloseTag(html, pos, stateTagName);
2279
- const wcsEnd = wcsCloseIdx === -1 ? len : wcsCloseIdx;
2280
- while (pos < wcsEnd) {
2281
- if (html.startsWith("<!--", pos)) {
2282
- const commentEnd = html.indexOf("-->", pos + 4);
2283
- if (commentEnd === -1) break;
2284
- pos = commentEnd + 3;
2285
- continue;
2286
- }
2287
- const scriptMatch = matchOpenTag(html, pos, "script");
2288
- if (scriptMatch === null) {
2289
- pos++;
2290
- continue;
2291
- }
2292
- const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
2293
- if (typeAttr?.toLowerCase() !== "module") {
2294
- pos = scriptMatch.end;
2295
- continue;
2296
- }
2297
- const contentStart = scriptMatch.end;
2298
- const scriptCloseIdx = findCloseTag(html, contentStart, "script");
2299
- if (scriptCloseIdx === -1) {
2300
- pos = contentStart;
2301
- break;
2302
- }
2303
- scriptBlocks.push({
2304
- contentStart,
2305
- contentEnd: scriptCloseIdx,
2306
- content: html.slice(contentStart, scriptCloseIdx),
2307
- mountPath
2308
- });
2309
- pos = html.indexOf(">", scriptCloseIdx) + 1;
2310
- if (pos === 0) break;
2311
- }
2312
- elements.push({ mountPath, bindComponent, jsonAttr, stateAttr, srcAttr, scriptBlocks, tagStart, tagEnd });
2313
- pos = wcsEnd;
2314
- if (wcsCloseIdx !== -1) {
2315
- const closeEnd = html.indexOf(">", wcsCloseIdx);
2316
- if (closeEnd !== -1) pos = closeEnd + 1;
2317
- }
2318
- }
2319
- return elements;
2320
- }
2321
- function findScriptJsonById(html, id2) {
2322
- let pos = 0;
2323
- const len = html.length;
2324
- while (pos < len) {
2325
- if (html.startsWith("<!--", pos)) {
2326
- const commentEnd = html.indexOf("-->", pos + 4);
2327
- if (commentEnd === -1) break;
2328
- pos = commentEnd + 3;
2329
- continue;
2330
- }
2331
- const scriptMatch = matchOpenTag(html, pos, "script");
2332
- if (scriptMatch === null) {
2333
- pos++;
2334
- continue;
2335
- }
2336
- const typeAttr = extractAttribute(scriptMatch.tagContent, "type");
2337
- const idAttr = extractAttribute(scriptMatch.tagContent, "id");
2338
- if (typeAttr?.toLowerCase() === "application/json" && idAttr === id2) {
2339
- const contentStart = scriptMatch.end;
2340
- const scriptCloseIdx = findCloseTag(html, contentStart, "script");
2341
- if (scriptCloseIdx === -1) return null;
2342
- return html.slice(contentStart, scriptCloseIdx);
2343
- }
2344
- pos = scriptMatch.end;
2345
- }
2346
- return null;
2347
- }
2348
- function matchOpenTag(html, pos, tagName) {
2349
- if (html[pos] !== "<") return null;
2350
- const nameStart = pos + 1;
2351
- const nameEnd = nameStart + tagName.length;
2352
- if (nameEnd > html.length) return null;
2353
- const slice2 = html.slice(nameStart, nameEnd);
2354
- if (slice2.toLowerCase() !== tagName.toLowerCase()) return null;
2355
- const charAfter = html[nameEnd];
2356
- if (charAfter !== ">" && charAfter !== " " && charAfter !== " " && charAfter !== "\n" && charAfter !== "\r" && charAfter !== "/") {
2357
- return null;
2358
- }
2359
- let i = nameEnd;
2360
- let inSingleQuote = false;
2361
- let inDoubleQuote = false;
2362
- while (i < html.length) {
2363
- const ch = html[i];
2364
- if (inSingleQuote) {
2365
- if (ch === "'") inSingleQuote = false;
2366
- } else if (inDoubleQuote) {
2367
- if (ch === '"') inDoubleQuote = false;
2368
- } else if (ch === "'") {
2369
- inSingleQuote = true;
2370
- } else if (ch === '"') {
2371
- inDoubleQuote = true;
2372
- } else if (ch === ">") {
2373
- return {
2374
- start: pos,
2375
- end: i + 1,
2376
- tagContent: html.slice(nameEnd, i)
2377
- };
2378
- }
2379
- i++;
2380
- }
2381
- return null;
2382
- }
2383
- function findCloseTag(html, startPos, tagName) {
2384
- const pattern = "</" + tagName;
2385
- const patternLower = pattern.toLowerCase();
2386
- const htmlLower = html.toLowerCase();
2387
- let pos = startPos;
2388
- while (pos < html.length) {
2389
- const idx = htmlLower.indexOf(patternLower, pos);
2390
- if (idx === -1) return -1;
2391
- const afterIdx = idx + pattern.length;
2392
- if (afterIdx < html.length) {
2393
- const ch = html[afterIdx];
2394
- if (ch === ">" || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
2395
- return idx;
2991
+ const isArray2 = items !== void 0 || (typeHint?.split("|").includes("array") ?? false);
2992
+ if (isArray2) {
2993
+ const itemNodes = items !== void 0 ? derefSchemaNodes(items, defs) : [];
2994
+ paths.push(withHint({ path: `${path}.*`, kind: "list", fromSchema: true }, schemaTypeHint(itemNodes)));
2995
+ paths.push({ path: `${path}.length`, kind: "data", typeHint: "number", fromSchema: true });
2996
+ if (depth >= MAX_OBJECT_NEST_DEPTH) return;
2997
+ const seen = /* @__PURE__ */ new Set();
2998
+ for (const n of itemNodes) {
2999
+ for (const [childKey, childNode] of Object.entries(n.properties ?? {})) {
3000
+ if (seen.has(childKey)) continue;
3001
+ seen.add(childKey);
3002
+ pushSchemaValuePaths(`${path}.*.${childKey}`, childNode, paths, defs, depth + 1);
2396
3003
  }
2397
3004
  }
2398
- pos = idx + 1;
3005
+ return;
2399
3006
  }
2400
- return -1;
2401
- }
2402
- function parseAttributeNames(tagContent) {
2403
- const names = /* @__PURE__ */ new Set();
2404
- const attribute = /([^\s"'<>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'<>`=]+))?/g;
2405
- let match;
2406
- while ((match = attribute.exec(tagContent)) !== null) {
2407
- names.add(match[1].toLowerCase());
3007
+ if (nodes.some((n) => n.properties !== void 0)) {
3008
+ collectSchemaObjectPaths(node, path, paths, defs, depth + 1);
2408
3009
  }
2409
- return names;
2410
3010
  }
2411
- function extractAttribute(tagContent, attrName) {
2412
- const regex = new RegExp(
2413
- `(?:^|\\s)${attrName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|(\\S+))`,
2414
- "i"
2415
- );
2416
- const match = tagContent.match(regex);
2417
- if (!match) return null;
2418
- return match[1] ?? match[2] ?? match[3] ?? null;
3011
+ function withHint(candidate, typeHint) {
3012
+ return typeHint === void 0 ? candidate : { ...candidate, typeHint };
2419
3013
  }
2420
3014
 
2421
3015
  // src/service/statePathResolver.ts
2422
3016
  function getStatePathsFromHtml(html, stateTagName = "wcs-state", fileReader) {
2423
3017
  const elements = parseWcsStateElements(html, stateTagName);
2424
3018
  const allPaths = [];
3019
+ const mountPoints = /* @__PURE__ */ new Set();
2425
3020
  for (const element of elements) {
2426
- const paths = resolveElementPaths(element, html, fileReader);
3021
+ const paths = resolveElementPaths(element, html, mountPoints, fileReader);
2427
3022
  allPaths.push(...paths);
2428
3023
  }
2429
3024
  return allPaths;
2430
3025
  }
2431
- function resolveElementPaths(element, html, fileReader) {
3026
+ function resolveElementPaths(element, html, mountPoints, fileReader) {
2432
3027
  const raw = resolveElementPathsRaw(element, html, fileReader);
2433
3028
  if (element.mountPath === null) return raw;
2434
3029
  const prefix = element.mountPath + ".";
@@ -2438,6 +3033,15 @@ function resolveElementPaths(element, html, fileReader) {
2438
3033
  if (p.kind === "method" || p.kind === "eventToken") continue;
2439
3034
  out.push({ ...p, path: prefix + p.path });
2440
3035
  }
3036
+ if (out.length > 0) {
3037
+ const segments = element.mountPath.split(".");
3038
+ for (let i = 1; i <= segments.length; i++) {
3039
+ const path = segments.slice(0, i).join(".");
3040
+ if (mountPoints.has(path)) continue;
3041
+ mountPoints.add(path);
3042
+ out.push({ path, kind: "data", typeHint: "object" });
3043
+ }
3044
+ }
2441
3045
  return out;
2442
3046
  }
2443
3047
  function resolveElementPathsRaw(element, html, fileReader) {
@@ -2549,7 +3153,7 @@ function countWildcardSegments(path) {
2549
3153
  }
2550
3154
  function forPathOf(raw) {
2551
3155
  let path = raw.trim();
2552
- const pipe = path.indexOf("|");
3156
+ const pipe = indexOfOutsideQuotes2(path, "|");
2553
3157
  if (pipe !== -1) path = path.slice(0, pipe).trim();
2554
3158
  const at2 = path.indexOf("@");
2555
3159
  if (at2 !== -1) path = path.slice(0, at2).trim();
@@ -2680,7 +3284,10 @@ var ja = {
2680
3284
  arrayIndexAssign: (sp) => `\u914D\u5217\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9\u3078\u306E\u76F4\u63A5\u4EE3\u5165\u306F\u30EA\u30A2\u30AF\u30C6\u30A3\u30D6\u66F4\u65B0\u3092\u30C8\u30EA\u30AC\u30FC\u3057\u307E\u305B\u3093\u3002this["${sp}"] \u306E\u3088\u3046\u306A\u30C9\u30C3\u30C8\u30D1\u30B9\u4EE3\u5165\u3001\u307E\u305F\u306F with() \u3068\u518D\u4EE3\u5165\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002`,
2681
3285
  tagMemberUnknown: (prop, tag) => `"${prop}" \u306F <${tag}> \u306E wcBindable \u30E1\u30F3\u30D0\u30FC\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u672A\u77E5\u30E1\u30F3\u30D0\u30FC\u3078\u306E\u30D0\u30A4\u30F3\u30C9\u306F\u9ED9\u3063\u3066\u7121\u8996\u3055\u308C\u307E\u3059\uFF09`,
2682
3286
  nameAlias: (written, canonical) => `"${written}" \u306F "${canonical}" \u306E\u65E7\u540D\u3067\u3059\u30023.x \u306E\u9593\u306F\u52D5\u304D\u307E\u3059\u304C 4.0 \u3067\u5916\u308C\u308B\u306E\u3067\u3001"${canonical}" \u3068\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08@wcstack/state 3.2\uFF09`,
2683
- onPrefixedMember: (member, tag) => `"${member}" \u306F <${tag}> \u306E\u30E1\u30F3\u30D0\u30FC\u3067\u3059\u304C\u3001"on" \u3067\u59CB\u307E\u308B\u540D\u524D\u306F\u30A4\u30D9\u30F3\u30C8\u675F\u7E1B\u306B\u306A\u308A\uFF08"${member.slice(2)}" \u30A4\u30D9\u30F3\u30C8\u3092\u5F85\u3064\uFF09\u3001\u5024\u306F\u5C4A\u304D\u307E\u305B\u3093\u3002\u30D7\u30ED\u30D1\u30C6\u30A3\u3068\u3057\u3066\u675F\u7E1B\u3059\u308B\u306B\u306F ".${member}:" \u3068\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08@wcstack/state 3.1\uFF09`,
3287
+ declarationAliasRead: (alias, canonical) => `"${alias}" \u306E\u8AAD\u307F\u51FA\u3057\u306F 3.x \u3067\u3082\u52D5\u304D\u307E\u305B\u3093\u3002"${alias}" \u306F "${canonical}" \u306E\u65E7\u540D\u3067\u3001\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u8AAD\u307F\u8FBC\u307F\u6642\u306B "${canonical}" \u3078\u5199\u3057\u3001\u65E7\u540D\u306E\u81EA\u524D\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u524A\u9664\u3059\u308B\u305F\u3081\u3001this["${alias}"] \u306F undefined \u306B\u306A\u308A\u307E\u3059\u3002"${canonical}" \u3092\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044\uFF08@wcstack/state 3.2\uFF09`,
3288
+ declarationAliasReadUncertain: (alias, canonical) => `"${alias}" \u306E\u8AAD\u307F\u51FA\u3057\u306F\u65E7\u540D\u306E\u307E\u307E\u306B\u3067\u304D\u307E\u305B\u3093\u3002"${alias}" \u306F "${canonical}" \u306E\u65E7\u540D\u3067\u3001\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u8AAD\u307F\u8FBC\u307F\u6642\u306B "${canonical}" \u3078\u5199\u3057\u307E\u3059\u3002\u65E7\u540D\u304C\u81EA\u524D\u30D7\u30ED\u30D1\u30C6\u30A3\u306A\u3089\u524A\u9664\u3055\u308C\u308B\u306E\u3067 this["${alias}"] \u306F undefined \u306B\u306A\u308A\u3001class \u306E\u30D7\u30ED\u30C8\u30BF\u30A4\u30D7\u306B\u7F6E\u3044\u305F\u30E1\u30BD\u30C3\u30C9 / \u30A2\u30AF\u30BB\u30B5\u306A\u3089\u4ECA\u306F\u8AAD\u3081\u307E\u3059\u304C 4.0 \u3067\u5916\u308C\u307E\u3059\u3002\u3069\u3061\u3089\u306E\u5F62\u3067\u3082 "${canonical}" \u3092\u8AAD\u3093\u3067\u304F\u3060\u3055\u3044\uFF08@wcstack/state 3.2\uFF09`,
3289
+ declarationAlias: (alias, canonical) => `\u3053\u306E state \u306F "${alias}" \u3068 "${canonical}" \u3092\u4E21\u65B9\u5BA3\u8A00\u3057\u3066\u3044\u307E\u3059\u3002"${alias}" \u306F "${canonical}" \u306E\u65E7\u540D\uFF083.x \u306E\u9593\u306F\u52D5\u304D\u307E\u3059\uFF09\u306A\u306E\u3067\u3001"${canonical}" \u3060\u3051\u3092\u6B8B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u8AAD\u307F\u8FBC\u307F\u6642\u306B throw \u3057\u307E\u3059\uFF09`,
3290
+ onPrefixedMember: (member, tag, modifiers) => `"${member}" \u306F <${tag}> \u306E\u30E1\u30F3\u30D0\u30FC\u3067\u3059\u304C\u3001"on" \u3067\u59CB\u307E\u308B\u540D\u524D\u306F\u30A4\u30D9\u30F3\u30C8\u675F\u7E1B\u306B\u306A\u308A\uFF08"${member.slice(2)}" \u30A4\u30D9\u30F3\u30C8\u3092\u5F85\u3064\uFF09\u3001\u5024\u306F\u5C4A\u304D\u307E\u305B\u3093\u3002\u30D7\u30ED\u30D1\u30C6\u30A3\u3068\u3057\u3066\u675F\u7E1B\u3059\u308B\u306B\u306F ".${member}${modifiers ? `#${modifiers}` : ""}:" \u3068\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\uFF08@wcstack/state 3.1\uFF09`,
2684
3291
  tagCommandUnknown: (name, tag, declared) => `"${name}" \u306F <${tag}> \u306E command \u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u5BA3\u8A00\u6E08\u307F: ${declared}\uFF09`,
2685
3292
  spreadNoBindable: (tag) => `'...'\uFF08spread\uFF09\u306F <${tag}> \u306B\u6709\u52B9\u306A wcBindable \u5BA3\u8A00\u304C\u5FC5\u8981\u3067\u3059 \u2014 \u3053\u306E\u30BF\u30B0\u306F\u5BA3\u8A00\u3092\u6301\u305F\u306A\u3044\u305F\u3081\u3001\u30E9\u30F3\u30BF\u30A4\u30E0\u306F\u30A8\u30E9\u30FC\u3092\u9001\u51FA\u3057\u307E\u3059`,
2686
3293
  tagEventTokenKeyUnknown: (name, tag, declared) => `eventToken \u306E\u30AD\u30FC "${name}" \u306F <${tag}> \u306E wcBindable \u30D7\u30ED\u30D1\u30C6\u30A3\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u751F DOM \u30A4\u30D9\u30F3\u30C8\u540D\u306F\u767A\u706B\u3057\u307E\u305B\u3093 \u2014 \u30D7\u30ED\u30D1\u30C6\u30A3\u540D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u5BA3\u8A00\u6E08\u307F: ${declared}\uFF09`,
@@ -2718,6 +3325,8 @@ var ja = {
2718
3325
  return `this["${p}"] \u3078\u306E\u4EE3\u5165\u306B "**" \u306F\u4F7F\u3048\u307E\u305B\u3093\uFF08\u518D\u5E30 setter \u306F\u521D\u7248\u3067\u306F\u6301\u3066\u305A\u3001\u4EE3\u5165\u306F\u5C55\u958B\u5F8C\u306E\u5177\u4F53\u30D1\u30B9\u306B\u3057\u304B\u6210\u7ACB\u3057\u307E\u305B\u3093\uFF09\u3002$setAll("${p}", [], value) \u3067\u5168\u6DF1\u3055\u3078\u30D6\u30ED\u30FC\u30C9\u30AD\u30E3\u30B9\u30C8\u3059\u308B\u304B\u3001\u5177\u4F53\u30D1\u30B9\u3078\u66F8\u3044\u3066\u304F\u3060\u3055\u3044`;
2719
3326
  case "postUpdate":
2720
3327
  return `$postUpdate("${p}") \u306B "**" \u306F\u6E21\u305B\u307E\u305B\u3093\u3002\u901A\u77E5\u306F\u5C55\u958B\u5F8C\u306E\u5177\u4F53\u30D1\u30B9\uFF08\u56FA\u5B9A\u672C\u6570\u306E "*"\uFF09\u306B\u5BFE\u3057\u3066\u306E\u307F\u6210\u7ACB\u3057\u307E\u3059`;
3328
+ case "dependOn":
3329
+ return `$dependOn("${p}") \u306B "**" \u306F\u6E21\u305B\u307E\u305B\u3093\u3002\u4F9D\u5B58\u306E\u767B\u9332\u306F\u5C55\u958B\u5F8C\u306E\u5177\u4F53\u30D1\u30B9\uFF08\u56FA\u5B9A\u672C\u6570\u306E "*"\uFF09\u306B\u5BFE\u3057\u3066\u306E\u307F\u6210\u7ACB\u3057\u307E\u3059`;
2721
3330
  case "trackDependency":
2722
3331
  return `$trackDependency("${p}") \u306B "**" \u306F\u6E21\u305B\u307E\u305B\u3093\u3002\u4F9D\u5B58\u306E\u767B\u9332\u306F\u5C55\u958B\u5F8C\u306E\u5177\u4F53\u30D1\u30B9\uFF08\u56FA\u5B9A\u672C\u6570\u306E "*"\uFF09\u306B\u5BFE\u3057\u3066\u306E\u307F\u6210\u7ACB\u3057\u307E\u3059`;
2723
3332
  case "listKeys":
@@ -2871,7 +3480,10 @@ var en = {
2871
3480
  arrayIndexAssign: (sp) => `Assigning directly to an array index does not trigger a reactive update. Use a dot-path assignment like this["${sp}"], or with() plus reassignment.`,
2872
3481
  tagMemberUnknown: (prop, tag) => `"${prop}" is not a wcBindable member of <${tag}> (bindings to unknown members are silently ignored)`,
2873
3482
  nameAlias: (written, canonical) => `"${written}" is the old name of "${canonical}". It works through 3.x and goes in 4.0 \u2014 write "${canonical}" (@wcstack/state 3.2)`,
2874
- onPrefixedMember: (member, tag) => `"${member}" is a member of <${tag}>, but a name starting with "on" makes an event binding (it listens for a "${member.slice(2)}" event) and the value never arrives. Write ".${member}:" to bind the property (@wcstack/state 3.1)`,
3483
+ declarationAliasRead: (alias, canonical) => `Reading "${alias}" does not work, not even in 3.x. "${alias}" is the old name of "${canonical}": the runtime maps it to "${canonical}" at load time and deletes the old own property, so this["${alias}"] is undefined. Read "${canonical}" instead (@wcstack/state 3.2)`,
3484
+ declarationAliasReadUncertain: (alias, canonical) => `Reading "${alias}" cannot stay on the old name. "${alias}" is the old name of "${canonical}": the runtime maps it to "${canonical}" at load time. If the old name is an own property it is deleted, so this["${alias}"] is undefined; if it sits on a class prototype (a method or accessor) it still reads today but goes in 4.0. Either way, read "${canonical}" (@wcstack/state 3.2)`,
3485
+ declarationAlias: (alias, canonical) => `The state declares both "${alias}" and "${canonical}". "${alias}" is the old name of "${canonical}" (it works through 3.x) \u2014 keep "${canonical}" (the runtime throws at load time)`,
3486
+ onPrefixedMember: (member, tag, modifiers) => `"${member}" is a member of <${tag}>, but a name starting with "on" makes an event binding (it listens for a "${member.slice(2)}" event) and the value never arrives. Write ".${member}${modifiers ? `#${modifiers}` : ""}:" to bind the property (@wcstack/state 3.1)`,
2875
3487
  tagCommandUnknown: (name, tag, declared) => `"${name}" is not a command of <${tag}> (declared: ${declared})`,
2876
3488
  spreadNoBindable: (tag) => `'...' (spread) requires <${tag}> to expose a valid wcBindable declaration \u2014 this tag declares none, so the runtime raises an error`,
2877
3489
  tagEventTokenKeyUnknown: (name, tag, declared) => `eventToken key "${name}" is not a wcBindable property of <${tag}>. Raw DOM event names never fire \u2014 use the property name (declared: ${declared})`,
@@ -2909,6 +3521,8 @@ var en = {
2909
3521
  return `this["${p}"] = \u2026 cannot use "**" (there are no recursive setters in this version; an assignment only resolves against an expanded concrete path). Broadcast with $setAll("${p}", [], value), or write a concrete path`;
2910
3522
  case "postUpdate":
2911
3523
  return `$postUpdate("${p}") cannot take "**" \u2014 a notification is defined against a concrete path (a fixed number of "*")`;
3524
+ case "dependOn":
3525
+ return `$dependOn("${p}") cannot take "**" \u2014 a dependency is registered against a concrete path (a fixed number of "*")`;
2912
3526
  case "trackDependency":
2913
3527
  return `$trackDependency("${p}") cannot take "**" \u2014 a dependency is registered against a concrete path (a fixed number of "*")`;
2914
3528
  case "listKeys":
@@ -3202,9 +3816,9 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
3202
3816
  if (nonEmptyCount > 1) {
3203
3817
  let scanPos = 0;
3204
3818
  for (const b of bindings) {
3205
- const colon = b.indexOf(":");
3819
+ const colon = indexOfOutsideQuotes2(b, ":");
3206
3820
  const prop = (colon === -1 ? b : b.slice(0, colon)).trim();
3207
- if (STRUCTURAL_BINDING_TYPE_SET.has(prop)) {
3821
+ if (STRUCTURAL_BINDING_TYPE_SET2.has(prop)) {
3208
3822
  const leading = b.length - b.trimStart().length;
3209
3823
  diagnostics.push({
3210
3824
  code: WcsDiagnosticCode.TemplateSyntax,
@@ -3413,778 +4027,345 @@ function validateBindings(html, attrName, stateTagName = "wcs-state", locale2, f
3413
4027
  const pathTrimmed = parsed.path.trim();
3414
4028
  if (pathTrimmed && !pathTrimmed.startsWith(".") && !isLiteral(pathTrimmed)) {
3415
4029
  const chainDiags = validateFilterChainTypes(
3416
- pathTrimmed,
3417
- parsed.filters,
3418
- scopedPaths,
3419
- bindingStart,
3420
- msgs
3421
- );
3422
- diagnostics.push(...chainDiags);
3423
- }
3424
- }
3425
- }
3426
- for (const filter of parsed.inputFilters) {
3427
- diagnostics.push(...validateFilterUsage(filter, bindingStart, msgs));
3428
- }
3429
- if (parsed.path && scopedPaths.length > 0) {
3430
- const pathTrimmed = parsed.path.trim();
3431
- if (pathTrimmed && !pathTrimmed.startsWith(".") && !isLiteral(pathTrimmed)) {
3432
- const resultType = resolveResultType(pathTrimmed, parsed.filters, scopedPaths);
3433
- if (resultType !== null) {
3434
- const typeReq = getExpectedType(
3435
- parsed.property,
3436
- () => isNegatedByElseChain(getStructuralTemplates(), attr.valueStart)
3437
- );
3438
- if (typeReq && resultType !== typeReq.expected) {
3439
- const pathOffset = binding.indexOf(parsed.path);
3440
- const pathStart = bindingStart + pathOffset;
3441
- const schemaDefinite = typeReq.expected === "array" && parsed.filters.length === 0 && applicationSchema !== void 0 && scopedPaths.some((p) => p.path === pathTrimmed && p.fromSchema === true);
3442
- diagnostics.push({
3443
- code: schemaDefinite ? WcsDiagnosticCode.PathTypeMismatch : WcsDiagnosticCode.BindingTypeExpectation,
3444
- start: pathStart,
3445
- end: pathStart + pathTrimmed.length,
3446
- message: schemaDefinite ? msgs.pathTypeMismatch(pathTrimmed, typeReq.label, typeReq.expected, resultType) : msgs.typeExpectation(typeReq.label, typeReq.expected, resultType),
3447
- severity: schemaDefinite ? "error" : typeReq.severity
3448
- });
3449
- }
3450
- }
3451
- }
3452
- }
3453
- pos += binding.length + 1;
3454
- }
3455
- }
3456
- return diagnostics;
3457
- }
3458
- function findAllBindAttributes(html, attrName) {
3459
- const attrs = [];
3460
- const escaped = attrName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3461
- const regex = new RegExp(`${escaped}\\s*=\\s*(["'])`, "gi");
3462
- let match;
3463
- while ((match = regex.exec(html)) !== null) {
3464
- const quote = match[1];
3465
- const valueStart = match.index + match[0].length;
3466
- const valueEnd = html.indexOf(quote, valueStart);
3467
- if (valueEnd === -1) continue;
3468
- attrs.push({
3469
- value: html.slice(valueStart, valueEnd),
3470
- valueStart
3471
- });
3472
- }
3473
- return attrs;
3474
- }
3475
- function splitBindingExpressions(value) {
3476
- const result = [];
3477
- let current2 = "";
3478
- let parenDepth = 0;
3479
- for (const ch of value) {
3480
- if (ch === "(") parenDepth++;
3481
- else if (ch === ")") parenDepth = Math.max(0, parenDepth - 1);
3482
- else if (ch === ";" && parenDepth === 0) {
3483
- result.push(current2);
3484
- current2 = "";
3485
- continue;
3486
- }
3487
- current2 += ch;
3488
- }
3489
- result.push(current2);
3490
- return result;
3491
- }
3492
- function parseBindingExpression(expr) {
3493
- const colonIndex = expr.indexOf(":");
3494
- if (colonIndex === -1) {
3495
- return { property: expr.trim(), path: null, filters: [], inputFilters: [] };
3496
- }
3497
- const rawProp = expr.slice(0, colonIndex);
3498
- const propSegments = splitByPipe(rawProp);
3499
- const property = propSegments[0].trim();
3500
- const inputFilters = parseFilterSegments(expr, propSegments.slice(1), propSegments[0].length + 1);
3501
- const afterColon = expr.slice(colonIndex + 1);
3502
- const segments = splitByPipe(afterColon);
3503
- const pathSegment = segments[0] || "";
3504
- const filterSegments = segments.slice(1);
3505
- const atIndex = pathSegment.indexOf("@");
3506
- const path = atIndex !== -1 ? pathSegment.slice(0, atIndex) : pathSegment;
3507
- const filters = parseFilterSegments(expr, filterSegments, colonIndex + 1 + pathSegment.length + 1);
3508
- return { property, path: path.trim() || null, filters, inputFilters };
3509
- }
3510
- function parseFilterSegments(expr, segments, searchStart) {
3511
- const filters = [];
3512
- let filterSearchStart = searchStart;
3513
- for (const seg of segments) {
3514
- const trimmed = seg.trim();
3515
- const filterMatch = trimmed.match(/^(\w+)(?:\(([^)]*)\))?/);
3516
- if (filterMatch) {
3517
- const nameOffset = expr.indexOf(trimmed, filterSearchStart);
3518
- const args = filterMatch[2] !== void 0 ? filterMatch[2].split(",").map((a) => a.trim()).filter((a) => a !== "") : [];
3519
- filters.push({
3520
- name: filterMatch[1],
3521
- offset: nameOffset >= 0 ? nameOffset : filterSearchStart,
3522
- args,
3523
- argsOffset: nameOffset >= 0 ? nameOffset + filterMatch[1].length : filterSearchStart
3524
- });
3525
- }
3526
- filterSearchStart += seg.length + 1;
3527
- }
3528
- return filters;
3529
- }
3530
- function validateFilterUsage(filter, bindingStart, msgs) {
3531
- const diagnostics = [];
3532
- const canonical = canonicalFilterName(filter.name);
3533
- const info = filterMap.get(canonical);
3534
- if (info && canonical !== filter.name) {
3535
- diagnostics.push({
3536
- code: WcsDiagnosticCode.NameAlias,
3537
- start: bindingStart + filter.offset,
3538
- end: bindingStart + filter.offset + filter.name.length,
3539
- message: msgs.nameAlias(filter.name, canonical),
3540
- severity: "info"
3541
- });
3542
- }
3543
- if (!info) {
3544
- diagnostics.push({
3545
- code: WcsDiagnosticCode.FilterUnknown,
3546
- start: bindingStart + filter.offset,
3547
- end: bindingStart + filter.offset + filter.name.length,
3548
- message: msgs.filterUnknown(filter.name),
3549
- severity: "warning"
3550
- });
3551
- return diagnostics;
3552
- }
3553
- const argCount = filter.args.length;
3554
- if (argCount < info.minArgs) {
3555
- diagnostics.push({
3556
- code: WcsDiagnosticCode.FilterArity,
3557
- start: bindingStart + filter.offset,
3558
- end: bindingStart + filter.offset + filter.name.length,
3559
- message: msgs.filterMinArgs(filter.name, info.minArgs, argCount),
3560
- severity: "error"
3561
- });
3562
- } else if (argCount > info.maxArgs) {
3563
- diagnostics.push({
3564
- code: WcsDiagnosticCode.FilterArity,
3565
- start: bindingStart + filter.offset,
3566
- end: bindingStart + filter.offset + filter.name.length,
3567
- message: msgs.filterMaxArgs(filter.name, info.maxArgs, argCount),
3568
- severity: "error"
3569
- });
3570
- }
3571
- if (info.argTypes && argCount > 0) {
3572
- for (let i = 0; i < Math.min(argCount, info.argTypes.length); i++) {
3573
- const expectedArgType = info.argTypes[i];
3574
- if (expectedArgType === "any") continue;
3575
- const actualArgType = inferArgType(filter.args[i]);
3576
- if (actualArgType !== expectedArgType) {
3577
- diagnostics.push({
3578
- code: WcsDiagnosticCode.FilterArgType,
3579
- start: bindingStart + filter.argsOffset,
3580
- end: bindingStart + filter.argsOffset + filter.name.length,
3581
- message: msgs.filterArgType(filter.name, i + 1, expectedArgType, filter.args[i], actualArgType),
3582
- severity: "warning"
3583
- });
3584
- }
3585
- }
3586
- }
3587
- return diagnostics;
3588
- }
3589
- function splitByPipe(value) {
3590
- const result = [];
3591
- let current2 = "";
3592
- let parenDepth = 0;
3593
- for (const ch of value) {
3594
- if (ch === "(") parenDepth++;
3595
- else if (ch === ")") parenDepth = Math.max(0, parenDepth - 1);
3596
- else if (ch === "|" && parenDepth === 0) {
3597
- result.push(current2);
3598
- current2 = "";
3599
- continue;
3600
- }
3601
- current2 += ch;
3602
- }
3603
- result.push(current2);
3604
- return result;
3605
- }
3606
- function validatePathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, msgs) {
3607
- if (/^\$\d+$/.test(checkPath)) return null;
3608
- if (checkPath.startsWith("$command.")) {
3609
- if (commandNames.size > 0 && !commandNames.has(checkPath)) {
3610
- return msgs.commandTokenUndeclared(displayPath);
3611
- }
3612
- return null;
3613
- }
3614
- if (checkPath.startsWith("$streamStatus.") || checkPath.startsWith("$streamError.")) {
3615
- const prefix = checkPath.startsWith("$streamStatus.") ? "$streamStatus." : "$streamError.";
3616
- const hasNamespace = scopedPaths.some((p) => p.path.startsWith(prefix));
3617
- if (hasNamespace && !scopedPathSet.has(checkPath)) {
3618
- return msgs.streamPathMissing(displayPath);
3619
- }
3620
- return null;
3621
- }
3622
- if (!scopedPathSet.has(checkPath) && !matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet)) {
3623
- return msgs.pathMissing(displayPath);
3624
- }
3625
- return null;
3626
- }
3627
- function matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet) {
3628
- const specs = collectRecursionSpecs(scopedPaths);
3629
- if (specs.length === 0) return false;
3630
- return matchesRecursion(specs, checkPath, (candidate) => scopedPathSet.has(candidate));
3631
- }
3632
- function toMissingVerdict(message) {
3633
- return message ? { code: WcsDiagnosticCode.BindingPathMissing, message, severity: "warning" } : null;
3634
- }
3635
- function validateSchemaPathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, schema, msgs) {
3636
- if (checkPath.startsWith("$")) {
3637
- return toMissingVerdict(validatePathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, msgs));
3638
- }
3639
- if (scopedPathSet.has(checkPath)) return null;
3640
- if (matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet)) return null;
3641
- const resolution = resolveSchemaPath(schema, schema.$defs ?? {}, checkPath.split("."));
3642
- if (resolution.kind === "nonexistent") {
3643
- return { code: WcsDiagnosticCode.PathNonexistent, message: msgs.pathNonexistent(displayPath), severity: "error" };
3644
- }
3645
- return null;
3646
- }
3647
- function collectStructuralTemplates(html, attrName) {
3648
- const escaped = attrName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3649
- const attrRegex = new RegExp(`${escaped}\\s*=\\s*(["'])`, "i");
3650
- const tagRegex = /<template(?:\s[^>]*)?>|<\/template\s*>/gi;
3651
- const templates = [];
3652
- let depth = 0;
3653
- let match;
3654
- while ((match = tagRegex.exec(html)) !== null) {
3655
- if (match[0].startsWith("</")) {
3656
- depth = Math.max(0, depth - 1);
3657
- continue;
3658
- }
3659
- const attrMatch = attrRegex.exec(match[0]);
3660
- if (attrMatch) {
3661
- const quote = attrMatch[1];
3662
- const valueStart = match.index + attrMatch.index + attrMatch[0].length;
3663
- const valueEnd = html.indexOf(quote, valueStart);
3664
- if (valueEnd !== -1) {
3665
- const first = splitBindingExpressions(html.slice(valueStart, valueEnd))[0] ?? "";
3666
- const prop = first.split(":")[0].replace(/#.*$/, "").trim();
3667
- const type = prop === "if" || prop === "elseif" || prop === "else" ? prop : "other";
3668
- templates.push({ valueStart, depth, type });
4030
+ pathTrimmed,
4031
+ parsed.filters,
4032
+ scopedPaths,
4033
+ bindingStart,
4034
+ msgs
4035
+ );
4036
+ diagnostics.push(...chainDiags);
4037
+ }
4038
+ }
3669
4039
  }
3670
- }
3671
- depth++;
3672
- }
3673
- return templates;
3674
- }
3675
- function isNegatedByElseChain(templates, valueStart) {
3676
- const index = templates.findIndex((t) => t.valueStart === valueStart);
3677
- if (index === -1) return false;
3678
- const selfDepth = templates[index].depth;
3679
- for (let i = index + 1; i < templates.length; i++) {
3680
- const next = templates[i];
3681
- if (next.depth > selfDepth) continue;
3682
- if (next.depth < selfDepth) return false;
3683
- if (next.type === "elseif" || next.type === "else") return true;
3684
- if (next.type === "if") return false;
3685
- }
3686
- return false;
3687
- }
3688
- function getExpectedType(property, isNegatedIf) {
3689
- const prop = property.replace(/#.*$/, "");
3690
- if (prop === "for") {
3691
- return { label: "for", expected: "array", severity: "error" };
3692
- }
3693
- if (prop === "if" || prop === "elseif") {
3694
- if (!isNegatedIf()) return null;
3695
- return { label: prop, expected: "boolean", severity: "warning" };
3696
- }
3697
- if (prop.startsWith("class.")) {
3698
- return { label: prop, expected: "boolean", severity: "warning" };
3699
- }
3700
- if (prop.startsWith("attr.")) {
3701
- return { label: prop, expected: "string", severity: "warning" };
3702
- }
3703
- if (prop.startsWith("style.")) {
3704
- return { label: prop, expected: "string", severity: "warning" };
3705
- }
3706
- return null;
3707
- }
3708
- function validateFilterChainTypes(path, filters, statePaths, bindingStart, msgs) {
3709
- const diagnostics = [];
3710
- const pathInfo = statePaths.find((p) => p.path === path);
3711
- if (!pathInfo?.typeHint) return diagnostics;
3712
- let currentType = pathInfo.typeHint;
3713
- for (const filter of filters) {
3714
- const info = filterMap.get(filter.name);
3715
- if (!info) break;
3716
- if (info.acceptTypes !== "any") {
3717
- const currentTypes = currentType.split("|");
3718
- const hasMatch = currentTypes.some((t) => info.acceptTypes.includes(t));
3719
- if (!hasMatch) {
3720
- diagnostics.push({
3721
- code: WcsDiagnosticCode.FilterInputType,
3722
- start: bindingStart + filter.offset,
3723
- end: bindingStart + filter.offset + filter.name.length,
3724
- message: msgs.filterInputType(filter.name, info.acceptTypes.join("|"), currentType),
3725
- severity: "warning"
3726
- });
4040
+ for (const filter of parsed.inputFilters) {
4041
+ diagnostics.push(...validateFilterUsage(filter, bindingStart, msgs));
3727
4042
  }
3728
- }
3729
- if (info.resultType !== "passthrough") {
3730
- currentType = info.resultType;
4043
+ if (parsed.path && scopedPaths.length > 0) {
4044
+ const pathTrimmed = parsed.path.trim();
4045
+ if (pathTrimmed && !pathTrimmed.startsWith(".") && !isLiteral(pathTrimmed)) {
4046
+ const resultType = resolveResultType(pathTrimmed, parsed.filters, scopedPaths);
4047
+ if (resultType !== null) {
4048
+ const typeReq = getExpectedType(
4049
+ parsed.property,
4050
+ () => isNegatedByElseChain(getStructuralTemplates(), attr.valueStart)
4051
+ );
4052
+ if (typeReq && resultType !== typeReq.expected) {
4053
+ const pathOffset = binding.indexOf(parsed.path);
4054
+ const pathStart = bindingStart + pathOffset;
4055
+ const schemaDefinite = typeReq.expected === "array" && parsed.filters.length === 0 && applicationSchema !== void 0 && scopedPaths.some((p) => p.path === pathTrimmed && p.fromSchema === true);
4056
+ diagnostics.push({
4057
+ code: schemaDefinite ? WcsDiagnosticCode.PathTypeMismatch : WcsDiagnosticCode.BindingTypeExpectation,
4058
+ start: pathStart,
4059
+ end: pathStart + pathTrimmed.length,
4060
+ message: schemaDefinite ? msgs.pathTypeMismatch(pathTrimmed, typeReq.label, typeReq.expected, resultType) : msgs.typeExpectation(typeReq.label, typeReq.expected, resultType),
4061
+ severity: schemaDefinite ? "error" : typeReq.severity
4062
+ });
4063
+ }
4064
+ }
4065
+ }
4066
+ }
4067
+ pos += binding.length + 1;
3731
4068
  }
3732
4069
  }
3733
4070
  return diagnostics;
3734
4071
  }
3735
- function resolveResultType(path, filters, statePaths) {
3736
- const pathInfo = statePaths.find((p) => p.path === path);
3737
- if (!pathInfo?.typeHint) return null;
3738
- let currentType = pathInfo.typeHint;
3739
- for (const filter of filters) {
3740
- const info = filterMap.get(filter.name);
3741
- if (!info) return null;
3742
- if (info.resultType === "passthrough") continue;
3743
- currentType = info.resultType;
4072
+ function findAllBindAttributes(html, attrName) {
4073
+ const attrs = [];
4074
+ const escaped = attrName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4075
+ const regex = new RegExp(`(?:^|[\\s/])${escaped}\\s*=\\s*(["'])`, "gi");
4076
+ for (const tag of findStartTagRegions(html)) {
4077
+ const attrsText = html.slice(tag.start, tag.end);
4078
+ regex.lastIndex = 0;
4079
+ let match;
4080
+ while ((match = regex.exec(attrsText)) !== null) {
4081
+ const quote = match[1];
4082
+ const valueStart = tag.start + match.index + match[0].length;
4083
+ const valueEnd = html.indexOf(quote, valueStart);
4084
+ if (valueEnd === -1 || valueEnd > tag.end) continue;
4085
+ attrs.push({ value: html.slice(valueStart, valueEnd), valueStart });
4086
+ regex.lastIndex = valueEnd - tag.start;
4087
+ }
3744
4088
  }
3745
- return currentType;
3746
- }
3747
- function inferArgType(arg) {
3748
- const v = arg.trim();
3749
- if (/^-?\d+(\.\d+)?$/.test(v)) return "number";
3750
- return "string";
4089
+ return attrs;
3751
4090
  }
3752
- function isLiteral(value) {
3753
- return /^-?\d/.test(value) || /^["'`]/.test(value) || value === "true" || value === "false" || value === "null";
4091
+ function splitBindingExpressions(value) {
4092
+ return splitBindTexts(value);
3754
4093
  }
3755
-
3756
- // src/service/stateTypeValidator.ts
3757
- function validateStateTypes(html, stateTagName = "wcs-state", locale2) {
3758
- const msgs = getMessages(locale2);
3759
- const blocks = parseWcsScriptBlocks(html, stateTagName);
3760
- const diagnostics = [];
3761
- for (const block of blocks) {
3762
- const props = findJsDocTypedProperties(block.content);
3763
- for (const prop of props) {
3764
- if (!isValueCompatible(prop.declaredTypes, prop.valueType)) {
3765
- const absStart = block.contentStart + prop.valueOffset;
3766
- const absEnd = absStart + prop.valueLength;
3767
- diagnostics.push({
3768
- start: absStart,
3769
- end: absEnd,
3770
- message: msgs.typeAnnotationIncompatible(prop.valueType, prop.rawType),
3771
- severity: "warning"
3772
- });
3773
- }
3774
- }
4094
+ function parseBindingExpression(expr) {
4095
+ const colonIndex = indexOfOutsideQuotes2(expr, ":");
4096
+ if (colonIndex === -1) {
4097
+ return { property: expr.trim(), path: null, filters: [], inputFilters: [] };
3775
4098
  }
3776
- return diagnostics;
4099
+ const rawProp = expr.slice(0, colonIndex);
4100
+ const propSegments = splitByPipe(rawProp);
4101
+ const property = propSegments[0].trim();
4102
+ const inputFilters = parseFilterSegments(expr, propSegments.slice(1), propSegments[0].length + 1);
4103
+ const afterColon = expr.slice(colonIndex + 1);
4104
+ const segments = splitByPipe(afterColon);
4105
+ const pathSegment = segments[0] || "";
4106
+ const filterSegments = segments.slice(1);
4107
+ const atIndex = pathSegment.indexOf("@");
4108
+ const path = atIndex !== -1 ? pathSegment.slice(0, atIndex) : pathSegment;
4109
+ const filters = parseFilterSegments(expr, filterSegments, colonIndex + 1 + pathSegment.length + 1);
4110
+ return { property, path: path.trim() || null, filters, inputFilters };
3777
4111
  }
3778
- function findJsDocTypedProperties(script) {
3779
- const results = [];
3780
- const regex = /\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*(?:"([^"]+)"|'([^']+)'|(\w+))\s*:\s*/g;
3781
- let match;
3782
- while ((match = regex.exec(script)) !== null) {
3783
- const rawType = match[1].trim();
3784
- const name = match[2] ?? match[3] ?? match[4];
3785
- const valueStart = match.index + match[0].length;
3786
- const valueText = extractValue(script, valueStart);
3787
- const valueType = inferValueType(valueText);
3788
- if (valueType) {
3789
- const declaredTypes = rawType.split("|").map((t) => normalizeType(t.trim()));
3790
- results.push({
4112
+ function parseFilterSegments(expr, segments, searchStart) {
4113
+ const filters = [];
4114
+ let filterSearchStart = searchStart;
4115
+ for (const seg of segments) {
4116
+ const trimmed = seg.trim();
4117
+ const open = trimmed.indexOf("(");
4118
+ const close = trimmed.lastIndexOf(")");
4119
+ const namePart = open === -1 ? trimmed : trimmed.slice(0, open);
4120
+ const nameMatch = /^\w+/.exec(namePart.trim());
4121
+ if (nameMatch !== null) {
4122
+ const name = nameMatch[0];
4123
+ const nameOffset = expr.indexOf(trimmed, filterSearchStart);
4124
+ const args = open !== -1 && close > open ? parseFilterArgsText(trimmed.slice(open + 1, close)) : [];
4125
+ filters.push({
3791
4126
  name,
3792
- rawType,
3793
- declaredTypes,
3794
- valueType,
3795
- valueOffset: valueStart,
3796
- valueLength: valueText.length
4127
+ offset: nameOffset >= 0 ? nameOffset : filterSearchStart,
4128
+ args,
4129
+ argsOffset: nameOffset >= 0 ? nameOffset + name.length : filterSearchStart
3797
4130
  });
3798
4131
  }
4132
+ filterSearchStart += seg.length + 1;
3799
4133
  }
3800
- return results;
3801
- }
3802
- function extractValue(script, start) {
3803
- let depth = 0;
3804
- let inString = null;
3805
- let i = start;
3806
- while (i < script.length) {
3807
- const ch = script[i];
3808
- if (inString) {
3809
- if (ch === inString && script[i - 1] !== "\\") inString = null;
3810
- } else if (ch === '"' || ch === "'" || ch === "`") {
3811
- inString = ch;
3812
- } else if (ch === "{" || ch === "[" || ch === "(") {
3813
- depth++;
3814
- } else if (ch === "}" || ch === "]" || ch === ")") {
3815
- if (depth === 0) break;
3816
- depth--;
3817
- } else if ((ch === "," || ch === "\n") && depth === 0) {
3818
- break;
3819
- }
3820
- i++;
3821
- }
3822
- return script.slice(start, i).trim();
3823
- }
3824
- function inferValueType(value) {
3825
- const v = value.replace(/,\s*$/, "").trim();
3826
- if (v === "null") return "null";
3827
- if (v === "undefined") return "null";
3828
- if (v === "true" || v === "false") return "boolean";
3829
- if (/^-?\d+\.\d/.test(v)) return "number";
3830
- if (/^-?\d/.test(v)) return "number";
3831
- if (/^["'`]/.test(v)) return "string";
3832
- if (v.startsWith("[")) return "array";
3833
- if (v.startsWith("{")) return "object";
3834
- return null;
3835
- }
3836
- function normalizeType(type) {
3837
- const lower = type.toLowerCase();
3838
- if (lower === "null" || lower === "undefined") return "null";
3839
- if (lower === "string") return "string";
3840
- if (lower === "number") return "number";
3841
- if (lower === "boolean") return "boolean";
3842
- if (lower.endsWith("[]") || lower.startsWith("array")) return "array";
3843
- if (lower === "object") return "object";
3844
- return type;
3845
- }
3846
- function isValueCompatible(declaredTypes, valueType) {
3847
- return declaredTypes.includes(valueType);
3848
- }
3849
-
3850
- // src/service/scriptPatterns.ts
3851
- var ID = String.raw`[\w$]+`;
3852
- var SUB = String.raw`\s*(?:\?\.)?\s*\[(?!\s*["'])[^\[\]]+\]`;
3853
- var DOT_SEG = String.raw`\s*\??\.\s*${ID}`;
3854
- var CHAIN = String.raw`(?:${DOT_SEG}|${SUB})*`;
3855
- var BRACKETS_ONLY = String.raw`(?:${SUB})+`;
3856
- var CHAIN_ONE_PLUS = String.raw`(?:${DOT_SEG}|${SUB})+`;
3857
- var ROOT_DOT = String.raw`\bthis\s*\??\.\s*(${ID})`;
3858
- var ROOT_BRACKET = String.raw`\bthis\s*(?:\?\.)?\s*\[\s*["']([^"']+)["']\s*\]`;
3859
- var ASSIGN_TAIL = String.raw`\s*(?:(?:\*\*|<<|>>>|>>|&&|\|\||\?\?|[+\-*/%&|^])?=(?!=)|\+\+|--)`;
3860
- var PRE_INCDEC = String.raw`(?:\+\+|--)\s*`;
3861
- function chainToDotted(chain) {
3862
- const token = new RegExp(String.raw`\s*(?:\??\.\s*(${ID})|(?:\?\.)?\s*\[([^\[\]]+)\])`, "g");
3863
- let out = "";
3864
- let match;
3865
- while ((match = token.exec(chain)) !== null) {
3866
- if (match[1] !== void 0) {
3867
- out += `.${match[1]}`;
3868
- } else {
3869
- const key = match[2].trim();
3870
- out += /^\d+$/.test(key) ? `.${key}` : `.<${key}>`;
3871
- }
3872
- }
3873
- return out;
3874
- }
3875
- function hasDotSegment(chain) {
3876
- return /[.]/.test(chain.replace(/\s*(?:\?\.)?\s*\[[^\[\]]+\]/g, ""));
4134
+ return filters;
3877
4135
  }
3878
- function isApiRoot(root) {
3879
- return root.startsWith("$");
4136
+ function parseFilterArgsText(argsText) {
4137
+ const args = splitOutsideQuotes2(argsText, ",").map((a) => a.trim());
4138
+ if (args[args.length - 1] === "") args.pop();
4139
+ return args;
3880
4140
  }
3881
-
3882
- // src/service/nestedAssignValidator.ts
3883
- var NESTED_ASSIGN = new RegExp(`${ROOT_DOT}(${CHAIN_ONE_PLUS})${ASSIGN_TAIL}`, "g");
3884
- var PRE_NESTED_INCDEC = new RegExp(`${PRE_INCDEC}${ROOT_DOT}(${CHAIN_ONE_PLUS})`, "g");
3885
- function validateNestedAssigns(html, stateTagName = "wcs-state", locale2) {
3886
- const msgs = getMessages(locale2);
3887
- const blocks = parseWcsScriptBlocks(html, stateTagName);
4141
+ function validateFilterUsage(filter, bindingStart, msgs) {
3888
4142
  const diagnostics = [];
3889
- for (const block of blocks) {
3890
- findNestedAssigns(block.content, block.contentStart, msgs, diagnostics);
4143
+ const canonical = canonicalFilterName(filter.name);
4144
+ const info = filterMap.get(canonical);
4145
+ if (info && canonical !== filter.name) {
4146
+ diagnostics.push({
4147
+ code: WcsDiagnosticCode.NameAlias,
4148
+ start: bindingStart + filter.offset,
4149
+ end: bindingStart + filter.offset + filter.name.length,
4150
+ message: msgs.nameAlias(filter.name, canonical),
4151
+ severity: "info"
4152
+ });
3891
4153
  }
3892
- return diagnostics;
3893
- }
3894
- function findNestedAssigns(script, baseOffset, msgs, out) {
3895
- for (const regex of [NESTED_ASSIGN, PRE_NESTED_INCDEC]) {
3896
- regex.lastIndex = 0;
3897
- let match;
3898
- while ((match = regex.exec(script)) !== null) {
3899
- const [full, topProp, chainPart] = match;
3900
- if (isApiRoot(topProp)) continue;
3901
- if (!hasDotSegment(chainPart)) continue;
3902
- const suggestedPath = topProp + chainToDotted(chainPart);
3903
- const start = baseOffset + match.index;
3904
- out.push({
3905
- start,
3906
- end: start + full.length,
3907
- message: msgs.nestedAssign(suggestedPath),
3908
- severity: "error"
3909
- });
4154
+ if (!info) {
4155
+ diagnostics.push({
4156
+ code: WcsDiagnosticCode.FilterUnknown,
4157
+ start: bindingStart + filter.offset,
4158
+ end: bindingStart + filter.offset + filter.name.length,
4159
+ message: msgs.filterUnknown(filter.name),
4160
+ severity: "warning"
4161
+ });
4162
+ return diagnostics;
4163
+ }
4164
+ const argCount = filter.args.length;
4165
+ if (argCount < info.minArgs) {
4166
+ diagnostics.push({
4167
+ code: WcsDiagnosticCode.FilterArity,
4168
+ start: bindingStart + filter.offset,
4169
+ end: bindingStart + filter.offset + filter.name.length,
4170
+ message: msgs.filterMinArgs(filter.name, info.minArgs, argCount),
4171
+ severity: "error"
4172
+ });
4173
+ } else if (argCount > info.maxArgs) {
4174
+ diagnostics.push({
4175
+ code: WcsDiagnosticCode.FilterArity,
4176
+ start: bindingStart + filter.offset,
4177
+ end: bindingStart + filter.offset + filter.name.length,
4178
+ message: msgs.filterMaxArgs(filter.name, info.maxArgs, argCount),
4179
+ severity: "error"
4180
+ });
4181
+ }
4182
+ if (info.argTypes && argCount > 0) {
4183
+ for (let i = 0; i < Math.min(argCount, info.argTypes.length); i++) {
4184
+ const expectedArgType = info.argTypes[i];
4185
+ if (expectedArgType === "any") continue;
4186
+ const actualArgType = inferArgType(filter.args[i]);
4187
+ if (actualArgType !== expectedArgType) {
4188
+ diagnostics.push({
4189
+ code: WcsDiagnosticCode.FilterArgType,
4190
+ start: bindingStart + filter.argsOffset,
4191
+ end: bindingStart + filter.argsOffset + filter.name.length,
4192
+ message: msgs.filterArgType(filter.name, i + 1, expectedArgType, filter.args[i], actualArgType),
4193
+ severity: "warning"
4194
+ });
4195
+ }
3910
4196
  }
3911
4197
  }
4198
+ return diagnostics;
3912
4199
  }
3913
-
3914
- // src/service/arrayMutationValidator.ts
3915
- var DESTRUCTIVE_METHODS = "push|pop|shift|unshift|splice|sort|reverse|fill|copyWithin";
3916
- var ALTERNATIVES = {
3917
- push: (a) => `${a} = ${a}.concat(item)`,
3918
- unshift: (a) => `${a} = [item, ...${a}]`,
3919
- pop: (a) => `${a} = ${a}.slice(0, -1)`,
3920
- shift: (a) => `${a} = ${a}.slice(1)`,
3921
- splice: (a) => `${a} = ${a}.toSpliced(...)`,
3922
- sort: (a) => `${a} = ${a}.toSorted(...)`,
3923
- reverse: (a) => `${a} = ${a}.toReversed()`,
3924
- fill: (a) => `${a} = ${a}.map(...)`,
3925
- copyWithin: (a) => `${a} = ${a}.map(...)`
3926
- };
3927
- var METHOD_TAIL = String.raw`\s*\??\.\s*(${DESTRUCTIVE_METHODS})(?=\s*\()`;
3928
- var DOT_ROOT_CALL = new RegExp(`${ROOT_DOT}(${CHAIN})${METHOD_TAIL}`, "g");
3929
- var BRACKET_ROOT_CALL = new RegExp(`${ROOT_BRACKET}(${CHAIN})${METHOD_TAIL}`, "g");
3930
- var DOT_INDEX_ASSIGN = new RegExp(`${ROOT_DOT}(${BRACKETS_ONLY})${ASSIGN_TAIL}`, "g");
3931
- var BRACKET_INDEX_ASSIGN = new RegExp(`${ROOT_BRACKET}(${BRACKETS_ONLY})${ASSIGN_TAIL}`, "g");
3932
- var PRE_DOT_INDEX = new RegExp(`${PRE_INCDEC}${ROOT_DOT}(${BRACKETS_ONLY})`, "g");
3933
- var PRE_BRACKET_INDEX = new RegExp(`${PRE_INCDEC}${ROOT_BRACKET}(${BRACKETS_ONLY})`, "g");
3934
- function toAccessor(path) {
3935
- return /^[A-Za-z_]\w*$/.test(path) ? `this.${path}` : `this["${path}"]`;
4200
+ function splitByPipe(value) {
4201
+ return splitOutsideQuotes2(value, "|");
3936
4202
  }
3937
- function validateArrayMutations(html, stateTagName = "wcs-state", locale2) {
3938
- const msgs = getMessages(locale2);
3939
- const blocks = parseWcsScriptBlocks(html, stateTagName);
3940
- const diagnostics = [];
3941
- for (const block of blocks) {
3942
- findDestructiveCalls(block.content, block.contentStart, msgs, diagnostics);
3943
- findIndexAssigns(block.content, block.contentStart, msgs, diagnostics);
4203
+ function validatePathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, msgs) {
4204
+ if (/^\$\d+$/.test(checkPath)) return null;
4205
+ if (checkPath.startsWith("$command.")) {
4206
+ if (commandNames.size > 0 && !commandNames.has(checkPath)) {
4207
+ return msgs.commandTokenUndeclared(displayPath);
4208
+ }
4209
+ return null;
3944
4210
  }
3945
- return diagnostics;
3946
- }
3947
- function findDestructiveCalls(script, baseOffset, msgs, out) {
3948
- for (const regex of [DOT_ROOT_CALL, BRACKET_ROOT_CALL]) {
3949
- regex.lastIndex = 0;
3950
- let match;
3951
- while ((match = regex.exec(script)) !== null) {
3952
- const [full, root, chain, method] = match;
3953
- if (isApiRoot(root)) continue;
3954
- const statePath = root + chainToDotted(chain);
3955
- const start = baseOffset + match.index;
3956
- out.push({
3957
- code: WcsDiagnosticCode.ArrayMutation,
3958
- start,
3959
- end: start + full.length,
3960
- message: msgs.arrayMutation(method, ALTERNATIVES[method](toAccessor(statePath))),
3961
- severity: "error",
3962
- statePath
3963
- });
4211
+ if (checkPath.startsWith("$streamStatus.") || checkPath.startsWith("$streamError.")) {
4212
+ const prefix = checkPath.startsWith("$streamStatus.") ? "$streamStatus." : "$streamError.";
4213
+ const hasNamespace = scopedPaths.some((p) => p.path.startsWith(prefix));
4214
+ if (hasNamespace && !scopedPathSet.has(checkPath)) {
4215
+ return msgs.streamPathMissing(displayPath);
3964
4216
  }
4217
+ return null;
3965
4218
  }
4219
+ if (!scopedPathSet.has(checkPath) && !matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet)) {
4220
+ return msgs.pathMissing(displayPath);
4221
+ }
4222
+ return null;
3966
4223
  }
3967
- function findIndexAssigns(script, baseOffset, msgs, out) {
3968
- for (const regex of [DOT_INDEX_ASSIGN, BRACKET_INDEX_ASSIGN, PRE_DOT_INDEX, PRE_BRACKET_INDEX]) {
3969
- regex.lastIndex = 0;
3970
- let match;
3971
- while ((match = regex.exec(script)) !== null) {
3972
- const [full, root, chain] = match;
3973
- if (isApiRoot(root)) continue;
3974
- const suggestedPath = root + chainToDotted(chain);
3975
- const start = baseOffset + match.index;
3976
- out.push({
3977
- code: WcsDiagnosticCode.ArrayIndexAssign,
3978
- start,
3979
- end: start + full.length,
3980
- message: msgs.arrayIndexAssign(suggestedPath),
3981
- severity: "error",
3982
- statePath: suggestedPath
3983
- });
3984
- }
4224
+ function matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet) {
4225
+ const specs = collectRecursionSpecs(scopedPaths);
4226
+ if (specs.length === 0) return false;
4227
+ return matchesRecursion(specs, checkPath, (candidate) => scopedPathSet.has(candidate));
4228
+ }
4229
+ function toMissingVerdict(message) {
4230
+ return message ? { code: WcsDiagnosticCode.BindingPathMissing, message, severity: "warning" } : null;
4231
+ }
4232
+ function validateSchemaPathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, schema, msgs) {
4233
+ if (checkPath.startsWith("$")) {
4234
+ return toMissingVerdict(validatePathExistence(checkPath, displayPath, scopedPaths, scopedPathSet, commandNames, msgs));
4235
+ }
4236
+ if (scopedPathSet.has(checkPath)) return null;
4237
+ if (matchesRecursionCandidates(scopedPaths, checkPath, scopedPathSet)) return null;
4238
+ const resolution = resolveSchemaPath(schema, schema.$defs ?? {}, checkPath.split("."));
4239
+ if (resolution.kind === "nonexistent") {
4240
+ return { code: WcsDiagnosticCode.PathNonexistent, message: msgs.pathNonexistent(displayPath), severity: "error" };
3985
4241
  }
4242
+ return null;
3986
4243
  }
3987
-
3988
- // src/service/templateSyntax.ts
3989
- function findAllMustacheSyntax(html) {
3990
- const results = [];
3991
- const regex = /\{\{\s*(.+?)\s*\}\}/g;
4244
+ function collectStructuralTemplates(html, attrName) {
4245
+ const escaped = attrName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4246
+ const attrRegex = new RegExp(`${escaped}\\s*=\\s*(["'])`, "i");
4247
+ const tagRegex = /<template(?:\s[^>]*)?>|<\/template\s*>/gi;
4248
+ const templates = [];
4249
+ let depth = 0;
3992
4250
  let match;
3993
- while ((match = regex.exec(html)) !== null) {
3994
- if (isInsideTag(html, match.index, "script") || isInsideTag(html, match.index, "style")) {
4251
+ while ((match = tagRegex.exec(html)) !== null) {
4252
+ if (match[0].startsWith("</")) {
4253
+ depth = Math.max(0, depth - 1);
3995
4254
  continue;
3996
4255
  }
3997
- const expr = match[1];
3998
- const exprStart = match.index + match[0].indexOf(expr);
3999
- results.push({
4000
- kind: "mustache",
4001
- expression: expr,
4002
- exprStart,
4003
- exprEnd: exprStart + expr.length,
4004
- matchStart: match.index,
4005
- matchEnd: match.index + match[0].length,
4006
- insideTemplate: isInsideTag(html, match.index, "template")
4007
- });
4256
+ const attrMatch = attrRegex.exec(match[0]);
4257
+ if (attrMatch) {
4258
+ const quote = attrMatch[1];
4259
+ const valueStart = match.index + attrMatch.index + attrMatch[0].length;
4260
+ const valueEnd = html.indexOf(quote, valueStart);
4261
+ if (valueEnd !== -1) {
4262
+ const first = splitBindingExpressions(html.slice(valueStart, valueEnd))[0] ?? "";
4263
+ const firstColon = indexOfOutsideQuotes2(first, ":");
4264
+ const prop = (firstColon === -1 ? first : first.slice(0, firstColon)).replace(/#.*$/, "").trim();
4265
+ const type = prop === "if" || prop === "elseif" || prop === "else" ? prop : "other";
4266
+ templates.push({ valueStart, depth, type });
4267
+ }
4268
+ }
4269
+ depth++;
4008
4270
  }
4009
- return results;
4271
+ return templates;
4010
4272
  }
4011
- function findAllCommentBindings(html, commentTextPrefix = "wcs-text") {
4012
- const results = [];
4013
- const escaped = commentTextPrefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4014
- const regex = new RegExp(`<!--\\s*@@\\s*(?:${escaped})?\\s*:\\s*(.+?)\\s*-->`, "g");
4015
- let match;
4016
- while ((match = regex.exec(html)) !== null) {
4017
- const expr = match[1];
4018
- if (!expr) continue;
4019
- const exprStart = match.index + match[0].indexOf(expr);
4020
- results.push({
4021
- kind: "comment",
4022
- expression: expr,
4023
- exprStart,
4024
- exprEnd: exprStart + expr.length,
4025
- matchStart: match.index,
4026
- matchEnd: match.index + match[0].length,
4027
- insideTemplate: isInsideTag(html, match.index, "template")
4028
- });
4273
+ function isNegatedByElseChain(templates, valueStart) {
4274
+ const index = templates.findIndex((t) => t.valueStart === valueStart);
4275
+ if (index === -1) return false;
4276
+ const selfDepth = templates[index].depth;
4277
+ for (let i = index + 1; i < templates.length; i++) {
4278
+ const next = templates[i];
4279
+ if (next.depth > selfDepth) continue;
4280
+ if (next.depth < selfDepth) return false;
4281
+ if (next.type === "elseif" || next.type === "else") return true;
4282
+ if (next.type === "if") return false;
4283
+ }
4284
+ return false;
4285
+ }
4286
+ function getExpectedType(property, isNegatedIf) {
4287
+ const prop = property.replace(/#.*$/, "");
4288
+ if (prop === "for") {
4289
+ return { label: "for", expected: "array", severity: "error" };
4290
+ }
4291
+ if (prop === "if" || prop === "elseif") {
4292
+ if (!isNegatedIf()) return null;
4293
+ return { label: prop, expected: "boolean", severity: "warning" };
4294
+ }
4295
+ if (prop.startsWith("class.")) {
4296
+ return { label: prop, expected: "boolean", severity: "warning" };
4297
+ }
4298
+ if (prop.startsWith("attr.")) {
4299
+ return { label: prop, expected: "string", severity: "warning" };
4029
4300
  }
4030
- return results;
4031
- }
4032
- function isInsideTag(html, offset2, tagName) {
4033
- const tagRegex = new RegExp(`<(/?)${tagName}[\\s>]`, "gi");
4034
- let depth = 0;
4035
- let match;
4036
- while ((match = tagRegex.exec(html)) !== null) {
4037
- if (match.index > offset2) break;
4038
- if (match[1]) {
4039
- depth = Math.max(0, depth - 1);
4040
- } else {
4041
- depth++;
4042
- }
4301
+ if (prop.startsWith("style.")) {
4302
+ return { label: prop, expected: "string", severity: "warning" };
4043
4303
  }
4044
- return depth > 0;
4304
+ return null;
4045
4305
  }
4046
-
4047
- // src/service/templateSyntaxValidator.ts
4048
- function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", locale2, fileReader, applicationSchema) {
4306
+ function validateFilterChainTypes(path, filters, statePaths, bindingStart, msgs) {
4049
4307
  const diagnostics = [];
4050
- const msgs = getMessages(locale2);
4051
- const allPaths = mergeSchemaCandidates(getStatePathsFromHtml(html, stateTagName, fileReader), applicationSchema);
4052
- const defaultSchema = applicationSchema;
4053
- const missingVerdict = (path, displayPath, pathSet2, scoped) => {
4054
- if (hasRecursionWildcard(path)) {
4055
- return {
4056
- code: WcsDiagnosticCode.RecursionUnsupported,
4057
- severity: "error",
4058
- message: msgs.recursionUnsupported(path, "binding")
4059
- };
4060
- }
4061
- if (isValidTemplatePath(path, pathSet2, scoped)) return null;
4062
- if (defaultSchema !== void 0 && !path.startsWith("$")) {
4063
- const resolution = resolveSchemaPath(defaultSchema, defaultSchema.$defs ?? {}, path.split("."));
4064
- return resolution.kind === "nonexistent" ? { code: WcsDiagnosticCode.PathNonexistent, severity: "error", message: msgs.pathNonexistent(displayPath) } : null;
4065
- }
4066
- return { code: WcsDiagnosticCode.BindingPathMissing, severity: "warning", message: msgs.pathMissing(displayPath) };
4067
- };
4068
- if (allPaths.length === 0) return diagnostics;
4069
- const defaultPaths = allPaths;
4070
- const pathSet = new Set(defaultPaths.map((p) => p.path));
4071
- const filterNameSet = new Set(BUILTIN_FILTERS.map((f) => f.name));
4072
- const mustaches = findAllMustacheSyntax(html);
4073
- const comments = findAllCommentBindings(html);
4074
- for (const item of [...mustaches, ...comments]) {
4075
- if (item.kind === "comment") {
4076
- diagnostics.push({
4077
- code: WcsDiagnosticCode.TemplateSyntax,
4078
- start: item.matchStart,
4079
- end: item.matchEnd,
4080
- message: msgs.wcsTextInfo(item.expression),
4081
- severity: "info"
4082
- });
4083
- }
4084
- if (item.kind === "mustache" && !item.insideTemplate) {
4085
- diagnostics.push({
4086
- code: WcsDiagnosticCode.TemplateSyntax,
4087
- start: item.matchStart,
4088
- end: item.matchEnd,
4089
- message: msgs.moustacheFouc(item.expression),
4090
- severity: "info"
4091
- });
4092
- }
4093
- if (!item.expression) continue;
4094
- const parts = item.expression.split("|");
4095
- const pathPart = (parts[0] || "").trim();
4096
- if (pathPart.includes("@")) continue;
4097
- const insideFor = item.insideTemplate && isInsideForTemplate(html, item.matchStart, bindAttrName);
4098
- if (pathPart && !/^-?\d|^["'`]|^true$|^false$|^null$/.test(pathPart)) {
4099
- if (!insideFor && pathPart.includes("*")) {
4100
- diagnostics.push({
4101
- code: WcsDiagnosticCode.TemplateSyntax,
4102
- start: item.exprStart,
4103
- end: item.exprStart + pathPart.length,
4104
- message: msgs.patternPathOutsideFor(pathPart),
4105
- severity: "warning"
4106
- });
4107
- }
4108
- if (!insideFor && pathPart.startsWith(".")) {
4109
- diagnostics.push({
4110
- code: WcsDiagnosticCode.TemplateSyntax,
4111
- start: item.exprStart,
4112
- end: item.exprStart + pathPart.length,
4113
- message: msgs.omittedPathOutsideFor(pathPart),
4114
- severity: "warning"
4115
- });
4116
- }
4117
- if (insideFor && !pathPart.startsWith(".")) {
4118
- const indexMatch = /^\$(\d+)$/.exec(pathPart);
4119
- const needed = indexMatch !== null ? Number(indexMatch[1]) : pathPart.includes("*") ? countWildcardSegments(pathPart) : 0;
4120
- if (needed > 0) {
4121
- const available = getAvailableWildcardRank(html, item.matchStart, bindAttrName);
4122
- if (available > 0 && needed > available) {
4123
- diagnostics.push({
4124
- code: WcsDiagnosticCode.WildcardRank,
4125
- start: item.exprStart,
4126
- end: item.exprStart + pathPart.length,
4127
- message: msgs.wildcardRank(`"${pathPart}"`, needed, available),
4128
- severity: "warning"
4129
- });
4130
- }
4131
- }
4132
- }
4133
- if (/\.\d+\.|\.\d+$/.test(pathPart)) {
4308
+ const pathInfo = statePaths.find((p) => p.path === path);
4309
+ if (!pathInfo?.typeHint) return diagnostics;
4310
+ let currentType = pathInfo.typeHint;
4311
+ for (const filter of filters) {
4312
+ const info = filterMap.get(canonicalFilterName(filter.name));
4313
+ if (!info) break;
4314
+ if (info.acceptTypes !== "any") {
4315
+ const currentTypes = currentType.split("|");
4316
+ const hasMatch = currentTypes.some((t) => info.acceptTypes.includes(t));
4317
+ if (!hasMatch) {
4134
4318
  diagnostics.push({
4135
- code: WcsDiagnosticCode.TemplateSyntax,
4136
- start: item.exprStart,
4137
- end: item.exprStart + pathPart.length,
4138
- message: msgs.resolvedPathInUi(pathPart),
4319
+ code: WcsDiagnosticCode.FilterInputType,
4320
+ start: bindingStart + filter.offset,
4321
+ end: bindingStart + filter.offset + filter.name.length,
4322
+ message: msgs.filterInputType(filter.name, info.acceptTypes.join("|"), currentType),
4139
4323
  severity: "warning"
4140
4324
  });
4141
4325
  }
4142
- if (pathPart.startsWith(".")) {
4143
- const forPath = insideFor ? getInnermostForPath(html, item.matchStart, bindAttrName) : null;
4144
- if (forPath && !forPath.startsWith(".")) {
4145
- const expandedPath = pathPart === "." ? `${forPath}.*` : `${forPath}.*.${pathPart.slice(1)}`;
4146
- const verdict = missingVerdict(expandedPath, pathPart, pathSet, defaultPaths);
4147
- if (verdict) {
4148
- diagnostics.push({
4149
- code: verdict.code,
4150
- start: item.exprStart,
4151
- end: item.exprStart + pathPart.length,
4152
- message: verdict.message + msgs.expansionSuffix(expandedPath),
4153
- severity: verdict.severity
4154
- });
4155
- }
4156
- }
4157
- } else {
4158
- const verdict = missingVerdict(pathPart, pathPart, pathSet, defaultPaths);
4159
- if (verdict) {
4160
- diagnostics.push({
4161
- code: verdict.code,
4162
- start: item.exprStart,
4163
- end: item.exprStart + pathPart.length,
4164
- message: verdict.message,
4165
- severity: verdict.severity
4166
- });
4167
- }
4168
- }
4169
4326
  }
4170
- for (let i = 1; i < parts.length; i++) {
4171
- const filterName = parts[i].trim().replace(/\(.*$/, "");
4172
- const filterOffset = item.expression.indexOf(parts[i]) + (parts[i].length - parts[i].trimStart().length);
4173
- const canonical = canonicalFilterName(filterName);
4174
- if (filterName && canonical !== filterName && filterNameSet.has(canonical)) {
4175
- diagnostics.push({
4176
- code: WcsDiagnosticCode.NameAlias,
4177
- start: item.exprStart + filterOffset,
4178
- end: item.exprStart + filterOffset + filterName.length,
4179
- message: msgs.nameAlias(filterName, canonical),
4180
- severity: "info"
4181
- });
4182
- } else if (filterName && !filterNameSet.has(filterName)) {
4327
+ if (info.resultType !== "passthrough") {
4328
+ currentType = info.resultType;
4329
+ }
4330
+ }
4331
+ return diagnostics;
4332
+ }
4333
+ function resolveResultType(path, filters, statePaths) {
4334
+ const pathInfo = statePaths.find((p) => p.path === path);
4335
+ if (!pathInfo?.typeHint) return null;
4336
+ let currentType = pathInfo.typeHint;
4337
+ for (const filter of filters) {
4338
+ const info = filterMap.get(canonicalFilterName(filter.name));
4339
+ if (!info) return null;
4340
+ if (info.resultType === "passthrough") continue;
4341
+ currentType = info.resultType;
4342
+ }
4343
+ return currentType;
4344
+ }
4345
+ function inferArgType(arg) {
4346
+ const v = arg.trim();
4347
+ if (/^-?\d+(\.\d+)?$/.test(v)) return "number";
4348
+ return "string";
4349
+ }
4350
+ function isLiteral(value) {
4351
+ return /^-?\d/.test(value) || /^["'`]/.test(value) || value === "true" || value === "false" || value === "null";
4352
+ }
4353
+
4354
+ // src/service/stateTypeValidator.ts
4355
+ function validateStateTypes(html, stateTagName = "wcs-state", locale2) {
4356
+ const msgs = getMessages(locale2);
4357
+ const blocks = parseWcsScriptBlocks(html, stateTagName);
4358
+ const diagnostics = [];
4359
+ for (const block of blocks) {
4360
+ const props = findJsDocTypedProperties(block.content);
4361
+ for (const prop of props) {
4362
+ if (!isValueCompatible(prop.declaredTypes, prop.valueType)) {
4363
+ const absStart = block.contentStart + prop.valueOffset;
4364
+ const absEnd = absStart + prop.valueLength;
4183
4365
  diagnostics.push({
4184
- code: WcsDiagnosticCode.FilterUnknown,
4185
- start: item.exprStart + filterOffset,
4186
- end: item.exprStart + filterOffset + filterName.length,
4187
- message: msgs.filterUnknown(filterName),
4366
+ start: absStart,
4367
+ end: absEnd,
4368
+ message: msgs.typeAnnotationIncompatible(prop.valueType, prop.rawType),
4188
4369
  severity: "warning"
4189
4370
  });
4190
4371
  }
@@ -4192,490 +4373,446 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
4192
4373
  }
4193
4374
  return diagnostics;
4194
4375
  }
4195
- function isValidTemplatePath(path, pathSet, scopedPaths) {
4196
- if (/^\$\d+$/.test(path)) return true;
4197
- if (path.startsWith("$streamStatus.") || path.startsWith("$streamError.")) {
4198
- const prefix = path.startsWith("$streamStatus.") ? "$streamStatus." : "$streamError.";
4199
- const hasNamespace = scopedPaths.some((p) => p.path.startsWith(prefix));
4200
- return !hasNamespace || pathSet.has(path);
4376
+ function findJsDocTypedProperties(script) {
4377
+ const results = [];
4378
+ const regex = /\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*(?:"([^"]+)"|'([^']+)'|(\w+))\s*:\s*/g;
4379
+ let match;
4380
+ while ((match = regex.exec(script)) !== null) {
4381
+ const rawType = match[1].trim();
4382
+ const name = match[2] ?? match[3] ?? match[4];
4383
+ const valueStart = match.index + match[0].length;
4384
+ const valueText = extractValue(script, valueStart);
4385
+ const valueType = inferValueType(valueText);
4386
+ if (valueType) {
4387
+ const declaredTypes = rawType.split("|").map((t) => normalizeType(t.trim()));
4388
+ results.push({
4389
+ name,
4390
+ rawType,
4391
+ declaredTypes,
4392
+ valueType,
4393
+ valueOffset: valueStart,
4394
+ valueLength: valueText.length
4395
+ });
4396
+ }
4201
4397
  }
4202
- return pathSet.has(path) || matchesRecursionCandidates(scopedPaths, path, pathSet);
4398
+ return results;
4203
4399
  }
4204
-
4205
- // ../state/dist/parser.esm.js
4206
- var DELIMITER2 = ".";
4207
- var WILDCARD2 = "*";
4208
- var MAX_WILDCARD_DEPTH2 = 128;
4209
- var BINDING_SEPARATOR2 = ";";
4210
- var PROP_VALUE_SEPARATOR2 = ":";
4211
- var MODIFIER_SEPARATOR2 = "#";
4212
- var FILTER_SEPARATOR2 = "|";
4213
- var ELSE_KEYWORD2 = "else";
4214
- var SPREAD_PROP2 = "...";
4215
- var EVENT_PROP_PREFIX2 = "on";
4216
- var EVENT_TOKEN_NAMESPACE2 = "eventToken";
4217
- var COMMAND_NAMESPACE2 = "command";
4218
- var CLASS_NAMESPACE2 = "class";
4219
- var ATTR_NAMESPACE2 = "attr";
4220
- var STYLE_NAMESPACE2 = "style";
4221
- var INDEX_PARAM_PREFIX2 = "$";
4222
- var tmpIndexByIndexName2 = {};
4223
- for (let i = 0; i < MAX_WILDCARD_DEPTH2; i++) {
4224
- tmpIndexByIndexName2[`${INDEX_PARAM_PREFIX2}${i + 1}`] = i;
4400
+ function extractValue(script, start) {
4401
+ let depth = 0;
4402
+ let inString = null;
4403
+ let i = start;
4404
+ while (i < script.length) {
4405
+ const ch = script[i];
4406
+ if (inString) {
4407
+ if (ch === inString && script[i - 1] !== "\\") inString = null;
4408
+ } else if (ch === '"' || ch === "'" || ch === "`") {
4409
+ inString = ch;
4410
+ } else if (ch === "{" || ch === "[" || ch === "(") {
4411
+ depth++;
4412
+ } else if (ch === "}" || ch === "]" || ch === ")") {
4413
+ if (depth === 0) break;
4414
+ depth--;
4415
+ } else if ((ch === "," || ch === "\n") && depth === 0) {
4416
+ break;
4417
+ }
4418
+ i++;
4419
+ }
4420
+ return script.slice(start, i).trim();
4225
4421
  }
4226
- Object.freeze(tmpIndexByIndexName2);
4227
- var RECURSION_WILDCARD2 = "**";
4228
- function raiseError2(message) {
4229
- throw new Error(`[@wcstack/state] ${message}`);
4422
+ function inferValueType(value) {
4423
+ const v = value.replace(/,\s*$/, "").trim();
4424
+ if (v === "null") return "null";
4425
+ if (v === "undefined") return "null";
4426
+ if (v === "true" || v === "false") return "boolean";
4427
+ if (/^-?\d+\.\d/.test(v)) return "number";
4428
+ if (/^-?\d/.test(v)) return "number";
4429
+ if (/^["'`]/.test(v)) return "string";
4430
+ if (v.startsWith("[")) return "array";
4431
+ if (v.startsWith("{")) return "object";
4432
+ return null;
4230
4433
  }
4231
- var _cache = /* @__PURE__ */ new Map();
4232
- function clearPathInfoCacheForTooling() {
4233
- _cache.clear();
4434
+ function normalizeType(type) {
4435
+ const lower = type.toLowerCase();
4436
+ if (lower === "null" || lower === "undefined") return "null";
4437
+ if (lower === "string") return "string";
4438
+ if (lower === "number") return "number";
4439
+ if (lower === "boolean") return "boolean";
4440
+ if (lower.endsWith("[]") || lower.startsWith("array")) return "array";
4441
+ if (lower === "object") return "object";
4442
+ return type;
4234
4443
  }
4235
- var id = 0;
4236
- function getPathInfo(path) {
4237
- let pathInfo = _cache.get(path);
4238
- if (typeof pathInfo !== "undefined") {
4239
- return pathInfo;
4240
- }
4241
- if (path.indexOf(RECURSION_WILDCARD2) !== -1) {
4242
- raiseError2(`[wcs/recursion-unsupported] "${path}" uses "${RECURSION_WILDCARD2}", which is not accepted here. It is only meaningful in a $recursion declaration, in a recursive getter key, and in the path argument of $getAll / $setAll \u2014 and only when the state declares a $recursion anchor.`);
4243
- }
4244
- pathInfo = Object.freeze(new PathInfo(path));
4245
- _cache.set(path, pathInfo);
4246
- return pathInfo;
4444
+ function isValueCompatible(declaredTypes, valueType) {
4445
+ return declaredTypes.includes(valueType);
4247
4446
  }
4248
- var PathInfo = class {
4249
- id = ++id;
4250
- path;
4251
- segments;
4252
- lastSegment;
4253
- cumulativePaths;
4254
- cumulativePathSet;
4255
- cumulativePathInfos;
4256
- cumulativePathInfoSet;
4257
- parentPath;
4258
- wildcardPaths;
4259
- wildcardPathSet;
4260
- indexByWildcardPath;
4261
- wildcardPathInfos;
4262
- wildcardPathInfoSet;
4263
- wildcardParentPaths;
4264
- wildcardParentPathSet;
4265
- wildcardParentPathInfos;
4266
- wildcardParentPathInfoSet;
4267
- wildcardPositions;
4268
- lastWildcardPath;
4269
- lastWildcardInfo;
4270
- wildcardCount;
4271
- parentPathInfo;
4272
- constructor(path) {
4273
- const getPattern = (_path) => {
4274
- return path === _path ? this : getPathInfo(_path);
4275
- };
4276
- const segments = path.split(".");
4277
- const cumulativePaths = [];
4278
- const cumulativePathInfos = [];
4279
- const wildcardPaths = [];
4280
- const indexByWildcardPath = {};
4281
- const wildcardPathInfos = [];
4282
- const wildcardParentPaths = [];
4283
- const wildcardParentPathInfos = [];
4284
- const wildcardPositions = [];
4285
- let currentPatternPath = "", prevPatternPath = "";
4286
- let wildcardCount = 0;
4287
- for (let i = 0; i < segments.length; i++) {
4288
- currentPatternPath += segments[i];
4289
- if (segments[i] === WILDCARD2) {
4290
- wildcardPaths.push(currentPatternPath);
4291
- indexByWildcardPath[currentPatternPath] = wildcardCount;
4292
- wildcardPathInfos.push(getPattern(currentPatternPath));
4293
- wildcardParentPaths.push(prevPatternPath);
4294
- wildcardParentPathInfos.push(getPattern(prevPatternPath));
4295
- wildcardPositions.push(i);
4296
- wildcardCount++;
4297
- }
4298
- cumulativePaths.push(currentPatternPath);
4299
- cumulativePathInfos.push(getPattern(currentPatternPath));
4300
- prevPatternPath = currentPatternPath;
4301
- currentPatternPath += ".";
4447
+
4448
+ // src/service/scriptPatterns.ts
4449
+ var ID = String.raw`[\w$]+`;
4450
+ var SUB = String.raw`\s*(?:\?\.)?\s*\[(?!\s*["'])[^\[\]]+\]`;
4451
+ var DOT_SEG = String.raw`\s*\??\.\s*${ID}`;
4452
+ var CHAIN = String.raw`(?:${DOT_SEG}|${SUB})*`;
4453
+ var BRACKETS_ONLY = String.raw`(?:${SUB})+`;
4454
+ var CHAIN_ONE_PLUS = String.raw`(?:${DOT_SEG}|${SUB})+`;
4455
+ var ROOT_DOT = String.raw`\bthis\s*\??\.\s*(${ID})`;
4456
+ var ROOT_BRACKET = String.raw`\bthis\s*(?:\?\.)?\s*\[\s*["']([^"']+)["']\s*\]`;
4457
+ var ASSIGN_TAIL = String.raw`\s*(?:(?:\*\*|<<|>>>|>>|&&|\|\||\?\?|[+\-*/%&|^])?=(?!=)|\+\+|--)`;
4458
+ var PRE_INCDEC = String.raw`(?:\+\+|--)\s*`;
4459
+ function chainToDotted(chain) {
4460
+ const token = new RegExp(String.raw`\s*(?:\??\.\s*(${ID})|(?:\?\.)?\s*\[([^\[\]]+)\])`, "g");
4461
+ let out = "";
4462
+ let match;
4463
+ while ((match = token.exec(chain)) !== null) {
4464
+ if (match[1] !== void 0) {
4465
+ out += `.${match[1]}`;
4466
+ } else {
4467
+ const key = match[2].trim();
4468
+ out += /^\d+$/.test(key) ? `.${key}` : `.<${key}>`;
4302
4469
  }
4303
- const lastWildcardPath = wildcardPaths.length > 0 ? wildcardPaths[wildcardPaths.length - 1] : null;
4304
- const parentPath = cumulativePaths.length > 1 ? cumulativePaths[cumulativePaths.length - 2] : null;
4305
- this.path = path;
4306
- this.segments = segments;
4307
- this.lastSegment = segments[segments.length - 1];
4308
- this.cumulativePaths = cumulativePaths;
4309
- this.cumulativePathSet = new Set(cumulativePaths);
4310
- this.cumulativePathInfos = cumulativePathInfos;
4311
- this.cumulativePathInfoSet = new Set(cumulativePathInfos);
4312
- this.wildcardPaths = wildcardPaths;
4313
- this.wildcardPathSet = new Set(wildcardPaths);
4314
- this.indexByWildcardPath = indexByWildcardPath;
4315
- this.wildcardPathInfos = wildcardPathInfos;
4316
- this.wildcardPathInfoSet = new Set(wildcardPathInfos);
4317
- this.wildcardParentPaths = wildcardParentPaths;
4318
- this.wildcardParentPathSet = new Set(wildcardParentPaths);
4319
- this.wildcardParentPathInfos = wildcardParentPathInfos;
4320
- this.wildcardParentPathInfoSet = new Set(wildcardParentPathInfos);
4321
- this.wildcardPositions = wildcardPositions;
4322
- this.lastWildcardPath = lastWildcardPath;
4323
- this.lastWildcardInfo = lastWildcardPath ? getPattern(lastWildcardPath) : null;
4324
- this.parentPath = parentPath;
4325
- this.parentPathInfo = parentPath ? getPattern(parentPath) : null;
4326
- this.wildcardCount = wildcardCount;
4327
4470
  }
4328
- };
4329
- var LINT_HINT = " Validate statically: npx @wcstack/lint <file>.";
4330
- var STRUCTURAL_BINDING_TYPE_SET2 = /* @__PURE__ */ new Set([
4331
- "if",
4332
- "elseif",
4333
- "else",
4334
- "for"
4335
- ]);
4336
- var resolvedByKey = /* @__PURE__ */ new Map();
4337
- function clearFilterResolutionCache() {
4338
- resolvedByKey.clear();
4471
+ return out;
4339
4472
  }
4340
- function finalizeArg(text, firstQuoteStart, lastQuoteEnd) {
4341
- const startLimit = firstQuoteStart === -1 ? text.length : firstQuoteStart;
4342
- let start = 0;
4343
- while (start < startLimit && /\s/.test(text[start])) {
4344
- start++;
4345
- }
4346
- const endLimit = lastQuoteEnd === -1 ? 0 : lastQuoteEnd;
4347
- let end = text.length;
4348
- while (end > endLimit && /\s/.test(text[end - 1])) {
4349
- end--;
4473
+ function hasDotSegment(chain) {
4474
+ return /[.]/.test(chain.replace(/\s*(?:\?\.)?\s*\[[^\[\]]+\]/g, ""));
4475
+ }
4476
+ function isApiRoot(root) {
4477
+ return root.startsWith("$");
4478
+ }
4479
+ function execAllMasked(pattern, script) {
4480
+ const masked = maskCommentsAndStrings(script);
4481
+ const regex = new RegExp(pattern, "gd");
4482
+ const out = [];
4483
+ let match;
4484
+ while ((match = regex.exec(masked)) !== null) {
4485
+ const indices = match.indices;
4486
+ out.push({
4487
+ index: match.index,
4488
+ length: match[0].length,
4489
+ groups: indices.slice(1).map((pair) => pair === void 0 ? void 0 : script.slice(pair[0], pair[1]))
4490
+ });
4350
4491
  }
4351
- return text.slice(start, end);
4492
+ return out;
4352
4493
  }
4353
- var NUMBER_LITERAL = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
4354
- function toLiteral(text, quoted) {
4355
- if (quoted)
4356
- return text;
4357
- if (text === "true")
4358
- return true;
4359
- if (text === "false")
4360
- return false;
4361
- if (text === "null")
4362
- return null;
4363
- return NUMBER_LITERAL.test(text) ? Number(text) : text;
4494
+
4495
+ // src/service/nestedAssignValidator.ts
4496
+ var NESTED_ASSIGN = `${ROOT_DOT}(${CHAIN_ONE_PLUS})${ASSIGN_TAIL}`;
4497
+ var PRE_NESTED_INCDEC = `${PRE_INCDEC}${ROOT_DOT}(${CHAIN_ONE_PLUS})`;
4498
+ function validateNestedAssigns(html, stateTagName = "wcs-state", locale2) {
4499
+ const msgs = getMessages(locale2);
4500
+ const blocks = parseWcsScriptBlocks(html, stateTagName);
4501
+ const diagnostics = [];
4502
+ for (const block of blocks) {
4503
+ findNestedAssigns(block.content, block.contentStart, msgs, diagnostics);
4504
+ }
4505
+ return diagnostics;
4364
4506
  }
4365
- function parseFilterArgsWithLiterals(argsText) {
4366
- const args = [];
4367
- const literals = [];
4368
- let current2 = "";
4369
- let inQuote = null;
4370
- let hasQuote = false;
4371
- let firstQuoteStart = -1;
4372
- let lastQuoteEnd = -1;
4373
- const flush = () => {
4374
- const arg = finalizeArg(current2, firstQuoteStart, lastQuoteEnd);
4375
- args.push(arg);
4376
- literals.push(toLiteral(arg, hasQuote));
4377
- current2 = "";
4378
- hasQuote = false;
4379
- firstQuoteStart = -1;
4380
- lastQuoteEnd = -1;
4381
- };
4382
- for (let i = 0; i < argsText.length; i++) {
4383
- const char = argsText[i];
4384
- if (inQuote) {
4385
- if (char === inQuote) {
4386
- inQuote = null;
4387
- } else {
4388
- if (firstQuoteStart === -1) {
4389
- firstQuoteStart = current2.length;
4390
- }
4391
- current2 += char;
4392
- lastQuoteEnd = current2.length;
4393
- }
4394
- } else if (char === '"' || char === "'") {
4395
- inQuote = char;
4396
- hasQuote = true;
4397
- } else if (char === ",") {
4398
- flush();
4399
- } else {
4400
- current2 += char;
4507
+ function findNestedAssigns(script, baseOffset, msgs, out) {
4508
+ for (const pattern of [NESTED_ASSIGN, PRE_NESTED_INCDEC]) {
4509
+ for (const match of execAllMasked(pattern, script)) {
4510
+ const [topProp, chainPart] = match.groups;
4511
+ if (topProp === void 0 || chainPart === void 0) continue;
4512
+ if (isApiRoot(topProp)) continue;
4513
+ if (!hasDotSegment(chainPart)) continue;
4514
+ const suggestedPath = topProp + chainToDotted(chainPart);
4515
+ const start = baseOffset + match.index;
4516
+ out.push({
4517
+ start,
4518
+ end: start + match.length,
4519
+ message: msgs.nestedAssign(suggestedPath),
4520
+ severity: "error"
4521
+ });
4401
4522
  }
4402
4523
  }
4403
- if (inQuote !== null) {
4404
- raiseError2(`[wcs/binding-syntax] unterminated ${inQuote} quote in the filter arguments "(${argsText})". Close the quote.${LINT_HINT}`);
4405
- }
4406
- const last = finalizeArg(current2, firstQuoteStart, lastQuoteEnd);
4407
- if (last || hasQuote) {
4408
- args.push(last);
4409
- literals.push(toLiteral(last, hasQuote));
4410
- }
4411
- return { args, literals };
4412
4524
  }
4413
- function clearFilterFnCacheForTooling() {
4414
- clearFilterResolutionCache();
4525
+
4526
+ // src/service/arrayMutationValidator.ts
4527
+ var DESTRUCTIVE_METHODS = "push|pop|shift|unshift|splice|sort|reverse|fill|copyWithin";
4528
+ var ALTERNATIVES = {
4529
+ push: (a) => `${a} = ${a}.concat(item)`,
4530
+ unshift: (a) => `${a} = [item, ...${a}]`,
4531
+ pop: (a) => `${a} = ${a}.slice(0, -1)`,
4532
+ shift: (a) => `${a} = ${a}.slice(1)`,
4533
+ splice: (a) => `${a} = ${a}.toSpliced(...)`,
4534
+ sort: (a) => `${a} = ${a}.toSorted(...)`,
4535
+ reverse: (a) => `${a} = ${a}.toReversed()`,
4536
+ fill: (a) => `${a} = ${a}.map(...)`,
4537
+ copyWithin: (a) => `${a} = ${a}.map(...)`
4538
+ };
4539
+ var METHOD_TAIL = String.raw`\s*\??\.\s*(${DESTRUCTIVE_METHODS})(?=\s*\()`;
4540
+ var DOT_ROOT_CALL = `${ROOT_DOT}(${CHAIN})${METHOD_TAIL}`;
4541
+ var BRACKET_ROOT_CALL = `${ROOT_BRACKET}(${CHAIN})${METHOD_TAIL}`;
4542
+ var DOT_INDEX_ASSIGN = `${ROOT_DOT}(${BRACKETS_ONLY})${ASSIGN_TAIL}`;
4543
+ var BRACKET_INDEX_ASSIGN = `${ROOT_BRACKET}(${BRACKETS_ONLY})${ASSIGN_TAIL}`;
4544
+ var PRE_DOT_INDEX = `${PRE_INCDEC}${ROOT_DOT}(${BRACKETS_ONLY})`;
4545
+ var PRE_BRACKET_INDEX = `${PRE_INCDEC}${ROOT_BRACKET}(${BRACKETS_ONLY})`;
4546
+ function toAccessor(path) {
4547
+ return /^[A-Za-z_]\w*$/.test(path) ? `this.${path}` : `this["${path}"]`;
4415
4548
  }
4416
- function parseFilters(filterTextList, _filterIOType) {
4417
- return filterTextList.map((filterText) => {
4418
- const openParenIndex = filterText.indexOf("(");
4419
- const closeParenIndex = filterText.lastIndexOf(")");
4420
- if (openParenIndex !== -1 && closeParenIndex === -1) {
4421
- raiseError2(`Invalid filter format: missing closing parenthesis in "${filterText}"`);
4422
- }
4423
- if (closeParenIndex !== -1 && openParenIndex === -1) {
4424
- raiseError2(`Invalid filter format: missing opening parenthesis in "${filterText}"`);
4425
- }
4426
- const filterName = (openParenIndex === -1 ? filterText : filterText.substring(0, openParenIndex)).trim();
4427
- if (filterName.length === 0) {
4428
- raiseError2(`[wcs/binding-syntax] an empty filter in "${filterTextList.join("|")}" \u2014 remove the extra "|" or name the filter.${LINT_HINT}`);
4429
- }
4430
- if (openParenIndex === -1) {
4431
- return { filterName, args: [], literals: [] };
4432
- }
4433
- const argsText = filterText.substring(openParenIndex + 1, closeParenIndex);
4434
- return { filterName, ...parseFilterArgsWithLiterals(argsText) };
4435
- });
4549
+ function validateArrayMutations(html, stateTagName = "wcs-state", locale2) {
4550
+ const msgs = getMessages(locale2);
4551
+ const blocks = parseWcsScriptBlocks(html, stateTagName);
4552
+ const diagnostics = [];
4553
+ for (const block of blocks) {
4554
+ findDestructiveCalls(block.content, block.contentStart, msgs, diagnostics);
4555
+ findIndexAssigns(block.content, block.contentStart, msgs, diagnostics);
4556
+ }
4557
+ return diagnostics;
4436
4558
  }
4437
- var trimFn = (s) => s.trim();
4438
- var isQuote = (c) => c === "'" || c === '"';
4439
- function indexOfOutsideQuotes(text, char) {
4440
- let quote = null;
4441
- for (let i = 0; i < text.length; i++) {
4442
- const c = text[i];
4443
- if (quote !== null) {
4444
- if (c === quote)
4445
- quote = null;
4446
- } else if (isQuote(c)) {
4447
- quote = c;
4448
- } else if (c === char) {
4449
- return i;
4559
+ function findDestructiveCalls(script, baseOffset, msgs, out) {
4560
+ for (const pattern of [DOT_ROOT_CALL, BRACKET_ROOT_CALL]) {
4561
+ for (const match of execAllMasked(pattern, script)) {
4562
+ const [root, chain, method] = match.groups;
4563
+ if (root === void 0 || chain === void 0 || method === void 0) continue;
4564
+ if (isApiRoot(root)) continue;
4565
+ const statePath = root + chainToDotted(chain);
4566
+ const start = baseOffset + match.index;
4567
+ out.push({
4568
+ code: WcsDiagnosticCode.ArrayMutation,
4569
+ start,
4570
+ end: start + match.length,
4571
+ message: msgs.arrayMutation(method, ALTERNATIVES[method](toAccessor(statePath))),
4572
+ severity: "error",
4573
+ statePath
4574
+ });
4450
4575
  }
4451
4576
  }
4452
- return -1;
4453
4577
  }
4454
- function splitOutsideQuotes(text, separator) {
4455
- const parts = [];
4456
- let quote = null;
4457
- let start = 0;
4458
- for (let i = 0; i < text.length; i++) {
4459
- const c = text[i];
4460
- if (quote !== null) {
4461
- if (c === quote)
4462
- quote = null;
4463
- } else if (isQuote(c)) {
4464
- quote = c;
4465
- } else if (c === separator) {
4466
- parts.push(text.slice(start, i));
4467
- start = i + 1;
4578
+ function findIndexAssigns(script, baseOffset, msgs, out) {
4579
+ for (const pattern of [DOT_INDEX_ASSIGN, BRACKET_INDEX_ASSIGN, PRE_DOT_INDEX, PRE_BRACKET_INDEX]) {
4580
+ for (const match of execAllMasked(pattern, script)) {
4581
+ const [root, chain] = match.groups;
4582
+ if (root === void 0 || chain === void 0) continue;
4583
+ if (isApiRoot(root)) continue;
4584
+ const suggestedPath = root + chainToDotted(chain);
4585
+ const start = baseOffset + match.index;
4586
+ out.push({
4587
+ code: WcsDiagnosticCode.ArrayIndexAssign,
4588
+ start,
4589
+ end: start + match.length,
4590
+ message: msgs.arrayIndexAssign(suggestedPath),
4591
+ severity: "error",
4592
+ statePath: suggestedPath
4593
+ });
4468
4594
  }
4469
4595
  }
4470
- parts.push(text.slice(start));
4471
- return parts;
4472
- }
4473
- var cacheFilterInfos$1 = /* @__PURE__ */ new Map();
4474
- function clearPropPartCacheForTooling() {
4475
- cacheFilterInfos$1.clear();
4476
4596
  }
4477
- function parsePropPart(propPart) {
4478
- const pos = indexOfOutsideQuotes(propPart, FILTER_SEPARATOR2);
4479
- let propText = "";
4480
- let filterTexts = [];
4481
- let filtersText = "";
4482
- let filters = [];
4483
- if (pos !== -1) {
4484
- propText = propPart.slice(0, pos).trim();
4485
- filtersText = propPart.slice(pos + 1).trim();
4486
- if (cacheFilterInfos$1.has(filtersText)) {
4487
- filters = cacheFilterInfos$1.get(filtersText);
4488
- } else {
4489
- filterTexts = splitOutsideQuotes(filtersText, FILTER_SEPARATOR2).map(trimFn);
4490
- filters = parseFilters(filterTexts);
4491
- cacheFilterInfos$1.set(filtersText, filters);
4597
+
4598
+ // src/service/templateSyntax.ts
4599
+ function findAllMustacheSyntax(html) {
4600
+ const results = [];
4601
+ const regex = /\{\{\s*(.+?)\s*\}\}/g;
4602
+ let match;
4603
+ while ((match = regex.exec(html)) !== null) {
4604
+ if (isInsideTag(html, match.index, "script") || isInsideTag(html, match.index, "style")) {
4605
+ continue;
4492
4606
  }
4493
- } else {
4494
- propText = propPart.trim();
4495
- }
4496
- const modifierParts = propText.split(MODIFIER_SEPARATOR2).map(trimFn);
4497
- if (modifierParts.length > 2) {
4498
- raiseError2(`[wcs/binding-syntax] "${propText}": a binding takes one modifier list after a single "${MODIFIER_SEPARATOR2}" \u2014 write "${modifierParts[0]}${MODIFIER_SEPARATOR2}${modifierParts.slice(1).join(",")}".${LINT_HINT}`);
4607
+ const expr = match[1];
4608
+ const exprStart = match.index + match[0].indexOf(expr);
4609
+ results.push({
4610
+ kind: "mustache",
4611
+ expression: expr,
4612
+ exprStart,
4613
+ exprEnd: exprStart + expr.length,
4614
+ matchStart: match.index,
4615
+ matchEnd: match.index + match[0].length,
4616
+ insideTemplate: isInsideTag(html, match.index, "template")
4617
+ });
4499
4618
  }
4500
- const [propName, propModifiersText] = modifierParts;
4501
- const propSegments = propName.split(DELIMITER2).map(trimFn);
4502
- const propModifiers = propModifiersText ? propModifiersText.split(",").map(trimFn) : [];
4503
- return {
4504
- propName,
4505
- propSegments,
4506
- propModifiers,
4507
- inFilters: filters
4508
- };
4619
+ return results;
4509
4620
  }
4510
- var cacheFilterInfos = /* @__PURE__ */ new Map();
4511
- function clearStatePartCacheForTooling() {
4512
- cacheFilterInfos.clear();
4621
+ function findAllCommentBindings(html, commentTextPrefix = "wcs-text") {
4622
+ const results = [];
4623
+ const escaped = commentTextPrefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4624
+ const regex = new RegExp(`<!--\\s*@@\\s*(?:${escaped})?\\s*:\\s*(.+?)\\s*-->`, "g");
4625
+ let match;
4626
+ while ((match = regex.exec(html)) !== null) {
4627
+ const expr = match[1];
4628
+ if (!expr) continue;
4629
+ const exprStart = match.index + match[0].indexOf(expr);
4630
+ results.push({
4631
+ kind: "comment",
4632
+ expression: expr,
4633
+ exprStart,
4634
+ exprEnd: exprStart + expr.length,
4635
+ matchStart: match.index,
4636
+ matchEnd: match.index + match[0].length,
4637
+ insideTemplate: isInsideTag(html, match.index, "template")
4638
+ });
4639
+ }
4640
+ return results;
4513
4641
  }
4514
- function parseStatePart(statePart) {
4515
- const pos = indexOfOutsideQuotes(statePart, FILTER_SEPARATOR2);
4516
- let stateAndPath = "";
4517
- let filterTexts = [];
4518
- let filtersText = "";
4519
- let filters = [];
4520
- if (pos !== -1) {
4521
- stateAndPath = statePart.slice(0, pos).trim();
4522
- filtersText = statePart.slice(pos + 1).trim();
4523
- if (cacheFilterInfos.has(filtersText)) {
4524
- filters = cacheFilterInfos.get(filtersText);
4642
+ function isInsideTag(html, offset2, tagName) {
4643
+ const tagRegex = new RegExp(`<(/?)${tagName}[\\s>]`, "gi");
4644
+ let depth = 0;
4645
+ let match;
4646
+ while ((match = tagRegex.exec(html)) !== null) {
4647
+ if (match.index > offset2) break;
4648
+ if (match[1]) {
4649
+ depth = Math.max(0, depth - 1);
4525
4650
  } else {
4526
- filterTexts = splitOutsideQuotes(filtersText, FILTER_SEPARATOR2).map(trimFn);
4527
- filters = parseFilters(filterTexts);
4528
- cacheFilterInfos.set(filtersText, filters);
4651
+ depth++;
4529
4652
  }
4530
- } else {
4531
- stateAndPath = statePart.trim();
4532
- }
4533
- if (stateAndPath.indexOf("@") !== -1) {
4534
- raiseError2(`"${stateAndPath}": the "@name" selector was removed in v2 \u2014 there is a single state tree. Mount the named state onto the tree (<wcs-state mount="...">) and read it by its path prefix instead.`);
4535
4653
  }
4536
- const statePathName = stateAndPath;
4537
- const pathInfo = getPathInfo(statePathName);
4538
- return {
4539
- statePathName,
4540
- statePathInfo: pathInfo,
4541
- outFilters: filters
4542
- };
4543
- }
4544
- var KEYWORDS_WITHOUT_MODIFIERS = /* @__PURE__ */ new Set([ELSE_KEYWORD2, "if", "elseif", "for", SPREAD_PROP2]);
4545
- var EXPLICIT_PROPERTY_REJECTED_HEADS = /* @__PURE__ */ new Set([
4546
- CLASS_NAMESPACE2,
4547
- ATTR_NAMESPACE2,
4548
- STYLE_NAMESPACE2,
4549
- COMMAND_NAMESPACE2,
4550
- EVENT_TOKEN_NAMESPACE2
4551
- ]);
4552
- function splitBindTexts(bindText) {
4553
- return splitOutsideQuotes(bindText, BINDING_SEPARATOR2);
4654
+ return depth > 0;
4554
4655
  }
4555
- function parseBindTextsForElement(bindText) {
4556
- const [...bindTexts] = splitBindTexts(bindText).map(trimFn).filter((s) => s.length > 0);
4557
- const results = bindTexts.map((bindText2) => {
4558
- const separatorIndex = bindText2.indexOf(PROP_VALUE_SEPARATOR2);
4559
- if (separatorIndex === -1) {
4560
- raiseError2(`Invalid bindText: "${bindText2}". Missing ':' separator between propPart and statePart.`);
4656
+
4657
+ // src/service/templateSyntaxValidator.ts
4658
+ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", locale2, fileReader, applicationSchema) {
4659
+ const diagnostics = [];
4660
+ const msgs = getMessages(locale2);
4661
+ const allPaths = mergeSchemaCandidates(getStatePathsFromHtml(html, stateTagName, fileReader), applicationSchema);
4662
+ const defaultSchema = applicationSchema;
4663
+ const missingVerdict = (path, displayPath, pathSet2, scoped) => {
4664
+ if (hasRecursionWildcard(path)) {
4665
+ return {
4666
+ code: WcsDiagnosticCode.RecursionUnsupported,
4667
+ severity: "error",
4668
+ message: msgs.recursionUnsupported(path, "binding")
4669
+ };
4670
+ }
4671
+ if (isValidTemplatePath(path, pathSet2, scoped)) return null;
4672
+ if (defaultSchema !== void 0 && !path.startsWith("$")) {
4673
+ const resolution = resolveSchemaPath(defaultSchema, defaultSchema.$defs ?? {}, path.split("."));
4674
+ return resolution.kind === "nonexistent" ? { code: WcsDiagnosticCode.PathNonexistent, severity: "error", message: msgs.pathNonexistent(displayPath) } : null;
4675
+ }
4676
+ return { code: WcsDiagnosticCode.BindingPathMissing, severity: "warning", message: msgs.pathMissing(displayPath) };
4677
+ };
4678
+ if (allPaths.length === 0) return diagnostics;
4679
+ const defaultPaths = allPaths;
4680
+ const pathSet = new Set(defaultPaths.map((p) => p.path));
4681
+ const filterNameSet = new Set(BUILTIN_FILTERS.map((f) => f.name));
4682
+ const mustaches = findAllMustacheSyntax(html);
4683
+ const comments = findAllCommentBindings(html);
4684
+ for (const item of [...mustaches, ...comments]) {
4685
+ if (item.kind === "comment") {
4686
+ diagnostics.push({
4687
+ code: WcsDiagnosticCode.TemplateSyntax,
4688
+ start: item.matchStart,
4689
+ end: item.matchEnd,
4690
+ message: msgs.wcsTextInfo(item.expression),
4691
+ severity: "info"
4692
+ });
4561
4693
  }
4562
- const propPart = bindText2.slice(0, separatorIndex).trim();
4563
- const statePart = bindText2.slice(separatorIndex + 1).trim();
4564
- const keyword = propPart.split(MODIFIER_SEPARATOR2)[0].split(FILTER_SEPARATOR2)[0].trim();
4565
- if (keyword !== propPart && KEYWORDS_WITHOUT_MODIFIERS.has(keyword)) {
4566
- raiseError2(`[wcs/binding-syntax] "${bindText2}": "${keyword}" takes no modifiers or filters on its left side \u2014 write "${keyword}:".${LINT_HINT}`);
4694
+ if (item.kind === "mustache" && !item.insideTemplate) {
4695
+ diagnostics.push({
4696
+ code: WcsDiagnosticCode.TemplateSyntax,
4697
+ start: item.matchStart,
4698
+ end: item.matchEnd,
4699
+ message: msgs.moustacheFouc(item.expression),
4700
+ severity: "info"
4701
+ });
4567
4702
  }
4568
- if (propPart === ELSE_KEYWORD2) {
4569
- if (statePart.length > 0) {
4570
- raiseError2(`[wcs/binding-syntax] "${bindText2}": "else" takes no value \u2014 write "else:".${LINT_HINT}`);
4571
- }
4572
- const pathInfo = getPathInfo("#else");
4573
- return {
4574
- propName: ELSE_KEYWORD2,
4575
- propSegments: [ELSE_KEYWORD2],
4576
- propModifiers: [],
4577
- statePathName: "#else",
4578
- statePathInfo: pathInfo,
4579
- inFilters: [],
4580
- outFilters: [],
4581
- bindingType: "else"
4582
- };
4583
- } else if (propPart === SPREAD_PROP2) {
4584
- const stateResult = parseStatePart(statePart);
4585
- if (stateResult.outFilters.length > 0) {
4586
- raiseError2(`Invalid spread binding "${bindText2}": filters are not allowed on spread targets.`);
4703
+ if (!item.expression) continue;
4704
+ const parts = splitOutsideQuotes2(item.expression, "|");
4705
+ const pathPart = (parts[0] || "").trim();
4706
+ if (pathPart.includes("@")) continue;
4707
+ const insideFor = item.insideTemplate && isInsideForTemplate(html, item.matchStart, bindAttrName);
4708
+ if (pathPart && !/^-?\d|^["'`]|^true$|^false$|^null$/.test(pathPart)) {
4709
+ if (!insideFor && pathPart.includes("*")) {
4710
+ diagnostics.push({
4711
+ code: WcsDiagnosticCode.TemplateSyntax,
4712
+ start: item.exprStart,
4713
+ end: item.exprStart + pathPart.length,
4714
+ message: msgs.patternPathOutsideFor(pathPart),
4715
+ severity: "warning"
4716
+ });
4587
4717
  }
4588
- if (stateResult.statePathName.length === 0) {
4589
- raiseError2(`Invalid spread binding "${bindText2}": spread target path is required.`);
4718
+ if (!insideFor && pathPart.startsWith(".")) {
4719
+ diagnostics.push({
4720
+ code: WcsDiagnosticCode.TemplateSyntax,
4721
+ start: item.exprStart,
4722
+ end: item.exprStart + pathPart.length,
4723
+ message: msgs.omittedPathOutsideFor(pathPart),
4724
+ severity: "warning"
4725
+ });
4590
4726
  }
4591
- return {
4592
- propName: SPREAD_PROP2,
4593
- propSegments: [SPREAD_PROP2],
4594
- propModifiers: [],
4595
- inFilters: [],
4596
- ...stateResult,
4597
- bindingType: "spread"
4598
- };
4599
- } else if (propPart === "if" || propPart === "elseif" || propPart === "for") {
4600
- const stateResult = parseStatePart(statePart);
4601
- return {
4602
- propName: propPart,
4603
- propSegments: [propPart],
4604
- propModifiers: [],
4605
- inFilters: [],
4606
- ...stateResult,
4607
- bindingType: propPart
4608
- };
4609
- } else if (keyword === "radio" || keyword === "checkbox") {
4610
- const stateResult = parseStatePart(statePart);
4611
- const propResult = parsePropPart(propPart);
4612
- return {
4613
- ...propResult,
4614
- ...stateResult,
4615
- bindingType: keyword
4616
- };
4617
- } else {
4618
- const stateResult = parseStatePart(statePart);
4619
- const propResult = parsePropPart(propPart);
4620
- if (propResult.propSegments[0] === "" && propResult.propSegments.length > 1) {
4621
- const propSegments = propResult.propSegments.slice(1);
4622
- if (propSegments.includes("") || EXPLICIT_PROPERTY_REJECTED_HEADS.has(propSegments[0])) {
4623
- raiseError2(`[wcs/binding-syntax] "${propPart}": a leading "." binds an element property by name \u2014 write a non-empty property that is not a namespace (${[...EXPLICIT_PROPERTY_REJECTED_HEADS].join(", ")}).${LINT_HINT}`);
4727
+ if (insideFor && !pathPart.startsWith(".")) {
4728
+ const indexMatch = /^\$(\d+)$/.exec(pathPart);
4729
+ const needed = indexMatch !== null ? Number(indexMatch[1]) : pathPart.includes("*") ? countWildcardSegments(pathPart) : 0;
4730
+ if (needed > 0) {
4731
+ const available = getAvailableWildcardRank(html, item.matchStart, bindAttrName);
4732
+ if (available > 0 && needed > available) {
4733
+ diagnostics.push({
4734
+ code: WcsDiagnosticCode.WildcardRank,
4735
+ start: item.exprStart,
4736
+ end: item.exprStart + pathPart.length,
4737
+ message: msgs.wildcardRank(`"${pathPart}"`, needed, available),
4738
+ severity: "warning"
4739
+ });
4740
+ }
4624
4741
  }
4625
- return {
4626
- ...propResult,
4627
- propName: propSegments.join(DELIMITER2),
4628
- propSegments,
4629
- ...stateResult,
4630
- bindingType: "prop"
4631
- };
4632
4742
  }
4633
- if (propResult.propSegments[0] === EVENT_TOKEN_NAMESPACE2) {
4634
- return {
4635
- ...propResult,
4636
- ...stateResult,
4637
- bindingType: "event"
4638
- };
4743
+ if (/\.\d+\.|\.\d+$/.test(pathPart)) {
4744
+ diagnostics.push({
4745
+ code: WcsDiagnosticCode.TemplateSyntax,
4746
+ start: item.exprStart,
4747
+ end: item.exprStart + pathPart.length,
4748
+ message: msgs.resolvedPathInUi(pathPart),
4749
+ severity: "warning"
4750
+ });
4639
4751
  }
4640
- if (propResult.propSegments[0].startsWith(EVENT_PROP_PREFIX2)) {
4641
- return {
4642
- ...propResult,
4643
- ...stateResult,
4644
- bindingType: "event"
4645
- };
4752
+ if (pathPart.startsWith(".")) {
4753
+ const forPath = insideFor ? getInnermostForPath(html, item.matchStart, bindAttrName) : null;
4754
+ if (forPath && !forPath.startsWith(".")) {
4755
+ const expandedPath = pathPart === "." ? `${forPath}.*` : `${forPath}.*.${pathPart.slice(1)}`;
4756
+ const verdict = missingVerdict(expandedPath, pathPart, pathSet, defaultPaths);
4757
+ if (verdict) {
4758
+ diagnostics.push({
4759
+ code: verdict.code,
4760
+ start: item.exprStart,
4761
+ end: item.exprStart + pathPart.length,
4762
+ message: verdict.message + msgs.expansionSuffix(expandedPath),
4763
+ severity: verdict.severity
4764
+ });
4765
+ }
4766
+ }
4646
4767
  } else {
4647
- return {
4648
- ...propResult,
4649
- ...stateResult,
4650
- bindingType: "prop"
4651
- };
4768
+ const verdict = missingVerdict(pathPart, pathPart, pathSet, defaultPaths);
4769
+ if (verdict) {
4770
+ diagnostics.push({
4771
+ code: verdict.code,
4772
+ start: item.exprStart,
4773
+ end: item.exprStart + pathPart.length,
4774
+ message: verdict.message,
4775
+ severity: verdict.severity
4776
+ });
4777
+ }
4652
4778
  }
4653
4779
  }
4654
- });
4655
- if (results.length > 1) {
4656
- const isIncludeSingleBinding = results.some((r) => STRUCTURAL_BINDING_TYPE_SET2.has(r.bindingType));
4657
- if (isIncludeSingleBinding) {
4658
- raiseError2(`[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}`);
4780
+ let segmentStart = parts[0].length + 1;
4781
+ for (let i = 1; i < parts.length; i++) {
4782
+ const segment = parts[i];
4783
+ const filterName = segment.trim().replace(/\(.*$/, "");
4784
+ const filterOffset = segmentStart + (segment.length - segment.trimStart().length);
4785
+ segmentStart += segment.length + 1;
4786
+ const canonical = canonicalFilterName(filterName);
4787
+ if (filterName && canonical !== filterName && filterNameSet.has(canonical)) {
4788
+ diagnostics.push({
4789
+ code: WcsDiagnosticCode.NameAlias,
4790
+ start: item.exprStart + filterOffset,
4791
+ end: item.exprStart + filterOffset + filterName.length,
4792
+ message: msgs.nameAlias(filterName, canonical),
4793
+ severity: "info"
4794
+ });
4795
+ } else if (filterName && !filterNameSet.has(filterName)) {
4796
+ diagnostics.push({
4797
+ code: WcsDiagnosticCode.FilterUnknown,
4798
+ start: item.exprStart + filterOffset,
4799
+ end: item.exprStart + filterOffset + filterName.length,
4800
+ message: msgs.filterUnknown(filterName),
4801
+ severity: "warning"
4802
+ });
4803
+ }
4659
4804
  }
4660
4805
  }
4661
- return results;
4662
- }
4663
- function parseBindTextForEmbeddedNode(bindText) {
4664
- const stateResult = parseStatePart(bindText);
4665
- return {
4666
- propName: "textContent",
4667
- propSegments: ["textContent"],
4668
- propModifiers: [],
4669
- inFilters: [],
4670
- ...stateResult,
4671
- bindingType: "text"
4672
- };
4806
+ return diagnostics;
4673
4807
  }
4674
- function clearParserCaches() {
4675
- clearPathInfoCacheForTooling();
4676
- clearPropPartCacheForTooling();
4677
- clearStatePartCacheForTooling();
4678
- clearFilterFnCacheForTooling();
4808
+ function isValidTemplatePath(path, pathSet, scopedPaths) {
4809
+ if (/^\$\d+$/.test(path)) return true;
4810
+ if (path.startsWith("$streamStatus.") || path.startsWith("$streamError.")) {
4811
+ const prefix = path.startsWith("$streamStatus.") ? "$streamStatus." : "$streamError.";
4812
+ const hasNamespace = scopedPaths.some((p) => p.path.startsWith(prefix));
4813
+ return !hasNamespace || pathSet.has(path);
4814
+ }
4815
+ return pathSet.has(path) || matchesRecursionCandidates(scopedPaths, path, pathSet);
4679
4816
  }
4680
4817
 
4681
4818
  // src/core/parser/positionalParser.ts
@@ -4698,7 +4835,7 @@ function parseEmbeddedTextWithPositions(expression) {
4698
4835
  if (parsed === null) {
4699
4836
  return { exprRange, exprText: expression, parsed, error, propRange: null, pathRange: null };
4700
4837
  }
4701
- const firstPipe = expression.indexOf(delimiters.filter);
4838
+ const firstPipe = indexOfOutsideQuotes2(expression, delimiters.filter);
4702
4839
  const pathScopeEnd = firstPipe === -1 ? expression.length : firstPipe;
4703
4840
  const pathLocal = locate(expression, parsed.statePathName, 0, pathScopeEnd);
4704
4841
  return {
@@ -4732,14 +4869,14 @@ function parseBindTextWithPositions(bindText) {
4732
4869
  results.push({ exprRange, exprText: expr, parsed, error, propRange: null, pathRange: null });
4733
4870
  continue;
4734
4871
  }
4735
- const colon = expr.indexOf(delimiters.propValue);
4872
+ const colon = indexOfOutsideQuotes2(expr, delimiters.propValue);
4736
4873
  const propEndLimit = colon === -1 ? expr.length : colon;
4737
4874
  const propLocal = locate(expr, parsed.propName, 0, propEndLimit);
4738
4875
  let pathLocal = null;
4739
4876
  if (colon !== -1) {
4740
4877
  const stateBase = colon + 1;
4741
- const firstPipe = expr.indexOf(delimiters.filter, stateBase);
4742
- const pathScopeEnd = firstPipe === -1 ? expr.length : firstPipe;
4878
+ const rhsPipe = indexOfOutsideQuotes2(expr.slice(stateBase), delimiters.filter);
4879
+ const pathScopeEnd = rhsPipe === -1 ? expr.length : stateBase + rhsPipe;
4743
4880
  pathLocal = locate(expr, parsed.statePathName, stateBase, pathScopeEnd);
4744
4881
  }
4745
4882
  const lift = (range) => range === null ? null : { start: exprStart + range.start, end: exprStart + range.end };
@@ -4781,13 +4918,13 @@ function validateBindingSyntax(html, bindAttrName = "data-wcs", locale2) {
4781
4918
  });
4782
4919
  }
4783
4920
  }
4784
- for (const mustache of findAllMustacheSyntax(html)) {
4785
- const detail = bindingSyntaxDetail(parseEmbeddedTextWithPositions(mustache.expression).error);
4921
+ for (const item of [...findAllMustacheSyntax(html), ...findAllCommentBindings(html)]) {
4922
+ const detail = bindingSyntaxDetail(parseEmbeddedTextWithPositions(item.expression).error);
4786
4923
  if (detail === null) continue;
4787
4924
  diagnostics.push({
4788
4925
  code: WcsDiagnosticCode.BindingSyntax,
4789
- start: mustache.exprStart,
4790
- end: mustache.exprStart + mustache.expression.length,
4926
+ start: item.exprStart,
4927
+ end: item.exprStart + item.expression.length,
4791
4928
  message: msgs.bindingSyntax(detail),
4792
4929
  severity: "error"
4793
4930
  });
@@ -6082,6 +6219,13 @@ var DOM_COMMON_PROPERTIES = /* @__PURE__ */ new Set([
6082
6219
  "className"
6083
6220
  ]);
6084
6221
  var STRUCTURAL_DIRECTIVES2 = /* @__PURE__ */ new Set(["for", "if", "elseif", "else"]);
6222
+ var EXPLICIT_PROPERTY_REJECTED_HEADS2 = /* @__PURE__ */ new Set([
6223
+ ...Object.values(getWcsManifest().syntax.bindingTypes.propNamespaces),
6224
+ "state"
6225
+ ]);
6226
+ var EXPLICIT_PROPERTY_REJECTED_HEADS_RE = new RegExp(
6227
+ `^(?:${[...EXPLICIT_PROPERTY_REJECTED_HEADS2].map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})(\\.|$)`
6228
+ );
6085
6229
  var EMPTYISH_SEEDS = /* @__PURE__ */ new Set(["''", '""', "``", "null", "[]", "{}"]);
6086
6230
  function validateIoNodes(html, bindAttribute = "data-wcs", stateTagName = "wcs-state", locale2, fileReader) {
6087
6231
  const diagnostics = [];
@@ -6148,7 +6292,8 @@ function validateBindingAgainstContract(tagName, contract, parsed, property, sta
6148
6292
  const explicit = property.startsWith(".") && property !== "...";
6149
6293
  if (explicit) {
6150
6294
  property = property.slice(1);
6151
- if (/^(class|style|attr|command|eventToken)(\.|$)/.test(property)) return;
6295
+ if (property.length === 0 || property.startsWith(".")) return;
6296
+ if (EXPLICIT_PROPERTY_REJECTED_HEADS_RE.test(property)) return;
6152
6297
  }
6153
6298
  if (property === "...") return;
6154
6299
  if (STRUCTURAL_DIRECTIVES2.has(property)) return;
@@ -6162,7 +6307,7 @@ function validateBindingAgainstContract(tagName, contract, parsed, property, sta
6162
6307
  severity: "warning",
6163
6308
  tag: tagName,
6164
6309
  member: property,
6165
- message: msgs.onPrefixedMember(property, tagName)
6310
+ message: msgs.onPrefixedMember(property, tagName, modifiers)
6166
6311
  });
6167
6312
  }
6168
6313
  return;
@@ -6933,12 +7078,12 @@ function createApiCallRegex(apis) {
6933
7078
  }
6934
7079
 
6935
7080
  // src/service/recursionValidator.ts
6936
- var RECURSION_APIS = ["getAll", "setAll", "resolve", "postUpdate", "trackDependency"];
7081
+ var RECURSION_APIS = ["getAll", "setAll", "resolve", "postUpdate", "dependOn", "trackDependency"];
6937
7082
  var UNSUPPORTED_API_SITE = {
6938
7083
  $resolve: "resolve",
6939
7084
  $postUpdate: "postUpdate",
6940
- $trackDependency: "trackDependency",
6941
- $dependOn: "trackDependency"
7085
+ $dependOn: "dependOn",
7086
+ $trackDependency: "trackDependency"
6942
7087
  };
6943
7088
  var BRACKET_ASSIGNMENT = new RegExp(`${ROOT_BRACKET}${ASSIGN_TAIL}`, "g");
6944
7089
  var PRE_BRACKET_INCDEC = new RegExp(`${PRE_INCDEC}${ROOT_BRACKET}`, "g");
@@ -7196,12 +7341,12 @@ function validateListKeys(script, offset2, msgs, out) {
7196
7341
  }
7197
7342
  }
7198
7343
  function validateApiCalls(script, offset2, spec, getterSuffixes, undeclared, msgs, out) {
7199
- const scan = blankComments(script);
7344
+ const scan = maskCommentsAndStrings(script);
7200
7345
  const regex = createApiCallRegex(RECURSION_APIS);
7201
7346
  let match;
7202
7347
  while ((match = regex.exec(scan)) !== null) {
7203
7348
  const api = `$${match[1]}`;
7204
- const parsed = splitCallArgs(scan, match.index + match[0].length);
7349
+ const parsed = splitCallArgs(script, match.index + match[0].length);
7205
7350
  if (parsed === null) continue;
7206
7351
  regex.lastIndex = parsed.end;
7207
7352
  if (parsed.args.length === 0) continue;
@@ -7354,19 +7499,10 @@ function isFunctionLiteral(arg) {
7354
7499
 
7355
7500
  // src/service/namedStateValidator.ts
7356
7501
  function findStateSelector(expr, embedded = false) {
7357
- const colon = embedded ? -1 : expr.indexOf(":");
7502
+ const colon = embedded ? -1 : indexOfOutsideQuotes2(expr, ":");
7358
7503
  const from = colon + 1;
7359
- let depth = 0;
7360
- let end = expr.length;
7361
- for (let i = from; i < expr.length; i++) {
7362
- const ch = expr[i];
7363
- if (ch === "(") depth++;
7364
- else if (ch === ")") depth = Math.max(0, depth - 1);
7365
- else if (ch === "|" && depth === 0) {
7366
- end = i;
7367
- break;
7368
- }
7369
- }
7504
+ const pipe = indexOfOutsideQuotes2(expr.slice(from), "|");
7505
+ const end = pipe === -1 ? expr.length : from + pipe;
7370
7506
  const at2 = expr.indexOf("@", from);
7371
7507
  if (at2 === -1 || at2 >= end) return null;
7372
7508
  const raw = expr.slice(at2 + 1, end);
@@ -13468,6 +13604,64 @@ function visitDestructure(pattern, prefix, scope, out) {
13468
13604
  emit(out, segments, { form: "destructure", callee: false, written: false }, property.start, property.end);
13469
13605
  }
13470
13606
  }
13607
+ function collectThisMemberRefs(body, names) {
13608
+ let program;
13609
+ try {
13610
+ program = parse3(PREFIX + body + SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13611
+ } catch {
13612
+ return null;
13613
+ }
13614
+ const fn = unwrapWrapper(program);
13615
+ if (fn === null) return null;
13616
+ return walkThisMembers(fn.body, names, PREFIX.length);
13617
+ }
13618
+ var VALUE_PREFIX = "(async function* () {\n(";
13619
+ var VALUE_SUFFIX = ")\n})";
13620
+ function collectThisMemberRefsInValue(value, names) {
13621
+ let program;
13622
+ try {
13623
+ program = parse3(VALUE_PREFIX + value + VALUE_SUFFIX, { ecmaVersion: "latest", sourceType: "module" });
13624
+ } catch {
13625
+ return null;
13626
+ }
13627
+ const wrapper = unwrapWrapper(program);
13628
+ if (wrapper === null || wrapper.body.body.length !== 1) return null;
13629
+ const statement = wrapper.body.body[0];
13630
+ if (statement.type !== "ExpressionStatement") return null;
13631
+ const expression = statement.expression;
13632
+ if (expression.type !== "FunctionExpression") return [];
13633
+ return walkThisMembers(expression.body, names, VALUE_PREFIX.length);
13634
+ }
13635
+ function walkThisMembers(root, names, offsetShift) {
13636
+ const out = [];
13637
+ const walk = (node, thisIsState) => {
13638
+ if (isClassNode(node)) return;
13639
+ if (isFunctionNode(node)) {
13640
+ const inner = node.type === "ArrowFunctionExpression" ? thisIsState : false;
13641
+ forEachChild(node, (child) => walk(child, inner));
13642
+ return;
13643
+ }
13644
+ if (thisIsState && node.type === "MemberExpression" && node.object.type === "ThisExpression") {
13645
+ const hit = thisMemberName(node);
13646
+ if (hit !== null && names.has(hit.name)) {
13647
+ out.push({ name: hit.name, start: hit.start - offsetShift, end: hit.end - offsetShift });
13648
+ }
13649
+ }
13650
+ forEachChild(node, (child) => walk(child, thisIsState));
13651
+ };
13652
+ walk(root, true);
13653
+ return out;
13654
+ }
13655
+ function thisMemberName(node) {
13656
+ const property = node.property;
13657
+ if (!node.computed && property.type === "Identifier") {
13658
+ return { name: property.name, start: property.start, end: property.end };
13659
+ }
13660
+ if (node.computed && property.type === "Literal" && typeof property.value === "string") {
13661
+ return { name: property.value, start: property.start + 1, end: property.end - 1 };
13662
+ }
13663
+ return null;
13664
+ }
13471
13665
 
13472
13666
  // src/core/index/referenceIndex.ts
13473
13667
  function buildReferenceIndex(html, options = {}) {
@@ -13580,10 +13774,30 @@ var STATE_UPDATED_CALLBACKS = /* @__PURE__ */ new Set(["$renderedCallback", "$up
13580
13774
  var OLD_API_NAMES = { $trackDependency: "$dependOn", $untrackDependency: "$untracked" };
13581
13775
  var OLD_DECLARATION_KEYS = { $streams: "$stream", $updatedCallback: "$renderedCallback" };
13582
13776
  var OLD_API_CALL = /\.\s*(\$trackDependency|\$untrackDependency)\b/g;
13583
- var OLD_DECLARATION_KEY = /(^|[{,\s])(\$streams|\$updatedCallback)(?=\s*[:(])/g;
13777
+ var OLD_DECLARATION_MEMBER = /\.\s*(\$streams|\$updatedCallback)\b/g;
13778
+ var OLD_DECLARATION_MEMBER_NAMES = new Set(Object.keys(OLD_DECLARATION_KEYS));
13779
+ var OLD_DECLARATION_KEY = /(^|[{,;\s])(\$streams|\$updatedCallback)(?=\s*(?:[:(]|=(?!=)))/g;
13780
+ function collectDeclarationAliasReads(script) {
13781
+ if (!hasDefaultExportObject(script)) return null;
13782
+ const out = [];
13783
+ const take = (refs, base) => {
13784
+ if (refs === null) return false;
13785
+ for (const ref2 of refs) out.push({ name: ref2.name, start: base + ref2.start });
13786
+ return true;
13787
+ };
13788
+ for (const callable of analyzeCallableBodies(script)) {
13789
+ if (!take(collectThisMemberRefs(callable.body, OLD_DECLARATION_MEMBER_NAMES), callable.bodyStart)) return null;
13790
+ }
13791
+ for (const handler of analyzeWatchHandlerSources(script)) {
13792
+ const refs = handler.kind === "body" ? collectThisMemberRefs(handler.text, OLD_DECLARATION_MEMBER_NAMES) : collectThisMemberRefsInValue(handler.text, OLD_DECLARATION_MEMBER_NAMES);
13793
+ if (!take(refs, handler.start)) return null;
13794
+ }
13795
+ out.sort((a, b) => a.start - b.start);
13796
+ return out;
13797
+ }
13584
13798
  function validateNameAliases(script, scriptStart, locale2) {
13585
13799
  const msgs = getMessages(locale2);
13586
- const scan = blankComments(script);
13800
+ const scan = maskCommentsAndStrings(script);
13587
13801
  const out = [];
13588
13802
  const push2 = (name, canonical, offset2) => {
13589
13803
  out.push({
@@ -13594,14 +13808,55 @@ function validateNameAliases(script, scriptStart, locale2) {
13594
13808
  severity: "info"
13595
13809
  });
13596
13810
  };
13811
+ const pushRead = (name, offset2, shape) => {
13812
+ const canonical = OLD_DECLARATION_KEYS[name];
13813
+ out.push({
13814
+ code: WcsDiagnosticCode.DeclarationAliasRead,
13815
+ start: scriptStart + offset2,
13816
+ end: scriptStart + offset2 + name.length,
13817
+ message: shape === "own" ? msgs.declarationAliasRead(name, canonical) : msgs.declarationAliasReadUncertain(name, canonical),
13818
+ severity: shape === "own" ? "warning" : "info"
13819
+ });
13820
+ };
13597
13821
  OLD_API_CALL.lastIndex = 0;
13598
13822
  let match;
13599
13823
  while ((match = OLD_API_CALL.exec(scan)) !== null) {
13600
- push2(match[1], OLD_API_NAMES[match[1]], match.index + match[0].length - match[1].length);
13824
+ const written = match[1];
13825
+ push2(written, OLD_API_NAMES[written], match.index + match[0].length - written.length);
13826
+ }
13827
+ const astReads = collectDeclarationAliasReads(script);
13828
+ if (astReads !== null) {
13829
+ for (const read of astReads) pushRead(read.name, read.start, "own");
13830
+ } else {
13831
+ OLD_DECLARATION_MEMBER.lastIndex = 0;
13832
+ while ((match = OLD_DECLARATION_MEMBER.exec(scan)) !== null) {
13833
+ const written = match[1];
13834
+ pushRead(written, match.index + match[0].length - written.length, "unknown");
13835
+ }
13836
+ }
13837
+ const spans = analyzeDeclarationSpans(script);
13838
+ if (spans.length === 0) {
13839
+ OLD_DECLARATION_KEY.lastIndex = 0;
13840
+ while ((match = OLD_DECLARATION_KEY.exec(scan)) !== null) {
13841
+ push2(match[2], OLD_DECLARATION_KEYS[match[2]], match.index + match[1].length);
13842
+ }
13843
+ return out;
13601
13844
  }
13602
- OLD_DECLARATION_KEY.lastIndex = 0;
13603
- while ((match = OLD_DECLARATION_KEY.exec(scan)) !== null) {
13604
- push2(match[2], OLD_DECLARATION_KEYS[match[2]], match.index + match[1].length);
13845
+ const declared = new Set(spans.map((span) => span.name));
13846
+ for (const span of spans) {
13847
+ const canonical = OLD_DECLARATION_KEYS[span.name];
13848
+ if (canonical === void 0) continue;
13849
+ if (declared.has(canonical)) {
13850
+ out.push({
13851
+ code: WcsDiagnosticCode.DeclarationAlias,
13852
+ start: scriptStart + span.start,
13853
+ end: scriptStart + span.end,
13854
+ message: msgs.declarationAlias(span.name, canonical),
13855
+ severity: "error"
13856
+ });
13857
+ continue;
13858
+ }
13859
+ push2(span.name, canonical, span.start);
13605
13860
  }
13606
13861
  return out;
13607
13862
  }
@@ -13609,9 +13864,10 @@ var API_CALL = /\.\s*\$(getAll|setAll|resolve)\s*\(/g;
13609
13864
  function validateIndexArity(script, scriptStart, locale2) {
13610
13865
  const msgs = getMessages(locale2);
13611
13866
  const out = [];
13867
+ const scan = maskCommentsAndStrings(script);
13612
13868
  API_CALL.lastIndex = 0;
13613
13869
  let match;
13614
- while ((match = API_CALL.exec(script)) !== null) {
13870
+ while ((match = API_CALL.exec(scan)) !== null) {
13615
13871
  const api = `$${match[1]}`;
13616
13872
  const parsed = splitCallArgs(script, match.index + match[0].length);
13617
13873
  if (parsed === null) continue;
@@ -13761,18 +14017,21 @@ function collectNestedWriteRoots(html, stateTagName, bindAttrName, blocks) {
13761
14017
  }
13762
14018
  for (const block of blocks) {
13763
14019
  if (block.mountPath !== null) addPrefixes(block.mountPath, true);
13764
- const scan = blankComments(block.content);
14020
+ const scan = maskCommentsAndStrings(block.content);
13765
14021
  for (const regex of [BRACKET_WRITE, PRE_BRACKET_INCDEC2]) {
13766
14022
  regex.lastIndex = 0;
13767
14023
  let match;
13768
- while ((match = regex.exec(scan)) !== null) addPrefixes(match[1], false);
14024
+ while ((match = regex.exec(scan)) !== null) {
14025
+ const keyStart = match.index + match[0].search(/["']/) + 1;
14026
+ addPrefixes(block.content.slice(keyStart, keyStart + match[1].length), false);
14027
+ }
13769
14028
  }
13770
14029
  API_CALL.lastIndex = 0;
13771
14030
  let call;
13772
14031
  while ((call = API_CALL.exec(scan)) !== null) {
13773
14032
  const api = call[1];
13774
14033
  if (api === "getAll") continue;
13775
- const parsed = splitCallArgs(scan, call.index + call[0].length);
14034
+ const parsed = splitCallArgs(block.content, call.index + call[0].length);
13776
14035
  if (parsed === null) continue;
13777
14036
  API_CALL.lastIndex = parsed.end;
13778
14037
  const path = parsed.args.length > 0 ? literalString(parsed.args[0]) : null;