@nova-energy/openamx 0.19.0 → 0.21.0
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/README.md +7 -2
- package/dist/cli.js +61 -0
- package/dist/index.js +1 -0
- package/dist/renderer/diagramBrowserRuntime.js +1 -1
- package/dist/runtime/evaluateExpression.js +105 -0
- package/dist/runtime/inputData.js +73 -20
- package/dist/runtime/moduleLoader.js +6 -3
- package/dist/transpiler/emit.js +842 -0
- package/dist/transpiler/filesystemGraph.js +267 -0
- package/dist/transpiler/graph.js +200 -0
- package/dist/transpiler/index.js +52 -0
- package/dist/transpiler/outputWriter.js +378 -0
- package/dist/transpiler/source.js +16 -0
- package/dist/transpiler/types.js +1 -0
- package/dist/transpilerRuntime.js +684 -0
- package/dist/typechecker/checkDocument.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
import { fieldRegistry } from '../typechecker/declarationRegistry';
|
|
2
|
+
import { rawFrontMatterComments, safeNarrativeComments } from './source';
|
|
3
|
+
export class LoweringFailure extends Error {
|
|
4
|
+
line;
|
|
5
|
+
column;
|
|
6
|
+
constructor(message, line, column) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.line = line;
|
|
9
|
+
this.column = column;
|
|
10
|
+
this.name = 'LoweringFailure';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const builtinNames = new Set([
|
|
14
|
+
'sum', 'min', 'max', 'mean', 'round', 'abs', 'sqrt', 'pow', 'len', 'trim',
|
|
15
|
+
'left', 'right', 'format', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan',
|
|
16
|
+
'sinh', 'cosh', 'tanh', 'asinh', 'acosh', 'atanh', 'ln', 'log', 'exp'
|
|
17
|
+
]);
|
|
18
|
+
const reservedWords = new Set([
|
|
19
|
+
'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger',
|
|
20
|
+
'default', 'delete', 'do', 'else', 'enum', 'export', 'extends', 'false',
|
|
21
|
+
'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'let',
|
|
22
|
+
'new', 'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try',
|
|
23
|
+
'typeof', 'var', 'void', 'while', 'with', 'yield'
|
|
24
|
+
]);
|
|
25
|
+
export function measurementVectorKey(vector) {
|
|
26
|
+
return JSON.stringify([...vector].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0));
|
|
27
|
+
}
|
|
28
|
+
function sameVector(left, right) {
|
|
29
|
+
return left.size === right.size && [...left].every(([key, exponent]) => right.get(key) === exponent);
|
|
30
|
+
}
|
|
31
|
+
function quote(value) {
|
|
32
|
+
return JSON.stringify(value).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
|
33
|
+
}
|
|
34
|
+
function hash(value) {
|
|
35
|
+
return Array.from(value, character => character.codePointAt(0).toString(16)).join('_') || 'empty';
|
|
36
|
+
}
|
|
37
|
+
function isComparison(operator) {
|
|
38
|
+
return ['==', '!=', '>', '>=', '<', '<=', 'and', 'or'].includes(operator);
|
|
39
|
+
}
|
|
40
|
+
class ModuleEmitter {
|
|
41
|
+
module;
|
|
42
|
+
isEntry;
|
|
43
|
+
measurementDimensionIds;
|
|
44
|
+
prefix;
|
|
45
|
+
declaredScopes = [new Set()];
|
|
46
|
+
mutationTargets = new Set();
|
|
47
|
+
localTypes = new Map();
|
|
48
|
+
recordTypes = new Map();
|
|
49
|
+
enumTypes = new Map();
|
|
50
|
+
functions = new Map();
|
|
51
|
+
viewDefinitions = new Map();
|
|
52
|
+
importedBindings = new Set();
|
|
53
|
+
inputs;
|
|
54
|
+
sourceFile;
|
|
55
|
+
expressionLoopReturns = [];
|
|
56
|
+
constructor(module, isEntry, measurementDimensionIds) {
|
|
57
|
+
this.module = module;
|
|
58
|
+
this.isEntry = isEntry;
|
|
59
|
+
this.measurementDimensionIds = measurementDimensionIds;
|
|
60
|
+
this.inputs = moduleStatements(module).filter((statement) => statement.type === 'inputDeclaration');
|
|
61
|
+
this.prefix = `__amx_${hash(module.input.outputPath)}_`;
|
|
62
|
+
this.sourceFile = module.input.sourcePath.startsWith('/') || /^[A-Za-z]:[\\/]/.test(module.input.sourcePath)
|
|
63
|
+
? module.input.outputPath.replace(/\.ts$/, '.amx')
|
|
64
|
+
: module.input.sourcePath;
|
|
65
|
+
for (const [name, type] of module.check.bindingTypes)
|
|
66
|
+
this.localTypes.set(name, type);
|
|
67
|
+
for (const statement of module.statements) {
|
|
68
|
+
if (statement.type === 'typeDeclaration')
|
|
69
|
+
this.recordTypes.set(statement.name, statement);
|
|
70
|
+
else if (statement.type === 'enumDeclaration')
|
|
71
|
+
this.enumTypes.set(statement.name, statement);
|
|
72
|
+
else if (statement.type === 'functionDeclaration')
|
|
73
|
+
this.functions.set(statement.name, statement);
|
|
74
|
+
else if (statement.type === 'tableDeclaration' || statement.type === 'chartDeclaration')
|
|
75
|
+
this.viewDefinitions.set(statement.name, statement);
|
|
76
|
+
}
|
|
77
|
+
for (const statement of module.statements) {
|
|
78
|
+
if (statement.type !== 'importDeclaration')
|
|
79
|
+
continue;
|
|
80
|
+
const dependency = module.imports.get(statement.path);
|
|
81
|
+
if (!dependency)
|
|
82
|
+
continue;
|
|
83
|
+
for (const imported of statement.names) {
|
|
84
|
+
const name = imported.name;
|
|
85
|
+
if (dependency.check.exportedTypes.has(name))
|
|
86
|
+
this.recordTypes.set(name, dependency.check.exportedTypes.get(name));
|
|
87
|
+
else if (dependency.check.exportedEnums.has(name))
|
|
88
|
+
this.enumTypes.set(name, dependency.check.exportedEnums.get(name));
|
|
89
|
+
else if (dependency.check.exportedFunctions.has(name))
|
|
90
|
+
this.functions.set(name, dependency.check.exportedFunctions.get(name));
|
|
91
|
+
else if (dependency.check.exportedBindings.has(name))
|
|
92
|
+
this.importedBindings.add(name);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const statement of module.statements)
|
|
96
|
+
this.collectMutationTargets(statement);
|
|
97
|
+
}
|
|
98
|
+
name(value) {
|
|
99
|
+
return `${this.prefix}${value}`;
|
|
100
|
+
}
|
|
101
|
+
sourceContext(source) {
|
|
102
|
+
return `{ file: ${quote(this.sourceFile)}${source ? `, line: ${source.line}, column: ${source.column}` : ''} }`;
|
|
103
|
+
}
|
|
104
|
+
checkedTypeForReference(reference, owner) {
|
|
105
|
+
if (reference.type === 'listType')
|
|
106
|
+
return { kind: 'list', element: this.checkedTypeForReference(reference.element, owner) };
|
|
107
|
+
if (reference.type === 'nullableType')
|
|
108
|
+
return { kind: 'nullable', element: this.checkedTypeForReference(reference.element, owner) };
|
|
109
|
+
const registry = owner ? fieldRegistry(owner, this.module.check) : this.module.check;
|
|
110
|
+
const dimension = registry?.dimensions.get(reference.name);
|
|
111
|
+
return dimension
|
|
112
|
+
? { kind: 'measurement', vector: dimension.vector }
|
|
113
|
+
: { kind: 'named', name: reference.name };
|
|
114
|
+
}
|
|
115
|
+
typeScriptType(type, external = false) {
|
|
116
|
+
switch (type.kind) {
|
|
117
|
+
case 'null': return 'null';
|
|
118
|
+
case 'measurement': {
|
|
119
|
+
const dimensionId = this.measurementDimensionId(type.vector);
|
|
120
|
+
return `${external ? '__AMXMeasurementInput' : '__AMXMeasurement'}<${quote(dimensionId)}>`;
|
|
121
|
+
}
|
|
122
|
+
case 'list': return `(${this.typeScriptType(type.element, external)})[]`;
|
|
123
|
+
case 'nullable': return `${this.typeScriptType(type.element, external)} | null`;
|
|
124
|
+
case 'named':
|
|
125
|
+
if (type.name === 'Number')
|
|
126
|
+
return 'number';
|
|
127
|
+
if (type.name === 'String' || type.name === 'DateTime')
|
|
128
|
+
return 'string';
|
|
129
|
+
if (type.name === 'Boolean')
|
|
130
|
+
return 'boolean';
|
|
131
|
+
if (external && this.recordTypes.has(type.name))
|
|
132
|
+
return `__AMXExternal_${this.name(type.name)}`;
|
|
133
|
+
return this.name(type.name);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
measurementDimensionId(vector) {
|
|
137
|
+
const canonicalId = this.measurementDimensionIds.get(measurementVectorKey(vector));
|
|
138
|
+
if (canonicalId)
|
|
139
|
+
return canonicalId;
|
|
140
|
+
const parts = [...vector].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
|
|
141
|
+
.map(([identity, exponent]) => `${identity}^${exponent}`);
|
|
142
|
+
return parts.length ? `vector:${parts.join('*')}` : 'dimensionless';
|
|
143
|
+
}
|
|
144
|
+
typeScriptReference(reference, external = false, owner) {
|
|
145
|
+
return this.typeScriptType(this.checkedTypeForReference(reference, owner), external);
|
|
146
|
+
}
|
|
147
|
+
collectMutationTargets(statement) {
|
|
148
|
+
if (statement.type === 'assignmentStatement' || statement.type === 'compoundAssignmentStatement') {
|
|
149
|
+
this.mutationTargets.add(statement.name);
|
|
150
|
+
}
|
|
151
|
+
else if (statement.type === 'functionDeclaration' && statement.body.kind === 'statements') {
|
|
152
|
+
statement.body.statements.forEach(child => this.collectMutationTargets(child));
|
|
153
|
+
}
|
|
154
|
+
else if (statement.type === 'forStatement') {
|
|
155
|
+
statement.body.forEach(child => this.collectMutationTargets(child));
|
|
156
|
+
}
|
|
157
|
+
else if (statement.type === 'bracedIfStatement') {
|
|
158
|
+
statement.consequent.forEach(child => this.collectMutationTargets(child));
|
|
159
|
+
statement.alternate?.forEach(child => this.collectMutationTargets(child));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
expressionType(expression, expected) {
|
|
163
|
+
if (expected)
|
|
164
|
+
return expected;
|
|
165
|
+
switch (expression.type) {
|
|
166
|
+
case 'numberLiteral': return { kind: 'named', name: 'Number' };
|
|
167
|
+
case 'stringLiteral':
|
|
168
|
+
case 'stringInterpolation': return { kind: 'named', name: 'String' };
|
|
169
|
+
case 'booleanLiteral':
|
|
170
|
+
case 'typeTestExpression': return { kind: 'named', name: 'Boolean' };
|
|
171
|
+
case 'nullLiteral': return { kind: 'null' };
|
|
172
|
+
case 'identifier': return this.localTypes.get(expression.name) ?? { kind: 'named', name: 'Number' };
|
|
173
|
+
case 'binaryExpression':
|
|
174
|
+
if (isComparison(expression.operator))
|
|
175
|
+
return { kind: 'named', name: 'Boolean' };
|
|
176
|
+
return this.expressionType(expression.left);
|
|
177
|
+
case 'unaryExpression': return expression.operator === 'not'
|
|
178
|
+
? { kind: 'named', name: 'Boolean' }
|
|
179
|
+
: this.expressionType(expression.argument);
|
|
180
|
+
case 'measurementAttachment': {
|
|
181
|
+
const unit = this.module.check.units.get(expression.unit);
|
|
182
|
+
return { kind: 'measurement', vector: unit?.vector ?? new Map() };
|
|
183
|
+
}
|
|
184
|
+
case 'measurementConversion': return this.expressionType(expression.value);
|
|
185
|
+
case 'conditionalExpression': return this.expressionType(expression.consequent);
|
|
186
|
+
case 'listLiteral': return {
|
|
187
|
+
kind: 'list',
|
|
188
|
+
element: expression.elements.length ? this.expressionType(expression.elements[0]) : { kind: 'named', name: 'Number' }
|
|
189
|
+
};
|
|
190
|
+
case 'rangeExpression': return { kind: 'list', element: { kind: 'named', name: 'Number' } };
|
|
191
|
+
case 'listAccess': {
|
|
192
|
+
const receiver = this.expressionType(expression.receiver);
|
|
193
|
+
return receiver.kind === 'list' ? receiver.element : { kind: 'named', name: 'Number' };
|
|
194
|
+
}
|
|
195
|
+
case 'recordConstructor': return { kind: 'named', name: expression.name };
|
|
196
|
+
case 'fieldAccess': {
|
|
197
|
+
if (expression.receiver.type === 'identifier') {
|
|
198
|
+
const enumeration = this.enumTypes.get(expression.receiver.name);
|
|
199
|
+
if (enumeration) {
|
|
200
|
+
const index = enumeration.members.findIndex(member => member.name === expression.field);
|
|
201
|
+
const value = enumeration.resolvedValues?.[index];
|
|
202
|
+
return { kind: 'named', name: typeof value === 'string' ? 'String' : 'Number' };
|
|
203
|
+
}
|
|
204
|
+
const record = this.recordTypes.get(expression.receiver.name);
|
|
205
|
+
const field = record?.fields.find(candidate => candidate.name === expression.field);
|
|
206
|
+
if (field)
|
|
207
|
+
return this.checkedTypeForReference(field.annotation, field);
|
|
208
|
+
}
|
|
209
|
+
const receiver = this.expressionType(expression.receiver);
|
|
210
|
+
if (receiver.kind === 'named') {
|
|
211
|
+
const field = this.recordTypes.get(receiver.name)?.fields.find(candidate => candidate.name === expression.field);
|
|
212
|
+
if (field)
|
|
213
|
+
return this.checkedTypeForReference(field.annotation, field);
|
|
214
|
+
}
|
|
215
|
+
return { kind: 'named', name: 'Number' };
|
|
216
|
+
}
|
|
217
|
+
case 'functionCall': {
|
|
218
|
+
const fn = this.functions.get(expression.callee);
|
|
219
|
+
if (fn)
|
|
220
|
+
return this.checkedTypeForReference(fn.returnType);
|
|
221
|
+
if (['trim', 'left', 'right', 'format'].includes(expression.callee))
|
|
222
|
+
return { kind: 'named', name: 'String' };
|
|
223
|
+
if (expression.callee === 'len')
|
|
224
|
+
return { kind: 'named', name: 'Number' };
|
|
225
|
+
if (['sum', 'min', 'max', 'mean', 'abs', 'round'].includes(expression.callee) && expression.arguments[0]) {
|
|
226
|
+
const first = this.expressionType(expression.arguments[0]);
|
|
227
|
+
return first.kind === 'list' ? first.element : first;
|
|
228
|
+
}
|
|
229
|
+
return { kind: 'named', name: 'Number' };
|
|
230
|
+
}
|
|
231
|
+
case 'matchExpression': return this.expressionType(expression.defaultExpression);
|
|
232
|
+
case 'forExpression': {
|
|
233
|
+
const returned = expression.body.find(statement => statement.type === 'returnStatement');
|
|
234
|
+
return { kind: 'list', element: returned?.type === 'returnStatement'
|
|
235
|
+
? this.expressionType(returned.expression)
|
|
236
|
+
: { kind: 'named', name: 'Number' } };
|
|
237
|
+
}
|
|
238
|
+
case 'bracedIfExpression': {
|
|
239
|
+
const returned = [...expression.consequent, ...expression.alternate]
|
|
240
|
+
.find(statement => statement.type === 'returnStatement');
|
|
241
|
+
return returned?.type === 'returnStatement' ? this.expressionType(returned.expression) : { kind: 'named', name: 'Number' };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
castExpression(code, type) {
|
|
246
|
+
return `(${code} as unknown as ${this.typeScriptType(type)})`;
|
|
247
|
+
}
|
|
248
|
+
expression(expression, expected) {
|
|
249
|
+
const resultType = this.expressionType(expression, expected);
|
|
250
|
+
const context = this.sourceContext(expression.source);
|
|
251
|
+
switch (expression.type) {
|
|
252
|
+
case 'numberLiteral': return String(expression.value);
|
|
253
|
+
case 'stringLiteral': return quote(expression.value);
|
|
254
|
+
case 'booleanLiteral': return String(expression.value);
|
|
255
|
+
case 'nullLiteral': return 'null';
|
|
256
|
+
case 'identifier':
|
|
257
|
+
if (expression.name === 'PI')
|
|
258
|
+
return 'Math.PI';
|
|
259
|
+
if (expression.name === 'E')
|
|
260
|
+
return 'Math.E';
|
|
261
|
+
return this.name(expression.name);
|
|
262
|
+
case 'binaryExpression':
|
|
263
|
+
return this.castExpression(`__amxBinary(${quote(expression.operator)}, ${this.expression(expression.left)} as unknown as __AMXValue, ${this.expression(expression.right)} as unknown as __AMXValue, ${this.sourceContext(expression.operatorSource ?? expression.source)})`, resultType);
|
|
264
|
+
case 'unaryExpression':
|
|
265
|
+
return this.castExpression(`__amxUnary(${quote(expression.operator)}, ${this.expression(expression.argument)} as unknown as __AMXValue, ${context})`, resultType);
|
|
266
|
+
case 'typeTestExpression':
|
|
267
|
+
return `__amxIsType(${this.expression(expression.value)} as unknown as __AMXValue, ${this.inputDescriptor(expression.target)})`;
|
|
268
|
+
case 'measurementAttachment': {
|
|
269
|
+
const unit = this.module.check.units.get(expression.unit);
|
|
270
|
+
if (!unit)
|
|
271
|
+
throw new LoweringFailure(`Missing checked unit '${expression.unit}'`, expression.unitSource?.line, expression.unitSource?.column);
|
|
272
|
+
return this.castExpression(`__amxAttach(${this.expression(expression.value)} as number, ${this.unitDescriptor(expression.unit)})`, resultType);
|
|
273
|
+
}
|
|
274
|
+
case 'measurementConversion':
|
|
275
|
+
return this.castExpression(`__amxConvert(${this.expression(expression.value)} as __AMXMeasurement, ${this.unitDescriptor(expression.unit)})`, resultType);
|
|
276
|
+
case 'stringInterpolation':
|
|
277
|
+
return `[${expression.parts.map(part => typeof part === 'string'
|
|
278
|
+
? quote(part)
|
|
279
|
+
: `__amxFormatValue(${this.expression(part)} as __AMXValue, ${this.sourceContext(part.source)})`).join(', ')}].join('')`;
|
|
280
|
+
case 'conditionalExpression':
|
|
281
|
+
return `(${this.expression(expression.test, { kind: 'named', name: 'Boolean' })} ? ${this.expression(expression.consequent, resultType)} : ${this.expression(expression.alternate, resultType)})`;
|
|
282
|
+
case 'bracedIfExpression': {
|
|
283
|
+
const branches = this.expressionLoopBranch(expression.consequent, expression.alternate, resultType);
|
|
284
|
+
return `((): ${this.typeScriptType(resultType)} => { if (${this.expression(expression.test, { kind: 'named', name: 'Boolean' })}) {\n${branches[0]}\n } else {\n${branches[1]}\n } throw new Error('Unreachable checked expression branch'); })()`;
|
|
285
|
+
}
|
|
286
|
+
case 'listLiteral':
|
|
287
|
+
return `[${expression.elements.map(element => this.expression(element, resultType.kind === 'list' ? resultType.element : undefined)).join(', ')}]`;
|
|
288
|
+
case 'rangeExpression':
|
|
289
|
+
return `__amxRange(${this.expression(expression.start, { kind: 'named', name: 'Number' })}, ${this.expression(expression.end, { kind: 'named', name: 'Number' })}, ${context})`;
|
|
290
|
+
case 'listAccess':
|
|
291
|
+
return this.castExpression(`__amxGet1Based(${this.expression(expression.receiver)} as unknown as __AMXValue[], ${this.expression(expression.index, { kind: 'named', name: 'Number' })}, ${context})`, resultType);
|
|
292
|
+
case 'fieldAccess':
|
|
293
|
+
return `${this.expression(expression.receiver)}[${quote(expression.field)}]`;
|
|
294
|
+
case 'functionCall': {
|
|
295
|
+
const args = expression.arguments.map(argument => this.expression(argument));
|
|
296
|
+
if (builtinNames.has(expression.callee)) {
|
|
297
|
+
return this.castExpression(`__amxBuiltin(${quote(expression.callee)} as __AMXBuiltinName, [${args.map(argument => `${argument} as unknown as __AMXValue`).join(', ')}], __amxRuntime)`, resultType);
|
|
298
|
+
}
|
|
299
|
+
const fn = this.functions.get(expression.callee);
|
|
300
|
+
if (!fn)
|
|
301
|
+
throw new LoweringFailure(`Missing checked function '${expression.callee}'`, expression.source?.line, expression.source?.column);
|
|
302
|
+
return `${this.name(expression.callee)}(${args.map((argument, index) => fn.parameters[index]?.annotation.type === 'listType'
|
|
303
|
+
? `__amxCopyListArgument(${argument})`
|
|
304
|
+
: argument).join(', ')})`;
|
|
305
|
+
}
|
|
306
|
+
case 'recordConstructor': return this.recordConstructor(expression, resultType);
|
|
307
|
+
case 'matchExpression': return this.matchExpression(expression, resultType);
|
|
308
|
+
case 'forExpression': return this.forExpression(expression, resultType);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
expressionLoopBranch(statements, alternate, resultType) {
|
|
312
|
+
const first = this.emitScopedStatements(statements, 2).join('\n');
|
|
313
|
+
const second = this.emitScopedStatements(alternate, 2).join('\n');
|
|
314
|
+
if (!first.includes('return ') || !second.includes('return ')) {
|
|
315
|
+
throw new LoweringFailure('Checked braced-if expression is missing a return branch');
|
|
316
|
+
}
|
|
317
|
+
void resultType;
|
|
318
|
+
return [first, second];
|
|
319
|
+
}
|
|
320
|
+
recordConstructor(expression, resultType) {
|
|
321
|
+
const declaration = this.recordTypes.get(expression.name);
|
|
322
|
+
if (!declaration)
|
|
323
|
+
throw new LoweringFailure(`Missing checked record '${expression.name}'`, expression.source?.line, expression.source?.column);
|
|
324
|
+
const entries = expression.fields.map(field => `[${quote(field.name)}, ${this.expression(field.expression)} as unknown]`).join(', ');
|
|
325
|
+
const fields = declaration.fields.map(field => {
|
|
326
|
+
const defaultExpression = field.defaultExpression
|
|
327
|
+
? this.expression(field.defaultExpression, this.checkedTypeForReference(field.annotation, field))
|
|
328
|
+
: 'null';
|
|
329
|
+
return `${quoteIdentifier(field.name)}: __amxSupplied.has(${quote(field.name)}) ? __amxSupplied.get(${quote(field.name)}) : ${defaultExpression}`;
|
|
330
|
+
}).join(', ');
|
|
331
|
+
return `(() => { const __amxSupplied = new Map<string, unknown>([${entries}]); return { ${fields} } as ${this.typeScriptType(resultType)}; })()`;
|
|
332
|
+
}
|
|
333
|
+
matchExpression(expression, resultType) {
|
|
334
|
+
const matched = `${this.prefix}match_${expression.source?.line ?? 0}_${expression.source?.column ?? 0}`;
|
|
335
|
+
const cases = expression.cases.map(item => `if (${matched} === ${this.expression(item.value)}) return ${this.expression(item.expression, resultType)};`);
|
|
336
|
+
return `((): ${this.typeScriptType(resultType)} => { const ${matched} = ${this.expression(expression.expression)}; ${cases.join(' ')} return ${this.expression(expression.defaultExpression, resultType)}; })()`;
|
|
337
|
+
}
|
|
338
|
+
forExpression(expression, resultType) {
|
|
339
|
+
const results = `${this.prefix}loop_results_${expression.source?.line ?? 0}_${expression.source?.column ?? 0}`;
|
|
340
|
+
const iterableType = this.expressionType(expression.iterable);
|
|
341
|
+
const elementType = iterableType.kind === 'list' ? iterableType.element : { kind: 'named', name: 'Number' };
|
|
342
|
+
const previousType = this.localTypes.get(expression.variable);
|
|
343
|
+
this.localTypes.set(expression.variable, elementType);
|
|
344
|
+
this.expressionLoopReturns.push(results);
|
|
345
|
+
this.declaredScopes.push(new Set());
|
|
346
|
+
const body = this.emitScopedStatements(expression.body, 3).join('\n');
|
|
347
|
+
this.declaredScopes.pop();
|
|
348
|
+
this.expressionLoopReturns.pop();
|
|
349
|
+
if (previousType)
|
|
350
|
+
this.localTypes.set(expression.variable, previousType);
|
|
351
|
+
else
|
|
352
|
+
this.localTypes.delete(expression.variable);
|
|
353
|
+
return `(() => { const ${results}: ${this.typeScriptType(resultType)} = []; for (const ${this.name(expression.variable)} of __amxIterate<${this.typeScriptType(elementType)}>(${this.expression(expression.iterable)} as __AMXValue, ${this.sourceContext(expression.source)})) {\n${body}\n } return ${results}; })()`;
|
|
354
|
+
}
|
|
355
|
+
emitScopedStatements(statements, depth) {
|
|
356
|
+
const previousTypes = new Map(this.localTypes);
|
|
357
|
+
this.declaredScopes.push(new Set());
|
|
358
|
+
const code = statements.flatMap(statement => this.emitStatement(statement, depth));
|
|
359
|
+
this.declaredScopes.pop();
|
|
360
|
+
this.localTypes.clear();
|
|
361
|
+
for (const [name, type] of previousTypes)
|
|
362
|
+
this.localTypes.set(name, type);
|
|
363
|
+
return code;
|
|
364
|
+
}
|
|
365
|
+
emitFunction(statement) {
|
|
366
|
+
const previousTypes = new Map(this.localTypes);
|
|
367
|
+
const parameterNames = new Set();
|
|
368
|
+
const argumentsList = statement.parameters.map((parameter, index) => {
|
|
369
|
+
const parameterName = `${this.prefix}arg_${index}_${parameter.name}`;
|
|
370
|
+
this.localTypes.set(parameter.name, this.checkedTypeForReference(parameter.annotation));
|
|
371
|
+
parameterNames.add(parameter.name);
|
|
372
|
+
return `${parameterName}: ${this.typeScriptReference(parameter.annotation)}`;
|
|
373
|
+
});
|
|
374
|
+
this.declaredScopes.push(parameterNames);
|
|
375
|
+
const body = statement.body.kind === 'expression'
|
|
376
|
+
? [` return ${this.expression(statement.body.expression, this.checkedTypeForReference(statement.returnType))};`]
|
|
377
|
+
: statement.body.statements.flatMap(child => this.emitStatement(child, 1));
|
|
378
|
+
this.declaredScopes.pop();
|
|
379
|
+
this.localTypes.clear();
|
|
380
|
+
for (const [name, type] of previousTypes)
|
|
381
|
+
this.localTypes.set(name, type);
|
|
382
|
+
const initialBindings = statement.parameters.map((parameter, index) => {
|
|
383
|
+
const parameterName = `${this.prefix}arg_${index}_${parameter.name}`;
|
|
384
|
+
const value = parameter.annotation.type === 'listType'
|
|
385
|
+
? `__amxCopyListArgument(${parameterName})`
|
|
386
|
+
: parameterName;
|
|
387
|
+
const keyword = this.mutationTargets.has(parameter.name) ? 'let' : 'const';
|
|
388
|
+
return ` ${keyword} ${this.name(parameter.name)} = ${value};`;
|
|
389
|
+
});
|
|
390
|
+
return `${statement.exported ? 'export ' : ''}function ${this.name(statement.name)}(${argumentsList.join(', ')}): ${this.typeScriptReference(statement.returnType)} {\n${initialBindings.join('\n')}${initialBindings.length ? '\n' : ''}${body.join('\n')}\n}`;
|
|
391
|
+
}
|
|
392
|
+
emitShow(name, source) {
|
|
393
|
+
const declaration = this.viewDefinitions.get(name);
|
|
394
|
+
if (!declaration)
|
|
395
|
+
throw new LoweringFailure(`Missing checked visualization '${name}'`, source?.line, source?.column);
|
|
396
|
+
const binding = this.name(declaration.binding);
|
|
397
|
+
const title = declaration.options.find(option => option.type === 'viewTitleOption')?.value ?? name;
|
|
398
|
+
if (declaration.type === 'tableDeclaration') {
|
|
399
|
+
const columns = declaration.options.filter((option) => option.type === 'tableColumnOption');
|
|
400
|
+
const columnData = columns.map(column => `{ field: ${quote(column.field)}, label: ${quote(column.label)} }`).join(', ');
|
|
401
|
+
const rows = `${binding}.map(__row => [${columns.map(column => `__amxSnapshotViewValue(__row[${quote(column.field)}])`).join(', ')}])`;
|
|
402
|
+
return `__context.views.push(__amxTableView(${quote(name)}, [${columnData}], ${rows}, ${quote(title)}, ''));`;
|
|
403
|
+
}
|
|
404
|
+
const scatter = declaration.kind === 'scatter';
|
|
405
|
+
const selectedColumns = scatter
|
|
406
|
+
? declaration.options.filter((option) => option.type === 'chartFieldOption' && (option.role === 'x' || option.role === 'y'))
|
|
407
|
+
.map(option => ({ role: option.role, field: option.field, label: option.role, source: option.source }))
|
|
408
|
+
: declaration.options.filter((option) => option.type === 'chartSeriesOption')
|
|
409
|
+
.map(option => ({ role: 'series', field: option.field, label: option.label, source: option.source }));
|
|
410
|
+
const columns = selectedColumns.map(column => `{ role: ${quote(column.role)}, ${column.field === undefined ? '' : `field: ${quote(column.field)}, `}label: ${quote(column.label)}, source: ${JSON.stringify(column.source ?? {})} }`).join(', ');
|
|
411
|
+
const labelsOption = declaration.options.find(option => option.type === 'chartFieldOption' && option.role === 'labels');
|
|
412
|
+
const labels = labelsOption?.type === 'chartFieldOption' ? this.name(labelsOption.field) : undefined;
|
|
413
|
+
const showTableOption = declaration.options.find(option => option.type === 'chartShowTableOption');
|
|
414
|
+
const showTable = showTableOption?.type === 'chartShowTableOption'
|
|
415
|
+
? this.expression(showTableOption.expression, { kind: 'named', name: 'Boolean' })
|
|
416
|
+
: 'false';
|
|
417
|
+
const description = declaration.options.find(option => option.type === 'viewDescriptionOption')?.value ?? '';
|
|
418
|
+
const labelData = labels
|
|
419
|
+
? `const __labels = ${labels}; if (__labels.length !== ${binding}.length) throw new __AMXInputError(${quote(`visualization ${name}.labels`)}, ${quote(`${binding}.length labels`)}, String(__labels.length) + ' labels', ${this.sourceContext(labelsOption?.source)});`
|
|
420
|
+
: 'const __labels = undefined;';
|
|
421
|
+
return `(() => { const __showTable = ${showTable}; ${labelData} const __snapshot = __amxChartSnapshot(${binding}, [${columns}], ${quote(name)}, ${String(scatter)}, __amxRuntime); __context.views.push(__amxChartView({ name: ${quote(name)}, chartKind: ${quote(declaration.kind)}, title: ${quote(title)}, description: ${quote(description)}, data: __snapshot.data, headings: __snapshot.headings, measurementDescriptors: __snapshot.measurementDescriptors.length ? __snapshot.measurementDescriptors : undefined, labels: __labels, showTable: __showTable })); })();`;
|
|
422
|
+
}
|
|
423
|
+
diagramProperty(element, name) {
|
|
424
|
+
const property = element.properties.find(item => item.name === name);
|
|
425
|
+
if (!property)
|
|
426
|
+
throw new LoweringFailure(`Missing checked diagram property '${name}'`, element.source?.line, element.source?.column);
|
|
427
|
+
return property;
|
|
428
|
+
}
|
|
429
|
+
diagramElementBuilder(element, controlled) {
|
|
430
|
+
const indent = ' ';
|
|
431
|
+
const number = (name, positive = false) => {
|
|
432
|
+
const property = this.diagramProperty(element, name);
|
|
433
|
+
return `__amxDiagramNumber(${this.expression(property.expression, { kind: 'named', name: 'Number' })}, __amxRuntime, 'AMXD008', 'Invalid primitive geometry', ${this.sourceContext(property.valueSource ?? property.source)}${positive ? ', true' : ''})`;
|
|
434
|
+
};
|
|
435
|
+
const string = (name) => {
|
|
436
|
+
const property = this.diagramProperty(element, name);
|
|
437
|
+
if (property.expression.type !== 'stringLiteral') {
|
|
438
|
+
throw new LoweringFailure(`Checked diagram style '${name}' is not a literal`, property.valueSource?.line, property.valueSource?.column);
|
|
439
|
+
}
|
|
440
|
+
return quote(property.expression.value);
|
|
441
|
+
};
|
|
442
|
+
const lineWidth = () => {
|
|
443
|
+
const property = this.diagramProperty(element, 'lineWidth');
|
|
444
|
+
if (property.expression.type !== 'numberLiteral') {
|
|
445
|
+
throw new LoweringFailure('Checked diagram lineWidth is not a literal', property.valueSource?.line, property.valueSource?.column);
|
|
446
|
+
}
|
|
447
|
+
return String(property.expression.value);
|
|
448
|
+
};
|
|
449
|
+
const guarded = (body) => [
|
|
450
|
+
...(controlled ? [`${indent}if (++__amxGeneratedDiagramElements > 64) throw new __AMXRuntimeError({ code: 'AMXD6004', message: 'Number of elements in this diagram exceed the maximum (64)', file: ${quote(this.sourceFile)}, line: ${element.source?.line ?? 1}, column: ${element.source?.column ?? 1} });`] : []),
|
|
451
|
+
...body
|
|
452
|
+
];
|
|
453
|
+
switch (element.primitive) {
|
|
454
|
+
case 'line': {
|
|
455
|
+
const arrowProperty = element.properties.find(item => item.name === 'arrow');
|
|
456
|
+
const arrow = arrowProperty?.expression.type === 'stringLiteral' ? quote(arrowProperty.expression.value) : quote('none');
|
|
457
|
+
return guarded([`${indent}__amxDiagramBuilders.push(() => ({ primitive: 'line', name: ${quote(element.name)}, x1: ${number('x1')}, y1: ${number('y1')}, x2: ${number('x2')}, y2: ${number('y2')}, stroke: ${string('stroke')}, lineWidth: ${lineWidth()}, arrow: ${arrow} }));`]);
|
|
458
|
+
}
|
|
459
|
+
case 'rectangle': {
|
|
460
|
+
const fill = element.properties.some(item => item.name === 'fill') ? `, fill: ${string('fill')}` : '';
|
|
461
|
+
return guarded([
|
|
462
|
+
`${indent}__amxDiagramBuilders.push(() => {`,
|
|
463
|
+
`${indent} const __width = ${number('width', true)};`,
|
|
464
|
+
`${indent} const __height = ${number('height', true)};`,
|
|
465
|
+
`${indent} const __fill = ${element.properties.some(item => item.name === 'fill') ? string('fill') : 'undefined'};`,
|
|
466
|
+
`${indent} const __x = ${number('x')};`,
|
|
467
|
+
`${indent} const __y = ${number('y')};`,
|
|
468
|
+
`${indent} return { primitive: 'rectangle', name: ${quote(element.name)}, x: __x, y: __y, width: __width, height: __height, stroke: ${string('stroke')}${fill}, lineWidth: ${lineWidth()} };`,
|
|
469
|
+
`${indent}});`
|
|
470
|
+
]);
|
|
471
|
+
}
|
|
472
|
+
case 'circle': {
|
|
473
|
+
const hasFill = element.properties.some(item => item.name === 'fill');
|
|
474
|
+
const fill = hasFill ? `, fill: ${string('fill')}` : '';
|
|
475
|
+
return guarded([
|
|
476
|
+
`${indent}__amxDiagramBuilders.push(() => {`,
|
|
477
|
+
`${indent} const __radius = ${number('r', true)};`,
|
|
478
|
+
`${indent} const __fill = ${hasFill ? string('fill') : 'undefined'};`,
|
|
479
|
+
`${indent} const __cx = ${number('cx')};`,
|
|
480
|
+
`${indent} const __cy = ${number('cy')};`,
|
|
481
|
+
`${indent} return { primitive: 'circle', name: ${quote(element.name)}, cx: __cx, cy: __cy, r: __radius, stroke: ${string('stroke')}${fill}, lineWidth: ${lineWidth()} };`,
|
|
482
|
+
`${indent}});`
|
|
483
|
+
]);
|
|
484
|
+
}
|
|
485
|
+
case 'text':
|
|
486
|
+
return guarded([`${indent}__amxDiagramBuilders.push(() => ({ primitive: 'text', name: ${quote(element.name)}, value: ${this.expression(this.diagramProperty(element, 'value').expression, { kind: 'named', name: 'String' })}, x: ${number('x')}, y: ${number('y')}, fill: ${string('fill')} }));`]);
|
|
487
|
+
default:
|
|
488
|
+
throw new LoweringFailure(`Unsupported diagram primitive '${element.primitive}'`, element.source?.line, element.source?.column);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
diagramContent(content, depth, controlled) {
|
|
492
|
+
const indent = ' '.repeat(depth);
|
|
493
|
+
const result = [];
|
|
494
|
+
for (const node of content) {
|
|
495
|
+
if (node.type === 'diagramElement') {
|
|
496
|
+
result.push(...this.diagramElementBuilder(node, controlled));
|
|
497
|
+
}
|
|
498
|
+
else if (node.type === 'diagramForBlock') {
|
|
499
|
+
const iterableType = this.expressionType(node.iterable);
|
|
500
|
+
const elementType = iterableType.kind === 'list' ? iterableType.element : { kind: 'named', name: 'Number' };
|
|
501
|
+
const previousType = this.localTypes.get(node.variable);
|
|
502
|
+
this.localTypes.set(node.variable, elementType);
|
|
503
|
+
const body = this.diagramContent(node.content, depth + 1, true);
|
|
504
|
+
if (previousType)
|
|
505
|
+
this.localTypes.set(node.variable, previousType);
|
|
506
|
+
else
|
|
507
|
+
this.localTypes.delete(node.variable);
|
|
508
|
+
result.push(`${indent}for (const ${this.name(node.variable)} of __amxIterate<${this.typeScriptType(elementType)}>(${this.expression(node.iterable)} as __AMXValue, ${this.sourceContext(node.iterableSource ?? node.source)})) {`, ...body, `${indent}}`);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
const consequent = this.diagramContent(node.consequent, depth + 1, true);
|
|
512
|
+
const alternate = node.alternate ? this.diagramContent(node.alternate, depth + 1, true) : [];
|
|
513
|
+
result.push(`${indent}if (${this.expression(node.test, { kind: 'named', name: 'Boolean' })}) {`, ...consequent, ...(node.alternate ? [`${indent}} else {`, ...alternate] : []), `${indent}}`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return result;
|
|
517
|
+
}
|
|
518
|
+
emitDiagram(diagram, depth) {
|
|
519
|
+
const property = (name) => {
|
|
520
|
+
const found = diagram.properties.find(item => item.name === name);
|
|
521
|
+
if (!found)
|
|
522
|
+
throw new LoweringFailure(`Missing checked diagram property '${name}'`, diagram.source?.line, diagram.source?.column);
|
|
523
|
+
return found;
|
|
524
|
+
};
|
|
525
|
+
const title = property('title').expression;
|
|
526
|
+
const description = property('description').expression;
|
|
527
|
+
const time = diagram.times[0];
|
|
528
|
+
if (!time || title.type !== 'stringLiteral' || description.type !== 'stringLiteral') {
|
|
529
|
+
throw new LoweringFailure('Checked diagram is missing a literal title, description, or time declaration', diagram.source?.line, diagram.source?.column);
|
|
530
|
+
}
|
|
531
|
+
const previousTimeType = this.localTypes.get(time.name);
|
|
532
|
+
this.localTypes.set(time.name, { kind: 'named', name: 'Number' });
|
|
533
|
+
const content = this.diagramContent(diagram.content, depth + 1, false);
|
|
534
|
+
if (previousTimeType)
|
|
535
|
+
this.localTypes.set(time.name, previousTimeType);
|
|
536
|
+
else
|
|
537
|
+
this.localTypes.delete(time.name);
|
|
538
|
+
const indent = ' '.repeat(depth);
|
|
539
|
+
const width = property('width');
|
|
540
|
+
const height = property('height');
|
|
541
|
+
const from = this.expression(time.from, { kind: 'named', name: 'Number' });
|
|
542
|
+
const to = this.expression(time.to, { kind: 'named', name: 'Number' });
|
|
543
|
+
const duration = this.expression(time.duration, { kind: 'named', name: 'Number' });
|
|
544
|
+
return [
|
|
545
|
+
`${indent}(() => {`,
|
|
546
|
+
`${indent} const __amxWidth = __amxDiagramNumber(${this.expression(width.expression, { kind: 'named', name: 'Number' })}, __amxRuntime, 'AMXD003', 'Canvas width is invalid', ${this.sourceContext(width.valueSource ?? width.source)}, true);`,
|
|
547
|
+
`${indent} const __amxHeight = __amxDiagramNumber(${this.expression(height.expression, { kind: 'named', name: 'Number' })}, __amxRuntime, 'AMXD014', 'Canvas height is invalid', ${this.sourceContext(height.valueSource ?? height.source)}, true);`,
|
|
548
|
+
`${indent} const __amxFrom = __amxDiagramNumber(${from}, __amxRuntime, 'AMXD004', 'Invalid time bounds', ${this.sourceContext(time.fromSource ?? time.source)});`,
|
|
549
|
+
`${indent} const __amxTo = __amxDiagramNumber(${to}, __amxRuntime, 'AMXD004', 'Invalid time bounds', ${this.sourceContext(time.toSource ?? time.source)});`,
|
|
550
|
+
`${indent} if (__amxFrom >= __amxTo) throw new __AMXRuntimeError({ code: 'AMXD004', message: 'Invalid time bounds', file: ${quote(this.sourceFile)}, line: ${time.source?.line ?? 1}, column: ${time.source?.column ?? 1} });`,
|
|
551
|
+
`${indent} const __amxDuration = __amxDiagramNumber(${duration}, __amxRuntime, 'AMXD005', 'Invalid playback duration value', ${this.sourceContext(time.durationSource ?? time.source)}, true);`,
|
|
552
|
+
`${indent} const ${this.name(time.name)} = __amxFrom;`,
|
|
553
|
+
`${indent} const __amxDiagramBuilders: Array<() => __AMXDiagramPrimitiveElement> = [];`,
|
|
554
|
+
`${indent} let __amxGeneratedDiagramElements = 0;`,
|
|
555
|
+
...content,
|
|
556
|
+
`${indent} const __amxElements = __amxDiagramBuilders.map(__build => __build());`,
|
|
557
|
+
`${indent} __context.views.push(__amxDiagramView({ schema: 'structured-v2', name: ${quote(diagram.name)}, title: ${quote(title.value)}, description: ${quote(description.value)}, canvas: { width: __amxWidth, height: __amxHeight, coordinates: 'bottom-left-y-up' }, timeline: { variable: ${quote(time.name)}, from: __amxFrom, to: __amxTo, duration: __amxDuration }, initialFrame: { time: __amxFrom, elements: __amxElements } }));`,
|
|
558
|
+
`${indent}})();`
|
|
559
|
+
];
|
|
560
|
+
}
|
|
561
|
+
inputDescriptor(reference, seen = new Set(), registry = this.module.check) {
|
|
562
|
+
if (reference.type === 'listType')
|
|
563
|
+
return `{ kind: 'list', element: ${this.inputDescriptor(reference.element, seen, registry)} }`;
|
|
564
|
+
if (reference.type === 'nullableType')
|
|
565
|
+
return `{ kind: 'nullable', value: ${this.inputDescriptor(reference.element, seen, registry)} }`;
|
|
566
|
+
const name = reference.name;
|
|
567
|
+
if (name === 'Number')
|
|
568
|
+
return `{ kind: 'number' }`;
|
|
569
|
+
if (name === 'String')
|
|
570
|
+
return `{ kind: 'string' }`;
|
|
571
|
+
if (name === 'Boolean')
|
|
572
|
+
return `{ kind: 'boolean' }`;
|
|
573
|
+
if (name === 'DateTime')
|
|
574
|
+
return `{ kind: 'dateTime' }`;
|
|
575
|
+
const dimension = registry.dimensions.get(name);
|
|
576
|
+
if (dimension) {
|
|
577
|
+
const units = [...registry.units.values()].filter(unit => sameVector(unit.vector, dimension.vector));
|
|
578
|
+
const unitMap = units.map(unit => `${quote(unit.name)}: ${this.unitDescriptor(unit.name, registry)}`).join(', ');
|
|
579
|
+
return `{ kind: 'measurement', dimensionName: ${quote(name)}, dimensionVector: ${JSON.stringify(Object.fromEntries(dimension.vector))}, units: { ${unitMap} } }`;
|
|
580
|
+
}
|
|
581
|
+
const enumeration = this.enumTypes.get(name);
|
|
582
|
+
if (enumeration) {
|
|
583
|
+
return `{ kind: 'enum', enumName: ${quote(name)}, members: ${JSON.stringify(enumeration.resolvedValues ?? [])} }`;
|
|
584
|
+
}
|
|
585
|
+
const declaration = this.recordTypes.get(name);
|
|
586
|
+
if (declaration) {
|
|
587
|
+
if (seen.has(name))
|
|
588
|
+
throw new LoweringFailure(`Recursive input descriptor for '${name}' is unsupported`, declaration.source?.line, declaration.source?.column);
|
|
589
|
+
const nested = new Set(seen).add(name);
|
|
590
|
+
const fields = declaration.fields.map(field => {
|
|
591
|
+
const fieldScope = fieldRegistry(field, registry) ?? registry;
|
|
592
|
+
const defaultValue = field.defaultExpression
|
|
593
|
+
? `, defaultValue: () => ${this.expression(field.defaultExpression, this.checkedTypeForReference(field.annotation, field))}`
|
|
594
|
+
: '';
|
|
595
|
+
return `{ name: ${quote(field.name)}, descriptor: ${this.inputDescriptor(field.annotation, nested, fieldScope)}${field.optional ? ', optional: true' : ''}${defaultValue} }`;
|
|
596
|
+
});
|
|
597
|
+
return `{ kind: 'record', recordName: ${quote(name)}, fields: [${fields.join(', ')}] }`;
|
|
598
|
+
}
|
|
599
|
+
throw new LoweringFailure(`Missing checked type descriptor '${name}'`, reference.source?.line, reference.source?.column);
|
|
600
|
+
}
|
|
601
|
+
unitDescriptor(name, registry = this.module.check) {
|
|
602
|
+
const unit = registry.units.get(name);
|
|
603
|
+
if (!unit)
|
|
604
|
+
throw new LoweringFailure(`Missing checked unit '${name}'`);
|
|
605
|
+
return `{ identity: ${quote(unit.identity)}, name: ${quote(unit.name)}, scale: ${unit.scale}, offset: ${unit.offset}, vector: ${JSON.stringify(Object.fromEntries(unit.vector))} }`;
|
|
606
|
+
}
|
|
607
|
+
emitTypeDeclaration(statement) {
|
|
608
|
+
const exported = statement.exported ? 'export ' : '';
|
|
609
|
+
const externalExported = statement.exported ? 'export ' : '';
|
|
610
|
+
const parents = (statement.parents ?? []).map(parent => this.name(parent.name));
|
|
611
|
+
const extendsClause = parents.length ? ` extends ${parents.join(', ')}` : '';
|
|
612
|
+
const fields = statement.fields.map(field => ` ${quoteIdentifier(field.name)}: ${this.typeScriptReference(field.annotation, false, field)};`).join('\n');
|
|
613
|
+
const externalFields = statement.fields.map(field => ` ${quoteIdentifier(field.name)}${field.optional || field.defaultExpression ? '?' : ''}: ${this.typeScriptReference(field.annotation, true, field)};`).join('\n');
|
|
614
|
+
return `${exported}interface ${this.name(statement.name)}${extendsClause} {\n${fields}\n}\n${externalExported}interface __AMXExternal_${this.name(statement.name)} {\n${externalFields}\n}`;
|
|
615
|
+
}
|
|
616
|
+
emitEnumDeclaration(statement) {
|
|
617
|
+
const values = statement.resolvedValues ?? [];
|
|
618
|
+
const members = statement.members.map((member, index) => {
|
|
619
|
+
const value = values[index];
|
|
620
|
+
return ` ${quoteIdentifier(member.name)}: ${typeof value === 'string' ? quote(value) : String(value)}`;
|
|
621
|
+
}).join(',\n');
|
|
622
|
+
const exported = statement.exported ? 'export ' : '';
|
|
623
|
+
return `${exported}const ${this.name(statement.name)} = Object.freeze({\n${members}\n} as const);\n${exported}type ${this.name(statement.name)} = typeof ${this.name(statement.name)}[keyof typeof ${this.name(statement.name)}];`;
|
|
624
|
+
}
|
|
625
|
+
emitStatement(statement, depth) {
|
|
626
|
+
const indent = ' '.repeat(depth);
|
|
627
|
+
switch (statement.type) {
|
|
628
|
+
case 'variableDeclaration': {
|
|
629
|
+
const name = this.name(statement.name);
|
|
630
|
+
const expected = this.localTypes.get(statement.name) ?? (statement.annotation ? this.checkedTypeForReference(statement.annotation) : undefined);
|
|
631
|
+
const inferred = expected ?? this.expressionType(statement.expression);
|
|
632
|
+
const value = this.expression(statement.expression, inferred);
|
|
633
|
+
const declared = this.declaredScopes[this.declaredScopes.length - 1];
|
|
634
|
+
this.localTypes.set(statement.name, inferred);
|
|
635
|
+
if (declared.has(statement.name))
|
|
636
|
+
return [`${indent}${name} = ${value};`];
|
|
637
|
+
declared.add(statement.name);
|
|
638
|
+
const keyword = this.mutationTargets.has(statement.name) ? 'let' : 'const';
|
|
639
|
+
return [`${indent}${keyword} ${name}: ${this.typeScriptType(inferred)} = ${value};`];
|
|
640
|
+
}
|
|
641
|
+
case 'assignmentStatement':
|
|
642
|
+
case 'compoundAssignmentStatement': {
|
|
643
|
+
const target = this.name(statement.name);
|
|
644
|
+
const type = this.localTypes.get(statement.name);
|
|
645
|
+
if (!type)
|
|
646
|
+
throw new LoweringFailure(`Missing checked binding '${statement.name}'`, statement.source?.line, statement.source?.column);
|
|
647
|
+
const value = this.expression(statement.expression, type);
|
|
648
|
+
return statement.type === 'assignmentStatement'
|
|
649
|
+
? [`${indent}${target} = ${value};`]
|
|
650
|
+
: [`${indent}${target} = ${this.castExpression(`__amxBinary('+', ${target} as __AMXValue, ${value} as __AMXValue, ${this.sourceContext(statement.source)})`, type)};`];
|
|
651
|
+
}
|
|
652
|
+
case 'addStatement':
|
|
653
|
+
return [`${indent}__amxAdd1Based(${this.name(statement.name)} as unknown as __AMXValue[], ${this.expression(statement.value)} as unknown as __AMXValue, ${statement.index ? this.expression(statement.index) : 'undefined'}, { ...${this.sourceContext(statement.source)}, targetName: ${quote(statement.name)}${this.importedBindings.has(statement.name) ? ', mutable: false' : ''} });`];
|
|
654
|
+
case 'removeStatement':
|
|
655
|
+
return [`${indent}__amxRemove1Based(${this.name(statement.name)} as unknown as __AMXValue[], ${this.expression(statement.count)}, ${statement.index ? this.expression(statement.index) : 'undefined'}, { ...${this.sourceContext(statement.source)}, targetName: ${quote(statement.name)}${this.importedBindings.has(statement.name) ? ', mutable: false' : ''} });`];
|
|
656
|
+
case 'forStatement': {
|
|
657
|
+
const iterableType = this.expressionType(statement.iterable);
|
|
658
|
+
const elementType = iterableType.kind === 'list' ? iterableType.element : { kind: 'named', name: 'Number' };
|
|
659
|
+
const previousType = this.localTypes.get(statement.variable);
|
|
660
|
+
this.localTypes.set(statement.variable, elementType);
|
|
661
|
+
const body = this.emitScopedStatements(statement.body, depth + 1);
|
|
662
|
+
if (previousType)
|
|
663
|
+
this.localTypes.set(statement.variable, previousType);
|
|
664
|
+
else
|
|
665
|
+
this.localTypes.delete(statement.variable);
|
|
666
|
+
return [`${indent}for (const ${this.name(statement.variable)} of __amxIterate<${this.typeScriptType(elementType)}>(${this.expression(statement.iterable)} as unknown as __AMXValue, ${this.sourceContext(statement.source)})) {`, ...body, `${indent}}`];
|
|
667
|
+
}
|
|
668
|
+
case 'bracedIfStatement': {
|
|
669
|
+
const consequent = this.emitScopedStatements(statement.consequent, depth + 1);
|
|
670
|
+
const alternate = statement.alternate ? this.emitScopedStatements(statement.alternate, depth + 1) : [];
|
|
671
|
+
return [
|
|
672
|
+
`${indent}if (${this.expression(statement.test, { kind: 'named', name: 'Boolean' })}) {`,
|
|
673
|
+
...consequent,
|
|
674
|
+
...(statement.alternate ? [`${indent}} else {`, ...alternate] : []),
|
|
675
|
+
`${indent}}`
|
|
676
|
+
];
|
|
677
|
+
}
|
|
678
|
+
case 'returnStatement': {
|
|
679
|
+
const target = this.expressionLoopReturns[this.expressionLoopReturns.length - 1];
|
|
680
|
+
return target
|
|
681
|
+
? [`${indent}${target}.push(${this.expression(statement.expression)});`]
|
|
682
|
+
: [`${indent}return ${this.expression(statement.expression)};`];
|
|
683
|
+
}
|
|
684
|
+
case 'tableDeclaration':
|
|
685
|
+
case 'chartDeclaration':
|
|
686
|
+
return [];
|
|
687
|
+
case 'showStatement':
|
|
688
|
+
return [`${indent}${this.emitShow(statement.name, statement.source)}`];
|
|
689
|
+
case 'diagramDeclaration':
|
|
690
|
+
return this.emitDiagram(statement, depth);
|
|
691
|
+
case 'typeDeclaration':
|
|
692
|
+
case 'enumDeclaration':
|
|
693
|
+
case 'functionDeclaration':
|
|
694
|
+
case 'dimensionDeclaration':
|
|
695
|
+
case 'unitDeclaration':
|
|
696
|
+
case 'inputDeclaration':
|
|
697
|
+
case 'importDeclaration':
|
|
698
|
+
case 'exportNamesDeclaration':
|
|
699
|
+
return [];
|
|
700
|
+
default:
|
|
701
|
+
{
|
|
702
|
+
const unmapped = statement;
|
|
703
|
+
throw new LoweringFailure(`AST node '${unmapped.type}' has no lowering rule`, unmapped.source?.line, unmapped.source?.column);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
emit() {
|
|
708
|
+
const statements = moduleStatements(this.module);
|
|
709
|
+
const code = [];
|
|
710
|
+
code.push(...rawFrontMatterComments(this.module.input.sourceText));
|
|
711
|
+
const runtimeStatements = [];
|
|
712
|
+
for (const node of this.module.document.nodes) {
|
|
713
|
+
if (node.type === 'narrative')
|
|
714
|
+
runtimeStatements.push(...safeNarrativeComments(node.content).map(line => ` ${line}`));
|
|
715
|
+
else if (node.type === 'variableDeclaration')
|
|
716
|
+
runtimeStatements.push(...this.emitStatement(node, 1));
|
|
717
|
+
else if (node.type === 'executableCodeBlock') {
|
|
718
|
+
for (const statement of node.statements)
|
|
719
|
+
runtimeStatements.push(...this.emitStatement(statement, 1));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const localDeclarations = statements.filter((statement) => statement.type === 'typeDeclaration' || statement.type === 'enumDeclaration');
|
|
723
|
+
const declarationCode = localDeclarations.map(statement => statement.type === 'typeDeclaration'
|
|
724
|
+
? this.emitTypeDeclaration(statement)
|
|
725
|
+
: this.emitEnumDeclaration(statement));
|
|
726
|
+
const functionCode = statements.filter((statement) => statement.type === 'functionDeclaration')
|
|
727
|
+
.map(statement => this.emitFunction(statement));
|
|
728
|
+
const dependencyImports = new Map();
|
|
729
|
+
for (const statement of statements) {
|
|
730
|
+
if (statement.type !== 'importDeclaration')
|
|
731
|
+
continue;
|
|
732
|
+
const dependency = this.module.imports.get(statement.path);
|
|
733
|
+
const specifier = this.module.importSpecifiers.get(statement.path);
|
|
734
|
+
if (!dependency || !specifier)
|
|
735
|
+
throw new LoweringFailure(`Missing resolved import context for '${statement.path}'`, statement.pathSource?.line, statement.pathSource?.column);
|
|
736
|
+
const key = dependency.input.outputPath;
|
|
737
|
+
const entry = dependencyImports.get(key) ?? { dependency, specifier, symbols: new Map() };
|
|
738
|
+
for (const imported of statement.names) {
|
|
739
|
+
if (dependency.check.exportedTypes.has(imported.name))
|
|
740
|
+
entry.symbols.set(imported.name, 'type');
|
|
741
|
+
else if (dependency.check.exportedEnums.has(imported.name) || dependency.check.exportedFunctions.has(imported.name)) {
|
|
742
|
+
entry.symbols.set(imported.name, 'value');
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
dependencyImports.set(key, entry);
|
|
746
|
+
}
|
|
747
|
+
const staticImports = [...dependencyImports.values()].map(({ dependency, specifier, symbols }) => {
|
|
748
|
+
const clauses = [`__amxInitialize as __amxInit_${hash(dependency.input.outputPath)}`];
|
|
749
|
+
for (const [name, kind] of symbols) {
|
|
750
|
+
const importedName = emittedName(dependency.input.outputPath, name);
|
|
751
|
+
const localName = this.name(name);
|
|
752
|
+
clauses.push(`${kind === 'type' ? 'type ' : ''}${importedName} as ${localName}`);
|
|
753
|
+
if (kind === 'type' && dependency.check.exportedTypes.has(name)) {
|
|
754
|
+
clauses.push(`type __AMXExternal_${importedName} as __AMXExternal_${localName}`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return `import { ${clauses.join(', ')} } from ${quote(specifier)};`;
|
|
758
|
+
});
|
|
759
|
+
const dependencyInitialization = [];
|
|
760
|
+
for (const [outputPath, { dependency }] of dependencyImports) {
|
|
761
|
+
const alias = `__amxInit_${hash(outputPath)}`;
|
|
762
|
+
const result = `__amxDependency_${hash(outputPath)}`;
|
|
763
|
+
dependencyInitialization.push(` const ${result} = ${alias}(__context);`);
|
|
764
|
+
for (const statement of statements) {
|
|
765
|
+
if (statement.type !== 'importDeclaration' || this.module.imports.get(statement.path)?.input.outputPath !== outputPath)
|
|
766
|
+
continue;
|
|
767
|
+
for (const imported of statement.names) {
|
|
768
|
+
if (!dependency.check.exportedBindings.has(imported.name))
|
|
769
|
+
continue;
|
|
770
|
+
const type = this.localTypes.get(imported.name);
|
|
771
|
+
if (!type)
|
|
772
|
+
throw new LoweringFailure(`Missing checked imported binding '${imported.name}'`, imported.source?.line, imported.source?.column);
|
|
773
|
+
dependencyInitialization.push(` const ${this.name(imported.name)} = ${result}[${quote(imported.name)}] as ${this.typeScriptType(type)};`);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const inputTypeFields = this.inputs.map(input => ` ${quoteIdentifier(input.name)}: ${this.typeScriptReference(input.annotation, true)};`).join('\n');
|
|
778
|
+
const validatedInputFields = this.inputs.map(input => ` ${quoteIdentifier(input.name)}: ${this.typeScriptReference(input.annotation, false)};`).join('\n');
|
|
779
|
+
const exportFields = [...this.module.check.exportedBindings].map(([name, type]) => ` ${quoteIdentifier(name)}: ${this.typeScriptType(type)};`).join('\n');
|
|
780
|
+
const exportValues = [...this.module.check.exportedBindings.keys()].map(name => `${quote(name)}: ${this.name(name)}`).join(', ');
|
|
781
|
+
const inputDescriptor = `{ kind: 'record', recordName: 'AMXRunInputs', fields: [${this.inputs.map(input => `{ name: ${quote(input.name)}, descriptor: ${this.inputDescriptor(input.annotation)} }`).join(', ')}] }`;
|
|
782
|
+
const unitDescriptors = [...this.module.check.units.keys()].map(name => this.unitDescriptor(name));
|
|
783
|
+
const generated = [
|
|
784
|
+
...code,
|
|
785
|
+
...staticImports,
|
|
786
|
+
`import { amxAdd1Based as __amxAdd1Based, amxAttach as __amxAttach, amxBinary as __amxBinary, amxBuiltin as __amxBuiltin, amxChartView as __amxChartView, amxConvert as __amxConvert, amxCopyListArgument as __amxCopyListArgument, amxDiagramView as __amxDiagramView, amxFormatValue as __amxFormatValue, amxGet1Based as __amxGet1Based, amxIsType as __amxIsType, amxIterate as __amxIterate, amxPhysicalValue as __amxPhysicalValue, amxRange as __amxRange, amxRemove1Based as __amxRemove1Based, amxTableView as __amxTableView, amxUnary as __amxUnary, validateAMXValue as __amxValidateValue, AMXInputError as __AMXInputError, AMXRuntimeError as __AMXRuntimeError, type AMXBuiltinName as __AMXBuiltinName, type AMXDiagramPrimitiveElement as __AMXDiagramPrimitiveElement, type AMXInputDescriptor as __AMXInputDescriptor, type AMXMeasurement as __AMXMeasurement, type AMXMeasurementInput as __AMXMeasurementInput, type AMXRunResult as __AMXRunResult, type AMXRuntimeContext as __AMXRuntimeContext, type AMXShownView as __AMXShownView, type AMXUnitDescriptor as __AMXUnitDescriptor, type AMXValue as __AMXValue, type AMXViewData as __AMXViewData } from 'openamx/transpiler-runtime';`,
|
|
787
|
+
...declarationCode,
|
|
788
|
+
...functionCode,
|
|
789
|
+
`const __amxUnits: readonly __AMXUnitDescriptor[] = [${unitDescriptors.join(', ')}];`,
|
|
790
|
+
`const __amxRuntime: __AMXRuntimeContext = { file: ${quote(this.sourceFile)}, unitDescriptors: __amxUnits };`,
|
|
791
|
+
...viewHelperSource(),
|
|
792
|
+
`interface __AMXRunContext { readonly modules: Map<string, unknown>; readonly views: __AMXShownView[] }`,
|
|
793
|
+
`export function __amxInitialize(__context: __AMXRunContext, __inputs: __AMXValidatedInputs = {} as __AMXValidatedInputs): Readonly<Record<string, unknown>> {`,
|
|
794
|
+
` if (__context.modules.has(${quote(this.module.input.outputPath)})) return __context.modules.get(${quote(this.module.input.outputPath)}) as Readonly<Record<string, unknown>>;`,
|
|
795
|
+
...dependencyInitialization,
|
|
796
|
+
...this.inputs.map(input => ` const ${this.name(input.name)} = __inputs[${quote(input.name)}];`),
|
|
797
|
+
...runtimeStatements,
|
|
798
|
+
` const __result: Readonly<Record<string, unknown>> = Object.freeze({ ${exportValues} });`,
|
|
799
|
+
` __context.modules.set(${quote(this.module.input.outputPath)}, __result);`,
|
|
800
|
+
` return __result;`,
|
|
801
|
+
`}`,
|
|
802
|
+
...(this.isEntry ? [
|
|
803
|
+
`export type AMXRunInputs = ${this.inputs.length ? `Readonly<{\n${inputTypeFields}\n}>` : 'Readonly<Record<string, never>>'};`,
|
|
804
|
+
`type __AMXValidatedInputs = ${this.inputs.length ? `Readonly<{\n${validatedInputFields}\n}>` : 'Readonly<Record<string, never>>'};`,
|
|
805
|
+
`export type AMXRunExports = ${this.module.check.exportedBindings.size ? `Readonly<{\n${exportFields}\n}>` : 'Readonly<Record<string, never>>'};`,
|
|
806
|
+
`export function run(inputs: AMXRunInputs): __AMXRunResult<AMXRunExports> {`,
|
|
807
|
+
` const __validated = __amxValidateValue<__AMXValidatedInputs>(inputs, ${inputDescriptor}, { file: ${quote(this.sourceFile)} });`,
|
|
808
|
+
` const __context: __AMXRunContext = { modules: new Map(), views: [] };`,
|
|
809
|
+
` const __exports = __amxInitialize(__context, __validated) as AMXRunExports;`,
|
|
810
|
+
` return { exports: __exports, views: Object.freeze(__context.views) };`,
|
|
811
|
+
`}`
|
|
812
|
+
] : [`type __AMXValidatedInputs = Readonly<Record<string, never>>;`])
|
|
813
|
+
];
|
|
814
|
+
return generated.join('\n') + '\n';
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function moduleStatements(module) {
|
|
818
|
+
return module.document.nodes.flatMap(node => node.type === 'executableCodeBlock'
|
|
819
|
+
? node.statements
|
|
820
|
+
: node.type === 'variableDeclaration' ? [node] : []);
|
|
821
|
+
}
|
|
822
|
+
function quoteIdentifier(name) {
|
|
823
|
+
return reservedWords.has(name) ? `[${quote(name)}]` : name;
|
|
824
|
+
}
|
|
825
|
+
function viewHelperSource() {
|
|
826
|
+
return [
|
|
827
|
+
`function __amxDiagramNumber(value: number, context: __AMXRuntimeContext, code: string, message: string, source: Readonly<{ file?: string; line?: number; column?: number }>, positive = false): number { if (!Number.isFinite(value) || positive && value <= 0) throw new __AMXRuntimeError({ code, message, file: source.file ?? context.file, line: source.line ?? context.line, column: source.column ?? context.column }); return value; }`,
|
|
828
|
+
`function __amxIsMeasurement(value: unknown): value is __AMXMeasurement { return typeof value === 'object' && value !== null && !Array.isArray(value) && '__amxMeasurement' in value && (value as { __amxMeasurement?: unknown }).__amxMeasurement === true; }`,
|
|
829
|
+
`function __amxSnapshotViewValue(value: unknown): __AMXViewData { if (value === null || typeof value === 'string' || typeof value === 'boolean') return value; if (typeof value === 'number') return value; if (Array.isArray(value)) return value.map(__amxSnapshotViewValue); if (__amxIsMeasurement(value)) return String(value.value) + ' ' + value.unit.text; if (typeof value === 'object') { const copy: Record<string, __AMXViewData> = {}; for (const [field, item] of Object.entries(value)) copy[field] = __amxSnapshotViewValue(item); return copy; } return null; }`,
|
|
830
|
+
`interface __AMXChartColumn { readonly role: 'series' | 'x' | 'y'; readonly field?: string; readonly label: string; readonly source?: Readonly<{ line?: number; column?: number }> }`,
|
|
831
|
+
`function __amxSameMeasurementDimension(left: __AMXMeasurement, right: __AMXMeasurement): boolean { const a = Object.entries(left.unit.vector); return a.length === Object.keys(right.unit.vector).length && a.every(([identity, exponent]) => right.unit.vector[identity] === exponent); }`,
|
|
832
|
+
`function __amxChartFailure(name: string, message: string, context: __AMXRuntimeContext, source?: __AMXChartColumn['source']): never { throw new __AMXRuntimeError({ code: 'AMX3007', message, file: context.file, line: source?.line ?? context.line, column: source?.column ?? context.column }); }`,
|
|
833
|
+
`function __amxChartValue(value: unknown, target: __AMXMeasurement | undefined, name: string, column: __AMXChartColumn | undefined, context: __AMXRuntimeContext): __AMXViewData { if (value === null || value === undefined) return null; if (!target) return __amxSnapshotViewValue(value); if (!__amxIsMeasurement(value) || !__amxSameMeasurementDimension(value, target)) return __amxChartFailure(name, 'Chart ' + name + ' contains an incompatible measurement value', context, column?.source); const converted = (__amxPhysicalValue(value) - target.unit.offset) / target.unit.scale; if (!Number.isFinite(converted)) return __amxChartFailure(name, 'Chart ' + name + ' measurement cannot be normalized to its first display unit', context, column?.source); return converted; }`,
|
|
834
|
+
`function __amxChartSnapshot(data: readonly unknown[], columns: readonly __AMXChartColumn[], name: string, scatter: boolean, context: __AMXRuntimeContext): { readonly data: readonly __AMXViewData[]; readonly headings: readonly string[]; readonly measurementDescriptors: readonly Readonly<{ role: 'series' | 'x' | 'y'; field?: string; label: string; unit: Readonly<{ text: string; scale: number; vector: Readonly<Record<string, number>>; factors: readonly Readonly<{ identity: string; name: string; exponent: number }>[] }> }>[] } { const chosen = columns.map(column => { const values = data.map(item => item !== null && typeof item === 'object' && !Array.isArray(item) && !__amxIsMeasurement(item) ? (item as Record<string, unknown>)[column.field ?? ''] : column.field === undefined ? item : undefined); const first = values.find(value => value !== null && value !== undefined); const target = __amxIsMeasurement(first) ? first : undefined; for (const value of values) { if (value === null || value === undefined) continue; if (target ? !__amxIsMeasurement(value) || !__amxSameMeasurementDimension(value, target) : __amxIsMeasurement(value)) __amxChartFailure(name, 'Chart ' + name + ' contains incompatible measurement dimensions', context, column.source); } return target; }); const headings = scatter ? (['x', 'y'] as const).map((axis, index) => chosen[index] ? axis + ' (' + chosen[index]!.unit.text + ')' : axis).concat('group') : ['label', ...columns.filter(column => column.role === 'series').map((column, index) => { const target = chosen[index]; return target ? column.label + ' (' + target.unit.text + ')' : column.label; })]; const measurementDescriptors = columns.flatMap((column, index) => { const target = chosen[index]; if (!target) return []; return [{ role: column.role, ...(column.field === undefined ? {} : { field: column.field }), label: column.label, unit: { text: target.unit.text, scale: target.unit.scale, vector: target.unit.vector, factors: target.unit.factors } }]; }); const normalized = data.map((item): __AMXViewData => { if (item !== null && typeof item === 'object' && !Array.isArray(item) && !__amxIsMeasurement(item)) { const values: Record<string, __AMXViewData> = {}; for (const [field, value] of Object.entries(item)) { const index = columns.findIndex(column => column.field === field); values[field] = index < 0 ? __amxSnapshotViewValue(value) : __amxChartValue(value, chosen[index], name, columns[index], context); } return values; } return __amxChartValue(item, chosen[0], name, columns[0], context); }); return { data: normalized, headings, measurementDescriptors }; }`
|
|
835
|
+
];
|
|
836
|
+
}
|
|
837
|
+
function emittedName(outputPath, name) {
|
|
838
|
+
return `__amx_${hash(outputPath)}_${name}`;
|
|
839
|
+
}
|
|
840
|
+
export function emitModule(module, isEntry, measurementDimensionIds) {
|
|
841
|
+
return new ModuleEmitter(module, isEntry, measurementDimensionIds).emit();
|
|
842
|
+
}
|