@patterkit/compiler 0.4.4 → 0.4.6

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/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @patterkit/compiler
2
+
3
+ Turns a Patter project's source files into the compiled bundle (`.patterc`) that every Patter runtime
4
+ plays, checking its conditions and effects on the way.
5
+
6
+ Most people won't need to install this directly. To play Patter dialogue in a game or web page, use
7
+ [`@patterkit/runtime`](https://www.npmjs.com/package/@patterkit/runtime); to work with Patter projects from
8
+ a terminal or a build script, use [`@patterkit/cli`](https://www.npmjs.com/package/@patterkit/cli).
9
+
10
+ ## What's in it
11
+
12
+ - **Export**: `exportBundle` takes a loaded project, its scenes, and optionally its locales, and returns
13
+ the bundle, with every expression compiled and every embedded string in place.
14
+ - **Expressions**: `compileExpression` compiles one condition or effect, and `validateConditions` and
15
+ `validateInterpolation` check a project's expressions and `{@name}` placeholders against its declared
16
+ properties, reporting each problem with where it is.
17
+ - **Scopes**: `projectScopes` and `externalGameScopes` work out which scopes a project can use, including
18
+ the ones the game declares.
19
+
20
+ To build a bundle without writing code, use the `patter export` command in
21
+ [`@patterkit/cli`](https://www.npmjs.com/package/@patterkit/cli), or Patterpad's Publish menu.
22
+
23
+ ```sh
24
+ npm install @patterkit/compiler
25
+ ```
26
+
27
+ ## Part of Patter
28
+
29
+ [Patter](https://patterkit.dev/) is a branching dialogue format with its own editor (Patterpad), command line
30
+ tool (`patter`), and runtimes for JavaScript, Unity, Unreal, and Godot. This package is one layer of the
31
+ JavaScript tooling, and the other `@patterkit` packages build on it. [How it fits
32
+ together](https://patterkit.dev/architecture/) shows where each piece sits, and the source is in the
33
+ [patter repository](https://github.com/patterkit/patter).
34
+
35
+ ## Licence
36
+
37
+ MIT
package/dist/index.cjs CHANGED
@@ -235,7 +235,11 @@ function validateConditions(input, options = {}) {
235
235
  function validateInterpolation(input, options = {}) {
236
236
  const issues = [];
237
237
  const voiced = input.project.voiced ?? false;
238
- const tables = (input.locales ?? []).map((l) => ({ locale: l.locale, strings: l.strings }));
238
+ const byLocale = /* @__PURE__ */ new Map();
239
+ for (const l of input.locales ?? []) {
240
+ const table = byLocale.get(l.locale) ?? byLocale.set(l.locale, /* @__PURE__ */ new Map()).get(l.locale);
241
+ for (const [id, text] of Object.entries(l.strings)) (table.get(id) ?? table.set(id, []).get(id)).push(text);
242
+ }
239
243
  const defaultLocale = input.project.locales.default;
240
244
  const { foreign, external, merged } = validationScopes(input.project, options);
241
245
  const opaqueForeign = opaqueForeignTokens(foreign);
@@ -249,11 +253,9 @@ function validateInterpolation(input, options = {}) {
249
253
  return schema.properties.get(scope)?.has(name) ?? false;
250
254
  };
251
255
  const checkString = (nodeId, id, voicedLine) => {
252
- for (const t of tables) {
253
- const text = t.strings[id];
254
- if (text === void 0) continue;
255
- const field = `text[${t.locale}]`;
256
- for (const slot of (0, import_dialect2.extractSlots)(text)) {
256
+ for (const [locale, table] of byLocale) {
257
+ const field = `text[${locale}]`;
258
+ for (const text of table.get(id) ?? []) for (const slot of (0, import_dialect2.extractSlots)(text)) {
257
259
  if (voicedLine) {
258
260
  issues.push({
259
261
  nodeId,
package/dist/index.js CHANGED
@@ -201,7 +201,11 @@ function validateConditions(input, options = {}) {
201
201
  function validateInterpolation(input, options = {}) {
202
202
  const issues = [];
203
203
  const voiced = input.project.voiced ?? false;
204
- const tables = (input.locales ?? []).map((l) => ({ locale: l.locale, strings: l.strings }));
204
+ const byLocale = /* @__PURE__ */ new Map();
205
+ for (const l of input.locales ?? []) {
206
+ const table = byLocale.get(l.locale) ?? byLocale.set(l.locale, /* @__PURE__ */ new Map()).get(l.locale);
207
+ for (const [id, text] of Object.entries(l.strings)) (table.get(id) ?? table.set(id, []).get(id)).push(text);
208
+ }
205
209
  const defaultLocale = input.project.locales.default;
206
210
  const { foreign, external, merged } = validationScopes(input.project, options);
207
211
  const opaqueForeign = opaqueForeignTokens(foreign);
@@ -215,11 +219,9 @@ function validateInterpolation(input, options = {}) {
215
219
  return schema.properties.get(scope)?.has(name) ?? false;
216
220
  };
217
221
  const checkString = (nodeId, id, voicedLine) => {
218
- for (const t of tables) {
219
- const text = t.strings[id];
220
- if (text === void 0) continue;
221
- const field = `text[${t.locale}]`;
222
- for (const slot of extractSlots(text)) {
222
+ for (const [locale, table] of byLocale) {
223
+ const field = `text[${locale}]`;
224
+ for (const text of table.get(id) ?? []) for (const slot of extractSlots(text)) {
223
225
  if (voicedLine) {
224
226
  issues.push({
225
227
  nodeId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/compiler",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
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,9 +34,9 @@
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts --clean"
35
35
  },
36
36
  "dependencies": {
37
- "@patterkit/model": "0.8.0",
38
- "@patterkit/core": "0.3.1",
39
- "@patterkit/dialect": "0.2.4",
37
+ "@patterkit/model": "0.10.0",
38
+ "@patterkit/core": "0.4.0",
39
+ "@patterkit/dialect": "0.2.6",
40
40
  "@wildwinter/expr": "^0.5.0"
41
41
  },
42
42
  "peerDependencies": {