@kubb/ast 5.18.2 → 5.18.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.
- package/dist/index.cjs +17 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -699,6 +699,12 @@ function extractStringsFromNodes(nodes) {
|
|
|
699
699
|
return collected.join("\n");
|
|
700
700
|
}
|
|
701
701
|
// src/utils/combineFileMembers.ts
|
|
702
|
+
/**
|
|
703
|
+
* File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and
|
|
704
|
+
* export entries of one file, while `combineSources` deduplicates source entries in original order.
|
|
705
|
+
* `combineImports` also drops imports nothing references. This works on a file's members, not on
|
|
706
|
+
* schema content.
|
|
707
|
+
*/
|
|
702
708
|
const IDENTIFIER_RUN = /[\w$]+/g;
|
|
703
709
|
/**
|
|
704
710
|
* How many imports a file needs before indexing the source beats scanning it once per name.
|
|
@@ -712,15 +718,24 @@ function importLocalName(item) {
|
|
|
712
718
|
return typeof item === "string" ? item : item.name ?? item.propertyName;
|
|
713
719
|
}
|
|
714
720
|
/**
|
|
721
|
+
* Returns the specifier a member is written with: POSIX and relative to the importing file when it
|
|
722
|
+
* has a `root`, like `getRelativePath` in parser-ts. Sorting on it keeps the order the same on every OS.
|
|
723
|
+
*/
|
|
724
|
+
function specifier(node) {
|
|
725
|
+
if (!node.root) return node.path;
|
|
726
|
+
const relative = path.relative(path.dirname(node.root), node.path).replaceAll("\\", "/");
|
|
727
|
+
return relative.startsWith("../") ? relative : `./${relative}`;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
715
730
|
* Computes a multi-level sort key for exports and imports:
|
|
716
|
-
* non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical
|
|
731
|
+
* non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical specifier. Unnamed before named.
|
|
717
732
|
*/
|
|
718
733
|
function sortKey(node) {
|
|
719
734
|
const isArray = Array.isArray(node.name) ? "1" : "0";
|
|
720
735
|
const typeOnly = node.isTypeOnly ? "0" : "1";
|
|
721
736
|
const hasName = node.name != null ? "1" : "0";
|
|
722
737
|
const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? "";
|
|
723
|
-
return `${isArray}:${typeOnly}:${node
|
|
738
|
+
return `${isArray}:${typeOnly}:${specifier(node)}:${hasName}:${name}`;
|
|
724
739
|
}
|
|
725
740
|
/**
|
|
726
741
|
* Sorts members by {@link sortKey}. Keys are computed once per node, not per comparison.
|