@hpcc-js/observablehq-compiler 3.7.6 → 3.7.8

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/src/parse.ts CHANGED
@@ -1,136 +1,136 @@
1
- // Compare with ../../../node_modules/@observablehq/parser/src/parse.js
2
- import { getLineInfo, tokTypes, Statement, ModuleDeclaration, Expression as ExpressionBase, Node } from "acorn";
3
- import { ancestor, RecursiveVisitors, AncestorVisitors } from "acorn-walk";
4
- import { CellParser, parseCell as ohqParseCell, walk as ohqWalk } from "@observablehq/parser";
5
- import defaultGlobals from "../../../node_modules/@observablehq/parser/src/globals.js";
6
- import findReferences from "../../../node_modules/@observablehq/parser/src/references.js";
7
- import findFeatures from "../../../node_modules/@observablehq/parser/src/features.js";
8
-
9
- export interface MutableExpression extends Node {
10
- type: "MutableExpression"
11
- }
12
-
13
- export interface ViewExpression extends Node {
14
- type: "ViewExpression"
15
- }
16
-
17
- export type Expression = ExpressionBase | MutableExpression | ViewExpression;
18
-
19
- // Find references.
20
- // Check for illegal references to arguments.
21
- // Check for illegal assignments to global references.
22
- function parseReferences(cell, input, globals = defaultGlobals) {
23
- if (!cell.body) {
24
- cell.references = [];
25
- } else if (cell.body.type === "ImportDeclaration") {
26
- // This is correct?!?
27
- cell.references = cell.body.specifiers
28
- ? cell.body.specifiers.map(i => i.imported)
29
- : [];
30
- } else {
31
- try {
32
- cell.references = findReferences(cell, globals);
33
- } catch (error: any) {
34
- if (error.node) {
35
- const loc = getLineInfo(input, error.node.start);
36
- error.message += ` (${loc.line}:${loc.column})`;
37
- error.pos = error.node.start;
38
- error.loc = loc;
39
- delete error.node;
40
- }
41
- throw error;
42
- }
43
- }
44
- return cell;
45
- }
46
-
47
- // Find features: file attachments, secrets, database clients.
48
- // Check for illegal references to arguments.
49
- // Check for illegal assignments to global references.
50
- function parseFeatures(cell, input) {
51
- if (cell.body && cell.body.type !== "ImportDeclaration") {
52
- try {
53
- cell.fileAttachments = findFeatures(cell, "FileAttachment");
54
- cell.databaseClients = findFeatures(cell, "DatabaseClient");
55
- cell.secrets = findFeatures(cell, "Secret");
56
- } catch (error: any) {
57
- if (error.node) {
58
- const loc = getLineInfo(input, error.node.start);
59
- error.message += ` (${loc.line}:${loc.column})`;
60
- error.pos = error.node.start;
61
- error.loc = loc;
62
- delete error.node;
63
- }
64
- throw error;
65
- }
66
- } else {
67
- cell.fileAttachments = new Map();
68
- cell.databaseClients = new Map();
69
- cell.secrets = new Map();
70
- }
71
- return cell;
72
- }
73
-
74
- class ModuleParser extends CellParser {
75
-
76
- parseTopLevel(node: { cells?: Cell[] }) {
77
- if (!node.cells) node.cells = [];
78
- // @ts-ignore
79
- while (this.type !== tokTypes.eof) {
80
- // @ts-ignore
81
- const cell: Cell = this.parseCell(this.startNode());
82
- // @ts-ignore
83
- cell.input = this.input;
84
- node.cells.push(cell);
85
- }
86
- // @ts-ignore
87
- this.next();
88
- // @ts-ignore
89
- return this.finishNode(node, "Program");
90
- }
91
- }
92
-
93
- // @ts-ignore
94
- export function parseModule(input, { globals }: { globals: any } = {}) {
95
- // @ts-ignore
96
- const program = ModuleParser.parse(input, { ecmaVersion: 2020 });
97
- for (const cell of program.cells) {
98
- parseReferences(cell, input, globals);
99
- parseFeatures(cell, input);
100
- }
101
- return program;
102
- }
103
-
104
- export interface Cell extends Node {
105
- type: "Cell";
106
- id: Expression;
107
- text: string;
108
- body?: Statement | ModuleDeclaration | Expression;
109
- references: unknown[];
110
- async: boolean;
111
- generator: boolean;
112
- strict: boolean;
113
- }
114
-
115
- export function splitModule(input: string): Cell[] {
116
- return (ModuleParser as any)
117
- .parse(input, { ecmaVersion: "latest" })
118
- .cells.map((cell: any) => ({
119
- type: "Cell",
120
- text: input.substring(cell.start, cell.end),
121
- start: cell.start,
122
- end: cell.end
123
- }));
124
- }
125
-
126
- export {
127
- type Node,
128
- ancestor,
129
- type AncestorVisitors
130
- };
131
-
132
- export function parseCell(input: string): Cell {
133
- return ohqParseCell(input);
134
- }
135
-
136
- export const walk: RecursiveVisitors<any> = ohqWalk;
1
+ // Compare with ../../../node_modules/@observablehq/parser/src/parse.js
2
+ import { getLineInfo, tokTypes, Statement, ModuleDeclaration, Expression as ExpressionBase, Node } from "acorn";
3
+ import { ancestor, RecursiveVisitors, AncestorVisitors } from "acorn-walk";
4
+ import { CellParser, parseCell as ohqParseCell, walk as ohqWalk } from "@observablehq/parser";
5
+ import defaultGlobals from "../../../node_modules/@observablehq/parser/src/globals.js";
6
+ import findReferences from "../../../node_modules/@observablehq/parser/src/references.js";
7
+ import findFeatures from "../../../node_modules/@observablehq/parser/src/features.js";
8
+
9
+ export interface MutableExpression extends Node {
10
+ type: "MutableExpression"
11
+ }
12
+
13
+ export interface ViewExpression extends Node {
14
+ type: "ViewExpression"
15
+ }
16
+
17
+ export type Expression = ExpressionBase | MutableExpression | ViewExpression;
18
+
19
+ // Find references.
20
+ // Check for illegal references to arguments.
21
+ // Check for illegal assignments to global references.
22
+ function parseReferences(cell, input, globals = defaultGlobals) {
23
+ if (!cell.body) {
24
+ cell.references = [];
25
+ } else if (cell.body.type === "ImportDeclaration") {
26
+ // This is correct?!?
27
+ cell.references = cell.body.specifiers
28
+ ? cell.body.specifiers.map(i => i.imported)
29
+ : [];
30
+ } else {
31
+ try {
32
+ cell.references = findReferences(cell, globals);
33
+ } catch (error: any) {
34
+ if (error.node) {
35
+ const loc = getLineInfo(input, error.node.start);
36
+ error.message += ` (${loc.line}:${loc.column})`;
37
+ error.pos = error.node.start;
38
+ error.loc = loc;
39
+ delete error.node;
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+ return cell;
45
+ }
46
+
47
+ // Find features: file attachments, secrets, database clients.
48
+ // Check for illegal references to arguments.
49
+ // Check for illegal assignments to global references.
50
+ function parseFeatures(cell, input) {
51
+ if (cell.body && cell.body.type !== "ImportDeclaration") {
52
+ try {
53
+ cell.fileAttachments = findFeatures(cell, "FileAttachment");
54
+ cell.databaseClients = findFeatures(cell, "DatabaseClient");
55
+ cell.secrets = findFeatures(cell, "Secret");
56
+ } catch (error: any) {
57
+ if (error.node) {
58
+ const loc = getLineInfo(input, error.node.start);
59
+ error.message += ` (${loc.line}:${loc.column})`;
60
+ error.pos = error.node.start;
61
+ error.loc = loc;
62
+ delete error.node;
63
+ }
64
+ throw error;
65
+ }
66
+ } else {
67
+ cell.fileAttachments = new Map();
68
+ cell.databaseClients = new Map();
69
+ cell.secrets = new Map();
70
+ }
71
+ return cell;
72
+ }
73
+
74
+ class ModuleParser extends CellParser {
75
+
76
+ parseTopLevel(node: { cells?: Cell[] }) {
77
+ if (!node.cells) node.cells = [];
78
+ // @ts-ignore
79
+ while (this.type !== tokTypes.eof) {
80
+ // @ts-ignore
81
+ const cell: Cell = this.parseCell(this.startNode());
82
+ // @ts-ignore
83
+ cell.input = this.input;
84
+ node.cells.push(cell);
85
+ }
86
+ // @ts-ignore
87
+ this.next();
88
+ // @ts-ignore
89
+ return this.finishNode(node, "Program");
90
+ }
91
+ }
92
+
93
+ // @ts-ignore
94
+ export function parseModule(input, { globals }: { globals: any } = {}) {
95
+ // @ts-ignore
96
+ const program = ModuleParser.parse(input, { ecmaVersion: 2020 });
97
+ for (const cell of program.cells) {
98
+ parseReferences(cell, input, globals);
99
+ parseFeatures(cell, input);
100
+ }
101
+ return program;
102
+ }
103
+
104
+ export interface Cell extends Node {
105
+ type: "Cell";
106
+ id: Expression;
107
+ text: string;
108
+ body?: Statement | ModuleDeclaration | Expression;
109
+ references: unknown[];
110
+ async: boolean;
111
+ generator: boolean;
112
+ strict: boolean;
113
+ }
114
+
115
+ export function splitModule(input: string): Cell[] {
116
+ return (ModuleParser as any)
117
+ .parse(input, { ecmaVersion: "latest" })
118
+ .cells.map((cell: any) => ({
119
+ type: "Cell",
120
+ text: input.substring(cell.start, cell.end),
121
+ start: cell.start,
122
+ end: cell.end
123
+ }));
124
+ }
125
+
126
+ export {
127
+ type Node,
128
+ ancestor,
129
+ type AncestorVisitors
130
+ };
131
+
132
+ export function parseCell(input: string): Cell {
133
+ return ohqParseCell(input);
134
+ }
135
+
136
+ export const walk: RecursiveVisitors<any> = ohqWalk;
package/src/types.ts CHANGED
@@ -1,180 +1,180 @@
1
- export namespace ohq {
2
-
3
- // ObservableHQ Notebook Format ---
4
- export interface Owner {
5
- id?: string;
6
- github_login?: string;
7
- avatar_url?: string;
8
- login?: string;
9
- name?: string;
10
- bio?: string;
11
- home_url?: string;
12
- type?: string;
13
- tier?: string;
14
- }
15
-
16
- export interface Creator {
17
- id?: string;
18
- github_login?: string;
19
- avatar_url?: string;
20
- login?: string;
21
- name?: string;
22
- bio?: string;
23
- home_url?: string;
24
- tier?: string;
25
- }
26
-
27
- export interface Author {
28
- id?: string;
29
- avatar_url?: string;
30
- name?: string;
31
- login?: string;
32
- bio?: string;
33
- home_url?: string;
34
- github_login?: string;
35
- tier?: string;
36
- approved?: boolean;
37
- description?: string;
38
- }
39
-
40
- export interface Owner2 {
41
- id?: string;
42
- github_login?: string;
43
- avatar_url?: string;
44
- login?: string;
45
- name?: string;
46
- bio?: string;
47
- home_url?: string;
48
- type?: string;
49
- tier?: string;
50
- }
51
-
52
- export interface Collection {
53
- id?: string;
54
- type?: string;
55
- slug?: string;
56
- title?: string;
57
- description?: string;
58
- update_time?: Date;
59
- pinned?: boolean;
60
- ordered?: boolean;
61
- custom_thumbnail?: any;
62
- default_thumbnail?: string;
63
- thumbnail?: string;
64
- listing_count?: number;
65
- parent_collection_count?: number;
66
- owner?: Owner2;
67
- }
68
-
69
- export interface File {
70
- id?: string;
71
- url: string;
72
- download_url?: string;
73
- name: string;
74
- create_time?: Date;
75
- status?: string;
76
- size?: number;
77
- mime_type?: string;
78
- content_encoding?: string;
79
- }
80
-
81
- export interface User {
82
- id?: string;
83
- github_login?: string;
84
- avatar_url?: string;
85
- login?: string;
86
- name?: string;
87
- bio?: string;
88
- home_url?: string;
89
- tier?: string;
90
- }
91
-
92
- export interface Comment {
93
- id?: string;
94
- content?: string;
95
- node_id?: number;
96
- create_time?: Date;
97
- update_time?: any;
98
- resolved?: boolean;
99
- user?: User;
100
- }
101
-
102
- export interface Node {
103
- id: string | number;
104
- mode: string;
105
- value: string;
106
- pinned?: boolean; // Show source code?
107
- data?: any;
108
- name?: string;
109
- // NodeEx ---
110
- start?: number;
111
- end?: number;
112
- private?: boolean;
113
- outputs?: string[];
114
- }
115
-
116
- export interface Notebook {
117
- id?: string;
118
- slug?: any;
119
- trashed?: boolean;
120
- description?: string;
121
- likes?: number;
122
- publish_level?: string;
123
- forks?: number;
124
- fork_of?: any;
125
- update_time?: Date;
126
- publish_time?: Date;
127
- publish_version?: number;
128
- latest_version?: number;
129
- thumbnail?: string;
130
- default_thumbnail?: string;
131
- roles?: any[];
132
- sharing?: any;
133
- owner?: Owner;
134
- creator?: Creator;
135
- authors?: Author[];
136
- collections?: Collection[];
137
- files: File[];
138
- comments?: Comment[];
139
- commenting_lock?: any;
140
- suggestion_from?: any;
141
- suggestions_to?: any[];
142
- version?: number;
143
- title?: string;
144
- license?: string;
145
- copyright?: string;
146
- nodes: Node[];
147
- resolutions?: any[];
148
- }
149
-
150
- // @observablehq/runtime API ---
151
- export type InspectorFactory = (name?: string) => Inspector;
152
-
153
- export interface Inspector {
154
- _node?: HTMLDivElement;
155
- pending();
156
- fulfilled(value);
157
- rejected(error);
158
- }
159
-
160
- export interface Runtime {
161
- fileAttachments(func: (name: string) => ohq.File): any;
162
- module(define?, inspector?: InspectorFactory): Module;
163
- dispose(): void;
164
- }
165
-
166
- export interface Module {
167
- derive(specifiers: string[] | { name: string, alias: string }[], source: any);
168
- import(name: string, alias: string | undefined, mod: Module): Variable;
169
- builtin(name: string, _: any);
170
- variable(inspector?: Inspector): Variable;
171
- value(name: string): Promise<any>;
172
- }
173
-
174
- export interface Variable {
175
- delete();
176
- define(name?: string, inputs?: string[], definition?: any);
177
- import(name: string, otherModule: ohq.Module);
178
- import(name: string, alias: string, otherModule: ohq.Module);
179
- }
1
+ export namespace ohq {
2
+
3
+ // ObservableHQ Notebook Format ---
4
+ export interface Owner {
5
+ id?: string;
6
+ github_login?: string;
7
+ avatar_url?: string;
8
+ login?: string;
9
+ name?: string;
10
+ bio?: string;
11
+ home_url?: string;
12
+ type?: string;
13
+ tier?: string;
14
+ }
15
+
16
+ export interface Creator {
17
+ id?: string;
18
+ github_login?: string;
19
+ avatar_url?: string;
20
+ login?: string;
21
+ name?: string;
22
+ bio?: string;
23
+ home_url?: string;
24
+ tier?: string;
25
+ }
26
+
27
+ export interface Author {
28
+ id?: string;
29
+ avatar_url?: string;
30
+ name?: string;
31
+ login?: string;
32
+ bio?: string;
33
+ home_url?: string;
34
+ github_login?: string;
35
+ tier?: string;
36
+ approved?: boolean;
37
+ description?: string;
38
+ }
39
+
40
+ export interface Owner2 {
41
+ id?: string;
42
+ github_login?: string;
43
+ avatar_url?: string;
44
+ login?: string;
45
+ name?: string;
46
+ bio?: string;
47
+ home_url?: string;
48
+ type?: string;
49
+ tier?: string;
50
+ }
51
+
52
+ export interface Collection {
53
+ id?: string;
54
+ type?: string;
55
+ slug?: string;
56
+ title?: string;
57
+ description?: string;
58
+ update_time?: Date;
59
+ pinned?: boolean;
60
+ ordered?: boolean;
61
+ custom_thumbnail?: any;
62
+ default_thumbnail?: string;
63
+ thumbnail?: string;
64
+ listing_count?: number;
65
+ parent_collection_count?: number;
66
+ owner?: Owner2;
67
+ }
68
+
69
+ export interface File {
70
+ id?: string;
71
+ url: string;
72
+ download_url?: string;
73
+ name: string;
74
+ create_time?: Date;
75
+ status?: string;
76
+ size?: number;
77
+ mime_type?: string;
78
+ content_encoding?: string;
79
+ }
80
+
81
+ export interface User {
82
+ id?: string;
83
+ github_login?: string;
84
+ avatar_url?: string;
85
+ login?: string;
86
+ name?: string;
87
+ bio?: string;
88
+ home_url?: string;
89
+ tier?: string;
90
+ }
91
+
92
+ export interface Comment {
93
+ id?: string;
94
+ content?: string;
95
+ node_id?: number;
96
+ create_time?: Date;
97
+ update_time?: any;
98
+ resolved?: boolean;
99
+ user?: User;
100
+ }
101
+
102
+ export interface Node {
103
+ id: string | number;
104
+ mode: string;
105
+ value: string;
106
+ pinned?: boolean; // Show source code?
107
+ data?: any;
108
+ name?: string;
109
+ // NodeEx ---
110
+ start?: number;
111
+ end?: number;
112
+ private?: boolean;
113
+ outputs?: string[];
114
+ }
115
+
116
+ export interface Notebook {
117
+ id?: string;
118
+ slug?: any;
119
+ trashed?: boolean;
120
+ description?: string;
121
+ likes?: number;
122
+ publish_level?: string;
123
+ forks?: number;
124
+ fork_of?: any;
125
+ update_time?: Date;
126
+ publish_time?: Date;
127
+ publish_version?: number;
128
+ latest_version?: number;
129
+ thumbnail?: string;
130
+ default_thumbnail?: string;
131
+ roles?: any[];
132
+ sharing?: any;
133
+ owner?: Owner;
134
+ creator?: Creator;
135
+ authors?: Author[];
136
+ collections?: Collection[];
137
+ files: File[];
138
+ comments?: Comment[];
139
+ commenting_lock?: any;
140
+ suggestion_from?: any;
141
+ suggestions_to?: any[];
142
+ version?: number;
143
+ title?: string;
144
+ license?: string;
145
+ copyright?: string;
146
+ nodes: Node[];
147
+ resolutions?: any[];
148
+ }
149
+
150
+ // @observablehq/runtime API ---
151
+ export type InspectorFactory = (name?: string) => Inspector;
152
+
153
+ export interface Inspector {
154
+ _node?: HTMLDivElement;
155
+ pending();
156
+ fulfilled(value);
157
+ rejected(error);
158
+ }
159
+
160
+ export interface Runtime {
161
+ fileAttachments(func: (name: string) => ohq.File): any;
162
+ module(define?, inspector?: InspectorFactory): Module;
163
+ dispose(): void;
164
+ }
165
+
166
+ export interface Module {
167
+ derive(specifiers: string[] | { name: string, alias: string }[], source: any);
168
+ import(name: string, alias: string | undefined, mod: Module): Variable;
169
+ builtin(name: string, _: any);
170
+ variable(inspector?: Inspector): Variable;
171
+ value(name: string): Promise<any>;
172
+ }
173
+
174
+ export interface Variable {
175
+ delete();
176
+ define(name?: string, inputs?: string[], definition?: any);
177
+ import(name: string, otherModule: ohq.Module);
178
+ import(name: string, alias: string, otherModule: ohq.Module);
179
+ }
180
180
  }