mirror of
https://github.com/wavetermdev/wails.git
synced 2026-04-22 15:26:15 -07:00
62374b9b53
* WIP * Generation of index.js * Add RelativeToCwd * Add JSDoc comments * Convert to ES6 syntax * Fix typo * Initial generation of typescript declarations * Typescript improvements * Improved @returns jsdoc * Improved declaration files * Simplified output * Rename file * Tidy up * Revert "Simplified output" This reverts commit 15cdf7382b21a15a36616adbca13c9b034a1907b. * Now parsing actual code * Support Array types * Reimagined parser * Wrap parsing in Parser * Rewritten module generator (TS Only) * Final touches * Slight refactor to improve output * Struct comments. External struct literal binding * Reworked project parser *working* * remove debug info * Refactor of parser * remove the spew * Better Ts support * Better project generation logic * Support local functions in bind() * JS Object generation. Linting. * Support json tags in module generation * Updated mod files * Support vscode file generation * Better global.d.ts * add ts-check to templates * Support TS declaration files * improved 'generate' command for module
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package parser
|
|
|
|
import "go/ast"
|
|
|
|
func (p *Package) getApplicationVariableName(file *ast.File, wailsImportName string) string {
|
|
|
|
// Iterate through the whole file looking for the application name
|
|
applicationVariableName := ""
|
|
|
|
// Inspect the file
|
|
ast.Inspect(file, func(n ast.Node) bool {
|
|
// Parse Assignments looking for application name
|
|
if assignStmt, ok := n.(*ast.AssignStmt); ok {
|
|
|
|
// Check the RHS is of the form:
|
|
// `app := wails.CreateApp()` or
|
|
// `app := wails.CreateAppWithOptions`
|
|
for _, rhs := range assignStmt.Rhs {
|
|
ce, ok := rhs.(*ast.CallExpr)
|
|
if !ok {
|
|
continue
|
|
}
|
|
se, ok := ce.Fun.(*ast.SelectorExpr)
|
|
if !ok {
|
|
continue
|
|
}
|
|
i, ok := se.X.(*ast.Ident)
|
|
if !ok {
|
|
continue
|
|
}
|
|
// Have we found the wails import name?
|
|
if i.Name == wailsImportName {
|
|
// Check we are calling a function to create the app
|
|
if se.Sel.Name == "CreateApp" || se.Sel.Name == "CreateAppWithOptions" {
|
|
if len(assignStmt.Lhs) == 1 {
|
|
i, ok := assignStmt.Lhs[0].(*ast.Ident)
|
|
if ok {
|
|
// Found the app variable name
|
|
applicationVariableName = i.Name
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
})
|
|
return applicationVariableName
|
|
}
|