@fraczak/k 6.1.2 → 6.1.3

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.
@@ -9,7 +9,7 @@ in [`POLYMORPHIC_BINARY_FORMAT.md`](./POLYMORPHIC_BINARY_FORMAT.md):
9
9
  encode($pattern_value : $pattern) encode(value : decoded_pattern)
10
10
  ```
11
11
 
12
- ## Purpose Of This File
12
+ ## Purpose of This File
13
13
 
14
14
  This file records constraints for any future optimized container layered above
15
15
  the canonical stream.
@@ -288,7 +288,7 @@ Decoding the stream yields `Value(pattern, tree)`. Encoding a runtime `Value`
288
288
  uses its carried pattern by default, or an explicit caller-supplied pattern when
289
289
  one is provided.
290
290
 
291
- ## Out Of Scope For The Base Codec
291
+ ## Out of Scope for the Base Codec
292
292
 
293
293
  The following are intentionally outside the primitive codec:
294
294
 
package/codes.mjs CHANGED
@@ -248,43 +248,24 @@ function finalizeIncremental(newCodes) {
248
248
  }
249
249
  }
250
250
 
251
- const representatives = minimize(resolvedCodes).representatives;
252
- for (const name in refResolution) {
253
- if (refResolution[name] !== name) {
254
- const target = refResolution[name];
255
- representatives[name] = representatives[target] || target;
256
- }
257
- }
251
+ const reachableCodes = {};
252
+ const queue = Object.keys(resolvedCodes);
253
+ while (queue.length > 0) {
254
+ const name = queue.shift();
255
+ if (reachableCodes[name]) continue;
258
256
 
259
- const normalizedCodes = normalizeAll(resolvedCodes, representatives);
260
- const allReadableCodes = { ...theRepository.codes, ...normalizedCodes };
261
- const globalNames = {};
257
+ const code = resolvedCodes[name] || theRepository.codes[name];
258
+ if (code == null) {
259
+ throw new Error(`Type references undefined type: ${name}`);
260
+ }
261
+ reachableCodes[name] = code;
262
262
 
263
- for (const name in normalizedCodes) {
264
- const globalDef = encodeCodeToString(name, allReadableCodes);
265
- normalizedCodes[name].def = globalDef;
266
- globalNames[name] = hash(globalDef);
263
+ for (const dest of Object.values(code[code.code] || {})) {
264
+ if (!reachableCodes[dest]) queue.push(dest);
265
+ }
267
266
  }
268
267
 
269
- const globalCodes = Object.keys(normalizedCodes).reduce((result, name) => {
270
- result[globalNames[name]] = normalizedCodes[name];
271
- return result;
272
- }, {});
273
-
274
- const extendedRepresentatives = Object.keys(representatives).reduce((result, name) => {
275
- result[name] = globalNames[representatives[name]] || representatives[name] || name;
276
- return result;
277
- }, {});
278
-
279
- Object.values(globalNames).forEach((name) => {
280
- extendedRepresentatives[name] = name;
281
- });
282
-
283
- const normalizedGlobalCodes = normalizeAll(globalCodes, extendedRepresentatives);
284
- return {
285
- codes: normalizedGlobalCodes,
286
- representatives: extendedRepresentatives
287
- };
268
+ return finalize(reachableCodes);
288
269
  }
289
270
 
290
271
  function register(newCodes) {
package/export.mjs CHANGED
@@ -87,13 +87,13 @@ function theID(alias, rel, scc, name) {
87
87
  break;
88
88
  case "ref": {
89
89
  const n = rel.ref;
90
- if (alias[n] != undefined) {
91
- newRel.ref = alias[n];
92
- } else if (auxNames[n] != undefined) {
90
+ if (auxNames[n] != undefined) {
93
91
  newRel.ref = auxNames[n];
94
92
  } else if (sccNames.has(n)) {
95
93
  auxNames[n] = `X${Object.keys(auxNames).length}`;
96
94
  newRel.ref = auxNames[n];
95
+ } else if (alias[n] != undefined) {
96
+ newRel.ref = alias[n];
97
97
  };
98
98
  }; break;
99
99
  default: