refactor: fix typescript imports

上级 ad5e2be4
......@@ -5,7 +5,7 @@ import "github.com/phodal/coca/pkg/domain"
type CodeFile struct {
FullName string
PackageName string
Imports []string // CodeImports
Imports []CodeImport
Members []*CodeMember
DataStructures []CodeDataStruct
// Deprecated: support for migration only
......@@ -13,8 +13,9 @@ type CodeFile struct {
}
type CodeImport struct {
Source string
AsName string
UsageName []string
Scope string // function, method or class
Source string
AsName string
ImportName string
UsageName []string
Scope string // function, method or class
}
......@@ -216,7 +216,7 @@ import { ZipCodeValidator } from "./ZipCodeValidator";
`, "")
g.Expect(len(results.Imports)).To(Equal(1))
g.Expect(results.Imports[0]).To(Equal("./ZipCodeValidator"))
g.Expect(results.Imports[0].Source).To(Equal("./ZipCodeValidator"))
}
func Test_ShouldReturnAsImports(t *testing.T) {
......@@ -230,7 +230,8 @@ import zip = require("./ZipCodeValidator");
`, "")
g.Expect(len(results.Imports)).To(Equal(1))
g.Expect(results.Imports[0]).To(Equal("./ZipCodeValidator"))
g.Expect(results.Imports[0].Source).To(Equal("./ZipCodeValidator"))
}
// Todo: fix for $ and *
......
......@@ -49,7 +49,10 @@ func (s *TypeScriptIdentListener) EnterProgram(ctx *parser.ProgramContext) {
func (s *TypeScriptIdentListener) EnterImportFromBlock(ctx *parser.ImportFromBlockContext) {
replaceSingleQuote := UpdateImportStr(ctx.StringLiteral().GetText())
codeFile.Imports = append(codeFile.Imports, replaceSingleQuote)
imp := &trial.CodeImport{Source: replaceSingleQuote}
importName := ctx.GetChild(0).(antlr.ParseTree).GetText()
imp.ImportName = importName
codeFile.Imports = append(codeFile.Imports, *imp)
}
func UpdateImportStr(importText string) string {
......@@ -60,12 +63,14 @@ func UpdateImportStr(importText string) string {
func (s *TypeScriptIdentListener) EnterImportAliasDeclaration(ctx *parser.ImportAliasDeclarationContext) {
replaceSingleQuote := UpdateImportStr(ctx.StringLiteral().GetText())
codeFile.Imports = append(codeFile.Imports, replaceSingleQuote)
imp := &trial.CodeImport{Source: replaceSingleQuote}
codeFile.Imports = append(codeFile.Imports, *imp)
}
func (s *TypeScriptIdentListener) EnterImportAll(ctx *parser.ImportAllContext) {
replaceSingleQuote := UpdateImportStr(ctx.StringLiteral().GetText())
codeFile.Imports = append(codeFile.Imports, replaceSingleQuote)
imp := &trial.CodeImport{Source: replaceSingleQuote}
codeFile.Imports = append(codeFile.Imports, *imp)
}
func (s *TypeScriptIdentListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册