@wcstack/typescript 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -641,7 +641,7 @@ function loadSchemaCore() {
641
641
  return cached;
642
642
  }
643
643
 
644
- var version = "4.7.0";
644
+ var version = "4.8.0";
645
645
  var pkg = {
646
646
  version: version};
647
647
 
@@ -3025,7 +3025,7 @@ function tokenize(text3) {
3025
3025
  i += 2;
3026
3026
  continue;
3027
3027
  }
3028
- if ("{}[]<>()|,;:?!*.=".includes(ch)) {
3028
+ if ("{}[]<>()|&,;:?!*.=".includes(ch)) {
3029
3029
  tokens.push({ t: "punct", v: ch });
3030
3030
  i++;
3031
3031
  continue;
@@ -3074,6 +3074,7 @@ function parseJsDocType(text3) {
3074
3074
  const member = parsePostfix();
3075
3075
  if (member === null) return null;
3076
3076
  members.push(member);
3077
+ if (expect("&")) continue;
3077
3078
  if (!expect("|")) break;
3078
3079
  }
3079
3080
  if (isPunct("=>")) {
@@ -3237,12 +3238,21 @@ function readBracedType(comment, tag) {
3237
3238
  return null;
3238
3239
  }
3239
3240
  function readJsDocTypeBefore(content, propIndex) {
3241
+ const comment = jsDocCommentBefore(content, propIndex);
3242
+ return comment === void 0 ? void 0 : readBracedType(comment, "type")?.type.trim();
3243
+ }
3244
+ function readJsDocReturnsBefore(content, propIndex) {
3245
+ const comment = jsDocCommentBefore(content, propIndex);
3246
+ if (comment === void 0) return void 0;
3247
+ return (readBracedType(comment, "returns") ?? readBracedType(comment, "return"))?.type.trim();
3248
+ }
3249
+ function jsDocCommentBefore(content, propIndex) {
3240
3250
  let end = propIndex;
3241
3251
  while (end > 0 && /\s/.test(content[end - 1])) end--;
3242
3252
  if (!content.startsWith("*/", end - 2)) return void 0;
3243
3253
  const start = content.lastIndexOf("/*", end - 2);
3244
3254
  if (start === -1 || content[start + 2] !== "*") return void 0;
3245
- return readBracedType(content.slice(start, end), "type")?.type.trim();
3255
+ return content.slice(start, end);
3246
3256
  }
3247
3257
  function collectJsDocTypedefs(script, scan) {
3248
3258
  const typedefs = /* @__PURE__ */ new Map();
@@ -3329,6 +3339,7 @@ function analyzeStatePaths(scriptContent) {
3329
3339
  const settable = !recursive && effective !== "data" && effective.set;
3330
3340
  paths.push({ path: prop.name, kind: recursive ? "recursive" : "computed", ...settable ? { settable } : {} });
3331
3341
  }
3342
+ if (prop.declaredType !== void 0) pushDeclaredShapePaths(prop.name, prop.declaredType, paths, 0, typedefs);
3332
3343
  continue;
3333
3344
  }
3334
3345
  pushDataPropertyPaths(prop, paths, typedefs);
@@ -4206,7 +4217,12 @@ function extractDefaultExportObject(script) {
4206
4217
  function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
4207
4218
  const props = [];
4208
4219
  const scan = maskCommentsAndStrings(objectContent);
4209
- const regex = allowEmptyDataKeys ? /(?:(?:get|set)\s+(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*\([^)]*\)\s*\{)|(?:(?:async\s+)?(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*\([^)]*\)\s*\{)|(?:(?:"([^"]*)"|'([^']*)'|([$\w]+))\s*:\s*)/gd : /(?:(?:get|set)\s+(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*\([^)]*\)\s*\{)|(?:(?:async\s+)?(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*\([^)]*\)\s*\{)|(?:(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*:\s*)/gd;
4220
+ const params = String.raw`\((?:[^()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*\)`;
4221
+ const dataKey = allowEmptyDataKeys ? String.raw`(?:"([^"]*)"|'([^']*)'|([$\w]+))` : String.raw`(?:"([^"]+)"|'([^']+)'|([$\w]+))`;
4222
+ const regex = new RegExp(
4223
+ String.raw`(?:(?:get|set)\s+(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params}\s*\{)|(?:(?:async\s+)?(?:"([^"]+)"|'([^']+)'|([$\w]+))\s*${params}\s*\{)|(?:${dataKey}\s*:\s*)`,
4224
+ "gd"
4225
+ );
4210
4226
  let match;
4211
4227
  while ((match = regex.exec(scan)) !== null) {
4212
4228
  const indices = match.indices;
@@ -4227,6 +4243,8 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
4227
4243
  if (accessorName) {
4228
4244
  const { body, bodyStart } = skipBody();
4229
4245
  const accessor = match[0].startsWith("set") ? "set" : "get";
4246
+ const returnsText = accessor === "get" ? readJsDocReturnsBefore(objectContent, match.index) : void 0;
4247
+ const declaredType = returnsText === void 0 ? null : parseJsDocType(returnsText);
4230
4248
  props.push({
4231
4249
  name: accessorName,
4232
4250
  kind: "getter",
@@ -4234,7 +4252,8 @@ function parseTopLevelProperties(objectContent, allowEmptyDataKeys = false) {
4234
4252
  value: body,
4235
4253
  valueStart: bodyStart,
4236
4254
  nameStart: nameSpan[0],
4237
- nameEnd: nameSpan[1]
4255
+ nameEnd: nameSpan[1],
4256
+ ...declaredType !== null ? { declaredType } : {}
4238
4257
  });
4239
4258
  continue;
4240
4259
  }
@@ -11916,7 +11935,7 @@ function forEachStateMethod(elements, html, fileReader, spelling, fn) {
11916
11935
  for (const callable of analyzeCallableBodies(script)) {
11917
11936
  if (callable.kind !== "method" || spelling !== null && !callable.body.includes(spelling)) continue;
11918
11937
  const head = script.slice(callable.end, callable.bodyStart - 1);
11919
- const params = /\(([^)]*)\)\s*$/.exec(head);
11938
+ const params = /\(([\s\S]*)\)\s*$/.exec(head);
11920
11939
  if (params === null) continue;
11921
11940
  fn(volume === null ? callable.name : `${volume}.${callable.name}`, params[1], callable.body);
11922
11941
  }
@@ -14279,6 +14298,7 @@ var BUILTIN_TAGS = {
14279
14298
  "withCredentials": "with-credentials",
14280
14299
  "events": "events",
14281
14300
  "raw": "raw",
14301
+ "staleAfter": "stale-after",
14282
14302
  "manual": "manual",
14283
14303
  "trigger": null
14284
14304
  },
@@ -14469,6 +14489,7 @@ var BUILTIN_TAGS = {
14469
14489
  "reconnectInterval": "reconnect-interval",
14470
14490
  "maxReconnects": "max-reconnects",
14471
14491
  "binaryType": "binary-type",
14492
+ "staleAfter": "stale-after",
14472
14493
  "manual": "manual",
14473
14494
  "trigger": null,
14474
14495
  "send": null
@@ -643,7 +643,7 @@ function loadSchemaCore() {
643
643
  return cached;
644
644
  }
645
645
 
646
- var version = "4.7.0";
646
+ var version = "4.8.0";
647
647
  var pkg = {
648
648
  version: version};
649
649
 
package/dist/wcs-tsc.mjs CHANGED
@@ -25,7 +25,7 @@ function unsupportedTypeScriptMessage(version) {
25
25
  return `@wcstack/typescript runs on TypeScript 5 or 6, and the project has TypeScript ${version}, which has no JavaScript compiler API: npm i -D typescript@6`;
26
26
  }
27
27
 
28
- var version = "4.7.0";
28
+ var version = "4.8.0";
29
29
  var pkg = {
30
30
  version: version};
31
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/typescript",
3
- "version": "4.7.0",
3
+ "version": "4.8.0",
4
4
  "description": "TypeScript tooling for wcstack apps: wcs-schema generates the sidecar stateSchema from a typed state file, so wcs-validate checks data-wcs paths against real types in CI and every editor.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",