Skip to content

Conversation

@angrychow
Copy link
Collaborator

What type of PR is this?

Bug fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level.

PR Title:

fix(parser): fix self-reference detection and type alias dependency extraction

(Optional) Translate the PR title into Chinese.

修复自引用检测和类型别名依赖提取

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

Fixes two bugs in type dependency extraction:

  1. Self-reference detection: Recursive types like type TreeNode = { children: TreeNode[] } incorrectly included themselves in dependencies. Fixed by checking if type reference is within type definition instead of checking if definition is within function.

  2. Type alias extraction: Type aliases like type Status = 'normal' | 'abnormal' were not extracted when used in function parameters or return types. Fixed by extracting direct symbol from type nodes before processing nested references.

zh(optional):

修复类型依赖提取中的两个 bug:

  1. 自引用检测:递归类型如 type TreeNode = { children: TreeNode[] } 错误地将自身包含在依赖中。通过检查类型引用是否在类型定义内(而非检查定义是否在函数内)修复。

  2. 类型别名提取:类型别名如 type Status = 'normal' | 'abnormal' 在函数参数或返回类型中使用时未被提取。通过在处理嵌套引用前先提取类型节点的直接符号修复。

angrychow and others added 6 commits November 6, 2025 19:07
… export check

Fixed an issue where arrow function default export detection was checking
the arrow function's symbol instead of the variable declaration's symbol.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed type dependency recognition for type aliases (especially union types) across all parsers by extracting symbols from TypeReference node's typeName child instead of the node itself.

Changes:
- DependencyUtils: capture union/intersection type aliases before recursing into members
- TypeParser: extract symbols from typeName for TypeReference nodes, handle ExpressionWithTypeArguments, put type alias dependencies in InlineStruct instead of Implements
- FunctionParser: extract symbols from TypeReference typeName for function parameter/return types
- VarParser: extract symbols from TypeReference typeName for variable/property type annotations
- Added comprehensive unit tests for all three parsers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@angrychow
Copy link
Collaborator Author

我对 TS-Parser 进行了变更,Regression Test 不通过属于正常现象。

@Hoblovski
Copy link
Collaborator

Hoblovski commented Dec 1, 2025

export const PI = 3.14159;
export const E = 2.71828;

export enum Color {
  RED = 'red',
  GREEN = 'green',
  BLUE = 'blue'
}

export type Result<T> = T | Error;

变更后,Result 的 Types 多了 T,这是期望行为吗

Item Added at: root['Modules']['test-repo']['Packages']['src/utils/constants.ts']['Types']['Result']['InlineStruct'][0]
  + new: {
  "ModPath": "test-repo",
  "PkgPath": "src/utils/constants.ts",
  "Name": "T",
  "File": "src/utils/constants.ts",
  "Line": 10,
  "StartOffset": 151,
  "EndOffset": 152
}

@angrychow
Copy link
Collaborator Author

export const PI = 3.14159;
export const E = 2.71828;

export enum Color {
  RED = 'red',
  GREEN = 'green',
  BLUE = 'blue'
}

export type Result<T> = T | Error;

变更后,Result 的 Types 多了 T,这是期望行为吗

Item Added at: root['Modules']['test-repo']['Packages']['src/utils/constants.ts']['Types']['Result']['InlineStruct'][0]
  + new: {
  "ModPath": "test-repo",
  "PkgPath": "src/utils/constants.ts",
  "Name": "T",
  "File": "src/utils/constants.ts",
  "Line": 10,
  "StartOffset": 151,
  "EndOffset": 152
}

fixed

Copy link
Collaborator

@Hoblovski Hoblovski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked at the test results. Make sense.

@AsterDY AsterDY merged commit df5a49f into cloudwego:main Dec 3, 2025
3 of 4 checks passed
Duslia pushed a commit that referenced this pull request Dec 7, 2025
…ollow-up to #123) (#125)

* fix: use variable symbol instead of arrow function symbol for default export check

Fixed an issue where arrow function default export detection was checking
the arrow function's symbol instead of the variable declaration's symbol.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* upd version

* fix: correct type alias symbol extraction from TypeReference nodes

Fixed type dependency recognition for type aliases (especially union types) across all parsers by extracting symbols from TypeReference node's typeName child instead of the node itself.

Changes:
- DependencyUtils: capture union/intersection type aliases before recursing into members
- TypeParser: extract symbols from typeName for TypeReference nodes, handle ExpressionWithTypeArguments, put type alias dependencies in InlineStruct instead of Implements
- FunctionParser: extract symbols from TypeReference typeName for function parameter/return types
- VarParser: extract symbols from TypeReference typeName for variable/property type annotations
- Added comprehensive unit tests for all three parsers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix type self-reference problem

* filtering type parameters

* support class parsing

* fix: if a property in a class is defined as a function, categorize it as a method

* fix bugs: construct symbol name by assignSymbolName

* update version

* add function parse

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants