@hey-api/codegen-core 0.8.4 → 0.9.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/README.md +25 -13
- package/dist/index.d.mts +120 -35
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +214 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,9 @@ function detectInteractiveSession() {
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/config/merge.ts
|
|
21
21
|
function isPlainObject(value) {
|
|
22
|
-
|
|
22
|
+
if (typeof value !== "object" || value === null) return false;
|
|
23
|
+
const proto = Object.getPrototypeOf(value);
|
|
24
|
+
return proto === Object.prototype || proto === null;
|
|
23
25
|
}
|
|
24
26
|
function mergeConfigs(configA, configB) {
|
|
25
27
|
const a = configA || {};
|
|
@@ -283,7 +285,8 @@ var File = class {
|
|
|
283
285
|
* Returns a debug‑friendly string representation identifying the file.
|
|
284
286
|
*/
|
|
285
287
|
toString() {
|
|
286
|
-
|
|
288
|
+
const finalPath = this._finalPath ? ` → ${this._finalPath}` : "";
|
|
289
|
+
return `${`${this._finalPath ? "✓" : "~"} `}File#${this.id} ${this._logicalFilePath}${finalPath}`;
|
|
287
290
|
}
|
|
288
291
|
};
|
|
289
292
|
//#endregion
|
|
@@ -542,10 +545,10 @@ var FileRegistry = class {
|
|
|
542
545
|
* const r2 = ref(r); // { '~ref': 123 } (not double-wrapped)
|
|
543
546
|
* ```
|
|
544
547
|
*/
|
|
545
|
-
|
|
548
|
+
function ref(value) {
|
|
546
549
|
if (isRef(value)) return value;
|
|
547
550
|
return { "~ref": value };
|
|
548
|
-
}
|
|
551
|
+
}
|
|
549
552
|
/**
|
|
550
553
|
* Converts a plain object to an object of Refs (deep, per property).
|
|
551
554
|
*
|
|
@@ -555,11 +558,11 @@ const ref = (value) => {
|
|
|
555
558
|
* const refs = refs(obj); // { a: { '~ref': 1 }, b: { '~ref': "x" } }
|
|
556
559
|
* ```
|
|
557
560
|
*/
|
|
558
|
-
|
|
561
|
+
function refs(obj) {
|
|
559
562
|
const result = {};
|
|
560
563
|
for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) result[key] = ref(obj[key]);
|
|
561
564
|
return result;
|
|
562
|
-
}
|
|
565
|
+
}
|
|
563
566
|
/**
|
|
564
567
|
* Unwraps a single Ref object to its value.
|
|
565
568
|
*
|
|
@@ -570,7 +573,9 @@ const refs = (obj) => {
|
|
|
570
573
|
* console.log(n); // 42
|
|
571
574
|
* ```
|
|
572
575
|
*/
|
|
573
|
-
|
|
576
|
+
function fromRef(ref) {
|
|
577
|
+
return ref?.["~ref"];
|
|
578
|
+
}
|
|
574
579
|
/**
|
|
575
580
|
* Converts an object of Refs back to a plain object (unwraps all refs).
|
|
576
581
|
*
|
|
@@ -580,18 +585,20 @@ const fromRef = (ref) => ref?.["~ref"];
|
|
|
580
585
|
* const plain = fromRefs(refs); // { a: 1, b: "x" }
|
|
581
586
|
* ```
|
|
582
587
|
*/
|
|
583
|
-
|
|
588
|
+
function fromRefs(obj) {
|
|
584
589
|
const result = {};
|
|
585
590
|
for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) result[key] = fromRef(obj[key]);
|
|
586
591
|
return result;
|
|
587
|
-
}
|
|
592
|
+
}
|
|
588
593
|
/**
|
|
589
594
|
* Checks whether a value is a Ref object.
|
|
590
595
|
*
|
|
591
596
|
* @param value Value to check
|
|
592
597
|
* @returns True if the value is a Ref object.
|
|
593
598
|
*/
|
|
594
|
-
|
|
599
|
+
function isRef(value) {
|
|
600
|
+
return typeof value === "object" && value !== null && "~ref" in value;
|
|
601
|
+
}
|
|
595
602
|
//#endregion
|
|
596
603
|
//#region src/nodes/registry.ts
|
|
597
604
|
var NodeRegistry = class {
|
|
@@ -664,17 +671,20 @@ function registerChildName(scope, name, kind) {
|
|
|
664
671
|
//#endregion
|
|
665
672
|
//#region src/planner/analyzer.ts
|
|
666
673
|
var AnalysisContext = class {
|
|
674
|
+
/** Arbitrary project metadata. */
|
|
675
|
+
meta;
|
|
667
676
|
/**
|
|
668
677
|
* Stack of parent nodes during analysis.
|
|
669
678
|
*
|
|
670
679
|
* The top of the stack is the current semantic container.
|
|
671
680
|
*/
|
|
672
|
-
|
|
681
|
+
parentStack = [];
|
|
673
682
|
scope;
|
|
674
683
|
scopes = createScope();
|
|
675
684
|
symbol;
|
|
676
|
-
constructor(node) {
|
|
677
|
-
this.
|
|
685
|
+
constructor(node, meta) {
|
|
686
|
+
this.parentStack.push(node);
|
|
687
|
+
this.meta = meta;
|
|
678
688
|
this.scope = this.scopes;
|
|
679
689
|
this.symbol = node.symbol;
|
|
680
690
|
}
|
|
@@ -682,7 +692,7 @@ var AnalysisContext = class {
|
|
|
682
692
|
* Get the current semantic parent (top of stack).
|
|
683
693
|
*/
|
|
684
694
|
get currentParent() {
|
|
685
|
-
return this.
|
|
695
|
+
return this.parentStack[this.parentStack.length - 1];
|
|
686
696
|
}
|
|
687
697
|
/**
|
|
688
698
|
* Register a child node under the current parent.
|
|
@@ -708,6 +718,7 @@ var AnalysisContext = class {
|
|
|
708
718
|
const node = fromRef(value);
|
|
709
719
|
this.addChild(node, "container");
|
|
710
720
|
this.pushParent(node);
|
|
721
|
+
node.meta = this.meta[node.language] ?? {};
|
|
711
722
|
node.analyze(this);
|
|
712
723
|
this.popParent();
|
|
713
724
|
}
|
|
@@ -736,7 +747,7 @@ var AnalysisContext = class {
|
|
|
736
747
|
* Call this when exiting a container node.
|
|
737
748
|
*/
|
|
738
749
|
popParent() {
|
|
739
|
-
this.
|
|
750
|
+
this.parentStack.pop();
|
|
740
751
|
}
|
|
741
752
|
popScope() {
|
|
742
753
|
this.scope = this.scope.parent ?? this.scope;
|
|
@@ -745,7 +756,7 @@ var AnalysisContext = class {
|
|
|
745
756
|
* Push a node as the current semantic parent.
|
|
746
757
|
*/
|
|
747
758
|
pushParent(node) {
|
|
748
|
-
this.
|
|
759
|
+
this.parentStack.push(node);
|
|
749
760
|
}
|
|
750
761
|
pushScope() {
|
|
751
762
|
const scope = createScope({ parent: this.scope });
|
|
@@ -763,12 +774,17 @@ var AnalysisContext = class {
|
|
|
763
774
|
}
|
|
764
775
|
};
|
|
765
776
|
var Analyzer = class {
|
|
777
|
+
meta;
|
|
766
778
|
nodeCache = /* @__PURE__ */ new WeakMap();
|
|
779
|
+
constructor(meta) {
|
|
780
|
+
this.meta = meta;
|
|
781
|
+
}
|
|
767
782
|
analyzeNode(node) {
|
|
768
783
|
const cached = this.nodeCache.get(node);
|
|
769
784
|
if (cached) return cached;
|
|
770
785
|
node.root = true;
|
|
771
|
-
|
|
786
|
+
node.meta = this.meta[node.language] ?? {};
|
|
787
|
+
const ctx = new AnalysisContext(node, this.meta);
|
|
772
788
|
node.analyze(ctx);
|
|
773
789
|
this.nodeCache.set(node, ctx);
|
|
774
790
|
return ctx;
|
|
@@ -783,21 +799,26 @@ var Analyzer = class {
|
|
|
783
799
|
//#endregion
|
|
784
800
|
//#region src/planner/planner.ts
|
|
785
801
|
const isTypeOnlyKind = (kind) => kind === "type" || kind === "interface";
|
|
786
|
-
var Planner = class {
|
|
787
|
-
|
|
802
|
+
var Planner = class Planner {
|
|
803
|
+
static MAX_ALLOCATION_ROUNDS = 100;
|
|
804
|
+
analyzer;
|
|
788
805
|
cacheResolvedNames = /* @__PURE__ */ new Set();
|
|
789
806
|
project;
|
|
790
807
|
constructor(project) {
|
|
808
|
+
this.analyzer = new Analyzer(project.meta);
|
|
791
809
|
this.project = project;
|
|
792
810
|
}
|
|
793
811
|
/**
|
|
794
812
|
* Executes the planning phase for the project.
|
|
795
813
|
*/
|
|
796
|
-
plan(
|
|
814
|
+
plan() {
|
|
797
815
|
this.cacheResolvedNames.clear();
|
|
798
|
-
|
|
799
|
-
this.
|
|
800
|
-
|
|
816
|
+
let rounds = 0;
|
|
817
|
+
while (this.allocateFiles()) {
|
|
818
|
+
this.assignLocalNames();
|
|
819
|
+
if (++rounds > Planner.MAX_ALLOCATION_ROUNDS) throw new Error(`File allocation failed to converge after ${Planner.MAX_ALLOCATION_ROUNDS} rounds`);
|
|
820
|
+
}
|
|
821
|
+
this.resolveFilePaths();
|
|
801
822
|
this.planExports();
|
|
802
823
|
this.planImports();
|
|
803
824
|
}
|
|
@@ -806,21 +827,25 @@ var Planner = class {
|
|
|
806
827
|
* and external dependency.
|
|
807
828
|
*/
|
|
808
829
|
allocateFiles() {
|
|
830
|
+
let allocated = 0;
|
|
809
831
|
this.analyzer.analyze(this.project.nodes.all(), (ctx, node) => {
|
|
810
832
|
const symbol = node.symbol;
|
|
811
833
|
if (!symbol) return;
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
834
|
+
if (!symbol.file) {
|
|
835
|
+
const file = this.project.files.register({
|
|
836
|
+
external: false,
|
|
837
|
+
language: node.language,
|
|
838
|
+
logicalFilePath: symbol.getFilePath?.(symbol) || this.project.defaultFileName
|
|
839
|
+
});
|
|
840
|
+
file.addNode(node);
|
|
841
|
+
symbol.setFile(file);
|
|
842
|
+
allocated++;
|
|
843
|
+
for (const logicalFilePath of symbol.getExportFromFilePath?.(symbol) ?? []) this.project.files.register({
|
|
844
|
+
external: false,
|
|
845
|
+
language: file.language,
|
|
846
|
+
logicalFilePath
|
|
847
|
+
});
|
|
848
|
+
}
|
|
824
849
|
ctx.walkScopes((dependency) => {
|
|
825
850
|
const dep = fromRef(dependency);
|
|
826
851
|
if (dep.external && dep.isCanonical && !dep.file) {
|
|
@@ -830,9 +855,11 @@ var Planner = class {
|
|
|
830
855
|
logicalFilePath: dep.external
|
|
831
856
|
});
|
|
832
857
|
dep.setFile(file);
|
|
858
|
+
allocated++;
|
|
833
859
|
}
|
|
834
860
|
});
|
|
835
861
|
});
|
|
862
|
+
return allocated;
|
|
836
863
|
}
|
|
837
864
|
/**
|
|
838
865
|
* Assigns final names to all symbols.
|
|
@@ -840,7 +867,11 @@ var Planner = class {
|
|
|
840
867
|
* First assigns top-level (file-scoped) symbol names, then local symbols.
|
|
841
868
|
*/
|
|
842
869
|
assignLocalNames() {
|
|
843
|
-
this.
|
|
870
|
+
const sorted = [...this.project.nodes.all()].sort((a, b) => {
|
|
871
|
+
const pa = a.symbol?.priority ?? 0;
|
|
872
|
+
return (b.symbol?.priority ?? 0) - pa;
|
|
873
|
+
});
|
|
874
|
+
this.analyzer.analyze(sorted, (ctx, node) => {
|
|
844
875
|
const symbol = node.symbol;
|
|
845
876
|
if (!symbol) return;
|
|
846
877
|
this.assignTopLevelName({
|
|
@@ -854,7 +885,7 @@ var Planner = class {
|
|
|
854
885
|
if (!file) return;
|
|
855
886
|
ctx.walkScopes((dependency) => {
|
|
856
887
|
const dep = fromRef(dependency);
|
|
857
|
-
if (dep.file) return;
|
|
888
|
+
if (dep.file || dep.external) return;
|
|
858
889
|
this.assignLocalName({
|
|
859
890
|
ctx,
|
|
860
891
|
file,
|
|
@@ -871,7 +902,7 @@ var Planner = class {
|
|
|
871
902
|
*
|
|
872
903
|
* Resolves final paths relative to the project's root directory.
|
|
873
904
|
*/
|
|
874
|
-
resolveFilePaths(
|
|
905
|
+
resolveFilePaths() {
|
|
875
906
|
for (const file of this.project.files.registered()) {
|
|
876
907
|
if (file.external) {
|
|
877
908
|
file.setFinalPath(file.logicalFilePath);
|
|
@@ -883,7 +914,6 @@ var Planner = class {
|
|
|
883
914
|
if (finalPath) file.setFinalPath(path.resolve(this.project.root, finalPath));
|
|
884
915
|
const ctx = {
|
|
885
916
|
file,
|
|
886
|
-
meta,
|
|
887
917
|
project: this.project
|
|
888
918
|
};
|
|
889
919
|
const renderer = this.project.renderers.find((r) => r.supports(ctx));
|
|
@@ -1018,6 +1048,7 @@ var Planner = class {
|
|
|
1018
1048
|
symbol: imp
|
|
1019
1049
|
};
|
|
1020
1050
|
fileMap.set(key, entry);
|
|
1051
|
+
dep.addImport(imp);
|
|
1021
1052
|
}
|
|
1022
1053
|
entry.kinds.add(dep.kind);
|
|
1023
1054
|
dependency["~ref"] = entry.symbol;
|
|
@@ -1203,12 +1234,24 @@ var Symbol = class {
|
|
|
1203
1234
|
*/
|
|
1204
1235
|
_importKind;
|
|
1205
1236
|
/**
|
|
1237
|
+
* Per-file imported instances of this symbol.
|
|
1238
|
+
*
|
|
1239
|
+
* @default []
|
|
1240
|
+
*/
|
|
1241
|
+
_imports = [];
|
|
1242
|
+
/**
|
|
1206
1243
|
* Kind of symbol (class, type, alias, etc.).
|
|
1207
1244
|
*
|
|
1208
1245
|
* @default 'var'
|
|
1209
1246
|
*/
|
|
1210
1247
|
_kind;
|
|
1211
1248
|
/**
|
|
1249
|
+
* Registered event listeners keyed by event name.
|
|
1250
|
+
*
|
|
1251
|
+
* @default {}
|
|
1252
|
+
*/
|
|
1253
|
+
_listeners = {};
|
|
1254
|
+
/**
|
|
1212
1255
|
* Arbitrary user metadata.
|
|
1213
1256
|
*
|
|
1214
1257
|
* @default undefined
|
|
@@ -1230,6 +1273,13 @@ var Symbol = class {
|
|
|
1230
1273
|
* @default false
|
|
1231
1274
|
*/
|
|
1232
1275
|
_override;
|
|
1276
|
+
/**
|
|
1277
|
+
* Naming priority. Higher value wins the canonical name when
|
|
1278
|
+
* multiple symbols in the same file compete for the same identifier.
|
|
1279
|
+
*
|
|
1280
|
+
* @default 0
|
|
1281
|
+
*/
|
|
1282
|
+
_priority;
|
|
1233
1283
|
/** Brand used for identifying symbols. */
|
|
1234
1284
|
"~brand" = symbolBrand;
|
|
1235
1285
|
/** Globally unique, stable symbol ID. */
|
|
@@ -1246,6 +1296,7 @@ var Symbol = class {
|
|
|
1246
1296
|
this._meta = input.meta;
|
|
1247
1297
|
this._name = input.name;
|
|
1248
1298
|
this._override = input.override ?? false;
|
|
1299
|
+
this._priority = input.priority ?? 0;
|
|
1249
1300
|
}
|
|
1250
1301
|
/**
|
|
1251
1302
|
* Returns the canonical symbol for this instance.
|
|
@@ -1313,12 +1364,24 @@ var Symbol = class {
|
|
|
1313
1364
|
return this.canonical._importKind;
|
|
1314
1365
|
}
|
|
1315
1366
|
/**
|
|
1367
|
+
* Read-only accessor for the per-file imported instances of this symbol.
|
|
1368
|
+
*/
|
|
1369
|
+
get imports() {
|
|
1370
|
+
return this.canonical._imports;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1316
1373
|
* Indicates whether this is a canonical symbol (not a stub).
|
|
1317
1374
|
*/
|
|
1318
1375
|
get isCanonical() {
|
|
1319
1376
|
return !this._canonical || this._canonical === this;
|
|
1320
1377
|
}
|
|
1321
1378
|
/**
|
|
1379
|
+
* Indicates whether this symbol was renamed during conflict resolution.
|
|
1380
|
+
*/
|
|
1381
|
+
get isRenamed() {
|
|
1382
|
+
return Boolean(this.canonical._finalName) && this.canonical._finalName !== this.canonical._name;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1322
1385
|
* The symbol's kind (class, type, alias, variable, etc.).
|
|
1323
1386
|
*/
|
|
1324
1387
|
get kind() {
|
|
@@ -1349,12 +1412,40 @@ var Symbol = class {
|
|
|
1349
1412
|
return this.canonical._override;
|
|
1350
1413
|
}
|
|
1351
1414
|
/**
|
|
1415
|
+
* Naming priority. Higher value wins the canonical name when
|
|
1416
|
+
* multiple symbols in the same file compete for the same identifier.
|
|
1417
|
+
*/
|
|
1418
|
+
get priority() {
|
|
1419
|
+
return this.canonical._priority;
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Registers a per-file imported instance of this symbol.
|
|
1423
|
+
*
|
|
1424
|
+
* @param symbol The imported instance to register.
|
|
1425
|
+
*/
|
|
1426
|
+
addImport(symbol) {
|
|
1427
|
+
this.assertCanonical();
|
|
1428
|
+
this._imports.push(symbol);
|
|
1429
|
+
this.emit("import", { symbol });
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Registers a listener for the given symbol lifecycle event.
|
|
1433
|
+
*
|
|
1434
|
+
* @param event The event to subscribe to.
|
|
1435
|
+
* @param listener Callback invoked when the event is emitted.
|
|
1436
|
+
* @returns `this` for chaining.
|
|
1437
|
+
*/
|
|
1438
|
+
on(event, listener) {
|
|
1439
|
+
(this.canonical._listeners[event] ??= []).push(listener);
|
|
1440
|
+
return this;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1352
1443
|
* Marks this symbol as a stub and assigns its canonical symbol.
|
|
1353
1444
|
*
|
|
1354
1445
|
* After calling this, all semantic queries (name, kind, file,
|
|
1355
1446
|
* meta, etc.) should reflect the canonical symbol's values.
|
|
1356
1447
|
*
|
|
1357
|
-
* @param symbol
|
|
1448
|
+
* @param symbol The canonical symbol this stub should resolve to.
|
|
1358
1449
|
*/
|
|
1359
1450
|
setCanonical(symbol) {
|
|
1360
1451
|
this._canonical = symbol;
|
|
@@ -1362,7 +1453,7 @@ var Symbol = class {
|
|
|
1362
1453
|
/**
|
|
1363
1454
|
* Assigns the child symbol bindings associated with this symbol.
|
|
1364
1455
|
*
|
|
1365
|
-
* @param children
|
|
1456
|
+
* @param children Child bindings to associate with the symbol.
|
|
1366
1457
|
*/
|
|
1367
1458
|
setChildren(children) {
|
|
1368
1459
|
this.assertCanonical();
|
|
@@ -1371,7 +1462,7 @@ var Symbol = class {
|
|
|
1371
1462
|
/**
|
|
1372
1463
|
* Marks the symbol as exported from its file.
|
|
1373
1464
|
*
|
|
1374
|
-
* @param exported
|
|
1465
|
+
* @param exported Whether the symbol is exported.
|
|
1375
1466
|
*/
|
|
1376
1467
|
setExported(exported) {
|
|
1377
1468
|
this.assertCanonical();
|
|
@@ -1390,6 +1481,10 @@ var Symbol = class {
|
|
|
1390
1481
|
throw new Error(message);
|
|
1391
1482
|
}
|
|
1392
1483
|
this._file = file;
|
|
1484
|
+
this.emit("file", {
|
|
1485
|
+
file,
|
|
1486
|
+
symbol: this
|
|
1487
|
+
});
|
|
1393
1488
|
}
|
|
1394
1489
|
/**
|
|
1395
1490
|
* Assigns the conflict‑resolved final local name for this symbol.
|
|
@@ -1404,11 +1499,15 @@ var Symbol = class {
|
|
|
1404
1499
|
throw new Error(message);
|
|
1405
1500
|
}
|
|
1406
1501
|
this._finalName = name;
|
|
1502
|
+
this.emit("finalName", {
|
|
1503
|
+
finalName: name,
|
|
1504
|
+
symbol: this
|
|
1505
|
+
});
|
|
1407
1506
|
}
|
|
1408
1507
|
/**
|
|
1409
1508
|
* Sets how this symbol should be imported.
|
|
1410
1509
|
*
|
|
1411
|
-
* @param kind
|
|
1510
|
+
* @param kind The import strategy (named/default/namespace).
|
|
1412
1511
|
*/
|
|
1413
1512
|
setImportKind(kind) {
|
|
1414
1513
|
this.assertCanonical();
|
|
@@ -1417,7 +1516,7 @@ var Symbol = class {
|
|
|
1417
1516
|
/**
|
|
1418
1517
|
* Sets the symbol's kind (class, type, alias, variable, etc.).
|
|
1419
1518
|
*
|
|
1420
|
-
* @param kind
|
|
1519
|
+
* @param kind The new symbol kind.
|
|
1421
1520
|
*/
|
|
1422
1521
|
setKind(kind) {
|
|
1423
1522
|
this.assertCanonical();
|
|
@@ -1426,7 +1525,7 @@ var Symbol = class {
|
|
|
1426
1525
|
/**
|
|
1427
1526
|
* Updates the intended user‑facing name for this symbol.
|
|
1428
1527
|
*
|
|
1429
|
-
* @param name
|
|
1528
|
+
* @param name The new name.
|
|
1430
1529
|
*/
|
|
1431
1530
|
setName(name) {
|
|
1432
1531
|
this.assertCanonical();
|
|
@@ -1449,7 +1548,7 @@ var Symbol = class {
|
|
|
1449
1548
|
/**
|
|
1450
1549
|
* Marks whether this symbol should be treated as an override.
|
|
1451
1550
|
*
|
|
1452
|
-
* @param override
|
|
1551
|
+
* @param override Override marker value.
|
|
1453
1552
|
*/
|
|
1454
1553
|
setOverride(override) {
|
|
1455
1554
|
this.assertCanonical();
|
|
@@ -1459,9 +1558,15 @@ var Symbol = class {
|
|
|
1459
1558
|
* Returns a debug‑friendly string representation identifying the symbol.
|
|
1460
1559
|
*/
|
|
1461
1560
|
toString() {
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1561
|
+
const c = this.canonical;
|
|
1562
|
+
const status = `${this._finalName ? "✓" : "~"} `;
|
|
1563
|
+
let renamed = "";
|
|
1564
|
+
let file = "";
|
|
1565
|
+
if (c._finalName) {
|
|
1566
|
+
renamed = c._finalName !== c._name ? ` → "${c._finalName}"` : "";
|
|
1567
|
+
file = c._file ? ` ${c._file.logicalFilePath}` : "";
|
|
1568
|
+
}
|
|
1569
|
+
return `${status}Symbol#${c.id} "${c._name}"${renamed}${file}`;
|
|
1465
1570
|
}
|
|
1466
1571
|
/**
|
|
1467
1572
|
* Ensures this symbol is canonical before allowing mutation.
|
|
@@ -1480,6 +1585,17 @@ var Symbol = class {
|
|
|
1480
1585
|
throw new Error(message);
|
|
1481
1586
|
}
|
|
1482
1587
|
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Invokes all registered listeners for the given event.
|
|
1590
|
+
*
|
|
1591
|
+
* @param event The event to emit.
|
|
1592
|
+
* @param args Arguments forwarded to each listener.
|
|
1593
|
+
*/
|
|
1594
|
+
emit(event, ...args) {
|
|
1595
|
+
const listeners = this._listeners[event];
|
|
1596
|
+
if (!listeners) return;
|
|
1597
|
+
for (const listener of listeners) listener(...args);
|
|
1598
|
+
}
|
|
1483
1599
|
};
|
|
1484
1600
|
//#endregion
|
|
1485
1601
|
//#region src/symbols/registry.ts
|
|
@@ -1653,6 +1769,7 @@ var SymbolRegistry = class {
|
|
|
1653
1769
|
var Project = class {
|
|
1654
1770
|
_isPlanned = false;
|
|
1655
1771
|
files;
|
|
1772
|
+
meta;
|
|
1656
1773
|
nodes = new NodeRegistry();
|
|
1657
1774
|
symbols = new SymbolRegistry();
|
|
1658
1775
|
defaultFileName;
|
|
@@ -1664,6 +1781,7 @@ var Project = class {
|
|
|
1664
1781
|
renderers;
|
|
1665
1782
|
root;
|
|
1666
1783
|
constructor(args) {
|
|
1784
|
+
this.meta = args.meta ?? {};
|
|
1667
1785
|
const fileName = args.fileName;
|
|
1668
1786
|
this.defaultFileName = args.defaultFileName ?? "main";
|
|
1669
1787
|
this.defaultNameConflictResolver = args.defaultNameConflictResolver ?? simpleNameConflictResolver;
|
|
@@ -1684,18 +1802,17 @@ var Project = class {
|
|
|
1684
1802
|
this.renderers = args.renderers ?? [];
|
|
1685
1803
|
this.root = path.resolve(args.root).replace(/[/\\]+$/, "");
|
|
1686
1804
|
}
|
|
1687
|
-
plan(
|
|
1805
|
+
plan() {
|
|
1688
1806
|
if (this._isPlanned) return;
|
|
1689
|
-
new Planner(this).plan(
|
|
1807
|
+
new Planner(this).plan();
|
|
1690
1808
|
this._isPlanned = true;
|
|
1691
1809
|
}
|
|
1692
|
-
render(
|
|
1693
|
-
if (!this._isPlanned) this.plan(
|
|
1810
|
+
render() {
|
|
1811
|
+
if (!this._isPlanned) this.plan();
|
|
1694
1812
|
const files = [];
|
|
1695
1813
|
for (const file of this.files.registered()) if (!file.external && file.finalPath && file.renderer) {
|
|
1696
1814
|
const content = file.renderer.render({
|
|
1697
1815
|
file,
|
|
1698
|
-
meta,
|
|
1699
1816
|
project: this
|
|
1700
1817
|
});
|
|
1701
1818
|
files.push({
|
|
@@ -1842,6 +1959,48 @@ var StructureModel = class {
|
|
|
1842
1959
|
}
|
|
1843
1960
|
};
|
|
1844
1961
|
//#endregion
|
|
1845
|
-
|
|
1962
|
+
//#region src/version.ts
|
|
1963
|
+
var Version = class Version {
|
|
1964
|
+
_segments;
|
|
1965
|
+
raw;
|
|
1966
|
+
constructor(version) {
|
|
1967
|
+
this.raw = version;
|
|
1968
|
+
this._segments = version.split(".").map((segment) => {
|
|
1969
|
+
const num = Number.parseInt(segment, 10);
|
|
1970
|
+
if (Number.isNaN(num)) throw new Error(`Invalid version segment "${segment}" in "${version}"`);
|
|
1971
|
+
return num;
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
_compare(other) {
|
|
1975
|
+
const b = other instanceof Version ? other : new Version(other);
|
|
1976
|
+
const len = Math.max(this._segments.length, b._segments.length);
|
|
1977
|
+
for (let i = 0; i < len; i++) {
|
|
1978
|
+
const a = this._segments[i] ?? 0;
|
|
1979
|
+
const bSeg = b._segments[i] ?? 0;
|
|
1980
|
+
if (a !== bSeg) return a - bSeg;
|
|
1981
|
+
}
|
|
1982
|
+
return 0;
|
|
1983
|
+
}
|
|
1984
|
+
eq(other) {
|
|
1985
|
+
return this._compare(other) === 0;
|
|
1986
|
+
}
|
|
1987
|
+
gt(other) {
|
|
1988
|
+
return this._compare(other) > 0;
|
|
1989
|
+
}
|
|
1990
|
+
gte(other) {
|
|
1991
|
+
return this._compare(other) >= 0;
|
|
1992
|
+
}
|
|
1993
|
+
lt(other) {
|
|
1994
|
+
return this._compare(other) < 0;
|
|
1995
|
+
}
|
|
1996
|
+
lte(other) {
|
|
1997
|
+
return this._compare(other) <= 0;
|
|
1998
|
+
}
|
|
1999
|
+
toString() {
|
|
2000
|
+
return this.raw;
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
//#endregion
|
|
2004
|
+
export { File, Logger, Project, StructureModel, StructureNode, Symbol, Version, defaultExtensions, defaultModuleEntryNames, defaultNameConflictResolvers, detectInteractiveSession, fromRef, fromRefs, isNode, isNodeRef, isRef, isSymbol, isSymbolRef, loadConfigFile, log, mergeConfigs, nodeBrand, pythonNameConflictResolver, ref, refs, simpleNameConflictResolver, symbolBrand, underscoreNameConflictResolver };
|
|
1846
2005
|
|
|
1847
2006
|
//# sourceMappingURL=index.mjs.map
|