mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-26 12:09:50 +01:00
fix: arrays
This commit is contained in:
1 parent
b5d61cebb3
commit
d88f7ad539
1 file changed
+31
-33
@@ -10,14 +10,18 @@ import { Code } from "./Code";
|
|||||||
import {
|
import {
|
||||||
createProgram,
|
createProgram,
|
||||||
forEachChild,
|
forEachChild,
|
||||||
|
isArrayTypeNode,
|
||||||
isEnumDeclaration,
|
isEnumDeclaration,
|
||||||
|
isExpressionWithTypeArguments,
|
||||||
isInterfaceDeclaration,
|
isInterfaceDeclaration,
|
||||||
isMethodSignature,
|
isMethodSignature,
|
||||||
isPropertySignature,
|
isPropertySignature,
|
||||||
isTypeAliasDeclaration,
|
isTypeAliasDeclaration,
|
||||||
|
isTypeNode,
|
||||||
isTypeReferenceNode,
|
isTypeReferenceNode,
|
||||||
type InterfaceDeclaration,
|
type InterfaceDeclaration,
|
||||||
type Node,
|
type Node,
|
||||||
|
type Symbol,
|
||||||
type TypeNode,
|
type TypeNode,
|
||||||
} from "typescript";
|
} from "typescript";
|
||||||
|
|
||||||
@@ -44,6 +48,7 @@ if (source === undefined) {
|
|||||||
|
|
||||||
const checker = program.getTypeChecker();
|
const checker = program.getTypeChecker();
|
||||||
const collected = new Map<string, string>();
|
const collected = new Map<string, string>();
|
||||||
|
const visited = new Set<Symbol>();
|
||||||
let declaration: InterfaceDeclaration | undefined;
|
let declaration: InterfaceDeclaration | undefined;
|
||||||
|
|
||||||
forEachChild(source, (node) => {
|
forEachChild(source, (node) => {
|
||||||
@@ -77,50 +82,43 @@ function collectNodes(node: Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function collectTypes(node: TypeNode) {
|
function collectTypes(node: TypeNode) {
|
||||||
|
if (isArrayTypeNode(node)) {
|
||||||
|
collectTypes(node.elementType);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTypeReferenceNode(node)) {
|
||||||
|
node.typeArguments?.forEach(collectTypes);
|
||||||
|
}
|
||||||
|
|
||||||
const type = checker.getTypeAtLocation(node);
|
const type = checker.getTypeAtLocation(node);
|
||||||
const symbol = type.getSymbol();
|
const symbol = type.getSymbol();
|
||||||
|
|
||||||
if (!symbol) return;
|
if (!symbol || visited.has(symbol)) return;
|
||||||
|
|
||||||
const name = symbol.getName();
|
visited.add(symbol);
|
||||||
|
|
||||||
if (!collected.has(name)) {
|
const declarations = symbol.getDeclarations();
|
||||||
const declarations = symbol.getDeclarations();
|
|
||||||
|
|
||||||
if (!declarations) return;
|
if (!declarations) return;
|
||||||
|
|
||||||
declarations.forEach((declaration) => {
|
for (const declaration of declarations) {
|
||||||
const source = declaration.getSourceFile();
|
if (isInterfaceDeclaration(declaration)) {
|
||||||
const isInSource = roots.some((root) => source.fileName.startsWith(root));
|
collected.set(declaration.name.text, declaration.getText());
|
||||||
|
|
||||||
if (!isInSource) return;
|
declaration.members.forEach((member) => {
|
||||||
|
if (isPropertySignature(member) && member.type) {
|
||||||
if (
|
collectTypes(member.type);
|
||||||
!isInterfaceDeclaration(declaration) &&
|
}
|
||||||
!isTypeAliasDeclaration(declaration) &&
|
});
|
||||||
!isEnumDeclaration(declaration)
|
} else {
|
||||||
) {
|
forEachChild(declaration, (child) => {
|
||||||
return;
|
if (isTypeNode(child)) collectTypes(child);
|
||||||
}
|
});
|
||||||
|
}
|
||||||
const name = declaration.name.text;
|
|
||||||
|
|
||||||
if (collected.has(name)) return;
|
|
||||||
|
|
||||||
collected.set(name, declaration.getText());
|
|
||||||
forEachChild(declaration, collectTypesFromNode);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectTypesFromNode(node: Node) {
|
|
||||||
if (isTypeReferenceNode(node)) {
|
|
||||||
collectTypes(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
forEachChild(node, collectTypesFromNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
collectNodes(declaration);
|
collectNodes(declaration);
|
||||||
|
|
||||||
let content = "";
|
let content = "";
|
||||||
|
|||||||
Reference in new issue
Block a user