@weborigami/language 0.6.0 → 0.6.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/main.js +1 -1
- package/package.json +2 -2
- package/src/compiler/optimize.js +3 -1
- package/src/compiler/origami.pegjs +2 -0
- package/src/compiler/parse.js +113 -91
- package/src/compiler/parserHelpers.js +3 -7
- package/src/handlers/getSource.js +36 -0
- package/src/handlers/ori_handler.js +5 -20
- package/src/handlers/oridocument_handler.js +5 -28
- package/src/handlers/yaml_handler.js +159 -3
- package/src/project/jsGlobals.js +2 -62
- package/src/protocols/constructHref.js +3 -0
- package/src/protocols/explorehttp.js +13 -0
- package/src/protocols/protocolGlobals.js +1 -0
- package/src/protocols/protocols.js +1 -0
- package/src/runtime/errors.js +27 -7
- package/src/runtime/evaluate.js +1 -1
- package/src/runtime/handleExtension.js +0 -5
- package/src/runtime/ops.js +10 -0
- package/test/compiler/parse.test.js +13 -19
- package/test/handlers/yaml_handler.test.js +28 -1
- package/test/project/jsGlobals.test.js +14 -8
- package/test/runtime/handleExtension.test.js +0 -7
- package/test/runtime/ops.test.js +34 -10
- package/test/runtime/jsGlobals.test.js +0 -21
package/test/runtime/ops.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectMap, Tree } from "@weborigami/async-tree";
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { describe, test } from "node:test";
|
|
4
4
|
|
|
@@ -155,16 +155,37 @@ describe("ops", () => {
|
|
|
155
155
|
assert(ops.greaterThanOrEqual("ab", "aa"));
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
+
test("ops.inOperator returns true if a is in object b", () => {
|
|
159
|
+
assert.strictEqual(ops.inOperator("a", { a: 1, b: 2 }), true);
|
|
160
|
+
assert.strictEqual(ops.inOperator("c", { a: 1, b: 2 }), false);
|
|
161
|
+
const arr = [0, 0, 0];
|
|
162
|
+
assert.strictEqual(ops.inOperator(1, arr), true);
|
|
163
|
+
assert.strictEqual(ops.inOperator(3, arr), false);
|
|
164
|
+
});
|
|
165
|
+
|
|
158
166
|
test("ops.inherited walks up the object parent chain", async () => {
|
|
159
|
-
const tree = new
|
|
160
|
-
|
|
161
|
-
|
|
167
|
+
const tree = new ObjectMap(
|
|
168
|
+
{
|
|
169
|
+
a: {
|
|
170
|
+
b: {},
|
|
171
|
+
},
|
|
162
172
|
},
|
|
163
|
-
|
|
173
|
+
{ deep: true }
|
|
174
|
+
);
|
|
164
175
|
const b = await Tree.traverse(tree, "a", "b");
|
|
165
176
|
assert.equal(await ops.inherited(2, { object: b }), tree);
|
|
166
177
|
});
|
|
167
178
|
|
|
179
|
+
test("ops.instanceOf checks prototype chain", () => {
|
|
180
|
+
class Parent {}
|
|
181
|
+
class Child extends Parent {}
|
|
182
|
+
const child = new Child();
|
|
183
|
+
assert.strictEqual(ops.instanceOf(child, Child), true);
|
|
184
|
+
assert.strictEqual(ops.instanceOf(child, Parent), true);
|
|
185
|
+
assert.strictEqual(ops.instanceOf(child, Object), true);
|
|
186
|
+
assert.strictEqual(ops.instanceOf(child, Array), false);
|
|
187
|
+
});
|
|
188
|
+
|
|
168
189
|
test("ops.lambda defines a function with no inputs", async () => {
|
|
169
190
|
const code = createCode([ops.lambda, [], [ops.literal, "result"]]);
|
|
170
191
|
const fn = await evaluate(code);
|
|
@@ -368,12 +389,15 @@ describe("ops", () => {
|
|
|
368
389
|
|
|
369
390
|
describe("ops.scope", () => {
|
|
370
391
|
test("returns the scope of the given tree", async () => {
|
|
371
|
-
const tree = new
|
|
372
|
-
|
|
373
|
-
|
|
392
|
+
const tree = new ObjectMap(
|
|
393
|
+
{
|
|
394
|
+
a: {
|
|
395
|
+
b: {},
|
|
396
|
+
},
|
|
397
|
+
c: 1,
|
|
374
398
|
},
|
|
375
|
-
|
|
376
|
-
|
|
399
|
+
{ deep: true }
|
|
400
|
+
);
|
|
377
401
|
const a = await tree.get("a");
|
|
378
402
|
const b = await a.get("b");
|
|
379
403
|
const scope = await ops.scope(b);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { describe, test } from "node:test";
|
|
3
|
-
import jsGlobals from "../../src/project/jsGlobals.js";
|
|
4
|
-
|
|
5
|
-
describe("jsGlobals", () => {
|
|
6
|
-
test("wraps static methods to bind them to defining object", async () => {
|
|
7
|
-
const all = jsGlobals.Promise.all;
|
|
8
|
-
const value = await all([Promise.resolve("hi")]);
|
|
9
|
-
assert.equal(value, "hi");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test("can invoke a global constructor", async () => {
|
|
13
|
-
const { Number: fixture } = jsGlobals;
|
|
14
|
-
// Without `new`
|
|
15
|
-
const instance1 = fixture(5);
|
|
16
|
-
assert.equal(instance1, 5);
|
|
17
|
-
// With `new`
|
|
18
|
-
const instance = new fixture();
|
|
19
|
-
assert(instance instanceof Number);
|
|
20
|
-
});
|
|
21
|
-
});
|