@hpcc-js/observablehq-compiler 1.1.0 → 1.1.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.
Files changed (49) hide show
  1. package/LICENSE +43 -0
  2. package/README.md +105 -105
  3. package/bin/ojscc.mjs +74 -74
  4. package/dist/index.esm.js +554 -554
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/index.esm.min.js +4 -0
  7. package/dist/index.esm.min.js.map +1 -0
  8. package/dist/index.js +6700 -6696
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.min.js +4 -0
  11. package/dist/index.min.js.map +1 -0
  12. package/package.json +4 -3
  13. package/src/__package__.ts +3 -3
  14. package/src/__tests__/File Attachments.ts +894 -894
  15. package/src/__tests__/Introduction to Imports.ts +748 -748
  16. package/src/__tests__/Observable TimeChart.ts +771 -771
  17. package/src/__tests__/index.ts +13 -13
  18. package/src/__tests__/node.ts +177 -177
  19. package/src/__tests__/tsconfig.json +20 -20
  20. package/src/compiler.md +234 -234
  21. package/src/compiler.ts +264 -264
  22. package/src/cst.ts +172 -172
  23. package/src/index.css +459 -459
  24. package/src/index.ts +7 -7
  25. package/src/util.md +113 -113
  26. package/src/util.ts +153 -153
  27. package/src/writer.ts +80 -80
  28. package/types/__package__.d.ts +3 -3
  29. package/types/__tests__/File Attachments.d.ts +109 -109
  30. package/types/__tests__/Introduction to Imports.d.ts +119 -119
  31. package/types/__tests__/Observable TimeChart.d.ts +110 -110
  32. package/types/__tests__/index.d.ts +1 -1
  33. package/types/__tests__/node.d.ts +1 -1
  34. package/types/compiler.d.ts +87 -87
  35. package/types/cst.d.ts +41 -41
  36. package/types/index.d.ts +5 -5
  37. package/types/util.d.ts +25 -25
  38. package/types/writer.d.ts +18 -18
  39. package/types-3.4/__package__.d.ts +4 -0
  40. package/types-3.4/__tests__/File Attachments.d.ts +110 -0
  41. package/types-3.4/__tests__/Introduction to Imports.d.ts +120 -0
  42. package/types-3.4/__tests__/Observable TimeChart.d.ts +111 -0
  43. package/types-3.4/__tests__/index.d.ts +2 -0
  44. package/types-3.4/__tests__/node.d.ts +2 -0
  45. package/types-3.4/compiler.d.ts +91 -0
  46. package/types-3.4/cst.d.ts +42 -0
  47. package/types-3.4/index.d.ts +6 -0
  48. package/types-3.4/util.d.ts +26 -0
  49. package/types-3.4/writer.d.ts +19 -0
