@weborigami/language 0.3.1 → 0.3.2
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 +3 -3
- package/src/runtime/expressionObject.js +2 -6
- package/src/runtime/handlers.js +2 -2
- package/src/runtime/ops.js +30 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/language",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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.8.2"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/async-tree": "0.3.
|
|
15
|
-
"@weborigami/types": "0.3.
|
|
14
|
+
"@weborigami/async-tree": "0.3.2",
|
|
15
|
+
"@weborigami/types": "0.3.2",
|
|
16
16
|
"watcher": "2.3.1",
|
|
17
17
|
"yaml": "2.7.0"
|
|
18
18
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
extension,
|
|
3
3
|
ObjectTree,
|
|
4
|
+
setParent,
|
|
4
5
|
symbols,
|
|
5
6
|
trailingSlash,
|
|
6
7
|
Tree,
|
|
@@ -116,12 +117,7 @@ export default async function expressionObject(entries, parent) {
|
|
|
116
117
|
});
|
|
117
118
|
|
|
118
119
|
// Attach the parent
|
|
119
|
-
|
|
120
|
-
configurable: true,
|
|
121
|
-
enumerable: false,
|
|
122
|
-
value: parent,
|
|
123
|
-
writable: true,
|
|
124
|
-
});
|
|
120
|
+
setParent(object, parent);
|
|
125
121
|
|
|
126
122
|
// Evaluate any properties that were declared as immediate: get their value
|
|
127
123
|
// and overwrite the property getter with the actual value.
|
package/src/runtime/handlers.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
isStringLike,
|
|
6
6
|
isUnpackable,
|
|
7
7
|
scope,
|
|
8
|
-
|
|
8
|
+
setParent,
|
|
9
9
|
trailingSlash,
|
|
10
10
|
} from "@weborigami/async-tree";
|
|
11
11
|
|
|
@@ -92,7 +92,7 @@ export async function handleExtension(parent, value, key) {
|
|
|
92
92
|
if (handler.mediaType) {
|
|
93
93
|
value.mediaType = handler.mediaType;
|
|
94
94
|
}
|
|
95
|
-
value
|
|
95
|
+
setParent(value, parent);
|
|
96
96
|
|
|
97
97
|
const unpack = handler.unpack;
|
|
98
98
|
if (unpack) {
|
package/src/runtime/ops.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
deepText,
|
|
12
12
|
isUnpackable,
|
|
13
13
|
scope as scopeFn,
|
|
14
|
-
|
|
14
|
+
setParent,
|
|
15
15
|
concat as treeConcat,
|
|
16
16
|
} from "@weborigami/async-tree";
|
|
17
17
|
import os from "node:os";
|
|
@@ -131,7 +131,7 @@ export async function document(frontData, bodyCode) {
|
|
|
131
131
|
...frontData,
|
|
132
132
|
"@text": body,
|
|
133
133
|
};
|
|
134
|
-
object
|
|
134
|
+
setParent(object, this);
|
|
135
135
|
return object;
|
|
136
136
|
}
|
|
137
137
|
addOpLabel(document, "«ops.document");
|
|
@@ -224,7 +224,8 @@ export async function inherited(key) {
|
|
|
224
224
|
return undefined;
|
|
225
225
|
}
|
|
226
226
|
const parentScope = scopeFn(this.parent);
|
|
227
|
-
|
|
227
|
+
const value = await parentScope.get(key);
|
|
228
|
+
return value;
|
|
228
229
|
}
|
|
229
230
|
addOpLabel(inherited, "«ops.inherited»");
|
|
230
231
|
|
|
@@ -388,17 +389,33 @@ export async function merge(...codes) {
|
|
|
388
389
|
return directObject;
|
|
389
390
|
}
|
|
390
391
|
|
|
391
|
-
//
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
392
|
+
// If we have direct property entries, create a context for them. The
|
|
393
|
+
// `expressionObject` function will set the object's parent symbol to `this`.
|
|
394
|
+
// Tree.from will call the ObjectTree constructor, which will use that symbol
|
|
395
|
+
// to set the parent for the new tree to `this`.
|
|
396
|
+
const context = directObject ? Tree.from(directObject) : this;
|
|
397
|
+
|
|
398
|
+
// Second pass: evaluate the trees. For the trees which are direct property
|
|
399
|
+
// entries, we'll copy over the values we've already calculated. We can't
|
|
400
|
+
// reuse the `directObject` as is because in a merge we need to respect the
|
|
401
|
+
// order in which the properties are defined. Trees that aren't direct
|
|
402
|
+
// property entries are evaluated with the direct property entries in scope.
|
|
400
403
|
const trees = await Promise.all(
|
|
401
|
-
codes.map(async (code) =>
|
|
404
|
+
codes.map(async (code) => {
|
|
405
|
+
if (code[0] === object) {
|
|
406
|
+
// Using the code as reference, create a new object with the direct
|
|
407
|
+
// property values we've already calculated.
|
|
408
|
+
const object = {};
|
|
409
|
+
for (const [key] of code.slice(1)) {
|
|
410
|
+
// @ts-ignore directObject will always be defined
|
|
411
|
+
object[key] = directObject[key];
|
|
412
|
+
}
|
|
413
|
+
setParent(object, this);
|
|
414
|
+
return object;
|
|
415
|
+
} else {
|
|
416
|
+
return evaluate.call(context, code);
|
|
417
|
+
}
|
|
418
|
+
})
|
|
402
419
|
);
|
|
403
420
|
|
|
404
421
|
return mergeTrees.call(this, ...trees);
|