feat: [ts] make first class identfier

上级 6fa89224
......@@ -8,9 +8,9 @@ import (
var (
output io.Writer
trialRootCmd = &cobra.Command{
Use: "coca",
Use: "cots",
Short: "A generator for Cobra based Applications",
Long: `coca`,
Long: `cots`,
}
)
......
......@@ -9,8 +9,33 @@ func Test_TypeScriptConsoleLog(t *testing.T) {
g := NewGomegaWithT(t)
app := new(TypeScriptApiApp)
results := app.Analysis("console.log('hello, world')");
results := app.Analysis("console.log('hello, world')")
g.Expect(len(results.MethodCalls)).To(Equal(1))
g.Expect(results.MethodCalls[0].Class).To(Equal("console"))
}
func Test_TypeScriptClassNode(t *testing.T) {
g := NewGomegaWithT(t)
app := new(TypeScriptApiApp)
results := app.Analysis(`
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;
}
}
`)
g.Expect(results.Class).To(Equal("Person"))
}
\ No newline at end of file
......@@ -21,6 +21,10 @@ func (s *TypeScriptIdentListener) EnterProgram(ctx *parser.ProgramContext) {
}
func (s *TypeScriptIdentListener) EnterClassDeclaration(ctx *parser.ClassDeclarationContext) {
currentNode.Class = ctx.Identifier().GetText()
}
func (s *TypeScriptIdentListener) EnterArgumentsExpression(ctx *parser.ArgumentsExpressionContext) {
if reflect.TypeOf(ctx.GetChild(0)).String() == "*parser.MemberDotExpressionContext" {
memberDotExprCtx := ctx.GetChild(0).(*parser.MemberDotExpressionContext)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册