Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that js-tagged fields are scalars #10

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions analysis/passes/embedjsobject/embedjsobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
if _, ok := reflect.StructTag(tv).Lookup("js"); !ok {
return true
}
switch field.Type.(type) {
case *ast.ArrayType, *ast.MapType, *ast.FuncType, *ast.ChanType, *ast.StructType:
pass.Reportf(field.Pos(), "non-scalar types not permitted in structs that embed js.Object")
}
fieldList := findFieldList(stack)
for i, field := range fieldList.List {
if len(field.Names) > 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package directjsobject

import (
"github.com/gopherjs/gopherjs/js"
)

type _ struct {
*js.Object
Slice []int `js:"slice"` // want "non-scalar types not permitted in structs that embed js.Object"
Array [10]int `js:"array"` // want "non-scalar types not permitted in structs that embed js.Object"
Map map[int]int `js:"map"` // want "non-scalar types not permitted in structs that embed js.Object"
Func func() `js:"func"` // want "non-scalar types not permitted in structs that embed js.Object"
Chan chan int `js:"chan"` // want "non-scalar types not permitted in structs that embed js.Object"
Struct struct{} `js:"struct"` // want "non-scalar types not permitted in structs that embed js.Object"
}