mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 02:51:56 +08:00

* 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 15cdf7382b
.
* 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
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package parser
|
|
|
|
import (
|
|
"fmt"
|
|
"go/ast"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Struct represents a struct that is used by the frontend
|
|
// in a Wails project
|
|
type Struct struct {
|
|
|
|
// The name of the struct
|
|
Name string
|
|
|
|
// The package this was declared in
|
|
Package *Package
|
|
|
|
// Comments for the struct
|
|
Comments []string
|
|
|
|
// The fields used in this struct
|
|
Fields []*Field
|
|
|
|
// The methods available to the front end
|
|
Methods []*Method
|
|
|
|
// Indicates if this struct is bound to the app
|
|
IsBound bool
|
|
|
|
// Indicates if this struct is used as data
|
|
IsUsedAsData bool
|
|
}
|
|
|
|
func parseStructNameFromStarExpr(starExpr *ast.StarExpr) (string, string, error) {
|
|
pkg := ""
|
|
name := ""
|
|
// Determine the FQN
|
|
switch x := starExpr.X.(type) {
|
|
case *ast.SelectorExpr:
|
|
switch i := x.X.(type) {
|
|
case *ast.Ident:
|
|
pkg = i.Name
|
|
default:
|
|
// TODO: Store warnings?
|
|
return "", "", errors.WithStack(fmt.Errorf("unknown type in selector for *ast.SelectorExpr: %+v", i))
|
|
}
|
|
|
|
name = x.Sel.Name
|
|
|
|
// TODO: IS this used?
|
|
case *ast.StarExpr:
|
|
switch s := x.X.(type) {
|
|
case *ast.Ident:
|
|
name = s.Name
|
|
default:
|
|
// TODO: Store warnings?
|
|
return "", "", errors.WithStack(fmt.Errorf("unknown type in selector for *ast.StarExpr: %+v", s))
|
|
}
|
|
case *ast.Ident:
|
|
name = x.Name
|
|
default:
|
|
// TODO: Store warnings?
|
|
return "", "", errors.WithStack(fmt.Errorf("unknown type in selector for *ast.StarExpr: %+v", starExpr))
|
|
}
|
|
return pkg, name, nil
|
|
}
|