@dancrumb/cant-compiler 0.0.0-stage → 0.10.1
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/dist/bodies.d.ts +33 -0
- package/dist/bodies.d.ts.map +1 -0
- package/dist/bodies.js +512 -0
- package/dist/bodies.js.map +1 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +30 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +90 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile.d.ts +20 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +777 -0
- package/dist/compile.js.map +1 -0
- package/dist/constants.d.ts +22 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +262 -0
- package/dist/constants.js.map +1 -0
- package/dist/declarations.d.ts +54 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +202 -0
- package/dist/declarations.js.map +1 -0
- package/dist/diagnostic.d.ts +19 -0
- package/dist/diagnostic.d.ts.map +1 -0
- package/dist/diagnostic.js +27 -0
- package/dist/diagnostic.js.map +1 -0
- package/dist/entities.d.ts +32 -0
- package/dist/entities.d.ts.map +1 -0
- package/dist/entities.js +235 -0
- package/dist/entities.js.map +1 -0
- package/dist/evaluate.d.ts +30 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +79 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/host.d.ts +8 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +13 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +93 -0
- package/dist/manifest.js.map +1 -0
- package/dist/modules.d.ts +84 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +259 -0
- package/dist/modules.js.map +1 -0
- package/dist/program.d.ts +24 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +38 -0
- package/dist/program.js.map +1 -0
- package/dist/resolve.d.ts +24 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +203 -0
- package/dist/resolve.js.map +1 -0
- package/dist/stdlib.d.ts +12 -0
- package/dist/stdlib.d.ts.map +1 -0
- package/dist/stdlib.js +38 -0
- package/dist/stdlib.js.map +1 -0
- package/dist/typecheck.d.ts +52 -0
- package/dist/typecheck.d.ts.map +1 -0
- package/dist/typecheck.js +1408 -0
- package/dist/typecheck.js.map +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +199 -0
- package/dist/types.js.map +1 -0
- package/dist/weave.d.ts +3 -0
- package/dist/weave.d.ts.map +1 -0
- package/dist/weave.js +40 -0
- package/dist/weave.js.map +1 -0
- package/package.json +47 -3
- package/README.md +0 -3
package/dist/compile.js
ADDED
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { dirname, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { COMPILED_FORMAT, } from '@dancrumb/cant-shared';
|
|
4
|
+
import { ConstantValues } from './evaluate.js';
|
|
5
|
+
import { fileSystemHost } from './host.js';
|
|
6
|
+
import { symbolOf } from './modules.js';
|
|
7
|
+
import { checkProgram } from './program.js';
|
|
8
|
+
import { STANDARD_LIBRARY } from './stdlib.js';
|
|
9
|
+
import { typeOf } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Compile a program, starting from its entry module: check it, and if it has no compile-time
|
|
12
|
+
* errors, give the compiled program the interpreter runs, and its source map
|
|
13
|
+
* (docs/adr/0039-compiled-programs.md). Otherwise, give the diagnostics that stopped it.
|
|
14
|
+
*/
|
|
15
|
+
export function compile(entry, host = fileSystemHost) {
|
|
16
|
+
const checked = checkProgram(entry, host);
|
|
17
|
+
if (checked.diagnostics.length > 0)
|
|
18
|
+
return { diagnostics: checked.diagnostics };
|
|
19
|
+
return new Compiler(checked).compile();
|
|
20
|
+
}
|
|
21
|
+
/** The program's root: the directory that holds its `cant.json`, or the entry module's directory. */
|
|
22
|
+
export const rootOf = (program) => dirname(program.manifest?.path ?? program.entry);
|
|
23
|
+
const keyOf = (symbol) => `${symbol.module}::${symbol.name}`;
|
|
24
|
+
/** The locals of one action or trigger, each given a slot. */
|
|
25
|
+
class Frame {
|
|
26
|
+
slots = new Map();
|
|
27
|
+
slot(declaration) {
|
|
28
|
+
let slot = this.slots.get(declaration);
|
|
29
|
+
if (slot === undefined) {
|
|
30
|
+
slot = this.slots.size;
|
|
31
|
+
this.slots.set(declaration, slot);
|
|
32
|
+
}
|
|
33
|
+
return slot;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class Compiler {
|
|
37
|
+
checked;
|
|
38
|
+
root;
|
|
39
|
+
values;
|
|
40
|
+
relationIndexes = new Map();
|
|
41
|
+
/** The module whose code is being compiled. */
|
|
42
|
+
module;
|
|
43
|
+
constructor(checked) {
|
|
44
|
+
this.checked = checked;
|
|
45
|
+
this.root = rootOf(checked);
|
|
46
|
+
this.values = new ConstantValues(checked.references, (symbol) => this.symbolId(symbol));
|
|
47
|
+
}
|
|
48
|
+
// ----- Names -----
|
|
49
|
+
moduleId(path) {
|
|
50
|
+
if (path.startsWith('cant::'))
|
|
51
|
+
return path;
|
|
52
|
+
return relative(this.root, path).split(sep).join('/');
|
|
53
|
+
}
|
|
54
|
+
symbolId(symbol) {
|
|
55
|
+
return `${this.moduleId(symbol.module)}#${symbol.name}`;
|
|
56
|
+
}
|
|
57
|
+
position(position) {
|
|
58
|
+
return {
|
|
59
|
+
module: this.moduleId(this.module.path),
|
|
60
|
+
start: { line: position.start.line, column: position.start.column },
|
|
61
|
+
end: { line: position.end.line, column: position.end.column },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ----- The program -----
|
|
65
|
+
compile() {
|
|
66
|
+
const program = {
|
|
67
|
+
format: COMPILED_FORMAT,
|
|
68
|
+
build: '',
|
|
69
|
+
entry: this.moduleId(this.checked.entry),
|
|
70
|
+
types: {},
|
|
71
|
+
actions: {},
|
|
72
|
+
constants: {},
|
|
73
|
+
relations: [],
|
|
74
|
+
permissions: [],
|
|
75
|
+
triggers: [],
|
|
76
|
+
};
|
|
77
|
+
// Relations first, so entities can name the relation that adds each navigation field.
|
|
78
|
+
for (const module of this.checked.modules.values()) {
|
|
79
|
+
this.module = module;
|
|
80
|
+
for (const declaration of module.program?.children ?? []) {
|
|
81
|
+
if (declaration.type !== 'relation')
|
|
82
|
+
continue;
|
|
83
|
+
this.relationIndexes.set(declaration, program.relations.length);
|
|
84
|
+
program.relations.push(this.relation(declaration));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const module of this.checked.modules.values()) {
|
|
88
|
+
this.module = module;
|
|
89
|
+
for (const declaration of module.program?.children ?? []) {
|
|
90
|
+
switch (declaration.type) {
|
|
91
|
+
case 'enumDeclaration':
|
|
92
|
+
program.types[this.idOfDeclaration(declaration.name)] = {
|
|
93
|
+
kind: 'enum',
|
|
94
|
+
members: declaration.members.map((member) => [member.name.value, member.value === undefined ? { kind: 'text', value: member.name.value } : this.base(member.value)]),
|
|
95
|
+
};
|
|
96
|
+
break;
|
|
97
|
+
case 'model':
|
|
98
|
+
program.types[this.idOfDeclaration(declaration.name)] = { kind: 'model', ...this.fields(declaration.fields) };
|
|
99
|
+
break;
|
|
100
|
+
case 'errorDeclaration':
|
|
101
|
+
program.types[this.idOfDeclaration(declaration.name)] = {
|
|
102
|
+
kind: 'error',
|
|
103
|
+
...(declaration.data !== undefined && {
|
|
104
|
+
data: Array.isArray(declaration.data) ? this.fields(declaration.data) : { model: this.reference(declaration.data) },
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
break;
|
|
108
|
+
case 'entity':
|
|
109
|
+
program.types[this.idOfDeclaration(declaration.name)] = this.entity(declaration);
|
|
110
|
+
break;
|
|
111
|
+
case 'action':
|
|
112
|
+
program.actions[this.idOfDeclaration(declaration.name)] = this.action(declaration);
|
|
113
|
+
break;
|
|
114
|
+
case 'const': {
|
|
115
|
+
const result = this.values.of(declaration);
|
|
116
|
+
if (result.kind === 'value') {
|
|
117
|
+
const type = declaration.valueType === undefined ? undefined : this.checkedType(declaration.valueType);
|
|
118
|
+
program.constants[this.idOfDeclaration(declaration.name)] = type === undefined ? result.value : this.convertValue(result.value, type);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'permissions':
|
|
123
|
+
program.permissions.push({
|
|
124
|
+
group: declaration.group.value,
|
|
125
|
+
...(declaration.role !== undefined && { role: declaration.role.value }),
|
|
126
|
+
permissions: declaration.permissions.map((permission) => this.text(permission)),
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
case 'trigger':
|
|
130
|
+
// Only the entry module's triggers take effect (docs/adr/0006-imports.md).
|
|
131
|
+
if (module.path === this.checked.entry)
|
|
132
|
+
program.triggers.push(this.trigger(declaration));
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.standardLibrary(program);
|
|
140
|
+
program.build = createHash('sha256').update(JSON.stringify(program)).digest('hex').slice(0, 16);
|
|
141
|
+
const sources = {};
|
|
142
|
+
for (const module of this.checked.modules.values())
|
|
143
|
+
sources[this.moduleId(module.path)] = module.source;
|
|
144
|
+
return { program, sourceMap: { format: COMPILED_FORMAT, build: program.build, sources }, root: this.root };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The standard library modules' actions and errors, which the interpreter provides. `cant::Errors`
|
|
148
|
+
* is always included, since the interpreter raises its errors whether or not it is imported.
|
|
149
|
+
*/
|
|
150
|
+
standardLibrary(program) {
|
|
151
|
+
const modules = new Set(['Errors']);
|
|
152
|
+
for (const module of this.checked.modules.values()) {
|
|
153
|
+
for (const target of module.imports.values())
|
|
154
|
+
if (target.kind === 'standard')
|
|
155
|
+
modules.add(target.name);
|
|
156
|
+
}
|
|
157
|
+
for (const name of modules) {
|
|
158
|
+
for (const [member, kind] of STANDARD_LIBRARY.get(name) ?? []) {
|
|
159
|
+
const id = `cant::${name}#${member}`;
|
|
160
|
+
if (kind === 'error')
|
|
161
|
+
program.types[id] = { kind: 'error' };
|
|
162
|
+
else {
|
|
163
|
+
program.actions[id] = {
|
|
164
|
+
parameters: [],
|
|
165
|
+
returns: { kind: 'unknown' },
|
|
166
|
+
optional: false,
|
|
167
|
+
raises: [],
|
|
168
|
+
passes: [],
|
|
169
|
+
defaultOrder: [],
|
|
170
|
+
implementation: { kind: 'standard' },
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
idOfDeclaration(name) {
|
|
177
|
+
return `${this.moduleId(this.module.path)}#${name.value}`;
|
|
178
|
+
}
|
|
179
|
+
/** The symbol ID a name in a declaration refers to. */
|
|
180
|
+
reference(name) {
|
|
181
|
+
const symbol = name.type === 'identifier' || name.type === 'qualifiedIdentifier' ? this.checked.references.get(name) : undefined;
|
|
182
|
+
if (symbol === undefined)
|
|
183
|
+
throw new Error(`The compiler couldn't resolve a name at ${this.where(name.position)}.`);
|
|
184
|
+
return this.symbolId(symbol);
|
|
185
|
+
}
|
|
186
|
+
where(position) {
|
|
187
|
+
return `${this.module.path}:${String(position.start.line)}:${String(position.start.column)}`;
|
|
188
|
+
}
|
|
189
|
+
// ----- Types -----
|
|
190
|
+
/** The compiler's type for a type written in the program. */
|
|
191
|
+
checkedType(ref) {
|
|
192
|
+
return typeOf(ref, this.checked.references);
|
|
193
|
+
}
|
|
194
|
+
typeRef(ref) {
|
|
195
|
+
switch (ref.type) {
|
|
196
|
+
case 'baseType':
|
|
197
|
+
return { kind: 'base', name: ref.name };
|
|
198
|
+
case 'unknownType':
|
|
199
|
+
return { kind: 'unknown' };
|
|
200
|
+
case 'enum':
|
|
201
|
+
return { kind: 'enum', values: ref.values.map((value) => this.base(value)) };
|
|
202
|
+
case 'arrayType':
|
|
203
|
+
return { kind: 'array', element: this.typeRef(ref.elementType) };
|
|
204
|
+
case 'setType':
|
|
205
|
+
return { kind: 'set', element: this.typeRef(ref.elementType) };
|
|
206
|
+
case 'mapType':
|
|
207
|
+
return { kind: 'map', value: this.typeRef(ref.valueType) };
|
|
208
|
+
case 'identifier':
|
|
209
|
+
case 'qualifiedIdentifier':
|
|
210
|
+
return { kind: 'named', symbol: this.reference(ref) };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** A type the type checker worked out, as a compiled program writes it. */
|
|
214
|
+
fromType(type) {
|
|
215
|
+
switch (type.kind) {
|
|
216
|
+
case 'base':
|
|
217
|
+
return { kind: 'base', name: type.name };
|
|
218
|
+
case 'unknown':
|
|
219
|
+
case 'unchecked':
|
|
220
|
+
return { kind: 'unknown' };
|
|
221
|
+
case 'void':
|
|
222
|
+
case 'nothing':
|
|
223
|
+
return { kind: 'nothing' };
|
|
224
|
+
case 'enum':
|
|
225
|
+
if (type.symbol !== undefined)
|
|
226
|
+
return { kind: 'named', symbol: this.symbolId(type.symbol) };
|
|
227
|
+
return { kind: 'enum', values: [...type.values].map(baseFromKey) };
|
|
228
|
+
case 'array':
|
|
229
|
+
case 'set':
|
|
230
|
+
return { kind: type.kind, element: this.fromType(type.element) };
|
|
231
|
+
case 'map':
|
|
232
|
+
return { kind: 'map', value: this.fromType(type.value) };
|
|
233
|
+
case 'model':
|
|
234
|
+
case 'entity':
|
|
235
|
+
return { kind: 'named', symbol: this.symbolId(type.symbol) };
|
|
236
|
+
case 'anonymous':
|
|
237
|
+
return { kind: 'object', fields: Object.fromEntries([...type.fields].map(([name, field]) => [name, this.fromType(field)])) };
|
|
238
|
+
case 'error':
|
|
239
|
+
return type.symbol === undefined ? { kind: 'anyError' } : { kind: 'named', symbol: this.symbolId(type.symbol) };
|
|
240
|
+
case 'result':
|
|
241
|
+
return this.fromType(type.value);
|
|
242
|
+
case 'optional':
|
|
243
|
+
return { kind: 'optional', inner: this.fromType(type.inner) };
|
|
244
|
+
case 'subject':
|
|
245
|
+
return { kind: 'subject' };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/** A literal's value, as an enum member's value or an inline enum's. */
|
|
249
|
+
base(value) {
|
|
250
|
+
const result = this.values.value(value);
|
|
251
|
+
if (result === undefined || result.kind === 'enum' || result.kind === 'object') {
|
|
252
|
+
throw new Error(`The compiler couldn't work out a value at ${this.where(value.position)}.`);
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
text(value) {
|
|
257
|
+
const result = this.values.value(value);
|
|
258
|
+
return result?.kind === 'text' ? result.value : '';
|
|
259
|
+
}
|
|
260
|
+
// ----- Declarations -----
|
|
261
|
+
fields(fields) {
|
|
262
|
+
const frame = new Frame();
|
|
263
|
+
return {
|
|
264
|
+
fields: fields.map((field) => ({
|
|
265
|
+
name: field.name.value,
|
|
266
|
+
type: this.typeRef(field.valueType),
|
|
267
|
+
optional: field.optional,
|
|
268
|
+
...(field.defaultValue !== undefined && { default: this.expression(field.defaultValue, frame) }),
|
|
269
|
+
})),
|
|
270
|
+
defaultOrder: this.defaultOrder(fields, 'field'),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The order to work out defaults in, so that each default is worked out after the ones it
|
|
275
|
+
* uses. Defaults that depend on each other in a cycle have already been reported.
|
|
276
|
+
*/
|
|
277
|
+
defaultOrder(items, kind) {
|
|
278
|
+
const indexes = new Map(items.map((item, index) => [item.name, index]));
|
|
279
|
+
const order = [];
|
|
280
|
+
const done = new Set();
|
|
281
|
+
const visit = (index) => {
|
|
282
|
+
if (done.has(index))
|
|
283
|
+
return;
|
|
284
|
+
done.add(index);
|
|
285
|
+
const item = items[index];
|
|
286
|
+
if (item?.defaultValue === undefined)
|
|
287
|
+
return;
|
|
288
|
+
walk(item.defaultValue, (node) => {
|
|
289
|
+
if (node.type !== 'identifier')
|
|
290
|
+
return;
|
|
291
|
+
const binding = this.checked.locals.get(node);
|
|
292
|
+
const used = binding?.kind === kind ? indexes.get(binding.declaration) : undefined;
|
|
293
|
+
if (used !== undefined)
|
|
294
|
+
visit(used);
|
|
295
|
+
});
|
|
296
|
+
order.push(index);
|
|
297
|
+
};
|
|
298
|
+
items.forEach((item, index) => {
|
|
299
|
+
if (item.defaultValue !== undefined)
|
|
300
|
+
visit(index);
|
|
301
|
+
});
|
|
302
|
+
return order;
|
|
303
|
+
}
|
|
304
|
+
action(action) {
|
|
305
|
+
const frame = new Frame();
|
|
306
|
+
for (const parameter of action.parameters)
|
|
307
|
+
frame.slot(parameter.name);
|
|
308
|
+
const parameters = action.parameters.map((parameter) => ({
|
|
309
|
+
name: parameter.name.value,
|
|
310
|
+
type: this.typeRef(parameter.valueType),
|
|
311
|
+
optional: parameter.optional,
|
|
312
|
+
...(parameter.defaultValue !== undefined && { default: this.expression(parameter.defaultValue, frame) }),
|
|
313
|
+
}));
|
|
314
|
+
const passes = action.passes.some((name) => name.type === 'builtIn')
|
|
315
|
+
? 'all'
|
|
316
|
+
: action.passes.flatMap((name) => (name.type === 'builtIn' ? [] : [this.reference(name)]));
|
|
317
|
+
let implementation;
|
|
318
|
+
if (action.native === undefined) {
|
|
319
|
+
const body = this.block(action.children, frame);
|
|
320
|
+
implementation = { kind: 'body', locals: frame.slots.size, body };
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// The native module, relative to the program's root (docs/adr/0036-native-modules.md).
|
|
324
|
+
const path = resolve(dirname(this.module.path), this.text(action.native));
|
|
325
|
+
implementation = { kind: 'native', module: this.moduleId(path) };
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
parameters,
|
|
329
|
+
returns: action.returnType.type === 'voidType' ? { kind: 'void' } : this.typeRef(action.returnType),
|
|
330
|
+
optional: action.optional,
|
|
331
|
+
raises: action.raises.map((name) => this.reference(name)),
|
|
332
|
+
passes,
|
|
333
|
+
defaultOrder: this.defaultOrder(action.parameters, 'parameter'),
|
|
334
|
+
implementation,
|
|
335
|
+
position: this.position(action.position),
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
entity(entity) {
|
|
339
|
+
const symbol = symbolOf(this.module.path, entity);
|
|
340
|
+
const modelName = entity.lines.find((line) => line.type === 'modelsBlock')?.models[0];
|
|
341
|
+
const modelSymbol = modelName === undefined ? undefined : this.checked.references.get(modelName);
|
|
342
|
+
const model = modelSymbol?.declaration?.type === 'model' ? modelSymbol.declaration : undefined;
|
|
343
|
+
const modelFields = model?.fields.map((field) => field.name.value) ?? [];
|
|
344
|
+
// `expose` and `hide`, with `@all` and renaming (docs/adr/0022-entities.md).
|
|
345
|
+
const exposed = new Map();
|
|
346
|
+
const items = entity.lines.filter((line) => line.type === 'exposeBlock').flatMap((line) => line.items);
|
|
347
|
+
const hidden = new Set(entity.lines.filter((line) => line.type === 'hideBlock').flatMap((line) => line.items.flatMap((item) => (item.type === 'identifier' ? [item.value] : []))));
|
|
348
|
+
if (items.some((item) => item.type === 'builtIn')) {
|
|
349
|
+
for (const name of modelFields)
|
|
350
|
+
if (!hidden.has(name))
|
|
351
|
+
exposed.set(name, name);
|
|
352
|
+
}
|
|
353
|
+
for (const item of items) {
|
|
354
|
+
if (item.type === 'builtIn')
|
|
355
|
+
continue;
|
|
356
|
+
if (item.as !== undefined)
|
|
357
|
+
exposed.delete(item.field.value);
|
|
358
|
+
exposed.set(item.as?.value ?? item.field.value, item.field.value);
|
|
359
|
+
}
|
|
360
|
+
const navigation = {};
|
|
361
|
+
for (const [name, field] of this.checked.navigation.get(keyOf(symbol)) ?? []) {
|
|
362
|
+
const { relation } = field;
|
|
363
|
+
const leftIsThis = relation.left.field.value === name && this.checked.references.get(relation.left.entity)?.name === entity.name.value;
|
|
364
|
+
navigation[name] = {
|
|
365
|
+
entity: this.symbolId(field.far),
|
|
366
|
+
cardinality: field.farCardinality,
|
|
367
|
+
inverse: (leftIsThis ? relation.right.field : relation.left.field).value,
|
|
368
|
+
relation: this.relationIndexes.get(relation) ?? -1,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const identityLine = entity.lines.find((line) => line.type === 'identityLine');
|
|
372
|
+
const group = entity.lines.find((line) => line.type === 'groupLine');
|
|
373
|
+
const membership = entity.lines.find((line) => line.type === 'membershipLine');
|
|
374
|
+
return {
|
|
375
|
+
kind: 'entity',
|
|
376
|
+
model: modelSymbol === undefined ? '' : this.symbolId(modelSymbol),
|
|
377
|
+
exposed: Object.fromEntries(exposed),
|
|
378
|
+
identity: (identityLine?.fields ?? []).map((field) => (field.value in navigation ? { navigation: field.value } : { field: field.value })),
|
|
379
|
+
navigation,
|
|
380
|
+
subject: entity.lines.some((line) => line.type === 'subjectLine'),
|
|
381
|
+
...(group !== undefined && {
|
|
382
|
+
group: { kind: group.name.value, roles: entity.lines.flatMap((line) => (line.type === 'roleLine' ? [line.name.value] : [])) },
|
|
383
|
+
}),
|
|
384
|
+
...(membership !== undefined && {
|
|
385
|
+
membership: { member: membership.member.value, group: membership.group.value, ...(membership.roles !== undefined && { roles: membership.roles.value }) },
|
|
386
|
+
}),
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
relation(relation) {
|
|
390
|
+
const end = (side) => ({
|
|
391
|
+
entity: this.reference(side.entity),
|
|
392
|
+
field: side.field.value,
|
|
393
|
+
cardinality: side.cardinality,
|
|
394
|
+
});
|
|
395
|
+
return { left: end(relation.left), right: end(relation.right) };
|
|
396
|
+
}
|
|
397
|
+
trigger(trigger) {
|
|
398
|
+
const frame = new Frame();
|
|
399
|
+
const parameters = {};
|
|
400
|
+
let subject;
|
|
401
|
+
for (const parameter of trigger.parameters ?? []) {
|
|
402
|
+
if (trigger.source.value === 'TestCase' && parameter.name.value === 'subject' && parameter.value.type === 'object') {
|
|
403
|
+
subject = this.testSubject(parameter.value);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const value = this.values.value(parameter.value);
|
|
407
|
+
if (value !== undefined)
|
|
408
|
+
parameters[parameter.name.value] = value;
|
|
409
|
+
}
|
|
410
|
+
const args = {};
|
|
411
|
+
for (const argument of trigger.arguments ?? [])
|
|
412
|
+
args[argument.name.value] = this.expression(argument.value, frame);
|
|
413
|
+
return {
|
|
414
|
+
action: this.reference(trigger.action),
|
|
415
|
+
source: trigger.source.value,
|
|
416
|
+
parameters,
|
|
417
|
+
...(subject !== undefined && { subject }),
|
|
418
|
+
arguments: args,
|
|
419
|
+
...(trigger.auth !== undefined && { auth: this.expression(trigger.auth, frame) }),
|
|
420
|
+
assertions: (trigger.assertions ?? []).map((assertion) => ({
|
|
421
|
+
test: this.expression(assertion.test, frame),
|
|
422
|
+
message: this.expression(assertion.message, frame),
|
|
423
|
+
})),
|
|
424
|
+
position: this.position(trigger.position),
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
/** A test case's subject: the entity its `@entity` names, and its fields as an object of the entity's model. */
|
|
428
|
+
testSubject(value) {
|
|
429
|
+
const entityName = value.items.find((item) => item.name.type === 'builtIn' && item.name.name === 'entity')?.value;
|
|
430
|
+
const entity = entityName === undefined ? undefined : this.checked.references.get(entityName);
|
|
431
|
+
const declaration = entity?.declaration;
|
|
432
|
+
if (entity === undefined || declaration?.type !== 'entity')
|
|
433
|
+
return undefined;
|
|
434
|
+
const modelName = declaration.lines.find((line) => line.type === 'modelsBlock')?.models[0];
|
|
435
|
+
const model = modelName === undefined ? undefined : this.checked.references.get(modelName);
|
|
436
|
+
const fields = this.values.value(value);
|
|
437
|
+
if (fields === undefined || model?.declaration?.type !== 'model')
|
|
438
|
+
return undefined;
|
|
439
|
+
return { entity: this.symbolId(entity), fields: this.convertValue(fields, { kind: 'model', symbol: model, declaration: model.declaration }) };
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* A constant value, given where `type` is expected: a base value given for an enum becomes the
|
|
443
|
+
* enum's member, and an object given for a model becomes an object of the model, with its
|
|
444
|
+
* defaults filled in where the compiler can work them out.
|
|
445
|
+
*/
|
|
446
|
+
convertValue(value, type) {
|
|
447
|
+
if (type.kind === 'enum' && type.symbol !== undefined && value.kind !== 'enum' && value.kind !== 'object') {
|
|
448
|
+
return { kind: 'enum', enum: this.symbolId(type.symbol), value };
|
|
449
|
+
}
|
|
450
|
+
if (type.kind === 'model' && value.kind === 'object') {
|
|
451
|
+
const declaration = type.declaration;
|
|
452
|
+
const given = new Map(value.members);
|
|
453
|
+
const known = new Map();
|
|
454
|
+
const members = [];
|
|
455
|
+
for (const field of declaration.fields) {
|
|
456
|
+
const member = given.get(field.name.value);
|
|
457
|
+
if (member !== undefined)
|
|
458
|
+
known.set(field.name, this.convertValue(member, this.checkedType(field.valueType)));
|
|
459
|
+
}
|
|
460
|
+
for (const index of this.defaultOrder(declaration.fields, 'field')) {
|
|
461
|
+
const field = declaration.fields[index];
|
|
462
|
+
if (field?.defaultValue === undefined || given.has(field.name.value))
|
|
463
|
+
continue;
|
|
464
|
+
const defaulted = this.values.value(field.defaultValue, this.checked.locals, known);
|
|
465
|
+
if (defaulted !== undefined)
|
|
466
|
+
known.set(field.name, defaulted);
|
|
467
|
+
}
|
|
468
|
+
for (const field of declaration.fields) {
|
|
469
|
+
const member = known.get(field.name);
|
|
470
|
+
if (member !== undefined)
|
|
471
|
+
members.push([field.name.value, member]);
|
|
472
|
+
}
|
|
473
|
+
const object = { kind: 'object', model: this.symbolId(type.symbol), members };
|
|
474
|
+
return object;
|
|
475
|
+
}
|
|
476
|
+
return value;
|
|
477
|
+
}
|
|
478
|
+
// ----- Code -----
|
|
479
|
+
block(statements, frame) {
|
|
480
|
+
return statements.map((statement) => this.statement(statement, frame, false));
|
|
481
|
+
}
|
|
482
|
+
statement(statement, frame, ignored) {
|
|
483
|
+
const position = this.position(statement.position);
|
|
484
|
+
switch (statement.type) {
|
|
485
|
+
case 'expressionStatement':
|
|
486
|
+
return { type: 'expression', expression: this.expression(statement.expression, frame), position };
|
|
487
|
+
case 'assignment':
|
|
488
|
+
if (statement.target.type === 'identifier') {
|
|
489
|
+
return { type: 'let', slot: frame.slot(statement.target), value: this.expression(statement.value, frame), position };
|
|
490
|
+
}
|
|
491
|
+
return { type: 'assign', target: this.target(statement.target, frame), value: this.expression(statement.value, frame), ignored, position };
|
|
492
|
+
case 'delete':
|
|
493
|
+
return { type: 'delete', target: this.target(statement.target, frame), ignored, position };
|
|
494
|
+
case 'ignoredStatement':
|
|
495
|
+
return this.statement(statement.statement, frame, true);
|
|
496
|
+
case 'return': {
|
|
497
|
+
const argument = statement.argument;
|
|
498
|
+
if (argument === undefined)
|
|
499
|
+
return { type: 'return', position };
|
|
500
|
+
if (argument.type === 'nothing')
|
|
501
|
+
return { type: 'return', value: { type: 'nothing' }, position };
|
|
502
|
+
return { type: 'return', value: this.expression(argument, frame), position };
|
|
503
|
+
}
|
|
504
|
+
case 'raise': {
|
|
505
|
+
const error = this.reference(statement.error);
|
|
506
|
+
if (statement.data !== undefined)
|
|
507
|
+
return { type: 'raise', error, data: this.expression(statement.data, frame), position };
|
|
508
|
+
if (statement.arguments === undefined)
|
|
509
|
+
return { type: 'raise', error, position };
|
|
510
|
+
// The data's fields, which the interpreter makes into the error's data, filling in defaults.
|
|
511
|
+
const members = statement.arguments.map((argument) => [
|
|
512
|
+
argument.name?.value ?? (argument.value.type === 'identifier' ? argument.value.value : ''),
|
|
513
|
+
this.expression(argument.value, frame),
|
|
514
|
+
]);
|
|
515
|
+
return { type: 'raise', error, data: { type: 'object', members, position }, position };
|
|
516
|
+
}
|
|
517
|
+
case 'pass':
|
|
518
|
+
return { type: 'pass', value: this.expression(statement.argument, frame), position };
|
|
519
|
+
case 'assert':
|
|
520
|
+
return {
|
|
521
|
+
type: 'assert',
|
|
522
|
+
test: this.expression(statement.test, frame),
|
|
523
|
+
...(statement.message !== undefined && { message: this.expression(statement.message, frame) }),
|
|
524
|
+
position,
|
|
525
|
+
};
|
|
526
|
+
case 'break':
|
|
527
|
+
return { type: 'break', position };
|
|
528
|
+
case 'continue':
|
|
529
|
+
return { type: 'continue', position };
|
|
530
|
+
case 'for':
|
|
531
|
+
return {
|
|
532
|
+
type: 'for',
|
|
533
|
+
slot: frame.slot(statement.variable),
|
|
534
|
+
iterable: this.expression(statement.iterable, frame),
|
|
535
|
+
body: this.block(statement.children, frame),
|
|
536
|
+
position,
|
|
537
|
+
};
|
|
538
|
+
case 'while':
|
|
539
|
+
return { type: 'while', test: this.expression(statement.test, frame), body: this.block(statement.children, frame), position };
|
|
540
|
+
case 'if': {
|
|
541
|
+
const [consequent, alternate] = statement.children;
|
|
542
|
+
return {
|
|
543
|
+
type: 'if',
|
|
544
|
+
test: this.expression(statement.test, frame),
|
|
545
|
+
then: this.block(consequent.children, frame),
|
|
546
|
+
...(alternate !== undefined && {
|
|
547
|
+
else: alternate.type === 'if' ? [this.statement(alternate, frame, false)] : this.block(alternate.children, frame),
|
|
548
|
+
}),
|
|
549
|
+
position,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
target(target, frame) {
|
|
555
|
+
const position = this.position(target.position);
|
|
556
|
+
return target.type === 'member'
|
|
557
|
+
? { type: 'member', object: this.expression(target.object, frame), name: target.property.value, position }
|
|
558
|
+
: { type: 'index', object: this.expression(target.object, frame), index: this.expression(target.index, frame), position };
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* An expression, given where `expected` is expected: what the type checker recorded for it, if
|
|
562
|
+
* nothing else is given. Values given for a model, a map, an enum or a collection are shaped
|
|
563
|
+
* by it, and a result used unchecked is unwrapped (docs/adr/0039-compiled-programs.md).
|
|
564
|
+
*/
|
|
565
|
+
expression(expression, frame, expected = this.checked.types.expected.get(expression)) {
|
|
566
|
+
const position = this.position(expression.position);
|
|
567
|
+
const target = expected?.kind === 'optional' ? expected.inner : expected;
|
|
568
|
+
// Object and collection values take their shape from where they are given.
|
|
569
|
+
if (target !== undefined && expression.type === 'object' && (target.kind === 'model' || target.kind === 'map')) {
|
|
570
|
+
const fields = target.kind === 'model' ? this.checked.types.modelFields(target.declaration) : undefined;
|
|
571
|
+
const members = this.members(expression, frame, (name) => {
|
|
572
|
+
if (target.kind === 'map')
|
|
573
|
+
return target.value;
|
|
574
|
+
const field = fields?.get(name)?.type;
|
|
575
|
+
return field?.kind === 'optional' ? field.inner : field;
|
|
576
|
+
});
|
|
577
|
+
return target.kind === 'model'
|
|
578
|
+
? { type: 'construct', model: this.symbolId(target.symbol), value: { type: 'object', members, position }, position }
|
|
579
|
+
: { type: 'map', value: this.fromType(target.value), members, position };
|
|
580
|
+
}
|
|
581
|
+
if (target !== undefined && (expression.type === 'array' || expression.type === 'set') && target.kind === expression.type) {
|
|
582
|
+
return {
|
|
583
|
+
type: expression.type,
|
|
584
|
+
element: this.fromType(target.element),
|
|
585
|
+
elements: expression.elements.map((element) => this.expression(element, frame, target.element)),
|
|
586
|
+
position,
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
let node = this.plain(expression, frame);
|
|
590
|
+
if (this.checked.types.unwrapped.has(expression))
|
|
591
|
+
node = { type: 'unwrap', value: node, position };
|
|
592
|
+
if (target === undefined)
|
|
593
|
+
return node;
|
|
594
|
+
let from = this.checked.types.types.get(expression);
|
|
595
|
+
if (from?.kind === 'result')
|
|
596
|
+
from = from.value;
|
|
597
|
+
if (from?.kind === 'optional')
|
|
598
|
+
from = from.inner;
|
|
599
|
+
if (from === undefined)
|
|
600
|
+
return node;
|
|
601
|
+
// A value of an enum's value type, given for the enum (docs/adr/0013-enums.md).
|
|
602
|
+
if (target.kind === 'enum' && from.kind === 'base') {
|
|
603
|
+
const enumType = this.fromType(target);
|
|
604
|
+
if (node.type === 'value' && node.value.kind !== 'enum' && node.value.kind !== 'object') {
|
|
605
|
+
return enumType.kind === 'named' ? { type: 'value', value: { kind: 'enum', enum: enumType.symbol, value: node.value }, position } : node;
|
|
606
|
+
}
|
|
607
|
+
return { type: 'toEnum', enum: enumType, value: node, position };
|
|
608
|
+
}
|
|
609
|
+
if (target.kind === 'model' && from.kind === 'anonymous')
|
|
610
|
+
return { type: 'construct', model: this.symbolId(target.symbol), value: node, position };
|
|
611
|
+
if (target.kind === 'map' && from.kind === 'anonymous')
|
|
612
|
+
return { type: 'toMap', value: node, position };
|
|
613
|
+
return node;
|
|
614
|
+
}
|
|
615
|
+
/** An object value's members, each given where its field's type is expected. */
|
|
616
|
+
members(expression, frame, expected) {
|
|
617
|
+
const members = [];
|
|
618
|
+
for (const item of expression.items) {
|
|
619
|
+
if (item.name.type === 'builtIn')
|
|
620
|
+
continue;
|
|
621
|
+
const name = item.name.type === 'identifier' ? item.name.value : this.text(item.name);
|
|
622
|
+
members.push([name, this.expression(item.value, frame, expected(name))]);
|
|
623
|
+
}
|
|
624
|
+
return members;
|
|
625
|
+
}
|
|
626
|
+
/** An expression as it is written, before anything its type decides. */
|
|
627
|
+
plain(expression, frame) {
|
|
628
|
+
const position = this.position(expression.position);
|
|
629
|
+
switch (expression.type) {
|
|
630
|
+
case 'number':
|
|
631
|
+
case 'boolean':
|
|
632
|
+
case 'dateTime':
|
|
633
|
+
case 'duration':
|
|
634
|
+
return { type: 'value', value: this.base(expression), position };
|
|
635
|
+
case 'string':
|
|
636
|
+
if (expression.parts.every((part) => part.type === 'text'))
|
|
637
|
+
return { type: 'value', value: { kind: 'text', value: this.text(expression) }, position };
|
|
638
|
+
return {
|
|
639
|
+
type: 'template',
|
|
640
|
+
parts: expression.parts.map((part) => (part.type === 'text' ? part.value : this.expression(part.expression, frame))),
|
|
641
|
+
position,
|
|
642
|
+
};
|
|
643
|
+
case 'identifier':
|
|
644
|
+
case 'qualifiedIdentifier': {
|
|
645
|
+
const local = expression.type === 'identifier' ? this.checked.locals.get(expression) : undefined;
|
|
646
|
+
if (local !== undefined) {
|
|
647
|
+
return local.kind === 'field'
|
|
648
|
+
? { type: 'field', name: local.declaration.value, position }
|
|
649
|
+
: { type: 'local', slot: frame.slot(local.declaration), position };
|
|
650
|
+
}
|
|
651
|
+
return { type: 'constant', symbol: this.reference(expression), position };
|
|
652
|
+
}
|
|
653
|
+
case 'builtIn':
|
|
654
|
+
return { type: 'builtIn', name: expression.name, position };
|
|
655
|
+
case 'array':
|
|
656
|
+
case 'set': {
|
|
657
|
+
const type = this.checked.types.types.get(expression);
|
|
658
|
+
const element = type?.kind === 'array' || type?.kind === 'set' ? this.fromType(type.element) : { kind: 'nothing' };
|
|
659
|
+
return { type: expression.type, element, elements: expression.elements.map((element) => this.expression(element, frame)), position };
|
|
660
|
+
}
|
|
661
|
+
case 'object':
|
|
662
|
+
return { type: 'object', members: this.members(expression, frame, () => undefined), position };
|
|
663
|
+
case 'member': {
|
|
664
|
+
const object = expression.object;
|
|
665
|
+
const enumSymbol = object.type === 'identifier' || object.type === 'qualifiedIdentifier' ? this.checked.references.get(object) : undefined;
|
|
666
|
+
if (enumSymbol?.typeKind === 'enum' && (object.type !== 'identifier' || this.checked.locals.get(object) === undefined)) {
|
|
667
|
+
const value = this.values.value(expression);
|
|
668
|
+
if (value !== undefined)
|
|
669
|
+
return { type: 'value', value, position };
|
|
670
|
+
}
|
|
671
|
+
return { type: 'member', object: this.expression(object, frame), name: expression.property.value, position };
|
|
672
|
+
}
|
|
673
|
+
case 'index':
|
|
674
|
+
return { type: 'index', object: this.expression(expression.object, frame), index: this.expression(expression.index, frame), position };
|
|
675
|
+
case 'call':
|
|
676
|
+
return this.call(expression, frame);
|
|
677
|
+
case 'unary':
|
|
678
|
+
return { type: 'unary', operator: expression.operator, argument: this.expression(expression.argument, frame), position };
|
|
679
|
+
case 'binary':
|
|
680
|
+
return { type: 'binary', operator: expression.operator, left: this.expression(expression.left, frame), right: this.expression(expression.right, frame), position };
|
|
681
|
+
case 'instanceOf': {
|
|
682
|
+
const type = expression.target.type === 'errorType' ? { kind: 'anyError' } : this.typeRef(expression.target);
|
|
683
|
+
return { type: 'instanceOf', value: this.expression(expression.value, frame), target: expression.optional ? { kind: 'optional', inner: type } : type, position };
|
|
684
|
+
}
|
|
685
|
+
case 'canPredicate':
|
|
686
|
+
return {
|
|
687
|
+
type: 'can',
|
|
688
|
+
permission: this.text(expression.permission),
|
|
689
|
+
...(expression.group !== undefined && { group: this.expression(expression.group, frame) }),
|
|
690
|
+
position,
|
|
691
|
+
};
|
|
692
|
+
case 'isPredicate': {
|
|
693
|
+
const subjectType = expression.subjectType;
|
|
694
|
+
const target = subjectType.type === 'builtIn' ? { builtIn: subjectType.name === 'anonymous' ? 'anonymous' : 'defined' } : { entity: this.reference(subjectType) };
|
|
695
|
+
return { type: 'is', target, position };
|
|
696
|
+
}
|
|
697
|
+
case 'rolePredicate':
|
|
698
|
+
return { type: 'hasRole', role: expression.role.value, group: this.expression(expression.group, frame), position };
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
call(expression, frame) {
|
|
702
|
+
const position = this.position(expression.position);
|
|
703
|
+
const callee = expression.callee;
|
|
704
|
+
const symbol = callee.type === 'identifier' || callee.type === 'qualifiedIdentifier' ? this.checked.references.get(callee) : undefined;
|
|
705
|
+
if (symbol === undefined)
|
|
706
|
+
throw new Error(`The compiler couldn't resolve a call at ${this.where(expression.position)}.`);
|
|
707
|
+
const action = symbol.declaration;
|
|
708
|
+
if (action?.type !== 'action') {
|
|
709
|
+
return {
|
|
710
|
+
type: 'callStandard',
|
|
711
|
+
action: this.symbolId(symbol),
|
|
712
|
+
arguments: expression.arguments.map((argument) => ({
|
|
713
|
+
...(argument.name !== undefined && { name: argument.name.value }),
|
|
714
|
+
value: this.expression(argument.value, frame),
|
|
715
|
+
})),
|
|
716
|
+
position,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
// Each parameter's argument, in order, matched as the type checker matched them (docs/adr/0020-action-parameters.md).
|
|
720
|
+
const required = action.parameters.filter((parameter) => !parameter.optional);
|
|
721
|
+
const byParameter = new Map();
|
|
722
|
+
for (const argument of expression.arguments) {
|
|
723
|
+
const name = argument.name?.value ??
|
|
724
|
+
(argument.value.type === 'identifier' && action.parameters.some((parameter) => parameter.name.value === argument.value.value)
|
|
725
|
+
? argument.value.value
|
|
726
|
+
: expression.arguments.length === 1 && required.length === 1
|
|
727
|
+
? required[0]?.name.value
|
|
728
|
+
: undefined);
|
|
729
|
+
if (name !== undefined)
|
|
730
|
+
byParameter.set(name, argument.value);
|
|
731
|
+
}
|
|
732
|
+
return {
|
|
733
|
+
type: 'call',
|
|
734
|
+
action: this.symbolId(symbol),
|
|
735
|
+
arguments: action.parameters.map((parameter) => {
|
|
736
|
+
const argument = byParameter.get(parameter.name.value);
|
|
737
|
+
return argument === undefined ? { type: 'omitted' } : this.expression(argument, frame);
|
|
738
|
+
}),
|
|
739
|
+
position,
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/** An inline enum's value, from the key the type checker gives it, such as `TEXT:paid`. */
|
|
744
|
+
function baseFromKey(key) {
|
|
745
|
+
const at = key.indexOf(':');
|
|
746
|
+
const kind = key.slice(0, at);
|
|
747
|
+
const value = key.slice(at + 1);
|
|
748
|
+
switch (kind) {
|
|
749
|
+
case 'NUMBER':
|
|
750
|
+
return { kind: 'number', value: Number(value) };
|
|
751
|
+
case 'BOOLEAN':
|
|
752
|
+
return { kind: 'boolean', value: value === 'true' };
|
|
753
|
+
case 'DATE_TIME':
|
|
754
|
+
return { kind: 'dateTime', value: Number(value) };
|
|
755
|
+
case 'DURATION':
|
|
756
|
+
return { kind: 'duration', value: Number(value) };
|
|
757
|
+
default:
|
|
758
|
+
return { kind: 'text', value };
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/** Call `visit` on every node in an expression. */
|
|
762
|
+
function walk(node, visit) {
|
|
763
|
+
if (typeof node !== 'object' || node === null)
|
|
764
|
+
return;
|
|
765
|
+
if (Array.isArray(node)) {
|
|
766
|
+
for (const child of node)
|
|
767
|
+
walk(child, visit);
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const typed = node;
|
|
771
|
+
if (typeof typed.type === 'string')
|
|
772
|
+
visit(node);
|
|
773
|
+
for (const [key, value] of Object.entries(node))
|
|
774
|
+
if (key !== 'position')
|
|
775
|
+
walk(value, visit);
|
|
776
|
+
}
|
|
777
|
+
//# sourceMappingURL=compile.js.map
|