@@ -1,13 +1,13 @@
1
- // @ts-ignore
2
- import fetch, { Blob, blobFrom, blobFromSync, File, fileFrom, fileFromSync, FormData, Headers, Request, Response } from "node-fetch";
3
- if (!globalThis.fetch) {
4
- // @ts-ignore
5
- globalThis.fetch = fetch;
6
- // @ts-ignore
7
- globalThis.Headers = Headers;
8
- // @ts-ignore
9
- globalThis.Request = Request;
10
- // @ts-ignore
11
- globalThis.Response = Response;
12
- }
13
- export * from "./node";
1
+ // @ts-ignore
2
+ import fetch, { Blob, blobFrom, blobFromSync, File, fileFrom, fileFromSync, FormData, Headers, Request, Response } from "node-fetch";
3
+ if (!globalThis.fetch) {
4
+ // @ts-ignore
5
+ globalThis.fetch = fetch;
6
+ // @ts-ignore
7
+ globalThis.Headers = Headers;
8
+ // @ts-ignore
9
+ globalThis.Request = Request;
10
+ // @ts-ignore
11
+ globalThis.Response = Response;
12
+ }
13
+ export * from "./node";
@@ -1,177 +1,177 @@
1
- import { Library, Runtime, Inspector } from "@observablehq/runtime";
2
- import { expect } from "chai";
3
- import { compile, download, ohq, ojs2notebook } from "../index";
4
- import { Writer } from "../writer";
5
- import { fa } from "./File Attachments";
6
- import { imports } from "./Introduction to Imports";
7
- import { timechart } from "./Observable TimeChart";
8
-
9
- const placeholder = globalThis?.document?.getElementById("placeholder");
10
-
11
- const ojs = `
12
- 42;
13
- a = 1
14
- b = 2
15
- c = a + b
16
- d = {
17
- yield 1;
18
- yield 2;
19
- yield 3;
20
- }
21
-
22
- viewof e = {
23
- let output = {};
24
- let listeners = [];
25
- output.value = 10;
26
- output.addEventListener = (listener) => listeners.push(listener);;
27
- output.removeEventListener = (listener) => {
28
- listeners = listeners.filter(l => l !== listener);
29
- };
30
- return output;
31
- }
32
-
33
- tenTimes = {
34
- for (let i = 0; i < 10; i++) {
35
- yield Promises.delay(100);
36
- }
37
- }
38
-
39
- f = {
40
- tenTimes;
41
- return (this || 0) + 1;
42
- }
43
- `;
44
-
45
- describe("ojs", function () {
46
- it("quickstart", async function () {
47
- this.timeout(10000);
48
-
49
- const notebook = await download("https://observablehq.com/@observablehq/summary-table");
50
- const compiledNB = await compile(notebook);
51
-
52
- const library = new Library();
53
- const runtime = new Runtime(library);
54
-
55
- compiledNB(runtime, name => {
56
- const div = globalThis?.document.createElement("div");
57
- placeholder.appendChild(div);
58
- return new Inspector(div);
59
- });
60
- });
61
-
62
- it.only("simple", async function () {
63
- this.timeout(10000);
64
-
65
- const notebook = ojs2notebook(ojs);
66
- const define = await compile(notebook);
67
-
68
- const library = new Library();
69
- const runtime = new Runtime(library);
70
- const main: ohq.Module = define(runtime, name => {
71
- if (placeholder) {
72
- const div = globalThis?.document.createElement("div");
73
- placeholder.appendChild(div);
74
- return new Inspector(div);
75
- }
76
- return {
77
- pending() { },
78
- fulfilled(value) { console.info("fulfilled", name, value); },
79
- rejected(error) { console.error("rejected", name, error); },
80
- };
81
- });
82
-
83
- expect(await main.value("d")).to.equal(1);
84
- expect(await main.value("d")).to.equal(2);
85
- expect(await main.value("d")).to.equal(3);
86
- expect(await main.value("d")).to.equal(3);
87
- expect(await main.value("d")).to.equal(3);
88
-
89
- expect(await main.value("c")).to.equal(3);
90
- expect(await main.value("a")).to.equal(1);
91
- expect(await main.value("b")).to.equal(2);
92
-
93
- expect(await main.value("e")).to.equal(10);
94
- const viewOfE = await main.value("viewof e");
95
- expect(viewOfE).to.have.property("value");
96
- expect(viewOfE).to.have.property("addEventListener");
97
- expect(viewOfE).to.have.property("removeEventListener");
98
-
99
- await main.value("tenTimes");
100
-
101
- for (const cell of define.cells) {
102
- cell.dispose();
103
- break;
104
- }
105
- });
106
-
107
- it("compiler", async function () {
108
- const writer = new Writer();
109
- const define = await compile(imports as any);
110
- define.write(writer);
111
- console.info(writer.toString());
112
- });
113
-
114
- it("File Attachements", async function () {
115
-
116
- const define = await compile(fa as any);
117
-
118
- const library = new Library();
119
- const runtime = new Runtime(library);
120
- /*const main: ohq.Module =*/ define(runtime, name => {
121
- if (placeholder) {
122
- const div = globalThis?.document.createElement("div");
123
- placeholder.appendChild(div);
124
- return new Inspector(div);
125
- }
126
- return {
127
- pending() { console.info("pending", name); },
128
- fulfilled(value) { console.info("fulfilled", name, value); },
129
- rejected(error) { console.error("rejected", name, error); },
130
- };
131
- });
132
-
133
- });
134
-
135
- it("Introduction to Imports", async function () {
136
-
137
- const define = await compile(imports as any);
138
-
139
- const library = new Library();
140
- const runtime = new Runtime(library);
141
- /*const main: ohq.Module =*/ define(runtime, name => {
142
- if (placeholder) {
143
- const div = globalThis?.document.createElement("div");
144
- placeholder.appendChild(div);
145
- return new Inspector(div);
146
- }
147
- return {
148
- pending() { console.info("pending", name); },
149
- fulfilled(value) { console.info("fulfilled", name, value); },
150
- rejected(error) { console.error("rejected", name, error); },
151
- };
152
- });
153
-
154
- });
155
-
156
- it("Observable TimeChart", async function () {
157
-
158
- const define2 = await compile(timechart as any);
159
-
160
- const library = new Library();
161
- const runtime = new Runtime(library);
162
- /*const main: ohq.Module =*/ define2(runtime, name => {
163
- if (placeholder) {
164
- const div = globalThis?.document.createElement("div");
165
- placeholder.appendChild(div);
166
- return new Inspector(div);
167
- }
168
- return {
169
- pending() { console.info("pending", name); },
170
- fulfilled(value) { console.info("fulfilled", name, value); },
171
- rejected(error) { console.error("rejected", name, error); },
172
- };
173
- });
174
-
175
- });
176
- });
177
-
1
+ import { Library, Runtime, Inspector } from "@observablehq/runtime";
2
+ import { expect } from "chai";
3
+ import { compile, download, ohq, ojs2notebook } from "../index";
4
+ import { Writer } from "../writer";
5
+ import { fa } from "./File Attachments";
6
+ import { imports } from "./Introduction to Imports";
7
+ import { timechart } from "./Observable TimeChart";
8
+
9
+ const placeholder = globalThis?.document?.getElementById("placeholder");
10
+
11
+ const ojs = `
12
+ 42;
13
+ a = 1
14
+ b = 2
15
+ c = a + b
16
+ d = {
17
+ yield 1;
18
+ yield 2;
19
+ yield 3;
20
+ }
21
+
22
+ viewof e = {
23
+ let output = {};
24
+ let listeners = [];
25
+ output.value = 10;
26
+ output.addEventListener = (listener) => listeners.push(listener);;
27
+ output.removeEventListener = (listener) => {
28
+ listeners = listeners.filter(l => l !== listener);
29
+ };
30
+ return output;
31
+ }
32
+
33
+ tenTimes = {
34
+ for (let i = 0; i < 10; i++) {
35
+ yield Promises.delay(100);
36
+ }
37
+ }
38
+
39
+ f = {
40
+ tenTimes;
41
+ return (this || 0) + 1;
42
+ }
43
+ `;
44
+
45
+ describe("ojs", function () {
46
+ it("quickstart", async function () {
47
+ this.timeout(10000);
48
+
49
+ const notebook = await download("https://observablehq.com/@observablehq/summary-table");
50
+ const compiledNB = await compile(notebook);
51
+
52
+ const library = new Library();
53
+ const runtime = new Runtime(library);
54
+
55
+ compiledNB(runtime, name => {
56
+ const div = globalThis?.document.createElement("div");
57
+ placeholder.appendChild(div);
58
+ return new Inspector(div);
59
+ });
60
+ });
61
+
62
+ it.only("simple", async function () {
63
+ this.timeout(10000);
64
+
65
+ const notebook = ojs2notebook(ojs);
66
+ const define = await compile(notebook);
67
+
68
+ const library = new Library();
69
+ const runtime = new Runtime(library);
70
+ const main: ohq.Module = define(runtime, name => {
71
+ if (placeholder) {
72
+ const div = globalThis?.document.createElement("div");
73
+ placeholder.appendChild(div);
74
+ return new Inspector(div);
75
+ }
76
+ return {
77
+ pending() { },
78
+ fulfilled(value) { console.info("fulfilled", name, value); },
79
+ rejected(error) { console.error("rejected", name, error); },
80
+ };
81
+ });
82
+
83
+ expect(await main.value("d")).to.equal(1);
84
+ expect(await main.value("d")).to.equal(2);
85
+ expect(await main.value("d")).to.equal(3);
86
+ expect(await main.value("d")).to.equal(3);
87
+ expect(await main.value("d")).to.equal(3);
88
+
89
+ expect(await main.value("c")).to.equal(3);
90
+ expect(await main.value("a")).to.equal(1);
91
+ expect(await main.value("b")).to.equal(2);
92
+
93
+ expect(await main.value("e")).to.equal(10);
94
+ const viewOfE = await main.value("viewof e");
95
+ expect(viewOfE).to.have.property("value");
96
+ expect(viewOfE).to.have.property("addEventListener");
97
+ expect(viewOfE).to.have.property("removeEventListener");
98
+
99
+ await main.value("tenTimes");
100
+
101
+ for (const cell of define.cells) {
102
+ cell.dispose();
103
+ break;
104
+ }
105
+ });
106
+
107
+ it("compiler", async function () {
108
+ const writer = new Writer();
109
+ const define = await compile(imports as any);
110
+ define.write(writer);
111
+ console.info(writer.toString());
112
+ });
113
+
114
+ it("File Attachements", async function () {
115
+
116
+ const define = await compile(fa as any);
117
+
118
+ const library = new Library();
119
+ const runtime = new Runtime(library);
120
+ /*const main: ohq.Module =*/ define(runtime, name => {
121
+ if (placeholder) {
122
+ const div = globalThis?.document.createElement("div");
123
+ placeholder.appendChild(div);
124
+ return new Inspector(div);
125
+ }
126
+ return {
127
+ pending() { console.info("pending", name); },
128
+ fulfilled(value) { console.info("fulfilled", name, value); },
129
+ rejected(error) { console.error("rejected", name, error); },
130
+ };
131
+ });
132
+
133
+ });
134
+
135
+ it("Introduction to Imports", async function () {
136
+
137
+ const define = await compile(imports as any);
138
+
139
+ const library = new Library();
140
+ const runtime = new Runtime(library);
141
+ /*const main: ohq.Module =*/ define(runtime, name => {
142
+ if (placeholder) {
143
+ const div = globalThis?.document.createElement("div");
144
+ placeholder.appendChild(div);
145
+ return new Inspector(div);
146
+ }
147
+ return {
148
+ pending() { console.info("pending", name); },
149
+ fulfilled(value) { console.info("fulfilled", name, value); },
150
+ rejected(error) { console.error("rejected", name, error); },
151
+ };
152
+ });
153
+
154
+ });
155
+
156
+ it("Observable TimeChart", async function () {
157
+
158
+ const define2 = await compile(timechart as any);
159
+
160
+ const library = new Library();
161
+ const runtime = new Runtime(library);
162
+ /*const main: ohq.Module =*/ define2(runtime, name => {
163
+ if (placeholder) {
164
+ const div = globalThis?.document.createElement("div");
165
+ placeholder.appendChild(div);
166
+ return new Inspector(div);
167
+ }
168
+ return {
169
+ pending() { console.info("pending", name); },
170
+ fulfilled(value) { console.info("fulfilled", name, value); },
171
+ rejected(error) { console.error("rejected", name, error); },
172
+ };
173
+ });
174
+
175
+ });
176
+ });
177
+
@@ -1,21 +1,21 @@
1
- {
2
- "extends": "../tsconfig.settings.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./lib-umd",
6
- "declarationDir": "./types",
7
- "target": "ES2018",
8
- "noImplicitThis": true,
9
- "resolveJsonModule": true,
10
- "lib": [
11
- "dom",
12
- "ES2018"
13
- ],
14
- "types": [
15
- "mocha"
16
- ]
17
- },
18
- "include": [
19
- "./src/**/*"
20
- ]
1
+ {
2
+ "extends": "../tsconfig.settings.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./lib-umd",
6
+ "declarationDir": "./types",
7
+ "target": "ES2018",
8
+ "noImplicitThis": true,
9
+ "resolveJsonModule": true,
10
+ "lib": [
11
+ "dom",
12
+ "ES2018"
13
+ ],
14
+ "types": [
15
+ "mocha"
16
+ ]
17
+ },
18
+ "include": [
19
+ "./src/**/*"
20
+ ]
21
21
  }