@weborigami/language 0.5.4 → 0.5.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/index.ts +16 -6
- package/main.js +9 -4
- package/package.json +4 -3
- package/src/compiler/compile.js +10 -4
- package/src/compiler/optimize.js +115 -97
- package/src/compiler/origami.pegjs +1 -4
- package/src/compiler/parse.js +568 -588
- package/src/compiler/parserHelpers.js +3 -3
- package/src/handlers/css_handler.js +7 -0
- package/src/handlers/csv_handler.js +129 -0
- package/src/handlers/handlers.js +33 -0
- package/src/handlers/htm_handler.js +2 -0
- package/src/handlers/html_handler.js +7 -0
- package/src/handlers/jpeg_handler.js +62 -0
- package/src/handlers/jpg_handler.js +2 -0
- package/src/handlers/js_handler.js +51 -0
- package/src/handlers/json_handler.js +26 -0
- package/src/handlers/md_handler.js +7 -0
- package/src/handlers/mjs_handler.js +2 -0
- package/src/handlers/ori_handler.js +47 -0
- package/src/handlers/oridocument_handler.js +77 -0
- package/src/handlers/parseFrontMatter.js +16 -0
- package/src/handlers/ts_handler.js +1 -0
- package/src/handlers/txt_handler.js +108 -0
- package/src/handlers/wasm_handler.js +15 -0
- package/src/handlers/xhtml_handler.js +2 -0
- package/src/handlers/yaml_handler.js +33 -0
- package/src/handlers/yml_handler.js +2 -0
- package/src/project/builtins.js +5 -0
- package/src/project/coreGlobals.js +17 -0
- package/src/{runtime → project}/jsGlobals.js +3 -1
- package/src/project/projectConfig.js +36 -0
- package/src/project/projectGlobals.js +19 -0
- package/src/project/projectRoot.js +59 -0
- package/src/protocols/constructHref.js +20 -0
- package/src/protocols/constructSiteTree.js +26 -0
- package/src/protocols/explore.js +14 -0
- package/src/protocols/fetchAndHandleExtension.js +25 -0
- package/src/protocols/files.js +26 -0
- package/src/protocols/http.js +15 -0
- package/src/protocols/https.js +15 -0
- package/src/protocols/httpstree.js +14 -0
- package/src/protocols/httptree.js +14 -0
- package/src/protocols/node.js +13 -0
- package/src/protocols/package.js +67 -0
- package/src/protocols/protocolGlobals.js +12 -0
- package/src/protocols/protocols.js +8 -0
- package/src/runtime/EventTargetMixin.js +1 -1
- package/src/runtime/HandleExtensionsTransform.js +3 -12
- package/src/runtime/ImportModulesMixin.js +4 -10
- package/src/runtime/InvokeFunctionsTransform.js +1 -1
- package/src/runtime/errors.js +2 -2
- package/src/runtime/evaluate.js +15 -8
- package/src/runtime/expressionFunction.js +5 -7
- package/src/runtime/expressionObject.js +10 -20
- package/src/runtime/functionResultsMap.js +5 -12
- package/src/runtime/{handlers.js → handleExtension.js} +14 -12
- package/src/runtime/mergeTrees.js +2 -10
- package/src/runtime/ops.js +91 -106
- package/test/compiler/compile.test.js +20 -19
- package/test/compiler/optimize.test.js +60 -25
- package/test/compiler/parse.test.js +10 -10
- package/test/generator/oriEval.js +4 -5
- package/test/handlers/csv.handler.test.js +36 -0
- package/test/handlers/fixtures/add.wasm +0 -0
- package/test/handlers/fixtures/exif.jpeg +0 -0
- package/test/handlers/fixtures/frontMatter.md +5 -0
- package/test/handlers/fixtures/list.js +4 -0
- package/test/handlers/fixtures/multiple.js +4 -0
- package/test/handlers/fixtures/obj.js +3 -0
- package/test/handlers/fixtures/site.ori +5 -0
- package/test/handlers/fixtures/string.js +1 -0
- package/test/handlers/fixtures/tag.yaml +5 -0
- package/test/handlers/fixtures/test.ori +9 -0
- package/test/handlers/jpeg.handler.test.js +18 -0
- package/test/handlers/js.handler.test.js +46 -0
- package/test/handlers/json.handler.test.js +14 -0
- package/test/handlers/ori.handler.test.js +87 -0
- package/test/handlers/oridocument.handler.test.js +68 -0
- package/test/handlers/txt.handler.test.js +41 -0
- package/test/handlers/wasm.handler.test.js +20 -0
- package/test/handlers/yaml.handler.test.js +17 -0
- package/test/project/fixtures/withConfig/config.ori +4 -0
- package/test/project/fixtures/withConfig/subfolder/greet.js +1 -0
- package/test/project/fixtures/withPackageJson/package.json +0 -0
- package/test/project/jsGlobals.test.js +21 -0
- package/test/project/projectConfig.test.js +28 -0
- package/test/project/projectRoot.test.js +40 -0
- package/test/protocols/package.test.js +11 -0
- package/test/runtime/evaluate.test.js +26 -42
- package/test/runtime/expressionObject.test.js +16 -20
- package/test/runtime/functionResultsMap.test.js +5 -9
- package/test/runtime/{handlers.test.js → handleExtension.test.js} +4 -20
- package/test/runtime/jsGlobals.test.js +4 -6
- package/test/runtime/mergeTrees.test.js +2 -4
- package/test/runtime/ops.test.js +70 -72
- package/src/runtime/getHandlers.js +0 -10
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FileTree } from "@weborigami/async-tree";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { describe, test } from "node:test";
|
|
4
|
+
import wasm_handler from "../../src/handlers/wasm_handler.js";
|
|
5
|
+
import ImportModulesMixin from "../../src/runtime/ImportModulesMixin.js";
|
|
6
|
+
|
|
7
|
+
const fixturesUrl = new URL("fixtures", import.meta.url);
|
|
8
|
+
const fixturesTree = new (ImportModulesMixin(FileTree))(fixturesUrl);
|
|
9
|
+
|
|
10
|
+
describe(".wasm handler", () => {
|
|
11
|
+
test("loads .wasm file that exports a function", async () => {
|
|
12
|
+
const buffer = await fixturesTree.get("add.wasm");
|
|
13
|
+
const { add } = await wasm_handler.unpack(buffer, {
|
|
14
|
+
key: "add.wasm",
|
|
15
|
+
parent: fixturesTree,
|
|
16
|
+
});
|
|
17
|
+
const sum = add(1, 2);
|
|
18
|
+
assert.strictEqual(sum, 3);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import yaml_handler from "../../src/handlers/yaml_handler.js";
|
|
4
|
+
|
|
5
|
+
describe(".yaml handler", () => {
|
|
6
|
+
test("loads input as a YAML file", async () => {
|
|
7
|
+
const text = `
|
|
8
|
+
a: 1
|
|
9
|
+
b: 2
|
|
10
|
+
`;
|
|
11
|
+
const data = yaml_handler.unpack(text);
|
|
12
|
+
assert.deepEqual(data, {
|
|
13
|
+
a: 1,
|
|
14
|
+
b: 2,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (name) => `Hello, ${name}!`;
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
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("can invoke static methods", async () => {
|
|
7
|
+
const { Promise } = jsGlobals;
|
|
8
|
+
const { all } = Promise;
|
|
9
|
+
const result = (
|
|
10
|
+
await all(["fruit", "computer", "park"].map((item) => `Apple ${item}`))
|
|
11
|
+
).join(", ");
|
|
12
|
+
assert.equal(result, "Apple fruit, Apple computer, Apple park");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("can invoke a method on a static method", () => {
|
|
16
|
+
const { Math } = jsGlobals;
|
|
17
|
+
const a = [1, 3, 2];
|
|
18
|
+
const b = Math.max.apply(null, a);
|
|
19
|
+
assert.equal(b, 3);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import projectConfig from "../../src/project/projectConfig.js";
|
|
5
|
+
|
|
6
|
+
describe("projectConfig", () => {
|
|
7
|
+
test("finds Origami configuration file", async () => {
|
|
8
|
+
// Find the folder that represents the project root.
|
|
9
|
+
const projectUrl = new URL("fixtures/withConfig/", import.meta.url);
|
|
10
|
+
// Find subfolder inside project root.
|
|
11
|
+
const subfolderUrl = new URL("./subfolder/", projectUrl);
|
|
12
|
+
const subfolderPath = fileURLToPath(subfolderUrl);
|
|
13
|
+
|
|
14
|
+
const config = await projectConfig(subfolderPath);
|
|
15
|
+
assert.equal(config.message, "Hello");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("defaults to an empty object", async () => {
|
|
19
|
+
// Find the folder that represents the project root.
|
|
20
|
+
const projectUrl = new URL("fixtures/withPackageJson/", import.meta.url);
|
|
21
|
+
// Find subfolder inside project root.
|
|
22
|
+
const subfolderUrl = new URL("./subfolder/", projectUrl);
|
|
23
|
+
const subfolderPath = fileURLToPath(subfolderUrl);
|
|
24
|
+
|
|
25
|
+
const config = await projectConfig(subfolderPath);
|
|
26
|
+
assert.deepEqual(config, {});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { describe, test } from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import projectRoot from "../../src/project/projectRoot.js";
|
|
6
|
+
|
|
7
|
+
describe("projectRoot", () => {
|
|
8
|
+
test("finds Origami configuration file", async () => {
|
|
9
|
+
// Find the folder that represents the project root.
|
|
10
|
+
const projectUrl = new URL("fixtures/withConfig/", import.meta.url);
|
|
11
|
+
// Find subfolder inside project root.
|
|
12
|
+
const subfolderUrl = new URL("./subfolder/", projectUrl);
|
|
13
|
+
const subfolderPath = fileURLToPath(subfolderUrl);
|
|
14
|
+
|
|
15
|
+
const root = await projectRoot(subfolderPath);
|
|
16
|
+
|
|
17
|
+
// Get result path, it'll need a trailing slash to compare.
|
|
18
|
+
const resultPath = root.path + path.sep;
|
|
19
|
+
assert.equal(resultPath, fileURLToPath(projectUrl));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("finds package.json file", async () => {
|
|
23
|
+
// Find the folder that represents the project root.
|
|
24
|
+
const projectUrl = new URL("fixtures/withPackageJson/", import.meta.url);
|
|
25
|
+
// Find subfolder inside project root.
|
|
26
|
+
const subfolderUrl = new URL("./subfolder/", projectUrl);
|
|
27
|
+
const subfolderPath = fileURLToPath(subfolderUrl);
|
|
28
|
+
|
|
29
|
+
const root = await projectRoot(subfolderPath);
|
|
30
|
+
|
|
31
|
+
// Get result path, it'll need a trailing slash to compare.
|
|
32
|
+
const resultPath = root.path + path.sep;
|
|
33
|
+
assert.equal(resultPath, fileURLToPath(projectUrl));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("defaults to current working directory", async () => {
|
|
37
|
+
const root = await projectRoot("/");
|
|
38
|
+
assert.equal(root.path, process.cwd());
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import packageProtocol from "../../src/protocols/package.js";
|
|
4
|
+
|
|
5
|
+
describe("package: protocol", () => {
|
|
6
|
+
test("returns a package's main export(s)", async () => {
|
|
7
|
+
const result = await packageProtocol("@weborigami", "async-tree");
|
|
8
|
+
const { toString } = result;
|
|
9
|
+
assert.equal(toString(123), "123");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -1,57 +1,41 @@
|
|
|
1
|
-
import { ObjectTree } from "@weborigami/async-tree";
|
|
2
1
|
import assert from "node:assert";
|
|
3
2
|
import { describe, test } from "node:test";
|
|
4
|
-
import * as ops from "../../src/runtime/ops.js";
|
|
5
3
|
|
|
4
|
+
import { ObjectTree } from "@weborigami/async-tree";
|
|
6
5
|
import evaluate from "../../src/runtime/evaluate.js";
|
|
7
6
|
import { createCode } from "../compiler/codeHelpers.js";
|
|
8
7
|
|
|
9
8
|
describe("evaluate", () => {
|
|
10
|
-
test("can retrieve values from scope", async () => {
|
|
11
|
-
const code = createCode([[ops.scope], "message"]);
|
|
12
|
-
const parent = new ObjectTree({
|
|
13
|
-
message: "Hello",
|
|
14
|
-
});
|
|
15
|
-
const tree = new ObjectTree({});
|
|
16
|
-
tree.parent = parent;
|
|
17
|
-
const result = await evaluate.call(tree, code);
|
|
18
|
-
assert.equal(result, "Hello");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("can invoke functions in scope", async () => {
|
|
22
|
-
// Match the array representation of code generated by the parser.
|
|
23
|
-
const code = createCode([
|
|
24
|
-
[[ops.scope], "greet"],
|
|
25
|
-
[[ops.scope], "name"],
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const tree = new ObjectTree({
|
|
29
|
-
async greet(name) {
|
|
30
|
-
return `Hello ${name}`;
|
|
31
|
-
},
|
|
32
|
-
name: "world",
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const result = await evaluate.call(tree, code);
|
|
36
|
-
assert.equal(result, "Hello world");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("passes context to invoked functions", async () => {
|
|
40
|
-
const code = createCode([[ops.scope], "fn"]);
|
|
41
|
-
const tree = new ObjectTree({
|
|
42
|
-
async fn() {
|
|
43
|
-
assert.equal(this, tree);
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
await evaluate.call(tree, code);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
9
|
test("if object in function position isn't a function, can unpack it", async () => {
|
|
50
10
|
const fn = (...args) => args.join(",");
|
|
51
11
|
const packed = new String();
|
|
52
12
|
/** @type {any} */ (packed).unpack = async () => fn;
|
|
53
13
|
const code = createCode([packed, "a", "b", "c"]);
|
|
54
|
-
const result = await evaluate
|
|
14
|
+
const result = await evaluate(code);
|
|
55
15
|
assert.equal(result, "a,b,c");
|
|
56
16
|
});
|
|
17
|
+
|
|
18
|
+
test("if function has needsState, it gets the state", async () => {
|
|
19
|
+
const fn = (state) => {
|
|
20
|
+
return state;
|
|
21
|
+
};
|
|
22
|
+
fn.needsState = true;
|
|
23
|
+
const state = {};
|
|
24
|
+
const code = createCode([fn]);
|
|
25
|
+
const result = await evaluate(code, state);
|
|
26
|
+
assert.equal(result, state);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("if function has containerAsTarget, it gets bound to state.container", async () => {
|
|
30
|
+
/** @this {import("@weborigami/types").AsyncTree} */
|
|
31
|
+
const fn = function () {
|
|
32
|
+
return this;
|
|
33
|
+
};
|
|
34
|
+
fn.containerAsTarget = true;
|
|
35
|
+
const container = new ObjectTree({});
|
|
36
|
+
const state = { container };
|
|
37
|
+
const code = createCode([fn]);
|
|
38
|
+
const result = await evaluate(code, state);
|
|
39
|
+
assert.equal(result, container);
|
|
40
|
+
});
|
|
57
41
|
});
|
|
@@ -7,59 +7,55 @@ import { ops } from "../../src/runtime/internal.js";
|
|
|
7
7
|
|
|
8
8
|
describe("expressionObject", () => {
|
|
9
9
|
test("can instantiate an object", async () => {
|
|
10
|
-
const
|
|
10
|
+
const container = new ObjectTree({
|
|
11
11
|
upper: (s) => s.toUpperCase(),
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
const entries = [
|
|
15
|
-
["hello", [[[ops.scope], "upper"], "hello"]],
|
|
16
|
-
["world", [[[ops.scope], "upper"], "world"]],
|
|
15
|
+
["hello", [[[ops.scope, container], "upper"], "hello"]],
|
|
16
|
+
["world", [[[ops.scope, container], "upper"], "world"]],
|
|
17
17
|
];
|
|
18
|
+
const context = new ObjectTree({});
|
|
18
19
|
|
|
19
|
-
const object = await expressionObject(entries,
|
|
20
|
+
const object = await expressionObject(entries, { object: context });
|
|
20
21
|
assert.equal(await object.hello, "HELLO");
|
|
21
22
|
assert.equal(await object.world, "WORLD");
|
|
22
|
-
assert.equal(object[symbols.parent],
|
|
23
|
+
assert.equal(object[symbols.parent], context);
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
test("can define a property getter", async () => {
|
|
26
27
|
let count = 0;
|
|
27
28
|
const increment = () => count++;
|
|
28
29
|
const entries = [["count", [ops.getter, [increment]]]];
|
|
29
|
-
const object = await expressionObject(entries
|
|
30
|
+
const object = await expressionObject(entries);
|
|
30
31
|
assert.equal(await object.count, 0);
|
|
31
32
|
assert.equal(await object.count, 1);
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
test("treats a getter for a primitive value as a regular property", async () => {
|
|
35
36
|
const entries = [["name", [ops.getter, "world"]]];
|
|
36
|
-
const object = await expressionObject(entries
|
|
37
|
+
const object = await expressionObject(entries);
|
|
37
38
|
assert.equal(object.name, "world");
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
test("can instantiate an Origami tree", async () => {
|
|
41
42
|
const entries = [
|
|
42
43
|
["name", "world"],
|
|
43
|
-
["message", [ops.concat, "Hello, ", [[ops.
|
|
44
|
+
["message", [ops.concat, "Hello, ", [[ops.inherited, 0], "name"], "!"]],
|
|
44
45
|
];
|
|
45
|
-
const
|
|
46
|
-
const object = await expressionObject(entries,
|
|
46
|
+
const context = new ObjectTree({});
|
|
47
|
+
const object = await expressionObject(entries, { object: context });
|
|
47
48
|
assert.deepEqual(await Tree.plain(object), {
|
|
48
49
|
name: "world",
|
|
49
50
|
message: "Hello, world!",
|
|
50
51
|
});
|
|
51
|
-
assert.equal(object[symbols.parent],
|
|
52
|
+
assert.equal(object[symbols.parent], context);
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
test("returned object values can be unpacked", async () => {
|
|
55
56
|
const entries = [["data.json", `{ "a": 1 }`]];
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
"json.handler": {
|
|
59
|
-
unpack: JSON.parse,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const result = await expressionObject(entries, parent);
|
|
57
|
+
const context = new ObjectTree({});
|
|
58
|
+
const result = await expressionObject(entries, { object: context });
|
|
63
59
|
const dataJson = await result["data.json"];
|
|
64
60
|
const json = await dataJson.unpack();
|
|
65
61
|
assert.deepEqual(json, { a: 1 });
|
|
@@ -70,7 +66,7 @@ describe("expressionObject", () => {
|
|
|
70
66
|
["(hidden)", "shh"],
|
|
71
67
|
["visible", "hey"],
|
|
72
68
|
];
|
|
73
|
-
const object = await expressionObject(entries
|
|
69
|
+
const object = await expressionObject(entries);
|
|
74
70
|
assert.deepEqual(Object.keys(object), ["visible"]);
|
|
75
71
|
assert.equal(object["hidden"], "shh");
|
|
76
72
|
});
|
|
@@ -84,7 +80,7 @@ describe("expressionObject", () => {
|
|
|
84
80
|
// Immediate treelike value, should have a slash
|
|
85
81
|
["object", [ops.object, ["b", [ops.literal, 2]]]],
|
|
86
82
|
];
|
|
87
|
-
const object = await expressionObject(entries
|
|
83
|
+
const object = await expressionObject(entries);
|
|
88
84
|
assert.deepEqual(object[symbols.keys](), [
|
|
89
85
|
"getter/",
|
|
90
86
|
"hasSlash/",
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { ObjectTree, 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
|
|
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:
|
|
13
|
-
return
|
|
9
|
+
fn: function () {
|
|
10
|
+
return "Hello";
|
|
14
11
|
},
|
|
15
12
|
string: "string",
|
|
16
13
|
});
|
|
17
|
-
|
|
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",
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import { ObjectTree } from "@weborigami/async-tree";
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { describe, test } from "node:test";
|
|
4
|
-
import
|
|
4
|
+
import handleExtension from "../../src/runtime/handleExtension.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
"json.handler": {
|
|
8
|
-
unpack: (buffer) => JSON.parse(String(buffer)),
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe("handlers", () => {
|
|
6
|
+
describe("handleExtension", () => {
|
|
13
7
|
test("attaches an unpack method to a value with an extension", async () => {
|
|
14
8
|
const fixture = createFixture();
|
|
15
9
|
const numberValue = await fixture.get("foo");
|
|
16
10
|
assert(typeof numberValue === "number");
|
|
17
11
|
assert.equal(numberValue, 1);
|
|
18
12
|
const jsonFile = await fixture.get("bar.json");
|
|
19
|
-
const withHandler = await handleExtension(
|
|
20
|
-
fixture,
|
|
21
|
-
jsonFile,
|
|
22
|
-
"bar.json",
|
|
23
|
-
handlers
|
|
24
|
-
);
|
|
13
|
+
const withHandler = await handleExtension(jsonFile, "bar.json", fixture);
|
|
25
14
|
assert.equal(String(withHandler), `{ "bar": 2 }`);
|
|
26
15
|
const data = await withHandler.unpack();
|
|
27
16
|
assert.deepEqual(data, { bar: 2 });
|
|
@@ -30,12 +19,7 @@ describe("handlers", () => {
|
|
|
30
19
|
test("immediately unpacks if key ends in slash", async () => {
|
|
31
20
|
const fixture = createFixture();
|
|
32
21
|
const jsonFile = await fixture.get("bar.json");
|
|
33
|
-
const data = await handleExtension(
|
|
34
|
-
fixture,
|
|
35
|
-
jsonFile,
|
|
36
|
-
"bar.json/",
|
|
37
|
-
handlers
|
|
38
|
-
);
|
|
22
|
+
const data = await handleExtension(jsonFile, "bar.json/", fixture);
|
|
39
23
|
assert.deepEqual(data, { bar: 2 });
|
|
40
24
|
});
|
|
41
25
|
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import jsGlobals from "../../src/
|
|
3
|
+
import jsGlobals from "../../src/project/jsGlobals.js";
|
|
4
4
|
|
|
5
5
|
describe("jsGlobals", () => {
|
|
6
|
-
test("wraps static methods to
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const promise = fixture.resolve.call(target, "hi");
|
|
10
|
-
const value = await promise;
|
|
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")]);
|
|
11
9
|
assert.equal(value, "hi");
|
|
12
10
|
});
|
|
13
11
|
|
|
@@ -7,8 +7,7 @@ describe("mergeTrees", () => {
|
|
|
7
7
|
test("if all arguments are plain objects, result is a plain object", async () => {
|
|
8
8
|
let calledFoo = false;
|
|
9
9
|
let calledBar = false;
|
|
10
|
-
const result = await mergeTrees
|
|
11
|
-
null,
|
|
10
|
+
const result = await mergeTrees(
|
|
12
11
|
{
|
|
13
12
|
a: 1,
|
|
14
13
|
b: 2,
|
|
@@ -42,8 +41,7 @@ describe("mergeTrees", () => {
|
|
|
42
41
|
});
|
|
43
42
|
|
|
44
43
|
test("merges heterogenous arguments as trees", async () => {
|
|
45
|
-
const tree = await mergeTrees
|
|
46
|
-
null,
|
|
44
|
+
const tree = await mergeTrees(
|
|
47
45
|
new ObjectTree({
|
|
48
46
|
a: 1,
|
|
49
47
|
b: 2,
|