chore(ipuaro): bump version to 0.3.1

This commit is contained in:
imfozilbek
2025-11-30 01:50:33 +05:00
parent 958e4daed5
commit 294d085ad4
6 changed files with 89 additions and 46 deletions

View File

@@ -306,38 +306,7 @@ export class ASTParser {
}
}
let extendsName: string | undefined
const implementsList: string[] = []
for (const child of node.children) {
if (child.type === NodeType.CLASS_HERITAGE) {
for (const clause of child.children) {
if (clause.type === NodeType.EXTENDS_CLAUSE) {
const typeNode = clause.children.find(
(c) =>
c.type === NodeType.TYPE_IDENTIFIER ||
c.type === NodeType.IDENTIFIER,
)
extendsName = typeNode?.text
} else if (clause.type === NodeType.IMPLEMENTS_CLAUSE) {
for (const impl of clause.children) {
if (
impl.type === NodeType.TYPE_IDENTIFIER ||
impl.type === NodeType.IDENTIFIER
) {
implementsList.push(impl.text)
}
}
}
}
} else if (child.type === NodeType.EXTENDS_CLAUSE) {
const typeNode = child.children.find(
(c) => c.type === NodeType.TYPE_IDENTIFIER || c.type === NodeType.IDENTIFIER,
)
extendsName = typeNode?.text
}
}
const { extendsName, implementsList } = this.extractClassHeritage(node)
const isAbstract = node.children.some((c) => c.type === NodeType.ABSTRACT)
ast.classes.push({
@@ -353,6 +322,56 @@ export class ASTParser {
})
}
private extractClassHeritage(node: SyntaxNode): {
extendsName: string | undefined
implementsList: string[]
} {
let extendsName: string | undefined
const implementsList: string[] = []
for (const child of node.children) {
if (child.type === NodeType.CLASS_HERITAGE) {
this.parseHeritageClause(child, (ext) => (extendsName = ext), implementsList)
} else if (child.type === NodeType.EXTENDS_CLAUSE) {
extendsName = this.findTypeIdentifier(child)
}
}
return { extendsName, implementsList }
}
private parseHeritageClause(
heritage: SyntaxNode,
setExtends: (name: string) => void,
implementsList: string[],
): void {
for (const clause of heritage.children) {
if (clause.type === NodeType.EXTENDS_CLAUSE) {
const typeId = this.findTypeIdentifier(clause)
if (typeId) {
setExtends(typeId)
}
} else if (clause.type === NodeType.IMPLEMENTS_CLAUSE) {
this.collectImplements(clause, implementsList)
}
}
}
private findTypeIdentifier(node: SyntaxNode): string | undefined {
const typeNode = node.children.find(
(c) => c.type === NodeType.TYPE_IDENTIFIER || c.type === NodeType.IDENTIFIER,
)
return typeNode?.text
}
private collectImplements(clause: SyntaxNode, list: string[]): void {
for (const impl of clause.children) {
if (impl.type === NodeType.TYPE_IDENTIFIER || impl.type === NodeType.IDENTIFIER) {
list.push(impl.text)
}
}
}
private extractMethod(node: SyntaxNode): MethodInfo {
const nameNode = node.childForFieldName(FieldName.NAME)
const params = this.extractParameters(node)

View File

@@ -25,7 +25,7 @@ export class RedisStorage implements IStorage {
if (!data) {
return null
}
return this.parseJSON<FileData>(data, "FileData")
return this.parseJSON(data, "FileData") as FileData
}
async setFile(path: string, data: FileData): Promise<void> {
@@ -44,7 +44,7 @@ export class RedisStorage implements IStorage {
const result = new Map<string, FileData>()
for (const [path, value] of Object.entries(data)) {
const parsed = this.parseJSON<FileData>(value, "FileData")
const parsed = this.parseJSON(value, "FileData") as FileData | null
if (parsed) {
result.set(path, parsed)
}
@@ -64,7 +64,7 @@ export class RedisStorage implements IStorage {
if (!data) {
return null
}
return this.parseJSON<FileAST>(data, "FileAST")
return this.parseJSON(data, "FileAST") as FileAST
}
async setAST(path: string, ast: FileAST): Promise<void> {
@@ -83,7 +83,7 @@ export class RedisStorage implements IStorage {
const result = new Map<string, FileAST>()
for (const [path, value] of Object.entries(data)) {
const parsed = this.parseJSON<FileAST>(value, "FileAST")
const parsed = this.parseJSON(value, "FileAST") as FileAST | null
if (parsed) {
result.set(path, parsed)
}
@@ -98,7 +98,7 @@ export class RedisStorage implements IStorage {
if (!data) {
return null
}
return this.parseJSON<FileMeta>(data, "FileMeta")
return this.parseJSON(data, "FileMeta") as FileMeta
}
async setMeta(path: string, meta: FileMeta): Promise<void> {
@@ -117,7 +117,7 @@ export class RedisStorage implements IStorage {
const result = new Map<string, FileMeta>()
for (const [path, value] of Object.entries(data)) {
const parsed = this.parseJSON<FileMeta>(value, "FileMeta")
const parsed = this.parseJSON(value, "FileMeta") as FileMeta | null
if (parsed) {
result.set(path, parsed)
}
@@ -133,7 +133,7 @@ export class RedisStorage implements IStorage {
return new Map()
}
const parsed = this.parseJSON<[string, unknown[]][]>(data, "SymbolIndex")
const parsed = this.parseJSON(data, "SymbolIndex") as [string, unknown[]][] | null
if (!parsed) {
return new Map()
}
@@ -157,10 +157,10 @@ export class RedisStorage implements IStorage {
}
}
const parsed = this.parseJSON<{
const parsed = this.parseJSON(data, "DepsGraph") as {
imports: [string, string[]][]
importedBy: [string, string[]][]
}>(data, "DepsGraph")
} | null
if (!parsed) {
return {
@@ -190,7 +190,7 @@ export class RedisStorage implements IStorage {
if (!data) {
return null
}
return this.parseJSON<unknown>(data, "ProjectConfig")
return this.parseJSON(data, "ProjectConfig")
}
async setProjectConfig(key: string, value: unknown): Promise<void> {
@@ -225,9 +225,9 @@ export class RedisStorage implements IStorage {
return this.client.getClient()
}
private parseJSON<T>(data: string, type: string): T | null {
private parseJSON(data: string, type: string): unknown {
try {
return JSON.parse(data) as T
return JSON.parse(data) as unknown
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error"
throw IpuaroError.parse(`Failed to parse ${type}: ${message}`)