@creationix/rex 0.1.3 → 0.1.4
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/package.json +1 -1
- package/rex-compile.js +19 -4
- package/rex-compile.ts +23 -5
package/package.json
CHANGED
package/rex-compile.js
CHANGED
|
@@ -2148,6 +2148,7 @@ semantics.addOperation("toIR", {
|
|
|
2148
2148
|
// rex-compile.ts
|
|
2149
2149
|
import { dirname, resolve } from "node:path";
|
|
2150
2150
|
import { readFile, writeFile } from "node:fs/promises";
|
|
2151
|
+
var FIRST_NON_RESERVED_REF = 5;
|
|
2151
2152
|
function parseArgs(argv) {
|
|
2152
2153
|
const options = {
|
|
2153
2154
|
ir: false,
|
|
@@ -2300,10 +2301,24 @@ async function loadDomainRefsFromFolder(folderPath) {
|
|
|
2300
2301
|
throw new Error(`Invalid rex-domain.json at ${schemaPath}: expected { globals: { ... } }`);
|
|
2301
2302
|
}
|
|
2302
2303
|
const refs = {};
|
|
2303
|
-
|
|
2304
|
-
for (const name of Object.
|
|
2305
|
-
|
|
2306
|
-
|
|
2304
|
+
const seenRefIds = new Map;
|
|
2305
|
+
for (const [name, entry] of Object.entries(parsed.globals)) {
|
|
2306
|
+
if (!entry || typeof entry !== "object") {
|
|
2307
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: globals.${name} must be an object with a numeric ref`);
|
|
2308
|
+
}
|
|
2309
|
+
const ref = entry.ref;
|
|
2310
|
+
if (!Number.isInteger(ref)) {
|
|
2311
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: globals.${name}.ref must be an integer`);
|
|
2312
|
+
}
|
|
2313
|
+
if (ref < FIRST_NON_RESERVED_REF) {
|
|
2314
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: globals.${name}.ref must be >= ${FIRST_NON_RESERVED_REF} (0-4 are reserved built-ins)`);
|
|
2315
|
+
}
|
|
2316
|
+
const existing = seenRefIds.get(ref);
|
|
2317
|
+
if (existing) {
|
|
2318
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: duplicate ref ${ref} for globals.${existing} and globals.${name}`);
|
|
2319
|
+
}
|
|
2320
|
+
seenRefIds.set(ref, name);
|
|
2321
|
+
refs[name] = ref;
|
|
2307
2322
|
}
|
|
2308
2323
|
return refs;
|
|
2309
2324
|
}
|
package/rex-compile.ts
CHANGED
|
@@ -15,9 +15,11 @@ type CliOptions = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
type DomainSchema = {
|
|
18
|
-
globals?: Record<string, unknown>;
|
|
18
|
+
globals?: Record<string, { ref?: unknown }>;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
const FIRST_NON_RESERVED_REF = 5;
|
|
22
|
+
|
|
21
23
|
function parseArgs(argv: string[]): CliOptions {
|
|
22
24
|
const options: CliOptions = {
|
|
23
25
|
ir: false,
|
|
@@ -160,10 +162,26 @@ async function loadDomainRefsFromFolder(folderPath: string): Promise<Record<stri
|
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
const refs: Record<string, number> = {};
|
|
163
|
-
|
|
164
|
-
for (const name of Object.
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
const seenRefIds = new Map<number, string>();
|
|
166
|
+
for (const [name, entry] of Object.entries(parsed.globals)) {
|
|
167
|
+
if (!entry || typeof entry !== "object") {
|
|
168
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: globals.${name} must be an object with a numeric ref`);
|
|
169
|
+
}
|
|
170
|
+
const ref = entry.ref;
|
|
171
|
+
if (!Number.isInteger(ref)) {
|
|
172
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: globals.${name}.ref must be an integer`);
|
|
173
|
+
}
|
|
174
|
+
if (ref < FIRST_NON_RESERVED_REF) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Invalid rex-domain.json at ${schemaPath}: globals.${name}.ref must be >= ${FIRST_NON_RESERVED_REF} (0-4 are reserved built-ins)`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
const existing = seenRefIds.get(ref);
|
|
180
|
+
if (existing) {
|
|
181
|
+
throw new Error(`Invalid rex-domain.json at ${schemaPath}: duplicate ref ${ref} for globals.${existing} and globals.${name}`);
|
|
182
|
+
}
|
|
183
|
+
seenRefIds.set(ref, name);
|
|
184
|
+
refs[name] = ref;
|
|
167
185
|
}
|
|
168
186
|
return refs;
|
|
169
187
|
}
|