feat: [cmd] add typescript analysis api integration

上级 8a0c5fe4
......@@ -550,10 +550,10 @@ results:
- [x] migrate to Golang Styles
- [ ] Story Cmd
- [ ] Languages Support
- [x] Java
- [ ] Golang (ongoing)
- [ ] TypeScript (ongoing)
- [ ] Python
- [x] Java (full features)
- [x] Golang (analysis API)
- [x] TypeScript (antlr4 performance issue)
- [x] Python (analysis API)
Documents Todo:
......
interface IPerson {
name: string;
}
class Person implements IPerson {
public publicString: string;
private privateString: string;
protected protectedString: string;
readonly readonlyString: string;
name: string;
constructor(name: string) {
this.name = name;
}
}
class Employee extends Person {
empCode: number;
static pi: number = 3.14;
constructor(empcode: number, name:string) {
super(name);
this.empCode = empcode;
}
displayName():void {
console.log("Name = " + this.name + ", Employee Code = " + this.empCode);
}
}
let emp = new Employee(100,"Steve");
\ No newline at end of file
......@@ -7,6 +7,7 @@ import (
"github.com/phodal/coca/pkg/adapter/cocafile"
"github.com/phodal/coca/pkg/application/analysis"
"github.com/phodal/coca/pkg/application/pyapp"
"github.com/phodal/coca/pkg/application/tsapp"
"github.com/phodal/coca/pkg/domain/core_domain"
"github.com/phodal/coca/pkg/infrastructure/ast/cocago"
"github.com/spf13/cobra"
......@@ -31,15 +32,39 @@ var analysisCmd = &cobra.Command{
switch analysisCmdConfig.Lang {
case "go":
analysisGo()
case "py":
case "python":
case "py", "python":
analysisPython()
case "ts", "typescript":
analysisTypeScript()
default:
analysisJava()
}
},
}
func analysisTypeScript() {
importPath := analysisCmdConfig.Path
var results []core_domain.CodeFile
files := cocafile.GetFilesWithFilter(importPath, cocafile.TypeScriptFileFilter)
fmt.Println(files)
for _, file := range files {
fmt.Fprintf(output, "Process TypeScript file: %s\n", file)
app := new(tsapp.TypeScriptApiApp)
content, _ := ioutil.ReadFile(file)
result := app.Analysis(string(content), "")
results = append(results, result)
}
var ds []core_domain.CodeDataStruct
for _, result := range results {
ds = append(ds, result.DataStructures...)
}
cModel, _ := json.MarshalIndent(ds, "", "\t")
cmd_util.WriteToCocaFile("tsdeps.json", string(cModel))
}
func analysisPython() {
importPath := analysisCmdConfig.Path
......
......@@ -26,3 +26,14 @@ func Test_Analysis_Python(t *testing.T) {
}}
RunTestCmd(t, analysis)
}
func Test_Analysis_TypeScript(t *testing.T) {
path := "../_fixtures/grammar/typescript"
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -l ts -p " + path,
Golden: "testdata/analysis_typescript.txt",
}}
RunTestCmd(t, analysis)
}
Process Python file: ../_fixtures/grammar/python/blog_entity.py
Process TypeScript file: ../_fixtures/grammar/typescript/Class.ts
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册