@patterkit/compiler 0.7.1 → 0.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.cjs CHANGED
@@ -154,7 +154,7 @@ function validateConditions(input, options = {}) {
154
154
  const validateElement = (blocks, sceneProps, onEntry, elementId) => {
155
155
  const schema = (0, import_dialect2.buildSchema)(input.project, sceneProps, foreign);
156
156
  const checkedSchema = checked ? (0, import_dialect2.buildSchema)(input.project, sceneProps, checked) : void 0;
157
- const check = (nodeId, field, src) => {
157
+ const check = (nodeId, field, src, assignedTo) => {
158
158
  let ast;
159
159
  try {
160
160
  ast = (0, import_expr.parse)(src, dialect);
@@ -162,7 +162,7 @@ function validateConditions(input, options = {}) {
162
162
  issues.push({ nodeId, field, src, severity: "error", message: e instanceof Error ? e.message : String(e) });
163
163
  return;
164
164
  }
165
- const strict = (0, import_expr.validateExpr)(ast, schema, dialect);
165
+ const strict = [...(0, import_expr.validateExpr)(ast, schema, dialect), ...assignedTo ? (0, import_expr.validateAssignment)(assignedTo, ast, schema, dialect) : []];
166
166
  for (const iss of strict) {
167
167
  issues.push({ nodeId, field, src, severity: iss.severity, message: iss.message });
168
168
  }
@@ -215,7 +215,7 @@ function validateConditions(input, options = {}) {
215
215
  const checkEffects = (nodeId, list, label) => {
216
216
  for (const e of list ?? []) {
217
217
  checkTarget(nodeId, `${label}.set`, e.target);
218
- check(nodeId, `${label}.set`, e.value);
218
+ check(nodeId, `${label}.set`, e.value, TARGET_REF.test(e.target) ? (0, import_dialect2.splitRef)(e.target, isScopeToken) : void 0);
219
219
  }
220
220
  };
221
221
  checkEffects(elementId, onEntry, "onEntry");
@@ -346,6 +346,7 @@ function readOnlyForeignTargets(spec) {
346
346
  var import_dialect4 = require("@patterkit/dialect");
347
347
 
348
348
  // src/export.ts
349
+ var import_scoperegistry = require("@wildwinter/scoperegistry");
349
350
  var import_core = require("@patterkit/core");
350
351
  var import_dialect3 = require("@patterkit/dialect");
351
352
  var import_model2 = require("@patterkit/model");
@@ -443,6 +444,9 @@ function externalScopesIn(scenes, external) {
443
444
  walk(scenes);
444
445
  return [...found].sort();
445
446
  }
447
+ function resolved(decls) {
448
+ return decls?.map((d) => d.default === void 0 ? { ...d, default: (0, import_scoperegistry.defaultFor)(d) } : d);
449
+ }
446
450
  function exportBundle(input) {
447
451
  const { project, scenes, locales = [], includeLocales } = input;
448
452
  const hostScopes = projectScopes(project, input.gameScopes).host;
@@ -517,13 +521,17 @@ function exportBundle(input) {
517
521
  ...speakerPattern !== void 0 ? { speakerPattern } : {},
518
522
  // The project's own line-padding default, only when it sets one: absent, every runtime uses the built-in one.
519
523
  ...typeof project.padAfterDefault === "number" ? { padAfterDefault: project.padAfterDefault } : {},
520
- properties: project.properties,
524
+ properties: resolved(project.properties),
525
+ // A host scope's declarations ship as written: there, "no default" is the game's to supply, and saying
526
+ // so is what an integrator reads the bundle for.
521
527
  scopeRegistry: hostScopes,
522
- gameDataFields: project.gameDataFields,
528
+ gameDataFields: project.gameDataFields && Object.fromEntries(
529
+ Object.entries(project.gameDataFields).map(([kind, fields]) => [kind, resolved(fields)])
530
+ ),
523
531
  // Closed-caption delimiters ride along only when the project pins a non-default pair (#214); the
524
532
  // runtime falls back to `[` / `]` when absent, so default projects keep their exact prior bundle.
525
533
  ...project.closedCaptions ? { closedCaptions: project.closedCaptions } : {},
526
- scenes: scenesOut,
534
+ scenes: Object.fromEntries(Object.entries(scenesOut).map(([id, sc]) => [id, sc.sceneProps ? { ...sc, sceneProps: resolved(sc.sceneProps) } : sc])),
527
535
  strings,
528
536
  // Other engines' scopes the content names, so the engine can say when the game has not registered one.
529
537
  ...externalScopes.length > 0 ? { externalScopes } : {}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/expressions.ts
2
- import { compile, parse, validateExpr } from "@wildwinter/expr";
2
+ import { compile, parse, validateAssignment, validateExpr } from "@wildwinter/expr";
3
3
  import { dialectWithForeignScopes, buildSchema, extractSlots, splitRef, withEngineScopes, hostScopesToSpec as hostScopesToSpec2 } from "@patterkit/dialect";
4
4
  import { referenceNote } from "@wildwinter/scoperegistry/scopes";
5
5
 
@@ -120,7 +120,7 @@ function validateConditions(input, options = {}) {
120
120
  const validateElement = (blocks, sceneProps, onEntry, elementId) => {
121
121
  const schema = buildSchema(input.project, sceneProps, foreign);
122
122
  const checkedSchema = checked ? buildSchema(input.project, sceneProps, checked) : void 0;
123
- const check = (nodeId, field, src) => {
123
+ const check = (nodeId, field, src, assignedTo) => {
124
124
  let ast;
125
125
  try {
126
126
  ast = parse(src, dialect);
@@ -128,7 +128,7 @@ function validateConditions(input, options = {}) {
128
128
  issues.push({ nodeId, field, src, severity: "error", message: e instanceof Error ? e.message : String(e) });
129
129
  return;
130
130
  }
131
- const strict = validateExpr(ast, schema, dialect);
131
+ const strict = [...validateExpr(ast, schema, dialect), ...assignedTo ? validateAssignment(assignedTo, ast, schema, dialect) : []];
132
132
  for (const iss of strict) {
133
133
  issues.push({ nodeId, field, src, severity: iss.severity, message: iss.message });
134
134
  }
@@ -181,7 +181,7 @@ function validateConditions(input, options = {}) {
181
181
  const checkEffects = (nodeId, list, label) => {
182
182
  for (const e of list ?? []) {
183
183
  checkTarget(nodeId, `${label}.set`, e.target);
184
- check(nodeId, `${label}.set`, e.value);
184
+ check(nodeId, `${label}.set`, e.value, TARGET_REF.test(e.target) ? splitRef(e.target, isScopeToken) : void 0);
185
185
  }
186
186
  };
187
187
  checkEffects(elementId, onEntry, "onEntry");
@@ -312,6 +312,7 @@ function readOnlyForeignTargets(spec) {
312
312
  import { hostScopesToSpec as hostScopesToSpec4, EXTERNAL_SCOPES as EXTERNAL_SCOPES2 } from "@patterkit/dialect";
313
313
 
314
314
  // src/export.ts
315
+ import { defaultFor } from "@wildwinter/scoperegistry";
315
316
  import { canonicalStringify, hash32 } from "@patterkit/core";
316
317
  import { hostScopesToSpec as hostScopesToSpec3, withEngineScopes as withEngineScopes2, EXTERNAL_SCOPES } from "@patterkit/dialect";
317
318
  import { usedQualifiers, usedSpeakerPairs, DEFAULT_SPEAKER_PATTERN } from "@patterkit/model";
@@ -409,6 +410,9 @@ function externalScopesIn(scenes, external) {
409
410
  walk(scenes);
410
411
  return [...found].sort();
411
412
  }
413
+ function resolved(decls) {
414
+ return decls?.map((d) => d.default === void 0 ? { ...d, default: defaultFor(d) } : d);
415
+ }
412
416
  function exportBundle(input) {
413
417
  const { project, scenes, locales = [], includeLocales } = input;
414
418
  const hostScopes = projectScopes(project, input.gameScopes).host;
@@ -483,13 +487,17 @@ function exportBundle(input) {
483
487
  ...speakerPattern !== void 0 ? { speakerPattern } : {},
484
488
  // The project's own line-padding default, only when it sets one: absent, every runtime uses the built-in one.
485
489
  ...typeof project.padAfterDefault === "number" ? { padAfterDefault: project.padAfterDefault } : {},
486
- properties: project.properties,
490
+ properties: resolved(project.properties),
491
+ // A host scope's declarations ship as written: there, "no default" is the game's to supply, and saying
492
+ // so is what an integrator reads the bundle for.
487
493
  scopeRegistry: hostScopes,
488
- gameDataFields: project.gameDataFields,
494
+ gameDataFields: project.gameDataFields && Object.fromEntries(
495
+ Object.entries(project.gameDataFields).map(([kind, fields]) => [kind, resolved(fields)])
496
+ ),
489
497
  // Closed-caption delimiters ride along only when the project pins a non-default pair (#214); the
490
498
  // runtime falls back to `[` / `]` when absent, so default projects keep their exact prior bundle.
491
499
  ...project.closedCaptions ? { closedCaptions: project.closedCaptions } : {},
492
- scenes: scenesOut,
500
+ scenes: Object.fromEntries(Object.entries(scenesOut).map(([id, sc]) => [id, sc.sceneProps ? { ...sc, sceneProps: resolved(sc.sceneProps) } : sc])),
493
501
  strings,
494
502
  // Other engines' scopes the content names, so the engine can say when the game has not registered one.
495
503
  ...externalScopes.length > 0 ? { externalScopes } : {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/compiler",
3
- "version": "0.7.1",
3
+ "version": "0.8.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",
@@ -34,15 +34,15 @@
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts --clean"
35
35
  },
36
36
  "dependencies": {
37
- "@patterkit/model": "0.14.0",
38
- "@patterkit/core": "0.7.1",
39
- "@patterkit/dialect": "0.2.11",
40
- "@wildwinter/expr": "^0.5.0"
37
+ "@patterkit/model": "0.15.0",
38
+ "@patterkit/core": "0.8.0",
39
+ "@patterkit/dialect": "0.2.12",
40
+ "@wildwinter/expr": "^0.6.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "@wildwinter/scoperegistry": ">=0.8.0 <1.0.0"
43
+ "@wildwinter/scoperegistry": ">=0.9.0 <1.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@wildwinter/scoperegistry": ">=0.8.0 <1.0.0"
46
+ "@wildwinter/scoperegistry": ">=0.9.0 <1.0.0"
47
47
  }
48
48
  }