@weborigami/language 0.5.3 → 0.5.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/language",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Web Origami expression language compiler and runtime",
5
5
  "type": "module",
6
6
  "main": "./main.js",
@@ -11,8 +11,8 @@
11
11
  "typescript": "5.9.2"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/async-tree": "0.5.3",
15
- "@weborigami/types": "0.5.3",
14
+ "@weborigami/async-tree": "0.5.5",
15
+ "@weborigami/types": "0.5.5",
16
16
  "watcher": "2.3.1",
17
17
  "yaml": "2.8.1"
18
18
  },
@@ -170,7 +170,7 @@ export function makeCall(target, args, location) {
170
170
 
171
171
  let fnCall;
172
172
  const op = args[0];
173
- if (op === markers.traverse || op === ops.optionalTraverse) {
173
+ if (op === markers.traverse /* || op === ops.optionalTraverse */) {
174
174
  // Traverse
175
175
  const keys = args.slice(1);
176
176
  fnCall = [target, ...keys];
@@ -2,9 +2,9 @@
2
2
 
3
3
  import {
4
4
  box,
5
- scope as scopeFn,
6
5
  trailingSlash,
7
6
  TraverseError,
7
+ Tree,
8
8
  } from "@weborigami/async-tree";
9
9
  import path from "node:path";
10
10
  import { fileURLToPath } from "node:url";
@@ -39,7 +39,7 @@ export function attachWarning(value, message) {
39
39
 
40
40
  export async function builtinReferenceError(tree, builtins, key) {
41
41
  // See if the key is in scope (but not as a builtin)
42
- const scope = scopeFn(tree);
42
+ const scope = await Tree.scope(tree);
43
43
  const value = await scope.get(key);
44
44
  let message;
45
45
  if (value === undefined) {
@@ -1,23 +1,18 @@
1
- import { map, Tree } from "@weborigami/async-tree";
1
+ import { Tree } from "@weborigami/async-tree";
2
2
 
3
3
  /**
4
4
  * When using `get` to retrieve a value from a tree, if the value is a
5
5
  * function, invoke it and return the result.
6
6
  */
7
- export default function functionResultsMap(treelike) {
8
- return map(treelike, {
7
+ export default async function functionResultsMap(treelike) {
8
+ return Tree.map(treelike, {
9
9
  description: "functionResultsMap",
10
10
 
11
11
  value: async (sourceValue, sourceKey, tree) => {
12
- let resultValue;
13
- if (typeof sourceValue === "function") {
14
- resultValue = await sourceValue.call(tree);
15
- if (Tree.isAsyncTree(resultValue) && !resultValue.parent) {
16
- resultValue.parent = tree;
17
- }
18
- } else {
19
- resultValue = sourceValue;
20
- }
12
+ const resultValue =
13
+ typeof sourceValue === "function"
14
+ ? await sourceValue.call(tree)
15
+ : sourceValue;
21
16
  return resultValue;
22
17
  },
23
18
  });
@@ -2,7 +2,7 @@ import {
2
2
  box,
3
3
  extension,
4
4
  isPacked,
5
- isStringLike,
5
+ isStringlike,
6
6
  isUnpackable,
7
7
  setParent,
8
8
  trailingSlash,
@@ -21,7 +21,7 @@ export async function handleExtension(parent, value, key, handlers) {
21
21
  if (
22
22
  handlers &&
23
23
  isPacked(value) &&
24
- isStringLike(key) &&
24
+ isStringlike(key) &&
25
25
  value.unpack === undefined
26
26
  ) {
27
27
  const hasSlash = trailingSlash.has(key);
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  isPlainObject,
3
3
  isUnpackable,
4
- merge,
5
4
  setParent,
6
5
  Tree,
7
6
  } from "@weborigami/async-tree";
@@ -54,7 +53,7 @@ export default async function mergeTrees(...trees) {
54
53
  }
55
54
 
56
55
  // Merge the trees.
57
- const result = merge(...unpacked);
56
+ const result = Tree.merge(...unpacked);
58
57
  setParent(result, this);
59
58
  return result;
60
59
  }
@@ -5,15 +5,7 @@
5
5
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
6
6
  */
7
7
 
8
- import {
9
- deepText,
10
- indent,
11
- isUnpackable,
12
- ObjectTree,
13
- scope as scopeFn,
14
- text,
15
- Tree,
16
- } from "@weborigami/async-tree";
8
+ import { isUnpackable, ObjectTree, Tree } from "@weborigami/async-tree";
17
9
  import os from "node:os";
18
10
  import expressionObject from "./expressionObject.js";
19
11
  import getHandlers from "./getHandlers.js";
@@ -119,7 +111,7 @@ comma.unevaluatedArgs = true;
119
111
  * @param {any[]} args
120
112
  */
121
113
  export async function concat(...args) {
122
- return deepText.call(this, args);
114
+ return Tree.deepText.call(this, args);
123
115
  }
124
116
  addOpLabel(concat, "«ops.concat»");
125
117
 
@@ -413,13 +405,13 @@ export async function object(...entries) {
413
405
  addOpLabel(object, "«ops.object»");
414
406
  object.unevaluatedArgs = true;
415
407
 
416
- export function optionalTraverse(treelike, key) {
417
- if (!treelike) {
418
- return undefined;
419
- }
420
- return Tree.traverseOrThrow(treelike, key);
421
- }
422
- addOpLabel(optionalTraverse, "«ops.optionalTraverse");
408
+ // export function optionalTraverse(treelike, key) {
409
+ // if (!treelike) {
410
+ // return undefined;
411
+ // }
412
+ // return Tree.traverseOrThrow(treelike, key);
413
+ // }
414
+ // addOpLabel(optionalTraverse, "«ops.optionalTraverse");
423
415
 
424
416
  /**
425
417
  * Return the indicated property
@@ -491,7 +483,7 @@ export async function scope(context) {
491
483
  if (!context) {
492
484
  return null;
493
485
  }
494
- return scopeFn(context);
486
+ return Tree.scope(context);
495
487
  }
496
488
  addOpLabel(scope, "«ops.scope»");
497
489
 
@@ -535,7 +527,7 @@ addOpLabel(subtraction, "«ops.subtraction»");
535
527
  * Apply the tree indent tagged template function.
536
528
  */
537
529
  export async function templateIndent(strings, ...values) {
538
- return indent(strings, ...values);
530
+ return Tree.indent(strings, ...values);
539
531
  }
540
532
  addOpLabel(templateIndent, "«ops.templateIndent»");
541
533
 
@@ -543,7 +535,7 @@ addOpLabel(templateIndent, "«ops.templateIndent»");
543
535
  * Apply the tree tagged template function.
544
536
  */
545
537
  export async function templateText(strings, ...values) {
546
- return text(strings, ...values);
538
+ return Tree.text(strings, ...values);
547
539
  }
548
540
  addOpLabel(templateText, "«ops.templateText»");
549
541
 
@@ -1125,12 +1125,12 @@ Body`,
1125
1125
  assertParse("objectPublicKey", `"foo bar"`, "foo bar", "shell", false);
1126
1126
  });
1127
1127
 
1128
- test.skip("optionalChaining", () => {
1129
- assertParse("optionalChaining", "?.key", [
1130
- ops.optionalTraverse,
1131
- [ops.literal, "key"],
1132
- ]);
1133
- });
1128
+ // test.skip("optionalChaining", () => {
1129
+ // assertParse("optionalChaining", "?.key", [
1130
+ // ops.optionalTraverse,
1131
+ // [ops.literal, "key"],
1132
+ // ]);
1133
+ // });
1134
1134
 
1135
1135
  test("parenthesesArguments", () => {
1136
1136
  assertParse("parenthesesArguments", "()", [undefined]);
@@ -1,21 +1,17 @@
1
- import { ObjectTree, Tree, scope } from "@weborigami/async-tree";
1
+ import { ObjectTree, Tree } from "@weborigami/async-tree";
2
2
  import assert from "node:assert";
3
3
  import { describe, test } from "node:test";
4
4
  import functionResultsMap from "../../src/runtime/functionResultsMap.js";
5
5
 
6
6
  describe("functionResultsMap", () => {
7
- test("get() invokes functions using scope, returns other values as is", async () => {
8
- const parent = new ObjectTree({
9
- message: "Hello",
10
- });
7
+ test("get() invokes functions, returns other values as is", async () => {
11
8
  const tree = new ObjectTree({
12
- fn: /** @this {import("@weborigami/types").AsyncTree} */ function () {
13
- return scope(this).get("message");
9
+ fn: function () {
10
+ return "Hello";
14
11
  },
15
12
  string: "string",
16
13
  });
17
- tree.parent = parent;
18
- const fixture = functionResultsMap(tree);
14
+ const fixture = await functionResultsMap(tree);
19
15
  assert.deepEqual(await Tree.plain(fixture), {
20
16
  fn: "Hello",
21
17
  string: "string",
@@ -280,10 +280,10 @@ describe("ops", () => {
280
280
  assert.strictEqual(ops.multiplication("foo", 2), NaN);
281
281
  });
282
282
 
283
- test("ops.optionalTraverse", async () => {
284
- assert.equal(await ops.optionalTraverse(null, "a"), undefined);
285
- assert.equal(await ops.optionalTraverse({ a: 1 }, "a"), 1);
286
- });
283
+ // test("ops.optionalTraverse", async () => {
284
+ // assert.equal(await ops.optionalTraverse(null, "a"), undefined);
285
+ // assert.equal(await ops.optionalTraverse({ a: 1 }, "a"), 1);
286
+ // });
287
287
 
288
288
  test("ops.notEqual", () => {
289
289
  assert(!ops.notEqual(1, 1));