Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ testdata/jsons

src/lang/testdata
*.json
!ts-parser/**/*.json

tools
abcoder

!testdata/asts/*.json
!testdata/asts/*.json
34 changes: 34 additions & 0 deletions ts-parser/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-explicit-any": "warn",
"prefer-const": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-arrow-callback": "error",
"@typescript-eslint/ban-types": "off"
},
"env": {
"node": true,
"es2022": true
},
"ignorePatterns": [
"dist/",
"node_modules/",
"**/*.js",
"**/*.d.ts",
"coverage/"
]
}
9 changes: 9 additions & 0 deletions ts-parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/

dist/

.vscode/

temp/

output.json
38 changes: 38 additions & 0 deletions ts-parser/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Dependencies
node_modules/

# Build outputs
dist/

# Test files and directories
**/*.test.ts
**/*.test.js
**/*.spec.ts
**/*.spec.js
**/test/
**/tests/
test-repo/

# Logs
*.log

# Environment files
.env*

# Package files
package-lock.json
yarn.lock

# Generated files
*.d.ts
*.js.map
*.ts.map

# Temporary files
*.tmp
*.temp
.DS_Store

# IDE
.vscode/
.idea/
10 changes: 10 additions & 0 deletions ts-parser/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid"
}
46 changes: 46 additions & 0 deletions ts-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# TypeScript Parser for ABCoder

A TypeScript AST parser that extracts method calls, variable references, and dependencies.

Usage:

Build: `npm run build`

Run: `node dist/index.js parse [options] <directory>`

Parse a TypeScript repository and generate UNIAST JSON

Arguments:
directory Directory to parse


| Option | Description |
|--------|-------------|
| -o, --output <file> | Output file path (default: "output.json") |
| -t, --tsconfig <file> | Path to tsconfig.json file, if you provide a relative path, it will be relative to **the directory of the input file** (default: "tsconfig.json") |
| --no-dist | Ignore dist folder and its contents |
| --pretty | Pretty print JSON output |
| --src <dirs> | Directory paths to include (comma-separated) |
| -h, --help | display help for command |


See `./index.ts` for more information.


## Notes

1. MUST correctly specify the location of the current project's `tsconfig.json`.

2. If you provide a relative path to argument `--tsconfig`, it will be relative to **the directory of the input file**.

3. Before usage, please configure the dependencies for your TypeScript project, such as running npm install and setting up cross-package dependencies in monorepo.

4. If the repository you're analyzing is too large, you may need to adjust Node.js's maximum memory allocation.


## Some known issues

- When there is a circular dependency, the parser will choose one of the dependencies as the main dependency.
- The parser does not handle dynamic imports.
- The parser does not handle TypeScript decorators.
- For external symbol which has no `.d.ts` declaration file, the parser will not be able to resolve the symbol.
Loading
Loading