@patterkit/compiler 0.12.0 → 0.13.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.cjs CHANGED
@@ -472,6 +472,29 @@ function extensionPass(input) {
472
472
  for (const p of (0, import_extensions.claimClashes)(claims)) issues.push({ severity: p.severity, file: projectPath, code: p.code, message: p.message });
473
473
  issues.push(...claimIssues(input, nodes, claims));
474
474
  const exists = (kind, id) => kind === "cast" ? (project.cast ?? []).some((c) => c.name === id) : nodes.get(id)?.kind === kind;
475
+ const projectId = project.project.id;
476
+ const projectEntries = /* @__PURE__ */ new Map();
477
+ for (const { shard } of input.shards) {
478
+ const entry = shard.entries?.["project"]?.[projectId];
479
+ if (typeof entry === "object" && entry !== null && !Array.isArray(entry) && !projectEntries.has(shard.extension)) {
480
+ projectEntries.set(shard.extension, entry);
481
+ }
482
+ }
483
+ const contexts = /* @__PURE__ */ new Map();
484
+ for (const [ext, manifest] of sound) {
485
+ contexts.set(ext, { exists, list: (0, import_extensions.pickLists)((0, import_extensions.targetOf)(manifest, "patter", "project"), projectEntries.get(ext)) });
486
+ }
487
+ const nodesOf = (kind) => kind === "cast" ? (project.cast ?? []).map((c) => ({ id: c.name })) : [...nodes].filter(([, n]) => n.kind === kind).map(([id]) => ({ id }));
488
+ for (const [ext, manifest] of [...sound].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
489
+ const said = /* @__PURE__ */ new Set();
490
+ for (const decl of pickDecls(manifest)) {
491
+ for (const p of (0, import_extensions.pickClashes)(decl, { nodes: nodesOf, list: contexts.get(ext).list })) {
492
+ if (said.has(p.message)) continue;
493
+ said.add(p.message);
494
+ issues.push({ severity: p.severity, file: projectPath, node: projectId, code: p.code, message: `the Patter extension "${ext}": ${p.message}` });
495
+ }
496
+ }
497
+ }
475
498
  const sceneIds = new Set(scenes.map((s) => s.id));
476
499
  const values = /* @__PURE__ */ new Map();
477
500
  const projectValues = /* @__PURE__ */ new Map();
@@ -541,7 +564,7 @@ function extensionPass(input) {
541
564
  message: `entries.${kind}.${id} belongs ${node.scene === void 0 ? "in the project's own shard" : `in scene "${node.scene}"'s shard`}; it's compiled from here all the same`
542
565
  });
543
566
  }
544
- const problems = (0, import_extensions.entryProblems)(target, entry, { exists });
567
+ const problems = (0, import_extensions.entryProblems)(target, entry, contexts.get(ext) ?? { exists });
545
568
  for (const p of problems) issues.push(issueOf(path, p, `entries.${kind}.${id}${p.path === "" ? ": " : "."}`, id));
546
569
  if (problems.some((p) => p.severity === "error")) continue;
547
570
  const compiled = (0, import_extensions.compileEntry)(target, entry);
@@ -574,6 +597,16 @@ function extensionPass(input) {
574
597
  const sortedNodes = new Map([...values.entries()].map(([id, v]) => [id, sortRecord(v)]));
575
598
  return { issues, compiled: { bundle, nodes: sortedNodes } };
576
599
  }
600
+ function pickDecls(manifest) {
601
+ const out = [];
602
+ const walk = (decl) => {
603
+ if (decl.type === "pick") out.push(decl);
604
+ for (const f of decl.fields ?? []) walk(f);
605
+ if (decl.of !== void 0) walk(decl.of);
606
+ };
607
+ for (const target of Object.values(manifest.targets.patter ?? {})) for (const f of target.fields ?? []) walk(f);
608
+ return out;
609
+ }
577
610
  function sortRecord(r) {
578
611
  return Object.fromEntries(Object.keys(r).sort().map((k) => [k, r[k]]));
579
612
  }
package/dist/index.js CHANGED
@@ -328,6 +328,8 @@ import {
328
328
  entryProblems,
329
329
  manifestProblems,
330
330
  orphanedEntries,
331
+ pickClashes,
332
+ pickLists,
331
333
  resolvedClaims,
332
334
  settingValues,
333
335
  targetOf,
@@ -449,6 +451,29 @@ function extensionPass(input) {
449
451
  for (const p of claimClashes(claims)) issues.push({ severity: p.severity, file: projectPath, code: p.code, message: p.message });
450
452
  issues.push(...claimIssues(input, nodes, claims));
451
453
  const exists = (kind, id) => kind === "cast" ? (project.cast ?? []).some((c) => c.name === id) : nodes.get(id)?.kind === kind;
454
+ const projectId = project.project.id;
455
+ const projectEntries = /* @__PURE__ */ new Map();
456
+ for (const { shard } of input.shards) {
457
+ const entry = shard.entries?.["project"]?.[projectId];
458
+ if (typeof entry === "object" && entry !== null && !Array.isArray(entry) && !projectEntries.has(shard.extension)) {
459
+ projectEntries.set(shard.extension, entry);
460
+ }
461
+ }
462
+ const contexts = /* @__PURE__ */ new Map();
463
+ for (const [ext, manifest] of sound) {
464
+ contexts.set(ext, { exists, list: pickLists(targetOf(manifest, "patter", "project"), projectEntries.get(ext)) });
465
+ }
466
+ const nodesOf = (kind) => kind === "cast" ? (project.cast ?? []).map((c) => ({ id: c.name })) : [...nodes].filter(([, n]) => n.kind === kind).map(([id]) => ({ id }));
467
+ for (const [ext, manifest] of [...sound].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
468
+ const said = /* @__PURE__ */ new Set();
469
+ for (const decl of pickDecls(manifest)) {
470
+ for (const p of pickClashes(decl, { nodes: nodesOf, list: contexts.get(ext).list })) {
471
+ if (said.has(p.message)) continue;
472
+ said.add(p.message);
473
+ issues.push({ severity: p.severity, file: projectPath, node: projectId, code: p.code, message: `the Patter extension "${ext}": ${p.message}` });
474
+ }
475
+ }
476
+ }
452
477
  const sceneIds = new Set(scenes.map((s) => s.id));
453
478
  const values = /* @__PURE__ */ new Map();
454
479
  const projectValues = /* @__PURE__ */ new Map();
@@ -518,7 +543,7 @@ function extensionPass(input) {
518
543
  message: `entries.${kind}.${id} belongs ${node.scene === void 0 ? "in the project's own shard" : `in scene "${node.scene}"'s shard`}; it's compiled from here all the same`
519
544
  });
520
545
  }
521
- const problems = entryProblems(target, entry, { exists });
546
+ const problems = entryProblems(target, entry, contexts.get(ext) ?? { exists });
522
547
  for (const p of problems) issues.push(issueOf(path, p, `entries.${kind}.${id}${p.path === "" ? ": " : "."}`, id));
523
548
  if (problems.some((p) => p.severity === "error")) continue;
524
549
  const compiled = compileEntry(target, entry);
@@ -551,6 +576,16 @@ function extensionPass(input) {
551
576
  const sortedNodes = new Map([...values.entries()].map(([id, v]) => [id, sortRecord(v)]));
552
577
  return { issues, compiled: { bundle, nodes: sortedNodes } };
553
578
  }
579
+ function pickDecls(manifest) {
580
+ const out = [];
581
+ const walk = (decl) => {
582
+ if (decl.type === "pick") out.push(decl);
583
+ for (const f of decl.fields ?? []) walk(f);
584
+ if (decl.of !== void 0) walk(decl.of);
585
+ };
586
+ for (const target of Object.values(manifest.targets.patter ?? {})) for (const f of target.fields ?? []) walk(f);
587
+ return out;
588
+ }
554
589
  function sortRecord(r) {
555
590
  return Object.fromEntries(Object.keys(r).sort().map((k) => [k, r[k]]));
556
591
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/compiler",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Patter compiler: compile condition/effect expressions, validate them, and export source to the runtime bundle.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@patterkit/model": "0.19.0",
38
- "@patterkit/core": "0.9.3",
38
+ "@patterkit/core": "0.9.4",
39
39
  "@patterkit/dialect": "0.2.16",
40
40
  "@wildwinter/expr": "^0.6.0",
41
- "@wildwinter/toolkit": "^0.2.2"
41
+ "@wildwinter/toolkit": "^0.2.5"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@wildwinter/scoperegistry": ">=0.9.0 <1.0.0"