@weborigami/language 0.0.39 → 0.0.40
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/index.ts +1 -0
- package/package.json +5 -5
- package/src/compiler/origami.pegjs +37 -36
- package/src/compiler/parse.js +340 -97
- package/src/runtime/FileLoadersTransform.js +1 -1
- package/src/runtime/concatTreeValues.js +15 -2
- package/src/runtime/ops.js +3 -1
- package/test/runtime/InheritScopeMixin.test.js +2 -2
|
@@ -32,7 +32,7 @@ export default function FileLoadersTransform(Base) {
|
|
|
32
32
|
value = new String(input);
|
|
33
33
|
const parent = this;
|
|
34
34
|
value.parent = parent;
|
|
35
|
-
value.unpack = (
|
|
35
|
+
value.unpack = unpackFn.bind(null, input, { key, parent });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Tree,
|
|
3
|
+
getRealmObjectPrototype,
|
|
4
|
+
isPlainObject,
|
|
5
|
+
} from "@weborigami/async-tree";
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* Concatenate the text values in a tree.
|
|
@@ -24,7 +28,16 @@ async function getText(value, scope) {
|
|
|
24
28
|
value = await value.call(scope);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
// We'd prefer to use Tree.isTreelike() here, but that counts an object with
|
|
32
|
+
// an unpack() function as a treelike object. In this case, we don't want to
|
|
33
|
+
// unpack anything that's not already treelike.
|
|
34
|
+
const isTreelike =
|
|
35
|
+
Tree.isAsyncTree(value) ||
|
|
36
|
+
value instanceof Function ||
|
|
37
|
+
value instanceof Array ||
|
|
38
|
+
value instanceof Set ||
|
|
39
|
+
isPlainObject(value);
|
|
40
|
+
if (isTreelike) {
|
|
28
41
|
// The mapReduce operation above only implicit casts its top-level input to
|
|
29
42
|
// a tree. If we're asked for the text of a treelike value, we need to
|
|
30
43
|
// explicitly recurse.
|
package/src/runtime/ops.js
CHANGED
|
@@ -189,7 +189,9 @@ export async function tree(...entries) {
|
|
|
189
189
|
return [key, value];
|
|
190
190
|
});
|
|
191
191
|
const object = Object.fromEntries(fns);
|
|
192
|
-
|
|
192
|
+
const result = new OrigamiTree(object);
|
|
193
|
+
result.scope = new Scope(result, this);
|
|
194
|
+
return result;
|
|
193
195
|
}
|
|
194
196
|
tree.toString = () => "«ops.tree»";
|
|
195
197
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectTree } from "@weborigami/async-tree";
|
|
1
|
+
import { DeepObjectTree, ObjectTree } from "@weborigami/async-tree";
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { describe, test } from "node:test";
|
|
4
4
|
import InheritScopeMixin from "../../src/runtime/InheritScopeMixin.js";
|
|
@@ -16,7 +16,7 @@ describe("InheritScopeMixin", () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
test("adds a subtree's parent to the subtrees's scope", async () => {
|
|
19
|
-
const fixture = new (InheritScopeMixin(
|
|
19
|
+
const fixture = new (InheritScopeMixin(DeepObjectTree))({
|
|
20
20
|
a: 1,
|
|
21
21
|
subtree: {
|
|
22
22
|
b: 2,
|