diff --git a/internal/compiler/compiler.go b/internal/compiler/compiler.go index b53bb714..4c53336b 100644 --- a/internal/compiler/compiler.go +++ b/internal/compiler/compiler.go @@ -8,12 +8,12 @@ import ( "github.com/matthewmueller/joy/internal/compiler/def" "github.com/matthewmueller/joy/internal/compiler/defs" "github.com/matthewmueller/joy/internal/compiler/index" + "github.com/matthewmueller/joy/internal/compiler/indexer" "github.com/matthewmueller/joy/internal/compiler/script" "github.com/matthewmueller/joy/internal/compiler/translator" "github.com/matthewmueller/joy/internal/jsast" "github.com/pkg/errors" - "github.com/matthewmueller/joy/internal/compiler/db" "github.com/matthewmueller/joy/internal/compiler/graph" "github.com/matthewmueller/joy/internal/compiler/loader" ) @@ -73,7 +73,7 @@ func (c *Compiler) Parse(packages ...string) (idx *index.Index, g *graph.Graph, return idx, g, errors.Wrapf(err, "load error") } - idx, err = db.New(program) + idx, err = indexer.New(program) if err != nil { return idx, g, errors.Wrapf(err, "indexing error") } diff --git a/internal/compiler/db/db.go b/internal/compiler/db/db.go deleted file mode 100644 index d52093d4..00000000 --- a/internal/compiler/db/db.go +++ /dev/null @@ -1,198 +0,0 @@ -package db - -import ( - "fmt" - "go/ast" - "path" - "strings" - - "github.com/apex/log" - "github.com/matthewmueller/joy/internal/compiler/defs" - "github.com/matthewmueller/joy/internal/compiler/index" - "github.com/matthewmueller/joy/internal/compiler/util" - "golang.org/x/tools/go/loader" -) - -// DB struct -type DB struct { - index *index.Index - // imports map[string]map[string]string - // index map[string]def.Definition -} - -// New fn -func New(program *loader.Program) (idx *index.Index, err error) { - // defer log.Trace("index").Stop(&err) - - db := &DB{ - index: index.New(program), - } - - jsPath, e := util.JSSourcePath() - if e != nil { - return nil, e - } - - for _, info := range program.AllPackages { - // ignore the joy/js package path - if info.Pkg.Path() == jsPath { - continue - } - - if e := db.pkg(info); e != nil { - return nil, e - } - } - - for id, def := range db.index.All() { - log.Debugf("index key: %s (%T)", id, def) - } - - return db.index, nil -} - -func (db *DB) pkg(info *loader.PackageInfo) (err error) { - for _, file := range info.Files { - ast.Inspect(file, func(node ast.Node) bool { - recurse, e := db.inspect(info, node) - if e != nil { - err = e - return false - } - return recurse - }) - } - return err -} - -func (db *DB) inspect(info *loader.PackageInfo, node ast.Node) (recurse bool, err error) { - switch t := node.(type) { - case *ast.FuncDecl: - if t.Recv != nil { - m, e := defs.Method(db.index, info, t) - if e != nil { - return false, e - } - - db.index.AddDefinition(m) - return false, nil - } - - d, e := defs.Function(db.index, info, t) - if e != nil { - return false, e - } - - db.index.AddDefinition(d) - return false, nil - case *ast.GenDecl: - for _, spec := range t.Specs { - e := db.spec(info, t, spec) - if e != nil { - return false, e - } - } - return false, nil - default: - return true, nil - } -} - -func (db *DB) spec(info *loader.PackageInfo, n *ast.GenDecl, spec ast.Spec) error { - switch t := spec.(type) { - case *ast.ValueSpec: - return db.valueSpec(info, n, t) - case *ast.ImportSpec: - return db.importSpec(info, n, t) - case *ast.TypeSpec: - return db.typeSpec(info, n, t) - default: - return fmt.Errorf("unhandled spec: %T", spec) - } -} - -func (db *DB) typeSpec(info *loader.PackageInfo, gn *ast.GenDecl, n *ast.TypeSpec) error { - switch t := n.Type.(type) { - case *ast.StructType: - st, e := defs.Struct(db.index, info, gn, n) - if e != nil { - return e - } - db.index.AddDefinition(st) - return nil - case *ast.InterfaceType: - iface, e := defs.Interface(db.index, info, gn, n) - if e != nil { - return e - } - db.index.AddDefinition(iface) - - methods := util.MethodsFromInterface(t, iface.Path(), iface.Name()) - for _, method := range methods { - db.index.Link(method, iface) - } - - return nil - case *ast.Ident, *ast.SelectorExpr, *ast.MapType, *ast.ArrayType: - typedef, e := defs.Type(db.index, info, gn, n) - if e != nil { - return e - } - db.index.AddDefinition(typedef) - return nil - default: - return fmt.Errorf("unhandled typeSpec: %T", n.Type) - } -} - -func (db *DB) importSpec(info *loader.PackageInfo, gn *ast.GenDecl, n *ast.ImportSpec) error { - // trim the "" of package path's - deppath := strings.Trim(n.Path.Value, `"`) - - // create a package path - packagePath := info.Pkg.Path() - - // alias - if n.Name != nil { - db.index.AddImport(packagePath, n.Name.Name, deppath) - return nil - } - - // use base name - name := path.Base(deppath) - db.index.AddImport(packagePath, name, deppath) - return nil -} - -func (db *DB) valueSpec(info *loader.PackageInfo, gn *ast.GenDecl, n *ast.ValueSpec) error { - d, e := defs.Value(db.index, info, gn, n) - if e != nil { - return e - } - db.index.AddDefinition(d) - return nil -} - -// // DefinitionOf fn -// func (db *DB) DefinitionOf(info *loader.PackageInfo, n ast.Node) (d def.Definition, err error) { -// return db.index.DefinitionOf(info, n) -// } - -// // TypeOf fn -// func (db *DB) TypeOf(info *loader.PackageInfo, n ast.Node) (kind types.Type, err error) { -// return db.index.TypeOf(info, n) -// } - -// // Mains gets all the main functions -// func (db *DB) Mains() (defs []def.Definition) { -// return db.index.Mains() -// // for _, info := range db.program.InitialPackages() { -// // p := info.Pkg.Path() -// // def := db.index.Get(p + " main") -// // if def == nil { -// // continue -// // } -// // defs = append(defs, def) -// // } -// // return defs -// } diff --git a/internal/compiler/indexer/indexer.go b/internal/compiler/indexer/indexer.go index 46ff84f2..0847333d 100644 --- a/internal/compiler/indexer/indexer.go +++ b/internal/compiler/indexer/indexer.go @@ -1,472 +1,196 @@ package indexer import ( - "errors" "fmt" "go/ast" - gotypes "go/types" - "os" "path" - "path/filepath" - "reflect" - "runtime" "strings" "github.com/apex/log" - "github.com/matthewmueller/joy/internal/compiler/db" - "github.com/matthewmueller/joy/types" + "github.com/matthewmueller/joy/internal/compiler/defs" + "github.com/matthewmueller/joy/internal/compiler/index" + "github.com/matthewmueller/joy/internal/compiler/util" "golang.org/x/tools/go/loader" ) -// Index struct -type Index struct { - program *loader.Program - declarations map[string]*types.Declaration - runtime map[string]*types.Declaration - imports map[string]map[string]string - interfaces map[string]*gotypes.Interface - receivers map[string][]*receiver - methods map[string][]*types.Declaration +// Indexer struct +type Indexer struct { + index *index.Index } -type receiver struct { - Type gotypes.Type - Function *types.Declaration -} - -// New maps all the declarations in all the packages -// this will be used as a lookup to map object declarations -// to actual AST nodes. object.String() is a unique identifier -// that points to a declaration in a go package (e.g. main()) -func New(program *loader.Program) (*Index, error) { - declarations := map[string]*types.Declaration{} - interfaces := map[string]*gotypes.Interface{} - runtime := map[string]*types.Declaration{} - imports := map[string]map[string]string{} - receivers := map[string][]*receiver{} +// New fn +func New(program *loader.Program) (idx *index.Index, err error) { + // defer log.Trace("index").Stop(&err) - database, err := db.New(program) - if err != nil { - return nil, err + index := &Indexer{ + index: index.New(program), } - _ = database - log.Infof("got database") - runtimePath, err := getRuntimePath() - if err != nil { - return nil, err + jsPath, e := util.JSSourcePath() + if e != nil { + return nil, e } - // map[object.String()] => ast for _, info := range program.AllPackages { - packagePath := info.Pkg.Path() - for _, file := range info.Files { - for _, decl := range file.Decls { - switch t := decl.(type) { - case *ast.FuncDecl: - idParts := []string{packagePath} - obj := info.ObjectOf(t.Name) - name := t.Name.Name - idParts = append(idParts, name) - - // if it has a receiver, include that in the ID - if t.Recv != nil && len(t.Recv.List) > 1 { - switch y := t.Recv.List[0].Type.(type) { - case *ast.Ident: - idParts = append(idParts, y.Name) - } - } - - id := strings.Join(idParts, " ") - - var params []string - for _, param := range t.Type.Params.List { - for _, ident := range param.Names { - params = append(params, ident.Name) - } - } - - // if it's a method don't export, - // if it's the main() function - // export either way - exported := obj.Exported() - if t.Recv != nil { - exported = false - } else if name == "main" { - exported = true - } - - declarations[id] = &types.Declaration{ - Exported: exported, - From: packagePath, - Name: name, - ID: id, - Node: decl, - Params: params, - } - - // declaration may satisfy an interface - // so we hold onto it for possible - // inclusion later - if t.Recv != nil { - recv := t.Recv.List[0] - if receivers[name] == nil { - receivers[name] = []*receiver{} - } - receivers[name] = append( - receivers[name], - &receiver{ - Type: info.TypeOf(recv.Type), - Function: declarations[id], - }, - ) - } - - // point human-friendly names to the declaration - if runtimePath == packagePath { - runtime[name] = declarations[id] - } - - case *ast.GenDecl: - for _, spec := range t.Specs { - switch y := spec.(type) { - case *ast.ValueSpec: - for _, name := range y.Names { - obj := info.ObjectOf(name) - idParts := []string{packagePath, name.Name} - id := strings.Join(idParts, " ") - - declarations[id] = &types.Declaration{ - Exported: obj.Exported(), - From: packagePath, - Name: name.Name, - ID: id, - Node: decl, - } - } - case *ast.TypeSpec: - typeof := info.TypeOf(y.Name) - obj := info.ObjectOf(y.Name) - idParts := []string{packagePath, y.Name.Name} - id := strings.Join(idParts, " ") - - declarations[id] = &types.Declaration{ - Exported: obj.Exported(), - From: packagePath, - Name: y.Name.Name, - ID: id, - Node: decl, - } - - // alias to typeof - // TODO: should this be the id we use? - // it wouldn't work for valuespec, but - // maybe here - declarations[typeof.String()] = declarations[id] - - // store interface declarations for faster access - if iface, ok := y.Type.(*ast.InterfaceType); ok { - // never export an interface - declarations[id].Exported = false - - ifacetype, ok := info.TypeOf(iface).(*gotypes.Interface) - if !ok { - return nil, fmt.Errorf("expected interface type to be gotypes.Interface") - } - // TODO: once again, not sure we need both here - interfaces[id] = ifacetype - interfaces[typeof.String()] = ifacetype - } - case *ast.ImportSpec: - if imports[packagePath] == nil { - imports[packagePath] = map[string]string{} - } - - // trim the "" of package path's - depPath := strings.Trim(y.Path.Value, `"`) - - // TODO: can y.Path be nil? - var name string - if y.Name != nil { - name = y.Name.Name - } else { - name = path.Base(depPath) - } + // ignore the joy/js package path + if info.Pkg.Path() == jsPath { + continue + } - imports[packagePath][name] = depPath - } - } - default: - return nil, fmt.Errorf("unhandled type %s", reflect.TypeOf(t)) - } - } + if e := index.pkg(info); e != nil { + return nil, e } } - // rejiggle receivers to make accessing methods by receiver ID easier - methods := map[string][]*types.Declaration{} - for _, list := range receivers { - for _, recv := range list { - typeof := recv.Type.String() - if methods[typeof] == nil { - methods[typeof] = []*types.Declaration{} - } - methods[typeof] = append(methods[typeof], recv.Function) - } + for id, def := range index.index.All() { + log.Debugf("index key: %s (%T)", id, def) } - return &Index{ - program: program, - declarations: declarations, - imports: imports, - runtime: runtime, - interfaces: interfaces, - receivers: receivers, - methods: methods, - }, nil + return index.index, nil } -// FindByID finds a declaration from type object -// func (i *Index) FindByID(id string) *types.Declaration { -// // ignore pointers (to support: p Person and p *Person) -// id = strings.TrimLeft(id, "*") -// return i.declarations[id] -// } - -// FindByObject finds a declaration from type object -// func (i *Index) FindByObject(obj gotypes.Object) *types.Declaration { -// id := getDependency(obj) -// if id == "" { -// return nil -// } - -// return i.FindByID(id) -// } +func (indexer *Indexer) pkg(info *loader.PackageInfo) (err error) { + for _, file := range info.Files { + ast.Inspect(file, func(node ast.Node) bool { + recurse, e := indexer.inspect(info, node) + if e != nil { + err = e + return false + } + return recurse + }) + } + return err +} -// FindByIdent finds a declaration from an identifier -// func (i *Index) FindByIdent(info *loader.PackageInfo, n *ast.Ident) *types.Declaration { -// obj := info.ObjectOf(n) -// if obj == nil { -// return nil -// } +func (indexer *Indexer) inspect(info *loader.PackageInfo, node ast.Node) (recurse bool, err error) { + switch t := node.(type) { + case *ast.FuncDecl: + if t.Recv != nil { + m, e := defs.Method(indexer.index, info, t) + if e != nil { + return false, e + } -// return i.FindByObject(obj) -// } + indexer.index.AddDefinition(m) + return false, nil + } -// FindByNode finds a declaration from a node -// func (i *Index) FindByNode(info *loader.PackageInfo, n ast.Node) *types.Declaration { -// switch t := n.(type) { -// case *ast.Ident: -// return i.FindByIdent(info, t) -// case *ast.StarExpr: -// return i.FindByNode(info, t.X) -// case *ast.SelectorExpr: -// return i.FindByNode(info, t.Sel) -// default: -// return nil -// } -// } + d, e := defs.Function(indexer.index, info, t) + if e != nil { + return false, e + } -// TypeOf fn -func (i *Index) TypeOf(info *loader.PackageInfo, n ast.Node) gotypes.Type { - switch t := n.(type) { - case *ast.Ident: - return info.TypeOf(t) - case *ast.StarExpr: - return i.TypeOf(info, t.X) - case *ast.SelectorExpr: - return i.TypeOf(info, t.Sel) - case *ast.UnaryExpr: - return i.TypeOf(info, t.X) + indexer.index.AddDefinition(d) + return false, nil + case *ast.GenDecl: + for _, spec := range t.Specs { + e := indexer.spec(info, t, spec) + if e != nil { + return false, e + } + } + return false, nil default: - return nil + return true, nil } } -// DeclarationOf gets the original declaration of the node -func (i *Index) DeclarationOf(info *loader.PackageInfo, n ast.Node) (*types.Declaration, error) { - switch t := n.(type) { - case *ast.Ident: - obj := info.ObjectOf(t) - if obj == nil { - return nil, errors.New("no object found") - } - return i.ObjectOf(obj) - case *ast.StarExpr: - return i.DeclarationOf(info, t.X) - case *ast.SelectorExpr: - return i.DeclarationOf(info, t.Sel) +func (indexer *Indexer) spec(info *loader.PackageInfo, n *ast.GenDecl, spec ast.Spec) error { + switch t := spec.(type) { + case *ast.ValueSpec: + return indexer.valueSpec(info, n, t) + case *ast.ImportSpec: + return indexer.importSpec(info, n, t) + case *ast.TypeSpec: + return indexer.typeSpec(info, n, t) default: - return nil, nil + return fmt.Errorf("unhandled spec: %T", spec) } } -// ObjectOf fn -func (i *Index) ObjectOf(obj gotypes.Object) (*types.Declaration, error) { - // built-in go type (e.g. nil, string, etc.) - // TODO: more specific - pkg := obj.Pkg() - if pkg == nil { - return nil, nil - } - - // packagePath := pkg.Path() - // name := obj.Name() - - idParts := []string{} - - switch t := obj.Type().(type) { - case *gotypes.Signature: - log.Infof("sig %s", t.String()) - idParts = append(idParts, obj.Pkg().Path()) - idParts = append(idParts, obj.Name()) - if t.Recv() != nil { - idParts = append(idParts, t.Recv().Name()) +func (indexer *Indexer) typeSpec(info *loader.PackageInfo, gn *ast.GenDecl, n *ast.TypeSpec) error { + switch t := n.Type.(type) { + case *ast.StructType: + st, e := defs.Struct(indexer.index, info, gn, n) + if e != nil { + return e } - id := strings.Join(idParts, " ") - return i.declarations[id], nil - case *gotypes.Named: - if t.Obj().Id() == "_.error" { - return nil, nil + indexer.index.AddDefinition(st) + return nil + case *ast.InterfaceType: + iface, e := defs.Interface(indexer.index, info, gn, n) + if e != nil { + return e } + indexer.index.AddDefinition(iface) - idParts = append( - idParts, - obj.Pkg().Path(), - t.Obj().Id(), - ) - - id := strings.Join(idParts, " ") - decl := i.declarations[id] - if decl == nil { - return nil, fmt.Errorf("decl shouldn't be nil: %T %s", t, id) + methods := util.MethodsFromInterface(t, iface.Path(), iface.Name()) + for _, method := range methods { + indexer.index.Link(method, iface) } - return decl, nil - - // if obj.Pkg() == nil { - // return nil, nil - // } - // log.Infof("pkg %+v", obj.Pkg()) - // log.Infof("named %s: %s %s", obj.Name(), , t.Obj().Id()) - // if t.Recv() != nil { - // idParts = append(idParts, t.Recv().Name()) - // } - // idParts = append(idParts, name) - // id := strings.Join(idParts, " ") - // return i.declarations[id], nil - // return nil, fmt.Errorf("unhandled object type: %T", obj.Type()) - case *gotypes.Chan: - return nil, nil - // log.Infof("chan %s", obj.Id()) - // log.Infof("chan %+v", t.Elem()) - // return nil, fmt.Errorf("unhandled object type: %T", obj.Type()) - case *gotypes.Interface: - idParts = append(idParts, obj.Pkg().Path()) - idParts = append(idParts, obj.Name()) - id := strings.Join(idParts, " ") - _ = id - log.Infof("interface id %s", t) - return nil, nil - // return nil, fmt.Errorf("unhandled object type: %T", obj.Type()) - case *gotypes.Pointer: - idParts = append(idParts, obj.Pkg().Path()) - log.Infof("t.Elem(): %T", t.Elem()) - idParts = append(idParts, obj.Name()) - id := strings.Join(idParts, " ") - log.Infof("pointer id %s", id) - return nil, fmt.Errorf("unhandled object type: %T", obj.Type()) - case *gotypes.Slice: - idParts = append(idParts, obj.Pkg().Path()) - idParts = append(idParts, obj.Name()) - id := strings.Join(idParts, " ") - decl := i.declarations[id] - if decl == nil { - return nil, fmt.Errorf("decl shouldn't be nil: %T %s", t, id) + return nil + case *ast.Ident, *ast.SelectorExpr, *ast.MapType, *ast.ArrayType: + typedef, e := defs.Type(indexer.index, info, gn, n) + if e != nil { + return e } - return decl, nil - case *gotypes.Basic: - return nil, nil + indexer.index.AddDefinition(typedef) + return nil default: - return nil, fmt.Errorf("unhandled object type: %T", obj.Type()) + return fmt.Errorf("unhandled typeSpec: %T", n.Type) } - // name := obj.Name() - - // id := strings.TrimLeft(obj.String(), "*") - // return nil, i.declarations[id] } -// Imports returns the imports along with their aliases -func (i *Index) Imports(packagePath string) map[string]string { - return i.imports[packagePath] -} +func (indexer *Indexer) importSpec(info *loader.PackageInfo, gn *ast.GenDecl, n *ast.ImportSpec) error { + // trim the "" of package path's + deppath := strings.Trim(n.Path.Value, `"`) -// Runtime returns a joy runtime declaration using it's name -func (i *Index) Runtime(name string) *types.Declaration { - return i.runtime[name] -} + // create a package path + packagePath := info.Pkg.Path() -// ImplementedBy returns a list of declarations that the interface implements -func (i *Index) ImplementedBy(id string, method string) (decls []*types.Declaration) { - iface := i.interfaces[id] - if iface == nil { - return decls - } - - for _, recv := range i.receivers[method] { - if gotypes.Implements(recv.Type, iface) { - decls = append(decls, recv.Function) - } + // alias + if n.Name != nil { + indexer.index.AddImport(packagePath, n.Name.Name, deppath) + return nil } - return decls + // use base name + name := path.Base(deppath) + indexer.index.AddImport(packagePath, name, deppath) + return nil } -// Methods gets all the functions with receivers of a struct -func (i *Index) Methods(id string) (decls []*types.Declaration) { - methods := i.methods[id] - if methods != nil { - return methods - } - methods = i.methods["*"+id] - if methods != nil { - return methods +func (indexer *Indexer) valueSpec(info *loader.PackageInfo, gn *ast.GenDecl, n *ast.ValueSpec) error { + d, e := defs.Value(indexer.index, info, gn, n) + if e != nil { + return e } - return decls + indexer.index.AddDefinition(d) + return nil } -func getDependency(obj gotypes.Object) string { - if obj == nil { - return "" - } - pkg := obj.Pkg() - if pkg == nil { - return "" - } - - switch t := obj.(type) { - case *gotypes.Var: - return t.String() - case *gotypes.Func: - return t.String() - case *gotypes.Const: - return t.String() - case *gotypes.TypeName: - return t.String() - } - - return "" -} +// // DefinitionOf fn +// func (db *DB) DefinitionOf(info *loader.PackageInfo, n ast.Node) (d def.Definition, err error) { +// return db.index.DefinitionOf(info, n) +// } -func getRuntimePath() (string, error) { - _, file, _, ok := runtime.Caller(0) - if !ok { - return "", errors.New("unable to get the filepath") - } - runtimePkg, err := filepath.Rel(path.Join(os.Getenv("GOPATH"), "src"), path.Join(path.Dir(path.Dir(path.Dir(file))), "runtime")) - if err != nil { - return "", err - } +// // TypeOf fn +// func (db *DB) TypeOf(info *loader.PackageInfo, n ast.Node) (kind types.Type, err error) { +// return db.index.TypeOf(info, n) +// } - return runtimePkg, nil -} +// // Mains gets all the main functions +// func (db *DB) Mains() (defs []def.Definition) { +// return db.index.Mains() +// // for _, info := range db.program.InitialPackages() { +// // p := info.Pkg.Path() +// // def := db.index.Get(p + " main") +// // if def == nil { +// // continue +// // } +// // defs = append(defs, def) +// // } +// // return defs +// } diff --git a/internal/compiler/db/db_test.go b/internal/compiler/indexer/indexer_test.go similarity index 99% rename from internal/compiler/db/db_test.go rename to internal/compiler/indexer/indexer_test.go index 0376fb37..48a05938 100644 --- a/internal/compiler/db/db_test.go +++ b/internal/compiler/indexer/indexer_test.go @@ -1,4 +1,4 @@ -package db_test +package indexer_test // import ( // "go/ast" diff --git a/internal/compiler/inspector/inspector.go b/internal/compiler/inspector/inspector.go deleted file mode 100644 index d9c3afd5..00000000 --- a/internal/compiler/inspector/inspector.go +++ /dev/null @@ -1,702 +0,0 @@ -package inspector - -import ( - "errors" - "fmt" - "go/ast" - "go/token" - gotypes "go/types" - "io/ioutil" - "os" - "path" - "path/filepath" - "runtime" - "strconv" - "strings" - - "github.com/apex/log" - "github.com/fatih/structtag" - "github.com/matthewmueller/joy/internal/compiler/indexer" - "github.com/matthewmueller/joy/types" - "golang.org/x/tools/go/loader" -) - -// Inspect fn -func Inspect(program *loader.Program, index *indexer.Index) (scripts []*types.Script, err error) { - // map[packagePath]map[variableName]dependencyPath - compositeLits := []string{} - maybeDependants := map[string]*types.Declaration{} - imports := map[string]map[string]string{} - fileMap := map[string][]*types.File{} - - // human-friendly pointers to the runtime declarations - // runtimeDecls := map[string]*types.Declaration{} - - // get the runtime path - runtimePath, err := getRuntimePath() - if err != nil { - return nil, err - } - - // get the mains for our initial packages - remaining := []*types.Declaration{} - mains := []*types.Declaration{} - for _, info := range program.InitialPackages() { - pkgPath := info.Pkg.Path() - main := info.Pkg.Scope().Lookup("main") - - if main == nil { - // ignore the runtime - // TODO: more robust - if path.Base(pkgPath) == "runtime" { - continue - } - return nil, fmt.Errorf("no main() found in: %s", info.Pkg.Path()) - } - - maindecl, err := index.ObjectOf(main) - if err != nil { - return nil, err - } - remaining = append(remaining, maindecl) - mains = append(mains, maindecl) - } - - // loop over each declaration we discover - // until we've discovered all the declarations - visited := map[string]bool{} - for len(remaining) > 0 { - declaration := remaining[0] - remaining = remaining[1:] - // TODO: this fixes the infinite loop, - // but the loop should be solved down - // inside the cases - if visited[declaration.ID] { - continue - } - visited[declaration.ID] = true - - // get the package information - info := program.Package(declaration.From) - - // walk through the AST of each declaration - // the goal of this inspection is to: - // - // - build the dependency tree for dead-code elimination - // - figure out which functions are async (from goroutines) - // - does this declaration contain "js" tags - var err error - ast.Inspect(declaration.Node, func(node ast.Node) bool { - switch n := node.(type) { - - // Get "js" comment tags from the top of functions - case *ast.FuncDecl: - tag, e := getJSTag(n.Doc) - if e != nil { - err = e - return false - } else if tag != nil { - declaration.JSTag = tag - if tag.HasOption("global") { - declaration.Exported = false - } - } - - // Get "js" comment tags from the top of types - case *ast.GenDecl: - tag, e := getJSTag(n.Doc) - if e != nil { - err = e - return false - } else if tag != nil { - declaration.JSTag = tag - if tag.HasOption("global") { - declaration.Exported = false - } - } - - case *ast.StructType: - for _, field := range n.Fields.List { - var jstag *structtag.Tag - - // parse the JS tag, if we have one - if field.Tag != nil { - value := field.Tag.Value - if field.Tag.Kind == token.STRING { - value = value[1 : len(value)-1] - } - - tag, e := getJSTagFromString(value) - if e != nil { - err = e - return false - } - jstag = tag - } - - // no name - // e.g. struct { *dep.Settings } - if len(field.Names) == 0 { - id, e := getIdentifier(field.Type) - if e != nil { - err = e - return false - } - declaration.Fields = append(declaration.Fields, types.Field{ - Name: id.Name, - Tag: jstag, - }) - continue - } - - for _, id := range field.Names { - declaration.Fields = append(declaration.Fields, types.Field{ - Name: id.Name, - Tag: jstag, - }) - } - } - - // // link each interface id with all method declarations - // // whose receiver's implement the interface - // case *ast.InterfaceType: - - // Include the Channel function when we find: - // make(chan ..., capacity) - case *ast.ChanType: - if imports[declaration.From] == nil { - imports[declaration.From] = map[string]string{} - } - imports[declaration.From]["runtime"] = runtimePath - - // if child is nil, it's a local variable or field - channel := index.Runtime("Channel") - if channel == nil { - return true - } - - // add the dependency - declaration.Dependencies = append( - declaration.Dependencies, - channel, - ) - - // append to the crawl - if !visited[channel.ID] { - remaining = append(remaining, channel) - } - - recv := index.Runtime("Recv") - if recv == nil { - return true - } - - // add the dependency - declaration.Dependencies = append( - declaration.Dependencies, - recv, - ) - - if !visited[recv.ID] { - remaining = append(remaining, recv) - } - - send := index.Runtime("Send") - if send == nil { - return true - } - - // add the dependency - declaration.Dependencies = append( - declaration.Dependencies, - send, - ) - - if !visited[send.ID] { - remaining = append(remaining, send) - } - - declaration.Async = true - // Send - case *ast.SendStmt: - // if imports[declaration.From] == nil { - // imports[declaration.From] = map[string]string{} - // } - // imports[declaration.From]["runtime"] = runtimePath - - // send := runtimeDecls["Send"] - // if send == nil { - // return true - // } - - // // add the dependency - // declaration.Dependencies = append( - // declaration.Dependencies, - // send, - // ) - - // if !visited[send.ID] { - // remaining = append(remaining, send) - // } - - // declaration.Async = true - - // Receive - case *ast.UnaryExpr: - // if n.Op != token.ARROW { - // return true - // } - - // if imports[declaration.From] == nil { - // imports[declaration.From] = map[string]string{} - // } - // imports[declaration.From]["runtime"] = runtimePath - - // recv := runtimeDecls["Recv"] - // if recv == nil { - // return true - // } - - // // add the dependency - // declaration.Dependencies = append( - // declaration.Dependencies, - // recv, - // ) - - // if !visited[recv.ID] { - // remaining = append(remaining, recv) - // } - - // declaration.Async = true - - // dig into our identifiers to figure out where - // they were defined and add those dependencies - // to the crawler - - case *ast.Ident: - // check if we depend on any other - // declarations with this identifier - if n.Name == "Render" { - typ := index.TypeOf(info, n) - log.Infof("%T", typ.Underlying()) - obj := info.ObjectOf(n) - log.Infof("typ %s", typ) - log.Infof("obj %s", obj) - switch t := typ.(type) { - case *gotypes.Interface: - log.Infof("interface!") - case *gotypes.Signature: - // log.Infof("%T", t.Recv().Type().Underlying().String()) - switch t := t.Recv().Type().Underlying().(type) { - case *gotypes.Interface: - log.Infof("interface %s", index.ImplementedBy(t.String(), "Render")) - // log.Infof("%T", t.Underlying()) - } - default: - log.Infof("type %T", t) - // case *gotypes.Signature: - // log.Infof(t.) - } - // log.Infof("typeof %T", typ) - d, _ := index.DeclarationOf(info, n) - c, _ := index.DeclarationOf(info, n) - log.Infof("d %+v child %+v", d, c) - } - - child, e := index.DeclarationOf(info, n) - if e != nil { - err = e - return true - } else if child == nil { - return true - } - - // add the dependency - declaration.Dependencies = append( - declaration.Dependencies, - child, - ) - - // append to the crawl - if !visited[child.ID] { - remaining = append(remaining, child) - } - - case *ast.CompositeLit: - // store composite literals since they will help - // us determine if we should make certain interface - // methods available in the source or not - kind := info.TypeOf(n.Type) - compositeLits = append(compositeLits, kind.String()) - - case *ast.CallExpr: - // look for macro.File(filename) - file, e := checkJSFile(n, declaration.From) - if e != nil { - err = e - return false - } else if file != nil { - // tack on the file's map - if fileMap[declaration.From] == nil { - fileMap[declaration.From] = []*types.File{} - } - fileMap[declaration.From] = append( - fileMap[declaration.From], - file, - ) - return true - } - - // look for macro.Rewrite(expression, variables...) - expr, vars, e := checkJSRewrite(n) - if e != nil { - err = e - return false - } else if expr != "" { - declaration.Rewrite = &types.Rewrite{ - Expression: expr, - Variables: vars, - } - declaration.Exported = false - return true - } - - switch t := n.Fun.(type) { - case *ast.SelectorExpr: - typeof := info.TypeOf(t.X) - method := t.Sel.Name - decls := index.ImplementedBy(typeof.String(), method) - - // maybe dependants if it's receivers are - // initialized anywhere in the source code - for _, decl := range decls { - maybeDependants[decl.ID] = declaration - } - // case *ast.Ident: - // log.Infof("fn: %s", t.Name) - // default: - // log.Infof("fn: %T", n.Fun) - } - } - - return true - }) - if err != nil { - return nil, err - } - } - - // map over the composite literals, - // pull their methods out if they - // have any and check those methods - // against maybeDependants. - for _, id := range compositeLits { - methods := index.Methods(id) - for _, method := range methods { - if parent, isset := maybeDependants[method.ID]; isset { - parent.Dependencies = append( - parent.Dependencies, - method, - ) - } - } - } - - // organize the declarations in topological - // order by package according to the initial - // main()'s - for _, main := range mains { - packages, pkgmap := groupByPackages(main) - files := []*types.File{} - - // tack on the dependencies along with their alias names - for _, pkg := range packages { - pkg.Dependencies = map[string]*types.Package{} - - // add the indexed imports - for alias, path := range index.Imports(pkg.Path) { - // check if we're actually using this package in - // this main (it may be used in other mains) - if pkgmap[path] == nil { - continue - } - - pkg.Dependencies[alias] = pkgmap[path] - } - // add any additional imports we add ourselves - for alias, path := range imports[pkg.Path] { - // check if we're actually using this package in - // this main (it may be used in other mains) - if pkgmap[path] == nil { - continue - } - - pkg.Dependencies[alias] = pkgmap[path] - } - - for _, file := range fileMap[pkg.Path] { - files = append(files, file) - } - } - - scripts = append(scripts, &types.Script{ - Name: main.From, - Packages: packages, - Files: files, - }) - } - - return scripts, nil -} - -// groupByPackages takes a dependency tree of declarations -// and organizes them into a topologically order list of -// packages -func groupByPackages(d *types.Declaration) (pkgs []*types.Package, pkgmap map[string]*types.Package) { - pkgmap = map[string]*types.Package{} - visited := map[string]bool{} - order := &[]string{} - - // get the list of packages from first to last referenced package - pkgs = recurseDeclaration(d, pkgmap, visited, order) - - // reverse the list for topological order - return reverse(pkgs), pkgmap -} - -// recurse the declarations, building up an ordered -// list of packages that contain these declarations -// TODO: cleanup, this is really bad recursion -func recurseDeclaration( - d *types.Declaration, - pkgmap map[string]*types.Package, - visited map[string]bool, - order *[]string, -) (pkgs []*types.Package) { - if visited[d.ID] { - return pkgs - } - visited[d.ID] = true - - // don't include joy/js in the build. - // this package contains only compile-time stubs - if strings.HasSuffix(d.From, "joy/js") { - return pkgs - } - - // if we haven't seen this package yet, - // then create it - if pkgmap[d.From] == nil { - *order = append(*order, d.From) - pkgmap[d.From] = &types.Package{ - Path: d.From, - } - } - // append the declaration - pkgmap[d.From].Declarations = append( - pkgmap[d.From].Declarations, - d, - ) - - if d.Exported { - // append the declaration - pkgmap[d.From].Exports = append( - pkgmap[d.From].Exports, - d, - ) - } - - // loop over each of the dependencies - for _, decl := range d.Dependencies { - recurseDeclaration(decl, pkgmap, visited, order) - - // async bubbles up, so if a child dependency is async, - // then the parent dependency also becomes async - if !d.Async && decl.Async { - d.Async = decl.Async - } - } - - // arrange according to first seen - for _, o := range *order { - pkgs = append(pkgs, pkgmap[o]) - } - - return pkgs -} - -func getJSTag(n *ast.CommentGroup) (*structtag.Tag, error) { - if n == nil { - return nil, nil - } - - comments := n.List - for _, comment := range comments { - if !strings.Contains(comment.Text, "js:") { - continue - } - - jstag, err := getJSTagFromString(comment.Text[2:]) - if err != nil { - return nil, err - } - - return jstag, nil - } - - return nil, nil -} - -func getJSTagFromString(tag string) (*structtag.Tag, error) { - tags, err := structtag.Parse(tag) - if err != nil { - return nil, err - } - - jstag, err := tags.Get("js") - if err != nil && err.Error() != "tag does not exist" { - return nil, err - } - - return jstag, nil -} - -func reverse(s []*types.Package) []*types.Package { - for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { - s[i], s[j] = s[j], s[i] - } - return s -} - -// unique returns a unique set of packages -func unique(input []*types.Package) []*types.Package { - u := make([]*types.Package, 0, len(input)) - m := make(map[string]bool) - - for _, pkg := range input { - if _, ok := m[pkg.Path]; !ok { - m[pkg.Path] = true - u = append(u, pkg) - } - } - - return u -} - -func getRuntimePath() (string, error) { - _, file, _, ok := runtime.Caller(0) - if !ok { - return "", errors.New("unable to get the filepath") - } - runtimePkg, err := filepath.Rel(path.Join(os.Getenv("GOPATH"), "src"), path.Join(path.Dir(path.Dir(path.Dir(file))), "runtime")) - if err != nil { - return "", err - } - - return runtimePkg, nil -} - -func checkJSFile(cx *ast.CallExpr, from string) (*types.File, error) { - sel, ok := cx.Fun.(*ast.SelectorExpr) - if !ok { - return nil, nil - } - - x, ok := sel.X.(*ast.Ident) - if !ok { - return nil, nil - } - - if x.Name != "js" || sel.Sel.Name != "File" { - return nil, nil - } - - if len(cx.Args) == 0 { - return nil, nil - } - - lit, ok := cx.Args[0].(*ast.BasicLit) - if !ok { - return nil, nil - } - - filepath := lit.Value[1 : len(lit.Value)-1] - importPath := path.Join(from, filepath) - filepath = path.Join(os.Getenv("GOPATH"), "src", importPath) - - // modify the value to be the fullpath - // TODO: this is super convenient, but - // it may not be clear that this function - // does make modifications to the AST - lit.Value = `"` + importPath + `"` - - src, err := ioutil.ReadFile(filepath) - if err != nil { - return nil, err - } - - return &types.File{ - Name: importPath, - Source: string(src), - }, nil -} - -func checkJSRewrite(cx *ast.CallExpr) (string, []string, error) { - sel, ok := cx.Fun.(*ast.SelectorExpr) - if !ok { - return "", nil, nil - } - - x, ok := sel.X.(*ast.Ident) - if !ok { - return "", nil, nil - } - - if x.Name != "js" || sel.Sel.Name != "Rewrite" { - return "", nil, nil - } - - if len(cx.Args) == 0 { - return "", nil, nil - } - - lit, ok := cx.Args[0].(*ast.BasicLit) - if !ok { - return "", nil, nil - } - - var args []string - for _, arg := range cx.Args[1:] { - switch t := arg.(type) { - case *ast.Ident: - args = append(args, t.Name) - default: - return "", nil, fmt.Errorf("unhandled checkJSRewrite(): %T", arg) - } - } - - // trim off quotes if we've got a string - expr := lit.Value - if lit.Kind == token.STRING { - x, e := strconv.Unquote(expr) - if e != nil { - return "", nil, e - } - expr = x - } - - return expr, args, nil -} - -func getIdentifier(n ast.Expr) (*ast.Ident, error) { - switch t := n.(type) { - case *ast.Ident: - return t, nil - case *ast.StarExpr: - return getIdentifier(t.X) - case *ast.SelectorExpr: - return t.Sel, nil - default: - return nil, fmt.Errorf("unhandled getIdentifier: %T", n) - } -} diff --git a/internal/compiler/translator/translator.go b/internal/compiler/translator/translator.go index 5fd2fc63..e52c6096 100644 --- a/internal/compiler/translator/translator.go +++ b/internal/compiler/translator/translator.go @@ -15,7 +15,6 @@ import ( "golang.org/x/tools/go/loader" - "github.com/matthewmueller/joy/internal/compiler/db" "github.com/matthewmueller/joy/internal/compiler/def" "github.com/matthewmueller/joy/internal/compiler/index" "github.com/matthewmueller/joy/internal/compiler/scope" @@ -25,7 +24,7 @@ import ( // context struct type context struct { - index *db.DB + index *index.Index info *loader.PackageInfo def def.Definition } diff --git a/internal/gendom/generator/funcs.go b/internal/gendom/generator/funcs.go deleted file mode 100644 index 95084f72..00000000 --- a/internal/gendom/generator/funcs.go +++ /dev/null @@ -1,99 +0,0 @@ -package generator - -import ( - "regexp" - "strings" - - "github.com/apex/log" - "github.com/matthewmueller/joy/internal/gen" -) - -var resequence = regexp.MustCompile(`sequence<([\w<>]+)>`) -var repromise = regexp.MustCompile(`Promise<([\w<>]+)>`) - -// coerce transforms the XML type to a Go type -func coerce(idx *index, pkgname string, kind string) (string, error) { - kind = strings.TrimSpace(kind) - isSlice := false - - // TODO: handle unions better - if strings.Contains(kind, " or ") { - return "interface{}", nil - } - - matches := repromise.FindStringSubmatch(kind) - if len(matches) > 1 { - kind = matches[1] - } - - matches = resequence.FindStringSubmatch(kind) - if len(matches) > 1 { - isSlice = true - kind = matches[1] - } - - if overrides[kind] == "" { - kind = gen.Pointer(findPackage(idx, pkgname, kind)) - } else { - kind = overrides[kind] - } - - if isSlice { - return "[]" + kind, nil - } - return kind, nil -} - -// check if the function is async -func isAsync(kind string) bool { - return strings.Contains(kind, "Promise<") -} - -func findPackage(idx *index, currentpkg, name string) string { - if iface, isset := idx.Interfaces[name]; isset { - pkgname := gen.Lowercase(iface.Name) - if pkgname == currentpkg { - return name - } - return pkgname + "." + name - } - - if iface, isset := idx.MixinInterfaces[name]; isset { - pkgname := gen.Lowercase(iface.Name) - if pkgname == currentpkg { - return name - } - return pkgname + "." + name - } - - if enum, isset := idx.Enums[name]; isset { - pkgname := gen.Lowercase(enum.Name) - if pkgname == currentpkg { - return name - } - return pkgname + "." + name - } - - if dict, isset := idx.Dictionaries[name]; isset { - pkgname := gen.Lowercase(dict.Name) - if pkgname == currentpkg { - return name - } - return pkgname + "." + name - } - log.Infof("name=%s", name) - return name -} - -// find the event, traversing up if necessary -func findEvent(idx *index, i *Interface, name string) *Event { - for _, event := range i.Events { - if event.Name == name { - return event - } - } - if i.Extends != "" && i.Extends != "Object" && idx.Interfaces[i.Extends] != nil { - return findEvent(idx, idx.Interfaces[i.Extends], name) - } - return nil -} diff --git a/internal/gendom/generator/generate.go b/internal/gendom/generator/generate.go deleted file mode 100644 index abf8cf7c..00000000 --- a/internal/gendom/generator/generate.go +++ /dev/null @@ -1,536 +0,0 @@ -package generator - -import ( - "fmt" - "path" - "strings" - - "github.com/apex/log" - "github.com/matthewmueller/joy/internal/gen" - "github.com/tj/go/semaphore" -) - -// Generate the DOM -func Generate(src string) (files []gen.File, err error) { - dom, e := parse(src) - if e != nil { - return files, e - } - - idx := newIndex(dom) - - // generate our enums - // TODO: actually generate enums - for _, enum := range dom.Enums { - src, e := enum.Generate(idx) - if e != nil { - return files, e - } - - name := gen.Lowercase(enum.Name) - files = append(files, gen.File{ - Name: path.Join(name, name+".go"), - Source: "package " + name + "\n\n" + src, - }) - } - - // generate our dictionaries - for _, dict := range dom.Dictionaries { - src, e := dict.Generate(idx) - if e != nil { - return files, e - } - - name := gen.Lowercase(dict.Name) - files = append(files, gen.File{ - Name: path.Join(name, name+".go"), - Source: "package " + name + "\n\n" + src, - }) - } - - // generate our mixin interfaces - for _, iface := range dom.MixinInterfaces { - src, e := iface.Generate(idx, nil) - if e != nil { - return files, e - } - - name := gen.Lowercase(iface.Name) - files = append(files, gen.File{ - Name: path.Join(name, name+".go"), - Source: "package " + name + "\n\n" + src, - }) - } - - // generate our interfaces - for _, iface := range dom.Interfaces { - src, e := iface.Generate(idx, nil) - if e != nil { - return files, e - } - - name := gen.Lowercase(iface.Name) - - files = append(files, gen.File{ - Name: path.Join(name, name+".go"), - Source: "package " + name + "\n\n" + src, - }) - } - - filemap := map[string]bool{} - - sem := semaphore.New(5) - for index, file := range files { - if filemap[file.Name] { - panic(file.Name + ": already exists") - } - filemap[file.Name] = true - - i := index - f := file - sem.Run(func() { - output, e := gen.Format(f.Source) - if e != nil { - log.WithError(e).WithField("name", f.Name).Errorf("format error: %s\n", f.Source) - err = e - } - f.Source = output - files[i] = f - }) - } - sem.Wait() - - return files, err -} - -// Generate enums -func (e *Enum) Generate(idx *index) (string, error) { - return gen.Generate("enum/"+e.Name, e, `type {{ .Name }} string`) -} - -type dictionaryData struct { - Name string - Extends string - Members []string -} - -// Generate the Dictionary -func (d *Dictionary) Generate(idx *index) (string, error) { - data := &dictionaryData{} - data.Name = d.Name - - if d.Extends != "" && d.Extends != "Object" { - data.Extends = gen.Pointer(d.Extends) - } - - for _, member := range d.Members { - m, e := member.Generate(idx) - if e != nil { - return "", e - } - data.Members = append(data.Members, m) - } - - return gen.Generate("dictionary/"+d.Name, data, ` - type {{ .Name }} struct { - {{ .Extends }} - - {{ range .Members }} - {{ . }} - {{- end }} - } - `) -} - -type interfaceData struct { - Name string - Extends string - Implements []string - Methods []string - Properties []string -} - -// Generate the type -func (i *Interface) Generate(idx *index, implementor *Interface) (string, error) { - data := interfaceData{} - data.Name = i.Name - - pkgname := gen.Lowercase(i.Name) - - recv := i - if implementor != nil { - recv = implementor - } - - if i.Extends != "" && i.Extends != "Object" { - data.Extends = gen.Pointer(findPackage(idx, pkgname, i.Extends)) - } - - for _, imp := range i.Implements { - data.Implements = append(data.Implements, gen.Pointer(findPackage(idx, pkgname, imp))) - } - - for _, method := range i.Methods { - if method == nil { - continue - } - - m, e := method.Generate(idx, recv) - if e != nil { - return "", e - } - data.Methods = append(data.Methods, m) - } - - for _, property := range i.Properties { - if property == nil { - continue - } - - m, e := property.Generate(idx, recv) - if e != nil { - return "", e - } - data.Properties = append(data.Properties, m) - } - - return gen.Generate("interface/"+i.Name, data, ` -type {{ .Name }} struct { - {{ .Extends }} - - {{- range .Implements }} - {{ . }} - {{- end }} -} - -{{ range .Methods -}} -{{ . }} -{{- end }} - -{{ range .Properties -}} -{{ . }} -{{- end }} -`) -} - -type methodData struct { - Recv string - Name string - Params []gen.Vartype - Result gen.Vartype -} - -// Generate fn -func (m *Method) Generate(idx *index, recv *Interface) (string, error) { - data := methodData{} - data.Recv = gen.Pointer(recv.Name) - data.Name = m.Name - - pkgname := gen.Lowercase(recv.Name) - - for _, param := range m.Params { - // handle callback interfaces - if idx.CallbackInterfaces[param.Type] != nil { - fn := idx.CallbackInterfaces[param.Type] - t, e := fn.Generate(idx, recv) - if e != nil { - return "", e - } - - data.Params = append(data.Params, gen.Vartype{ - Var: gen.Identifier(param.Name), - Type: t, - }) - continue - } - - // handle callback functions - if idx.CallbackFunctions[param.Type] != nil { - fn := idx.CallbackFunctions[param.Type] - t, e := fn.Generate(idx, recv) - if e != nil { - return "", e - } - - data.Params = append(data.Params, gen.Vartype{ - Var: gen.Identifier(param.Name), - Type: t, - }) - continue - } - - t, e := coerce(idx, pkgname, param.Type) - if e != nil { - return "", e - } - - data.Params = append(data.Params, gen.Vartype{ - Var: gen.Identifier(param.Name), - Type: t, - }) - } - - t, e := coerce(idx, pkgname, m.Type) - if e != nil { - return "", e - } - data.Result = gen.Vartype{ - Var: gen.Variable(t), - Type: t, - } - - async := isAsync(m.Type) - - if t == "void" { - if async { - return gen.Generate("method/"+m.Name, data, ` - func ({{ .Recv }}) {{ capitalize .Name }}({{ joinvt .Params }}) { - macro.Rewrite("await $_.{{ .Name }}({{ len .Params | sequence | join }})", {{ joinv .Params }}) - } - `) - } - - return gen.Generate("method/"+m.Name, data, ` - func ({{ .Recv }}) {{ capitalize .Name }}({{ joinvt .Params }}) { - macro.Rewrite("$_.{{ .Name }}({{ len .Params | sequence | join }})", {{ joinv .Params }}) - } - `) - } - - if async { - return gen.Generate("method/"+m.Name, data, ` - func ({{ .Recv }}) {{ capitalize .Name }}({{ joinvt .Params }}) ({{ .Result.Var }} {{ .Result.Type }}) { - macro.Rewrite("await $_.{{ .Name }}({{ len .Params | sequence | join }})", {{ joinv .Params }}) - return {{ .Result.Var }} - } - `) - } - return gen.Generate("method/"+m.Name, data, ` - func ({{ .Recv }}) {{ capitalize .Name }}({{ joinvt .Params }}) ({{ .Result.Var }} {{ .Result.Type }}) { - macro.Rewrite("$_.{{ .Name }}({{ len .Params | sequence | join }})", {{ joinv .Params }}) - return {{ .Result.Var }} - } - `) -} - -type paramData struct { - Name string - Type string -} - -// Generate fn -func (p *Param) Generate(idx *index, recv *Interface) (string, error) { - data := paramData{} - data.Name = gen.Identifier(p.Name) - pkgname := gen.Lowercase(recv.Name) - - t, e := coerce(idx, pkgname, p.Type) - if e != nil { - return "", e - } - data.Type = t - - return gen.Generate("param/"+p.Name, data, `{{ .Name }} {{ .Type }}`) -} - -type propertyData struct { - Recv string - Name string - Result gen.Vartype -} - -// Generate fn -func (p *Property) Generate(idx *index, recv *Interface) (string, error) { - var result []string - - data := propertyData{} - data.Recv = gen.Pointer(recv.Name) - data.Name = p.Name - - pkgname := gen.Lowercase(recv.Name) - - if p.Type == "EventHandler" { - n := "e" - event := idx.Interfaces["Event"] - - ev := findEvent(idx, recv, p.EventHandler) - if ev != nil { - n = ev.Name - event = idx.Interfaces[ev.Type] - } - if event == nil { - return "", fmt.Errorf("%s.%s: couldn't find event name: %s", recv.Name, p.Name, p.EventHandler) - } - - t, e := coerce(idx, pkgname, event.Name) - if e != nil { - return "", e - } - - data.Result = gen.Vartype{ - Var: gen.Identifier(n), - Type: t, - } - } else if idx.CallbackFunctions[p.Type] != nil { - fn := idx.CallbackFunctions[p.Type] - t, e := fn.Generate(idx, recv) - if e != nil { - return "", e - } - - data.Result = gen.Vartype{ - Var: gen.Identifier(fn.Name), - Type: t, - } - } else { - t, e := coerce(idx, pkgname, p.Type) - if e != nil { - return "", e - } - data.Result = gen.Vartype{ - Var: gen.Identifier(p.Name), - Type: t, - } - } - - // only one known instance of this (property that returns a Promise that returns undefined) - // so we'll just special case this for now - async := isAsync(p.Type) - if async && data.Result.Type == "void" { - getter, e := gen.Generate("property_getter/"+p.Name, data, ` - func ({{ .Recv }}) Get{{ capitalize .Name }}() { - macro.Rewrite("await $_.{{ .Name }}") - } - `) - if e != nil { - return "", e - } - result = append(result, getter) - } else { - getter, e := gen.Generate("property_getter/"+p.Name, data, ` - func ({{ .Recv }}) Get{{ capitalize .Name }}() ({{ .Result.Var }} {{ .Result.Type }}) { - macro.Rewrite("$_.{{ .Name }}") - return {{ .Result.Var }} - } - `) - if e != nil { - return "", e - } - result = append(result, getter) - } - - if !p.ReadOnly { - setter, e := gen.Generate("property_setter/"+p.Name, data, ` - func ({{ .Recv }}) Set{{ capitalize .Name }} ({{ .Result.Var }} {{ .Result.Type }}) { - macro.Rewrite("$_.{{ .Name }} = $1", {{ .Result.Var }}) - } - `) - if e != nil { - return "", e - } - result = append(result, setter) - } - - return strings.Join(result, "\n"), nil -} - -type callbackInterfaceData struct { - Name string - Extends string - Params []string - Result string -} - -// Generate the type -func (i *CallbackInterface) Generate(idx *index, recv *Interface) (string, error) { - data := callbackInterfaceData{} - data.Name = i.Name - - pkgname := gen.Lowercase(recv.Name) - - if i.Extends != "" && i.Extends != "Object" { - data.Extends = gen.Pointer(findPackage(idx, pkgname, i.Extends)) - } - - if len(i.Methods) != 1 { - return "", fmt.Errorf("callback_interface: expected %s to only have 1 method, but it has %d methods", i.Name, len(i.Methods)) - } - - method := i.Methods[0] - for _, param := range method.Params { - p, e := param.Generate(idx, recv) - if e != nil { - return "", e - } - data.Params = append(data.Params, p) - } - - t, e := coerce(idx, pkgname, method.Type) - if e != nil { - return "", e - } - data.Result = t - - if t == "void" { - return gen.Generate("callback_interface/"+i.Name, data, `func ({{ join .Params }})`) - } - - return gen.Generate("callback_interface/"+i.Name, data, `func ({{ join .Params }}) ({{ .Result }})`) -} - -type memberData struct { - Name string - Type string -} - -// Generate fn -func (m *Member) Generate(idx *index) (string, error) { - data := memberData{} - data.Name = gen.Identifier(m.Name) - - t, e := coerce(idx, "dom", m.Type) - if e != nil { - return "", e - } - - // make the optional fields pointers - if m.Nullable || !m.Required { - t = gen.Pointer(t) - } - data.Type = t - - return gen.Generate("member/"+m.Name, data, `{{ .Name }} {{ .Type }}`) -} - -// callbackFunctionData struct -type callbackFunctionData struct { - Params []string - Result string -} - -// Generate fn -func (c *CallbackFunction) Generate(idx *index, recv *Interface) (string, error) { - data := callbackFunctionData{} - - pkgname := gen.Lowercase(recv.Name) - - for _, param := range c.Params { - p, e := param.Generate(idx, recv) - if e != nil { - return "", e - } - data.Params = append(data.Params, p) - } - - t, e := coerce(idx, pkgname, c.Type) - if e != nil { - return "", e - } - data.Result = t - - if t == "void" { - return gen.Generate("callback_fn/"+c.Name, data, `func ({{ join .Params }})`) - } - - return gen.Generate("callback_fn/"+c.Name, data, `func ({{ join .Params }}) ({{ .Result }})`) -} diff --git a/internal/gendom/generator/index.go b/internal/gendom/generator/index.go deleted file mode 100644 index 51d2f42d..00000000 --- a/internal/gendom/generator/index.go +++ /dev/null @@ -1,76 +0,0 @@ -package generator - -type index struct { - CallbackFunctions map[string]*CallbackFunction - CallbackInterfaces map[string]*CallbackInterface - Dictionaries map[string]*Dictionary - Enums map[string]*Enum - Interfaces map[string]*Interface - MixinInterfaces map[string]*Interface - TypeDefs map[string]*Typedef -} - -func newIndex(d *dom) *index { - idx := &index{ - CallbackFunctions: map[string]*CallbackFunction{}, - CallbackInterfaces: map[string]*CallbackInterface{}, - Dictionaries: map[string]*Dictionary{}, - Enums: map[string]*Enum{}, - Interfaces: map[string]*Interface{}, - MixinInterfaces: map[string]*Interface{}, - TypeDefs: map[string]*Typedef{}, - } - for _, node := range d.CallbackFunctions { - idx.CallbackFunctions[node.Name] = node - } - for _, node := range d.CallbackInterfaces { - idx.CallbackInterfaces[node.Name] = node - } - for _, node := range d.Dictionaries { - idx.Dictionaries[node.Name] = node - } - for _, node := range d.Enums { - idx.Enums[node.Name] = node - } - for _, node := range d.Interfaces { - idx.Interfaces[node.Name] = node - } - for _, node := range d.MixinInterfaces { - idx.MixinInterfaces[node.Name] = node - } - for _, node := range d.TypeDefs { - idx.TypeDefs[node.NewType] = node - } - - idx = adjust(idx) - return idx -} - -// manual adjustments -func adjust(idx *index) *index { - var iface *Interface - - // Remove some Pointer event properties that - // conflict with methods of the same name - // and aren't in the spec - iface = idx.Interfaces["MSPointerEvent"] - for i, prop := range iface.Properties { - if prop.Name == "currentPoint" { - iface.Properties[i] = nil - } - if prop.Name == "intermediatePoints" { - iface.Properties[i] = nil - } - } - iface = idx.Interfaces["PointerEvent"] - for i, prop := range iface.Properties { - if prop.Name == "currentPoint" { - iface.Properties[i] = nil - } - if prop.Name == "intermediatePoints" { - iface.Properties[i] = nil - } - } - - return idx -} diff --git a/internal/gendom/generator/overrides.go b/internal/gendom/generator/overrides.go deleted file mode 100644 index c1042cc3..00000000 --- a/internal/gendom/generator/overrides.go +++ /dev/null @@ -1,60 +0,0 @@ -package generator - -var overrides = map[string]string{ - "DOMString": "string", - "USVString": "string", - "IDBKeyPath": "string", - "AAGUID": "string", - "EndOfStreamError": "string", - "ReadyState": "string", - - "boolean": "bool", - "bool": "bool", - "Boolean": "bool", - "MSAttestationStatement": "bool", - - "unsigned long": "uint", - "unsigned long long": "uint64", - "unsigned short": "uint8", - "Uint8Array": "[]uint8", - "Uint8ClampedArray": "[]uint8", - - "short": "int8", - "long": "int", - "long long": "int64", - "DOMTimeStamp": "int", - "DOMHighResTimeStamp": "int", - "Int32Array": "[]int32", - - "float": "float32", - "double": "float32", - "unrestricted double": "float32", - "UnrestrictedDouble": "float32", - "Float32Array": "[]float32", - - "void": "void", - - "object": "interface{}", - "any": "interface{}", - "Dictionary": "interface{}", - "payloadType": "interface{}", - "Entry": "interface{}", - "Transferable": "interface{}", - "BodyInit": "interface{}", - - "ArrayBuffer": "[]byte", - "ArrayBufferView": "[]byte", - "BufferSource": "[]byte", - "octet": "byte", - - "EventHandler": "EventHandler", - - "RequestInfo": "*request.Request", - - "function": "func()", - "Function": "func()", - - "Date": "time.Time", - - "WebKitEntry[]": "[]*WebKitEntry", -} diff --git a/internal/gendom/generator/parse.go b/internal/gendom/generator/parse.go deleted file mode 100644 index 3ac9c2cb..00000000 --- a/internal/gendom/generator/parse.go +++ /dev/null @@ -1,27 +0,0 @@ -package generator - -import ( - "bytes" - "encoding/xml" -) - -// dom struct -type dom struct { - WebIDL xml.Name `xml:"webidl-xml"` - CallbackFunctions []*CallbackFunction `xml:"callback-functions>callback-function"` - CallbackInterfaces []*CallbackInterface `xml:"callback-interfaces>interface"` - Dictionaries []*Dictionary `xml:"dictionaries>dictionary"` - Enums []*Enum `xml:"enums>enum"` - Interfaces []*Interface `xml:"interfaces>interface"` - MixinInterfaces []*Interface `xml:"mixin-interfaces>interface"` - TypeDefs []*Typedef `xml:"typedefs>typedef"` -} - -func parse(src string) (*dom, error) { - var d dom - xmlDecoder := xml.NewDecoder(bytes.NewBufferString(src)) - if e := xmlDecoder.Decode(&d); e != nil { - return nil, e - } - return &d, nil -} diff --git a/internal/gendom/generator/structs.go b/internal/gendom/generator/structs.go deleted file mode 100644 index 552b87fa..00000000 --- a/internal/gendom/generator/structs.go +++ /dev/null @@ -1,170 +0,0 @@ -package generator - -import "encoding/xml" - -// Interface struct -type Interface struct { - Name string `xml:"name,attr"` - Extends string `xml:"extends,attr"` - Implements []string `xml:"implements,omitempty"` - NoInterfaceObject bool `xml:"no-interface-object,attr"` - Element []*Element `xml:"element"` - Methods []*Method `xml:"methods>method"` - AnonymousMethods []*Method `xml:"anonymous-methods>method"` - Properties []*Property `xml:"properties>property"` - Constants []*Constant `xml:"constants>constant"` - Constructor Constructor `xml:"constructor,omitempty"` - NamedConstructor NamedConstructor `xml:"named-constructor"` - Events []*Event `xml:"events>event"` - AnonymousContentAttributes []*AnonymousContentAttributes `xml:"anonymous-content-attributes>parsedattribute"` -} - -type addedType struct { - Kind string `json:"kind,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - Flavor string `json:"flavor,omitempty"` - Interface string `json:"interface,omitempty"` - Readonly bool `json:"readonly,omitempty"` - ExposeGlobally bool `json:"expose_globally,omitempty"` - Extends string `json:"extends,omitempty"` - Properties []struct { - Name string `json:"name,omitempty"` - Kind string `json:"kind,omitempty"` - Readonly bool `json:"readonly,omitempty"` - } `json:"properties,omitempty"` - Methods []struct { - Name string `json:"name,omitempty"` - Signatures []string `json:"signatures,omitempty"` - } `json:"methods,omitempty"` - Indexer []struct { - Signatures []string `json:"signatures,omitempty"` - } `json:"indexer,omitempty"` -} - -// CallbackFunction struct -type CallbackFunction struct { - XMLName xml.Name `xml:"callback-function"` - Name string `xml:"name,attr"` - Callback bool `xml:"callback,attr,omitempty"` - Type string `xml:"type,attr"` - Params []Param `xml:"param"` -} - -// Typedef struct -type Typedef struct { - NewType string `xml:"new-type,attr"` - Type string `xml:"type,attr"` -} - -// Enum struct -type Enum struct { - Name string `xml:"name,attr"` - Values []string `xml:"value"` -} - -// Dictionary struct -type Dictionary struct { - Name string `xml:"name,attr"` - Extends string `xml:"extends,attr"` - Members []Member `xml:"members>member"` -} - -// Member struct -type Member struct { - Name string `xml:"name,attr"` - Type string `xml:"type,attr,omitempty"` - Required bool `xml:"required,attr,omitempty"` - Default string `xml:"default,attr,omitempty"` - Nullable bool `xml:"nullable,attr,omitempty"` -} - -// Constant struct -type Constant struct { - Name string `xml:"name,attr"` - Type string `xml:"type,attr"` - TypeOriginal string `xml:"type-original,attr"` - Value string `xml:"value,attr"` -} - -// Constructor struct -type Constructor struct { - Params []Param `xml:"param"` -} - -// NamedConstructor struct -type NamedConstructor struct { - Name string `xml:"name,attr"` - Params []Param `xml:"param"` -} - -// AnonymousContentAttributes struct -type AnonymousContentAttributes struct { - Name string `xml:"name,attr"` - EnumValues string `xml:"enum-values,attr"` - ValueSyntax string `xml:"value-syntax,attr"` -} - -// CallbackInterface struct -type CallbackInterface struct { - Name string `xml:"name,attr"` - Extends string `xml:"extends,attr"` - Methods []*Method `xml:"methods>method"` -} - -// Event struct -type Event struct { - Name string `xml:"name,attr"` - Bubbles bool `xml:"bubbles,attr"` - Cancelable bool `xml:"cancelable,attr"` - Tags string `xml:"tags,attr"` - Dispatch string `xml:"dispatch,attr"` - Follows string `xml:"follows,attr"` - Precedes string `xml:"precedes,attr"` - SkipsWindow bool `xml:"skips-window,attr"` - Type string `xml:"type,attr"` - Aliases string `xml:"aliases,attr"` -} - -// Element struct -type Element struct { - Name string `xml:"name,attr"` - HTMLSelfClosing bool `xml:"html-self-closing,attr"` - Namespace string `xml:"namespace,attr"` -} - -// Method struct -type Method struct { - Name string `xml:"name,attr"` - Type string `xml:"type,attr"` - Creator bool `xml:"creator,attr"` - Setter bool `xml:"setter,attr"` - DoNotCheckDomainSecurity bool `xml:"do-not-check-domain-security,attr"` - Params []Param `xml:"param"` -} - -// Property struct -type Property struct { - Name string `xml:"name,attr"` - Type string `xml:"type,attr"` - ReadOnly bool `xml:"read-only,attr"` - ContentAttribute string `xml:"content-attribute,attr"` - ContentAttributeReflects bool `xml:"content-attribute-reflects,attr"` - ContentAttributeValueSyntax string `xml:"content-attribute-value-syntax,attr"` - ContentAttributeEnumValues string `xml:"content-attribute-enum-values,attr"` - EventHandler string `xml:"event-handler,attr"` - TreatNullAs string `xml:"treat-null-as,attr"` - Nullable bool `xml:"nullable,attr"` - Replaceable bool `xml:"replaceable,attr"` - PropertyDescriptorNotConfigurable bool `xml:"property-descriptor-not-configurable,attr"` - DoNotCheckDomainSecurity bool `xml:"do-not-check-domain-security,attr"` - Unforgeable bool `xml:"unforgeable,attr"` -} - -// Param struct -type Param struct { - Name string `xml:"name,attr"` - Type string `xml:"type,attr,omitempty"` - Optional bool `xml:"optional,attr,omitempty"` - Variadic bool `xml:"variadic,attr,omitempty"` -} diff --git a/internal/gendom/inputs/addedTypes.json b/internal/gendom/inputs/addedTypes.json deleted file mode 100644 index fbb79c10..00000000 --- a/internal/gendom/inputs/addedTypes.json +++ /dev/null @@ -1,2472 +0,0 @@ -[ - { - "kind": "interface", - "name": "BroadcastChannel", - "extends": "EventTarget", - "constructorSignatures": [ - "new(name: string): BroadcastChannel" - ], - "properties": [ - { - "readonly": true, - "name": "name", - "type": "string" - }, - { - "name": "onmessage", - "type": "(ev: MessageEvent) => any" - }, - { - "name": "onmessageerror", - "type": "(ev: MessageEvent) => any" - } - ], - "methods": [ - { - "name": "close", - "signatures": [ - "close(): void" - ] - }, - { - "name": "postMessage", - "signatures": [ - "postMessage(message: any): void" - ] - }, - { - "name": "addEventListener", - "signatures": [ - "addEventListener(type: K, listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void", - "addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void" - ] - }, - { - "name": "removeEventListener", - "signatures": [ - "removeEventListener(type: K, listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, options?: boolean | EventListenerOptions): void", - "removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void" - ] - } - ] - }, - { - "kind": "interface", - "name": "BroadcastChannelEventMap", - "properties": [ - { - "name": "message", - "type": "MessageEvent" - }, - { - "name": "messageerror", - "type": "MessageEvent" - } - ] - }, - { - "kind": "interface", - "name": "ErrorEventInit", - "properties": [ - { - "name": "message?", - "type": "string" - }, - { - "name": "filename?", - "type": "string" - }, - { - "name": "lineno?", - "type": "number" - }, - { - "name": "conlno?", - "type": "number" - }, - { - "name": "error?", - "type": "any" - } - ] - }, - { - "kind": "property", - "interface": "CSSStyleDeclaration", - "name": "resize", - "type": "string | null" - }, - { - "kind": "property", - "interface": "CSSStyleDeclaration", - "name": "userSelect", - "type": "string | null" - }, - { - "kind": "interface", - "name": "StorageEventInit", - "flavor": "Web", - "extends": "EventInit", - "properties": [ - { - "name": "key?", - "type": "string" - }, - { - "name": "oldValue?", - "type": "string" - }, - { - "name": "newValue?", - "type": "string" - }, - { - "name": "url", - "type": "string" - }, - { - "name": "storageArea?", - "type": "Storage" - } - ] - }, - { - "kind": "interface", - "name": "Canvas2DContextAttributes", - "flavor": "Web", - "properties": [ - { - "name": "alpha?", - "type": "boolean" - }, - { - "name": "willReadFrequently?", - "type": "boolean" - }, - { - "name": "storage?", - "type": "boolean" - }, - { - "name": "[attribute: string]", - "type": "boolean | string | undefined" - } - ] - }, - { - "kind": "interface", - "flavor": "Worker", - "name": "ImageBitmapOptions", - "properties": [ - { - "name": "imageOrientation?", - "type": "\"none\" | \"flipY\"" - }, - { - "name": "premultiplyAlpha?", - "type": "\"none\" | \"premultiply\" | \"default\"" - }, - { - "name": "colorSpaceConversion?", - "type": "\"none\" | \"default\"" - }, - { - "name": "resizeWidth?", - "type": "number" - }, - { - "name": "resizeHeight?", - "type": "number" - }, - { - "name": "resizeQuality?", - "type": "\"pixelated\" | \"low\" | \"medium\" | \"high\"" - } - ] - }, - { - "kind": "interface", - "name": "ImageBitmap", - "flavor": "Worker", - "properties": [ - { - "name": "width", - "readonly": true, - "type": "number" - }, - { - "name": "height", - "readonly": true, - "type": "number" - } - ], - "methods": [ - { - "name": "close", - "signatures": [ - "close(): void" - ] - } - ] - }, - { - "kind": "method", - "interface": "Window", - "name": "createImageBitmap", - "signatures": [ - "createImageBitmap(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | ImageData | Blob, options?: ImageBitmapOptions): Promise", - "createImageBitmap(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | ImageData | Blob, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise" - ] - }, - { - "kind": "method", - "interface": "WorkerGlobalScope", - "name": "createImageBitmap", - "signatures": [ - "createImageBitmap(image: ImageBitmap | ImageData | Blob, options?: ImageBitmapOptions): Promise", - "createImageBitmap(image: ImageBitmap | ImageData | Blob, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise" - ] - }, - { - "kind": "property", - "interface": "IDBObjectStoreParameters", - "name": "autoIncrement?", - "type": "boolean" - }, - { - "kind": "property", - "interface": "IDBIndexParameters", - "name": "multiEntry?", - "type": "boolean" - }, - { - "kind": "property", - "interface": "IDBIndex", - "name": "multiEntry", - "type": "boolean" - }, - { - "kind": "interface", - "name": "URLSearchParams", - "constructorSignatures": [ - "new (init?: string | URLSearchParams): URLSearchParams" - ], - "methods": [ - { - "name": "append", - "signatures": [ - "append(name: string, value: string): void" - ] - }, - { - "name": "delete", - "signatures": [ - "delete(name: string): void" - ] - }, - { - "name": "get", - "signatures": [ - "get(name: string): string | null" - ] - }, - { - "name": "getAll", - "signatures": [ - "getAll(name: string): string[]" - ] - }, - { - "name": "has", - "signatures": [ - "has(name: string): boolean" - ] - }, - { - "name": "set", - "signatures": [ - "set(name: string, value: string): void" - ] - } - ] - }, - { - "kind": "property", - "interface": "URL", - "name": "searchParams", - "readonly": true, - "type": "URLSearchParams" - }, - { - "kind": "property", - "interface": "Window", - "exposeGlobally": false, - "name": "URL", - "type": "typeof URL" - }, - { - "kind": "property", - "interface": "Window", - "exposeGlobally": false, - "name": "URLSearchParams", - "type": "typeof URLSearchParams" - }, - { - "kind": "property", - "interface": "Window", - "exposeGlobally": false, - "name": "Blob", - "type": "typeof Blob" - }, - { - "kind": "interface", - "name": "NodeListOf", - "flavor": "Web", - "extends": "NodeList", - "properties": [ - { - "name": "length", - "type": "number" - } - ], - "methods": [ - { - "name": "item", - "signatures": [ - "item(index: number): TNode" - ] - } - ], - "indexer": [ - { - "signatures": [ - "[index: number]: TNode" - ] - } - ] - }, - { - "kind": "interface", - "name": "HTMLCollectionOf", - "flavor": "Web", - "extends": "HTMLCollection", - "methods": [ - { - "name": "item", - "signatures": [ - "item(index: number): T" - ] - }, - { - "name": "namedItem", - "signatures": [ - "namedItem(name: string): T" - ] - } - ], - "indexer": [ - { - "signatures": [ - "[index: number]: T" - ] - } - ] - }, - { - "kind": "interface", - "name": "BlobPropertyBag", - "properties": [ - { - "name": "type?", - "type": "string" - }, - { - "name": "endings?", - "type": "string" - } - ] - }, - { - "kind": "interface", - "name": "FilePropertyBag", - "extends": "BlobPropertyBag", - "properties": [ - { - "name": "lastModified?", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "EventListenerObject", - "methods": [ - { - "name": "handleEvent", - "signatures": [ - "handleEvent(evt: Event): void" - ] - } - ] - }, - { - "kind": "property", - "interface": "MessageEventInit", - "name": "lastEventId?", - "type": "string" - }, - { - "kind": "property", - "interface": "MessageEventInit", - "name": "channel?", - "type": "string" - }, - { - "kind": "interface", - "name": "ProgressEventInit", - "extends": "EventInit", - "properties": [ - { - "name": "lengthComputable?", - "type": "boolean" - }, - { - "name": "loaded?", - "type": "number" - }, - { - "name": "total?", - "type": "number" - } - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "getElementsByClassName(classNames: string): NodeListOf" - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "matches(selector: string): boolean" - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "closest(selector: K): ElementTagNameMap[K] | null" - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "closest(selector: string): Element | null" - ] - }, - { - "kind": "typedef", - "flavor": "Web", - "name": "ScrollBehavior", - "type": "\"auto\" | \"instant\" | \"smooth\"" - }, - { - "kind": "interface", - "flavor": "Web", - "name": "ScrollOptions", - "properties": [ - { - "name": "behavior?", - "type": "ScrollBehavior" - } - ] - }, - { - "kind": "interface", - "flavor": "Web", - "name": "ScrollToOptions", - "extends": "ScrollOptions", - "properties": [ - { - "name": "left?", - "type": "number" - }, - { - "name": "top?", - "type": "number" - } - ] - }, - { - "kind": "method", - "interface": "Window", - "signatures": [ - "scroll(options?: ScrollToOptions): void" - ] - }, - { - "kind": "method", - "interface": "Window", - "signatures": [ - "scrollTo(options?: ScrollToOptions): void" - ] - }, - { - "kind": "method", - "interface": "Window", - "signatures": [ - "scrollBy(options?: ScrollToOptions): void" - ] - }, - { - "kind": "typedef", - "flavor": "Web", - "name": "ScrollLogicalPosition", - "type": "\"start\" | \"center\" | \"end\" | \"nearest\"" - }, - { - "kind": "interface", - "flavor": "Web", - "name": "ScrollIntoViewOptions", - "extends": "ScrollOptions", - "properties": [ - { - "name": "block?", - "type": "ScrollLogicalPosition" - }, - { - "name": "inline?", - "type": "ScrollLogicalPosition" - } - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void" - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "scroll(options?: ScrollToOptions): void", - "scroll(x: number, y: number): void" - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "scrollTo(options?: ScrollToOptions): void", - "scrollTo(x: number, y: number): void" - ] - }, - { - "kind": "method", - "interface": "Element", - "signatures": [ - "scrollBy(options?: ScrollToOptions): void", - "scrollBy(x: number, y: number): void" - ] - }, - { - "kind": "signatureoverload", - "name": "createElementNS", - "interface": "Document", - "signatures": [ - "createElementNS(namespaceURI: \"http://www.w3.org/1999/xhtml\", qualifiedName: string): HTMLElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"a\"): SVGAElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"circle\"): SVGCircleElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"clipPath\"): SVGClipPathElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"componentTransferFunction\"): SVGComponentTransferFunctionElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"defs\"): SVGDefsElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"desc\"): SVGDescElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"ellipse\"): SVGEllipseElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feBlend\"): SVGFEBlendElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feColorMatrix\"): SVGFEColorMatrixElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feComponentTransfer\"): SVGFEComponentTransferElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feComposite\"): SVGFECompositeElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feConvolveMatrix\"): SVGFEConvolveMatrixElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feDiffuseLighting\"): SVGFEDiffuseLightingElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feDisplacementMap\"): SVGFEDisplacementMapElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feDistantLight\"): SVGFEDistantLightElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feFlood\"): SVGFEFloodElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feFuncA\"): SVGFEFuncAElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feFuncB\"): SVGFEFuncBElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feFuncG\"): SVGFEFuncGElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feFuncR\"): SVGFEFuncRElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feGaussianBlur\"): SVGFEGaussianBlurElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feImage\"): SVGFEImageElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feMerge\"): SVGFEMergeElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feMergeNode\"): SVGFEMergeNodeElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feMorphology\"): SVGFEMorphologyElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feOffset\"): SVGFEOffsetElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"fePointLight\"): SVGFEPointLightElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feSpecularLighting\"): SVGFESpecularLightingElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feSpotLight\"): SVGFESpotLightElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feTile\"): SVGFETileElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"feTurbulence\"): SVGFETurbulenceElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"filter\"): SVGFilterElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"foreignObject\"): SVGForeignObjectElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"g\"): SVGGElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"image\"): SVGImageElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"gradient\"): SVGGradientElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"line\"): SVGLineElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"linearGradient\"): SVGLinearGradientElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"marker\"): SVGMarkerElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"mask\"): SVGMaskElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"path\"): SVGPathElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"metadata\"): SVGMetadataElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"pattern\"): SVGPatternElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"polygon\"): SVGPolygonElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"polyline\"): SVGPolylineElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"radialGradient\"): SVGRadialGradientElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"rect\"): SVGRectElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"svg\"): SVGSVGElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"script\"): SVGScriptElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"stop\"): SVGStopElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"style\"): SVGStyleElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"switch\"): SVGSwitchElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"symbol\"): SVGSymbolElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"tspan\"): SVGTSpanElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"textContent\"): SVGTextContentElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"text\"): SVGTextElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"textPath\"): SVGTextPathElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"textPositioning\"): SVGTextPositioningElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"title\"): SVGTitleElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"use\"): SVGUseElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: \"view\"): SVGViewElement", - "createElementNS(namespaceURI: \"http://www.w3.org/2000/svg\", qualifiedName: string): SVGElement" - ] - }, - { - "kind": "method", - "interface": "Navigator", - "signatures": [ - "vibrate(pattern: number | number[]): boolean" - ] - }, - { - "kind": "property", - "interface": "Navigator", - "readonly": true, - "name": "doNotTrack", - "type": "string | null" - }, - { - "kind": "property", - "interface": "Navigator", - "name": "hardwareConcurrency", - "readonly": true, - "type": "number" - }, - { - "kind": "property", - "interface": "Navigator", - "name": "languages", - "readonly": true, - "type": "string[]" - }, - { - "kind": "property", - "interface": "WorkerNavigator", - "name": "hardwareConcurrency", - "readonly": true, - "type": "number" - }, - { - "kind": "property", - "interface": "HTMLLinkElement", - "name": "import?", - "type": "Document" - }, - { - "kind": "method", - "interface": "HTMLCanvasElement", - "name": "toBlob", - "signatures": [ - "toBlob(callback: (result: Blob | null) => void, type?: string, ...arguments: any[]): void" - ] - }, - { - "kind": "property", - "interface": "StorageEvent", - "name": "key?", - "type": "string" - }, - { - "kind": "property", - "interface": "StorageEvent", - "name": "oldValue?", - "type": "string" - }, - { - "kind": "property", - "interface": "StorageEvent", - "name": "newValue?", - "type": "string" - }, - { - "kind": "property", - "interface": "StorageEvent", - "name": "storageArea?", - "type": "Storage" - }, - { - "kind": "property", - "interface": "IDBObjectStore", - "name": "autoIncrement", - "type": "boolean" - }, - { - "kind": "interface", - "flavor": "Web", - "name": "ClipboardEventInit", - "extends": "EventInit", - "properties": [ - { - "name": "data?", - "type": "string" - }, - { - "name": "dataType?", - "type": "string" - } - ] - }, - { - "kind": "typedef", - "name": "IDBValidKey", - "type": "number | string | Date | IDBArrayKey" - }, - { - "kind": "interface", - "name": "IDBArrayKey", - "extends": "Array" - }, - { - "kind": "property", - "interface": "HTMLInputElement", - "name": "minLength", - "type": "number" - }, - { - "kind": "property", - "interface": "HTMLTextAreaElement", - "name": "minLength", - "type": "number" - }, - { - "kind": "property", - "interface": "IDBDatabase", - "name": "onversionchange", - "type": "(ev: IDBVersionChangeEvent) => any" - }, - { - "kind": "method", - "interface": "IDBDatabase", - "name": "addEventListener", - "signatures": [ - "addEventListener(type: \"versionchange\", listener: (this: IDBDatabase, ev: IDBVersionChangeEvent) => any, options?: boolean | AddEventListenerOptions): void" - ] - }, - { - "kind": "method", - "interface": "IDBDatabase", - "name": "removeEventListener", - "signatures": [ - "removeEventListener(type: \"versionchange\", listener: (this: IDBDatabase, ev: IDBVersionChangeEvent) => any, options?: boolean | EventListenerOptions): void" - ] - }, - { - "kind": "property", - "interface": "CanvasRenderingContext2D", - "name": "mozImageSmoothingEnabled", - "type": "boolean" - }, - { - "kind": "property", - "interface": "CanvasRenderingContext2D", - "name": "webkitImageSmoothingEnabled", - "type": "boolean" - }, - { - "kind": "property", - "interface": "CanvasRenderingContext2D", - "name": "oImageSmoothingEnabled", - "type": "boolean" - }, - { - "kind": "property", - "interface": "WebGLContextAttributes", - "name": "failIfMajorPerformanceCaveat?", - "type": "boolean" - }, - { - "kind": "typedef", - "name": "BufferSource", - "type": "ArrayBuffer | ArrayBufferView" - }, - { - "kind": "interface", - "name": "RsaKeyGenParams", - "extends": "Algorithm", - "properties": [ - { - "name": "modulusLength", - "type": "number" - }, - { - "name": "publicExponent", - "type": "Uint8Array" - } - ] - }, - { - "kind": "interface", - "name": "RsaHashedKeyGenParams", - "extends": "RsaKeyGenParams", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - } - ] - }, - { - "kind": "interface", - "name": "RsaKeyAlgorithm", - "extends": "KeyAlgorithm", - "properties": [ - { - "name": "modulusLength", - "type": "number" - }, - { - "name": "publicExponent", - "type": "Uint8Array" - } - ] - }, - { - "kind": "interface", - "name": "RsaHashedKeyAlgorithm", - "extends": "RsaKeyAlgorithm", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - } - ] - }, - { - "kind": "interface", - "name": "RsaHashedImportParams", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - } - ] - }, - { - "kind": "interface", - "name": "RsaPssParams", - "properties": [ - { - "name": "saltLength", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "RsaOaepParams", - "extends": "Algorithm", - "properties": [ - { - "name": "label?", - "type": "BufferSource" - } - ] - }, - { - "kind": "interface", - "name": "EcdsaParams", - "extends": "Algorithm", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - } - ] - }, - { - "kind": "interface", - "name": "EcKeyGenParams", - "extends": "Algorithm", - "properties": [ - { - "name": "namedCurve", - "type": "string" - } - ] - }, - { - "kind": "interface", - "name": "EcKeyAlgorithm", - "extends": "KeyAlgorithm", - "properties": [ - { - "name": "typedCurve", - "type": "string" - } - ] - }, - { - "kind": "interface", - "name": "EcKeyImportParams", - "extends": "Algorithm", - "properties": [ - { - "name": "namedCurve", - "type": "string" - } - ] - }, - { - "kind": "interface", - "name": "EcdhKeyDeriveParams", - "extends": "Algorithm", - "properties": [ - { - "name": "public", - "type": "CryptoKey" - } - ] - }, - { - "kind": "interface", - "name": "AesCtrParams", - "extends": "Algorithm", - "properties": [ - { - "name": "counter", - "type": "BufferSource" - }, - { - "name": "length", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "AesKeyAlgorithm", - "extends": "KeyAlgorithm", - "properties": [ - { - "name": "length", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "AesKeyGenParams", - "extends": "Algorithm", - "properties": [ - { - "name": "length", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "AesDerivedKeyParams", - "extends": "Algorithm", - "properties": [ - { - "name": "length", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "AesCbcParams", - "extends": "Algorithm", - "properties": [ - { - "name": "iv", - "type": "BufferSource" - } - ] - }, - { - "kind": "interface", - "name": "AesCmacParams", - "extends": "Algorithm", - "properties": [ - { - "name": "length", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "AesGcmParams", - "extends": "Algorithm", - "properties": [ - { - "name": "iv", - "type": "BufferSource" - }, - { - "name": "additionalData?", - "type": "BufferSource" - }, - { - "name": "tagLength?", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "AesCfbParams", - "extends": "Algorithm", - "properties": [ - { - "name": "iv", - "type": "BufferSource" - } - ] - }, - { - "kind": "interface", - "name": "HmacImportParams", - "extends": "Algorithm", - "properties": [ - { - "name": "hash?", - "type": "AlgorithmIdentifier" - }, - { - "name": "length?", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "HmacKeyAlgorithm", - "extends": "KeyAlgorithm", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - }, - { - "name": "length", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "HmacKeyGenParams", - "extends": "Algorithm", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - }, - { - "name": "length?", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "DhKeyGenParams", - "extends": "Algorithm", - "properties": [ - { - "name": "prime", - "type": "Uint8Array" - }, - { - "name": "generator", - "type": "Uint8Array" - } - ] - }, - { - "kind": "interface", - "name": "DhKeyAlgorithm", - "extends": "KeyAlgorithm", - "properties": [ - { - "name": "prime", - "type": "Uint8Array" - }, - { - "name": "generator", - "type": "Uint8Array" - } - ] - }, - { - "kind": "interface", - "name": "DhKeyDeriveParams", - "extends": "Algorithm", - "properties": [ - { - "name": "public", - "type": "CryptoKey" - } - ] - }, - { - "kind": "interface", - "name": "DhImportKeyParams", - "extends": "Algorithm", - "properties": [ - { - "name": "prime", - "type": "Uint8Array" - }, - { - "name": "generator", - "type": "Uint8Array" - } - ] - }, - { - "kind": "interface", - "name": "ConcatParams", - "extends": "Algorithm", - "properties": [ - { - "name": "hash?", - "type": "AlgorithmIdentifier" - }, - { - "name": "algorithmId", - "type": "Uint8Array" - }, - { - "name": "partyUInfo", - "type": "Uint8Array" - }, - { - "name": "partyVInfo", - "type": "Uint8Array" - }, - { - "name": "publicInfo?", - "type": "Uint8Array" - }, - { - "name": "privateInfo?", - "type": "Uint8Array" - } - ] - }, - { - "kind": "interface", - "name": "HkdfCtrParams", - "extends": "Algorithm", - "properties": [ - { - "name": "hash", - "type": "AlgorithmIdentifier" - }, - { - "name": "label", - "type": "BufferSource" - }, - { - "name": "context", - "type": "BufferSource" - } - ] - }, - { - "kind": "interface", - "name": "Pbkdf2Params", - "extends": "Algorithm", - "properties": [ - { - "name": "salt", - "type": "BufferSource" - }, - { - "name": "iterations", - "type": "number" - }, - { - "name": "hash", - "type": "AlgorithmIdentifier" - } - ] - }, - { - "kind": "interface", - "name": "RsaOtherPrimesInfo", - "properties": [ - { - "name": "r", - "type": "string" - }, - { - "name": "d", - "type": "string" - }, - { - "name": "t", - "type": "string" - } - ] - }, - { - "kind": "interface", - "name": "JsonWebKey", - "properties": [ - { - "name": "kty", - "type": "string" - }, - { - "name": "use?", - "type": "string" - }, - { - "name": "key_ops?", - "type": "string[]" - }, - { - "name": "alg?", - "type": "string" - }, - { - "name": "kid?", - "type": "string" - }, - { - "name": "x5u?", - "type": "string" - }, - { - "name": "x5c?", - "type": "string" - }, - { - "name": "x5t?", - "type": "string" - }, - { - "name": "ext?", - "type": "boolean" - }, - { - "name": "crv?", - "type": "string" - }, - { - "name": "x?", - "type": "string" - }, - { - "name": "y?", - "type": "string" - }, - { - "name": "d?", - "type": "string" - }, - { - "name": "n?", - "type": "string" - }, - { - "name": "e?", - "type": "string" - }, - { - "name": "p?", - "type": "string" - }, - { - "name": "q?", - "type": "string" - }, - { - "name": "dp?", - "type": "string" - }, - { - "name": "dq?", - "type": "string" - }, - { - "name": "qi?", - "type": "string" - }, - { - "name": "oth?", - "type": "RsaOtherPrimesInfo[]" - }, - { - "name": "k?", - "type": "string" - } - ] - }, - { - "kind": "property", - "name": "msCaching?", - "interface": "XMLHttpRequest", - "type": "string" - }, - { - "kind": "typedef", - "name": "MouseWheelEvent", - "flavor": "Web", - "type": "WheelEvent" - }, - { - "kind": "method", - "interface": "DataTransfer", - "name": "setDragImage", - "signatures": [ - "setDragImage(image: Element, x: number, y: number): void" - ] - }, - { - "kind": "method", - "interface": "Element", - "name": "insertAdjacentElement", - "signatures": [ - "insertAdjacentElement(position: InsertPosition, insertedElement: Element): Element | null" - ] - }, - { - "kind": "method", - "interface": "Element", - "name": "insertAdjacentHTML", - "signatures": [ - "insertAdjacentHTML(where: InsertPosition, html: string): void" - ] - }, - { - "kind": "method", - "interface": "Element", - "name": "insertAdjacentText", - "signatures": [ - "insertAdjacentText(where: InsertPosition, text: string): void" - ] - }, - { - "kind": "property", - "name": "secureConnectionStart", - "interface": "PerformanceTiming", - "readonly": true, - "type": "number" - }, - { - "kind": "property", - "interface": "HTMLLinkElement", - "name": "integrity", - "type": "string" - }, - { - "kind": "property", - "interface": "HTMLScriptElement", - "name": "integrity", - "type": "string" - }, - { - "kind": "property", - "interface": "KeyboardEvent", - "readonly": true, - "name": "code", - "type": "string" - }, - { - "kind": "property", - "interface": "KeyboardEventInit", - "name": "code?", - "type": "string" - }, - { - "kind": "interface", - "name": "ParentNode", - "flavor": "DOM", - "properties": [ - { - "name": "children", - "readonly": true, - "type": "HTMLCollection" - }, - { - "name": "firstElementChild", - "readonly": true, - "type": "Element | null" - }, - { - "name": "lastElementChild", - "readonly": true, - "type": "Element | null" - }, - { - "name": "childElementCount", - "readonly": true, - "type": "number" - } - ] - }, - { - "kind": "extends", - "baseInterface": "ParentNode", - "interface": "Element" - }, - { - "kind": "extends", - "baseInterface": "ParentNode", - "interface": "Document" - }, - { - "kind": "extends", - "baseInterface": "ParentNode", - "interface": "DocumentFragment" - }, - { - "kind": "typedef", - "name": "ScrollRestoration", - "flavor": "DOM", - "type": "\"auto\" | \"manual\"" - }, - { - "kind": "property", - "interface": "History", - "name": "scrollRestoration", - "type": "ScrollRestoration" - }, - { - "kind": "method", - "interface": "CanvasPattern", - "name": "setTransform", - "signatures": [ - "setTransform(matrix: SVGMatrix): void" - ] - }, - { - "kind": "interface", - "name": "DocumentOrShadowRoot", - "flavor": "DOM", - "methods": [ - { - "name": "getSelection", - "signatures": [ - "getSelection(): Selection | null" - ] - }, - { - "name": "elementFromPoint", - "signatures": [ - "elementFromPoint(x: number, y: number): Element | null" - ] - }, - { - "name": "elementsFromPoint", - "signatures": [ - "elementsFromPoint(x: number, y: number): Element[]" - ] - } - ], - "properties": [ - { - "name": "activeElement", - "type": "Element | null", - "readonly": true - }, - { - "name": "stylesheets", - "type": "StyleSheetList", - "readonly": true - } - ] - }, - { - "kind": "interface", - "name": "ShadowRoot", - "extends": "DocumentOrShadowRoot, DocumentFragment", - "flavor": "DOM", - "properties": [ - { - "name": "host", - "type": "Element", - "readonly": true - }, - { - "name": "innerHTML", - "type": "string" - } - ] - }, - { - "kind": "method", - "interface": "Element", - "name": "attachShadow", - "signatures": [ - "attachShadow(shadowRootInitDict: ShadowRootInit): ShadowRoot" - ] - }, - { - "kind": "property", - "interface": "Element", - "name": "assignedSlot", - "type": "HTMLSlotElement | null", - "readonly": true - }, - { - "kind": "property", - "interface": "Element", - "name": "slot", - "type": "string" - }, - { - "kind": "property", - "interface": "Element", - "name": "shadowRoot", - "type": "ShadowRoot | null", - "readonly": true - }, - { - "kind": "interface", - "name": "ShadowRootInit", - "flavor": "DOM", - "properties": [ - { - "name": "mode", - "type": "\"open\" | \"closed\"" - }, - { - "name": "delegatesFocus?", - "type": "boolean" - } - ] - }, - { - "kind": "property", - "interface": "Text", - "name": "assignedSlot", - "type": "HTMLSlotElement | null", - "readonly": true - }, - { - "kind": "interface", - "name": "HTMLSlotElement", - "extends": "HTMLElement", - "flavor": "DOM", - "properties": [ - { - "name": "name", - "type": "string" - } - ], - "methods": [ - { - "name": "assignedNodes", - "signatures": [ - "assignedNodes(options?: AssignedNodesOptions): Node[]" - ] - } - ] - }, - { - "kind": "interface", - "name": "AssignedNodesOptions", - "flavor": "DOM", - "properties": [ - { - "name": "flatten?", - "type": "boolean" - } - ] - }, - { - "kind": "property", - "interface": "EventInit", - "name": "scoped?", - "type": "boolean" - }, - { - "kind": "property", - "interface": "Event", - "name": "scoped", - "type": "boolean", - "readonly": true - }, - { - "kind": "method", - "interface": "Event", - "name": "deepPath", - "signatures": [ - "deepPath(): EventTarget[]" - ] - }, - { - "kind": "interface", - "name": "ElementDefinitionOptions", - "flavor": "DOM", - "properties": [ - { - "name": "extends", - "type": "string" - } - ] - }, - { - "kind": "interface", - "name": "CustomElementRegistry", - "flavor": "DOM", - "methods": [ - { - "name": "define", - "signatures": [ - "define(name: string, constructor: Function, options?: ElementDefinitionOptions): void" - ] - }, - { - "name": "get", - "signatures": [ - "get(name: string): any" - ] - }, - { - "name": "whenDefined", - "signatures": [ - "whenDefined(name: string): PromiseLike" - ] - } - ] - }, - { - "kind": "property", - "interface": "Window", - "name": "customElements", - "type": "CustomElementRegistry" - }, - { - "kind": "interface", - "name": "PromiseRejectionEvent", - "extends": "Event", - "flavor": "Web", - "properties": [ - { - "name": "promise", - "type": "PromiseLike", - "readonly": true - }, - { - "name": "reason", - "type": "any", - "readonly": true - } - ] - }, - { - "kind": "interface", - "name": "PromiseRejectionEventInit", - "extends": "EventInit", - "flavor": "Web", - "properties": [ - { - "name": "promise", - "type": "PromiseLike" - }, - { - "name": "reason?", - "type": "any" - } - ] - }, - { - "kind": "method", - "interface": "Body", - "name": "formData", - "flavor": "Web", - "signatures": [ - "formData(): Promise" - ] - }, - { - "kind": "method", - "interface": "DocumentFragment", - "name": "getElementById", - "flavor": "DOM", - "signatures": [ - "getElementById(elementId: string): HTMLElement | null" - ] - }, - { - "kind": "typedef", - "name": "FormDataEntryValue", - "type": "string | File" - }, - { - "kind": "method", - "interface": "FormData", - "name": "delete", - "flavor": "Web", - "signatures": [ - "delete(name: string): void" - ] - }, - { - "kind": "method", - "interface": "FormData", - "name": "get", - "flavor": "Web", - "signatures": [ - "get(name: string): FormDataEntryValue | null" - ] - }, - { - "kind": "method", - "interface": "FormData", - "name": "getAll", - "flavor": "Web", - "signatures": [ - "getAll(name: string): FormDataEntryValue[]" - ] - }, - { - "kind": "method", - "interface": "FormData", - "name": "has", - "flavor": "Web", - "signatures": [ - "has(name: string): boolean" - ] - }, - { - "kind": "method", - "interface": "FormData", - "name": "set", - "flavor": "Web", - "signatures": [ - "set(name: string, value: string | Blob, fileName?: string): void" - ] - }, - { - "kind": "interface", - "name": "EventListenerOptions", - "properties": [ - { - "name": "capture?", - "type": "boolean" - } - ] - }, - { - "kind": "interface", - "name": "AddEventListenerOptions", - "extends": "EventListenerOptions", - "properties": [ - { - "name": "passive?", - "type": "boolean" - }, - { - "name": "once?", - "type": "boolean" - } - ] - }, - { - "kind": "interface", - "name": "TouchEventInit", - "flavor": "Web", - "extends": "EventModifierInit", - "properties": [ - { - "name": "touches?", - "type": "Touch[]" - }, - { - "name": "targetTouches?", - "type": "Touch[]" - }, - { - "name": "changedTouches?", - "type": "Touch[]" - } - ] - }, - { - "kind": "typedef", - "name": "InsertPosition", - "flavor": "Web", - "type": "\"beforebegin\" | \"afterbegin\" | \"beforeend\" | \"afterend\"" - }, - { - "kind": "property", - "interface": "IntersectionObserverEntryInit", - "name": "isIntersecting", - "type": "boolean" - }, - { - "kind": "property", - "interface": "IntersectionObserverEntry", - "name": "isIntersecting", - "type": "boolean", - "readonly": true - }, - { - "kind": "property", - "interface": "ValidityState", - "name": "tooShort", - "flavor": "Web", - "readonly": true, - "type": "boolean" - }, - { - "kind": "interface", - "name": "HTMLDialogElement", - "constructorSignatures": [ - "new(): HTMLDialogElement" - ], - "extends": "HTMLElement", - "flavor": "DOM", - "properties": [ - { - "name": "open", - "type": "boolean" - }, - { - "name": "returnValue", - "type": "string" - } - ], - "methods": [ - { - "name": "close", - "signatures": [ - "close(returnValue?: string): void" - ] - }, - { - "name": "show", - "signatures": [ - "show(): void" - ] - }, - { - "name": "showModal", - "signatures": [ - "showModal(): void" - ] - } - ] - }, - { - "kind": "property", - "interface": "Response", - "name": "redirected", - "readonly": true, - "type": "boolean" - }, - { - "kind": "interface", - "name": "HTMLMainElement", - "constructorSignatures": [ - "new(): HTMLMainElement" - ], - "extends": "HTMLElement", - "flavor": "DOM" - }, - { - "kind": "interface", - "name": "HTMLDetailsElement", - "constructorSignatures": [ - "new(): HTMLDetailsElement" - ], - "extends": "HTMLElement", - "flavor": "DOM", - "properties": [ - { - "name": "open", - "type": "boolean" - } - ] - }, - { - "kind": "interface", - "name": "HTMLSummaryElement", - "constructorSignatures": [ - "new(): HTMLSummaryElement" - ], - "extends": "HTMLElement", - "flavor": "DOM" - }, - { - "kind": "interface", - "name": "EXT_blend_minmax", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "MIN_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "MAX_EXT", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "EXT_frag_depth", - "flavor": "DOM", - "properties": [] - }, - { - "kind": "interface", - "name": "EXT_shader_texture_lod", - "flavor": "DOM", - "properties": [] - }, - { - "kind": "interface", - "name": "EXT_sRGB", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "SRGB_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "SRGB_ALPHA_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "SRGB8_ALPHA8_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "OES_vertex_array_object", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "VERTEX_ARRAY_BINDING_OES", - "type": "number" - } - ], - "methods": [ - { - "name": "createVertexArrayOES", - "signatures": [ - "createVertexArrayOES(): WebGLVertexArrayObjectOES" - ] - }, - { - "name": "deleteVertexArrayOES", - "signatures": [ - "deleteVertexArrayOES(arrayObject: WebGLVertexArrayObjectOES): void" - ] - }, - { - "name": "isVertexArrayOES", - "signatures": [ - "isVertexArrayOES(value: any): value is WebGLVertexArrayObjectOES" - ] - }, - { - "name": "bindVertexArrayOES", - "signatures": [ - "bindVertexArrayOES(arrayObject: WebGLVertexArrayObjectOES): void" - ] - } - ] - }, - { - "kind": "interface", - "name": "WebGLVertexArrayObjectOES", - "flavor": "DOM", - "properties": [] - }, - { - "kind": "interface", - "name": "WEBGL_color_buffer_float", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "RGBA32F_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "RGB32F_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "UNSIGNED_NORMALIZED_EXT", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "WEBGL_compressed_texture_astc", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_4x4_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_5x4_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_5x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_6x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_6x6_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_8x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_8x6_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_8x8_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_10x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_10x6_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_10x8_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_10x10_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_12x10_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_RGBA_ASTC_12x12_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR", - "type": "number" - } - ], - "methods": [ - { - "name": "getSupportedProfiles", - "signatures": [ - "getSupportedProfiles(): string[]" - ] - } - ] - }, - { - "kind": "interface", - "name": "WEBGL_compressed_texture_s3tc_srgb", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "COMPRESSED_SRGB_S3TC_DXT1_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT", - "type": "number" - }, - { - "readonly": true, - "name": "COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT", - "type": "number" - } - ] - }, - { - "kind": "interface", - "name": "WEBGL_debug_shaders", - "flavor": "DOM", - "methods": [ - { - "name": "getTranslatedShaderSource", - "signatures": [ - "getTranslatedShaderSource(shader: WebGLShader): string" - ] - } - ] - }, - { - "kind": "interface", - "name": "WEBGL_draw_buffers", - "flavor": "DOM", - "properties": [ - { - "readonly": true, - "name": "COLOR_ATTACHMENT0_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT1_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT2_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT3_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT4_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT5_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT6_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT7_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT8_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT9_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT10_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT11_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT12_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT13_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT14_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "COLOR_ATTACHMENT15_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER0_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER1_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER2_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER3_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER4_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER5_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER6_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER7_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER8_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER9_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER10_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER11_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER12_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER13_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER14_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "DRAW_BUFFER15_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "MAX_COLOR_ATTACHMENTS_WEBGL", - "type": "number" - }, - { - "readonly": true, - "name": "MAX_DRAW_BUFFERS_WEBGL", - "type": "number" - } - ], - "methods": [ - { - "name": "drawBuffersWEBGL", - "signatures": [ - "drawBuffersWEBGL(buffers: number[]): void" - ] - } - ] - }, - { - "kind": "interface", - "name": "WEBGL_lose_context", - "flavor": "DOM", - "methods": [ - { - "name": "loseContext", - "signatures": [ - "loseContext(): void" - ] - }, - { - "name": "restoreContext", - "signatures": [ - "restoreContext(): void" - ] - } - ] - }, - { - "kind": "method", - "interface": "HTMLFormElement", - "name": "reportValidity", - "flavor": "DOM", - "signatures": [ - "reportValidity(): boolean" - ] - }, - { - "kind": "typedef", - "name": "HeadersInit", - "type": "Headers | string[][] | { [key: string]: string }" - }, - { - "kind": "property", - "interface": "HTMLLabelElement", - "readonly": true, - "name": "control", - "type": "HTMLInputElement | null" - } -] \ No newline at end of file diff --git a/internal/gendom/inputs/overrides.json b/internal/gendom/inputs/overrides.json deleted file mode 100644 index 9e26dfee..00000000 --- a/internal/gendom/inputs/overrides.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/internal/gendom/main.go b/internal/gendom/main.go deleted file mode 100644 index 34576b00..00000000 --- a/internal/gendom/main.go +++ /dev/null @@ -1,38 +0,0 @@ -//go:generate go run main.go - -package main - -import ( - "io/ioutil" - "os" - "path" - - "github.com/apex/log" - "github.com/apex/log/handlers/text" - "github.com/matthewmueller/joy/internal/gendom/generator" -) - -func main() { - log.SetHandler(text.New(os.Stderr)) - - dom := path.Join("inputs", "browser.webidl.xml") - src, err := ioutil.ReadFile(dom) - if err != nil { - log.WithError(err).Fatalf("error reading file") - } - - files, err := generator.Generate(string(src)) - if err != nil { - log.WithError(err).Fatalf("error generating dom") - } - - for _, file := range files { - outpath := path.Join("dom", file.Name) - if e := os.MkdirAll(path.Dir(outpath), os.ModePerm); e != nil { - log.WithError(e).Fatalf("error making directory") - } - if e := ioutil.WriteFile(outpath, []byte(file.Source), os.ModePerm); e != nil { - log.WithError(e).Fatalf("error writing file") - } - } -} diff --git a/internal/genvdom/data/elements.json b/internal/genvdom/data/elements.json deleted file mode 100644 index 38591013..00000000 --- a/internal/genvdom/data/elements.json +++ /dev/null @@ -1,1011 +0,0 @@ -{ - "tags": [ - "a", - "abbr", - "acronym", - "address", - "applet", - "area", - "article", - "aside", - "audio", - "b", - "base", - "basefont", - "bdi", - "bdo", - "bgsound", - "big", - "blink", - "blockquote", - "body", - "br", - "button", - "canvas", - "caption", - "center", - "cite", - "code", - "col", - "colgroup", - "command", - "content", - "data", - "datalist", - "dd", - "del", - "details", - "dfn", - "dialog", - "dir", - "div", - "dl", - "dt", - "element", - "em", - "embed", - "fieldset", - "figcaption", - "figure", - "font", - "footer", - "form", - "frame", - "frameset", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "head", - "header", - "hgroup", - "hr", - "html", - "i", - "iframe", - "image", - "img", - "input", - "ins", - "isindex", - "kbd", - "keygen", - "label", - "legend", - "li", - "link", - "listing", - "main", - "map", - "mark", - "marquee", - "math", - "menu", - "menuitem", - "meta", - "meter", - "multicol", - "nav", - "nextid", - "nobr", - "noembed", - "noframes", - "noscript", - "object", - "ol", - "optgroup", - "option", - "output", - "p", - "param", - "picture", - "plaintext", - "pre", - "progress", - "q", - "rb", - "rbc", - "rp", - "rt", - "rtc", - "ruby", - "s", - "samp", - "script", - "section", - "select", - "shadow", - "small", - "source", - "spacer", - "span", - "strike", - "strong", - "style", - "sub", - "summary", - "sup", - "svg", - "table", - "tbody", - "td", - "template", - "textarea", - "tfoot", - "th", - "thead", - "time", - "title", - "tr", - "track", - "tt", - "u", - "ul", - "var", - "video", - "wbr", - "xmp" - ], - "index": [ - [ - 52, - 53, - 54, - 55, - 56, - 20, - 57, - 58, - 59, - 60, - 22, - 49 - ], - [], - [], - [], - [ - 1, - 23, - 67, - 68, - 69, - 8, - 70, - 20, - 71, - 72, - 13 - ], - [ - 23, - 53, - 54, - 55, - 56, - 61, - 57, - 58, - 60, - 22, - 49 - ], - [], - [], - [ - 130, - 131, - 82, - 132, - 133, - 134, - 135, - 47 - ], - [], - [ - 55, - 22 - ], - [ - 111, - 112, - 46 - ], - [], - [], - [], - [], - [], - [ - 108 - ], - [ - 98, - 99, - 3, - 100, - 101, - 102 - ], - [ - 110 - ], - [ - 24, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 62, - 20, - 49, - 51 - ], - [ - 8, - 13 - ], - [ - 1 - ], - [], - [], - [], - [ - 1, - 4, - 5, - 97, - 12, - 13 - ], - [ - 1, - 4, - 5, - 97, - 12, - 13 - ], - [], - [], - [ - 51 - ], - [], - [], - [ - 108, - 109 - ], - [ - 145 - ], - [], - [ - 145 - ], - [ - 113 - ], - [ - 1 - ], - [ - 113 - ], - [], - [], - [], - [ - 8, - 47, - 49, - 13 - ], - [ - 27, - 28, - 20 - ], - [], - [], - [ - 111, - 112, - 46 - ], - [], - [ - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22 - ], - [ - 74, - 75, - 76, - 77, - 20, - 121, - 79, - 47 - ], - [ - 64, - 65 - ], - [ - 1 - ], - [ - 1 - ], - [ - 1 - ], - [ - 1 - ], - [ - 1 - ], - [ - 1 - ], - [ - 124 - ], - [], - [], - [ - 1, - 96, - 46, - 13 - ], - [ - 126, - 127 - ], - [], - [ - 1, - 73, - 74, - 8, - 75, - 76, - 77, - 20, - 78, - 79, - 47, - 80, - 13 - ], - [], - [ - 1, - 23, - 81, - 82, - 8, - 70, - 35, - 75, - 20, - 83, - 47, - 84, - 50, - 72, - 13 - ], - [ - 14, - 1, - 23, - 17, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 8, - 34, - 35, - 36, - 37, - 38, - 39, - 40, - 41, - 20, - 42, - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 13 - ], - [ - 108, - 109 - ], - [ - 125 - ], - [], - [ - 24, - 128, - 27, - 28, - 129, - 20 - ], - [ - 63, - 28 - ], - [ - 1 - ], - [ - 49, - 51 - ], - [ - 52, - 82, - 55, - 56, - 103, - 58, - 59, - 83, - 22, - 49 - ], - [], - [], - [ - 20 - ], - [], - [], - [], - [ - 113, - 114, - 49 - ], - [ - 25, - 137, - 27, - 143, - 114, - 144, - 49 - ], - [ - 52, - 117, - 118, - 20, - 119 - ], - [ - 140, - 141, - 37, - 39, - 142, - 51 - ], - [], - [], - [], - [], - [], - [], - [], - [ - 1, - 67, - 81, - 85, - 69, - 86, - 87, - 88, - 28, - 8, - 70, - 20, - 89, - 49, - 90, - 50, - 72, - 13 - ], - [ - 113, - 115, - 116, - 49 - ], - [ - 27, - 114 - ], - [ - 27, - 114, - 120, - 51 - ], - [ - 63, - 28, - 20 - ], - [ - 1 - ], - [ - 20, - 49, - 51, - 123 - ], - [], - [], - [ - 13 - ], - [ - 37, - 51 - ], - [ - 108 - ], - [], - [], - [], - [], - [], - [], - [], - [], - [ - 104, - 52, - 82, - 105, - 106, - 107, - 47, - 49 - ], - [], - [ - 17, - 24, - 27, - 28, - 41, - 20, - 45, - 46 - ], - [], - [], - [ - 103, - 83, - 47, - 84, - 49 - ], - [], - [], - [], - [], - [ - 103, - 107, - 122, - 49 - ], - [], - [], - [], - [], - [ - 1, - 3, - 81, - 91, - 92, - 93, - 94, - 95, - 13 - ], - [ - 1, - 4, - 5, - 12 - ], - [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13 - ], - [], - [ - 17, - 24, - 64, - 26, - 27, - 28, - 34, - 38, - 40, - 20, - 43, - 44, - 45, - 65, - 66 - ], - [ - 1, - 4, - 5, - 12 - ], - [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13 - ], - [ - 1, - 4, - 5, - 12 - ], - [ - 109 - ], - [], - [ - 1, - 3, - 4, - 5, - 12 - ], - [ - 137, - 138, - 114, - 47, - 139 - ], - [], - [], - [ - 113, - 49 - ], - [], - [ - 130, - 131, - 82, - 8, - 132, - 133, - 134, - 136, - 135, - 47, - 13 - ], - [], - [] - ], - "all": [ - "accesskey", - "class", - "contenteditable", - "contextmenu", - "dir", - "draggable", - "dropzone", - "hidden", - "id", - "itemid", - "itemprop", - "itemref", - "itemscope", - "itemtype", - "lang", - "spellcheck", - "style", - "tabindex", - "title", - "translate", - "key", - "onMount", - "onUnmount", - "onCopy", - "onCut", - "onPaste", - "onCompositionEnd", - "onCompositionStart", - "onCompositionUpdate", - "onKeyDown", - "onKeyPress", - "onKeyUp", - "onFocus", - "onBlur", - "onChange", - "onInput", - "onSubmit", - "onClick", - "onContextMenu", - "onDoubleClick", - "onDrag", - "onDragEnd", - "onDragEnter", - "onDragExit", - "onDragLeave", - "onDragOver", - "onDragStart", - "onDrop", - "onMouseDown", - "onMouseEnter", - "onMouseLeave", - "onMouseMove", - "onMouseOut", - "onMouseOver", - "onMouseUp", - "onSelect", - "onTouchCancel", - "onTouchEnd", - "onTouchMove", - "onTouchStart", - "onScroll", - "onWheel", - "onAbort", - "onCanPlay", - "onCanPlayThrough", - "onDurationChange", - "onEmptied", - "onEncrypted", - "onEnded", - "onError", - "onLoadedData", - "onLoadedMetadata", - "onLoadStart", - "onPause", - "onPlay", - "onPlaying", - "onProgress", - "onRateChange", - "onSeeked", - "onSeeking", - "onStalled", - "onSuspend", - "onTimeUpdate", - "onVolumeChange", - "onWaiting", - "onLoad", - "onAnimationStart", - "onAnimationEnd", - "onAnimationIteration", - "onTransitionEnd" - ], - "attributes": [ - "abbr", - "align", - "axis", - "bgcolor", - "char", - "charoff", - "colspan", - "headers", - "height", - "nowrap", - "rowspan", - "scope", - "valign", - "width", - "accept", - "accept-charset", - "action", - "autocomplete", - "enctype", - "method", - "name", - "novalidate", - "target", - "alt", - "autofocus", - "checked", - "dirname", - "disabled", - "form", - "formaction", - "formenctype", - "formmethod", - "formnovalidate", - "formtarget", - "inputmode", - "ismap", - "list", - "max", - "maxlength", - "min", - "minlength", - "multiple", - "pattern", - "placeholder", - "readonly", - "required", - "size", - "src", - "step", - "type", - "usemap", - "value", - "charset", - "coords", - "download", - "href", - "hreflang", - "ping", - "rel", - "rev", - "shape", - "nohref", - "menu", - "for", - "cols", - "rows", - "wrap", - "archive", - "code", - "codebase", - "hspace", - "object", - "vspace", - "allowfullscreen", - "frameborder", - "longdesc", - "marginheight", - "marginwidth", - "sandbox", - "scrolling", - "srcdoc", - "border", - "crossorigin", - "sizes", - "srcset", - "classid", - "codetype", - "data", - "declare", - "standby", - "typemustmatch", - "cellpadding", - "cellspacing", - "frame", - "rules", - "summary", - "noshade", - "span", - "alink", - "background", - "link", - "text", - "vlink", - "media", - "async", - "defer", - "language", - "nonce", - "cite", - "datetime", - "clear", - "color", - "face", - "compact", - "label", - "reversed", - "start", - "content", - "http-equiv", - "scheme", - "selected", - "noresize", - "scoped", - "valuetype", - "profile", - "prompt", - "manifest", - "version", - "challenge", - "keytype", - "autoplay", - "controls", - "loop", - "mediagroup", - "muted", - "preload", - "poster", - "default", - "kind", - "srclang", - "high", - "low", - "optimum", - "icon", - "radiogroup", - "open" - ] -} \ No newline at end of file diff --git a/internal/genvdom/main.go b/internal/genvdom/main.go deleted file mode 100644 index 88f3f942..00000000 --- a/internal/genvdom/main.go +++ /dev/null @@ -1,345 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "errors" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "strings" - "text/template" - - "github.com/apex/log" - "github.com/knq/snaker" -) - -func main() { - if e := generate(); e != nil { - log.WithError(e).Fatal("error generating") - } -} - -// DB struct -type DB struct { - Tags []string `json:"tags"` - Index [][]int `json:"index"` - All []string `json:"all"` - Attrs []string `json:"attributes"` -} - -func generate() error { - buf, err := ioutil.ReadFile("./elements.json") - if err != nil { - return err - } - - var db DB - if e := json.Unmarshal(buf, &db); e != nil { - return e - } - - tags := map[string][]string{} - for i, attrs := range db.Index { - tag := db.Tags[i] - - tags[tag] = append(tags[tag], db.All...) - - if len(attrs) > 0 { - for _, attr := range attrs { - tags[tag] = append(tags[tag], db.Attrs[attr]) - } - } - } - - pwd, err := os.Getwd() - if err != nil { - return err - } - - out := map[string]string{} - for tag, attrs := range tags { - code, err := render(&data{ - Tag: tag, - Attrs: attrs, - }) - if err != nil { - return err - } - - formatted, err := format(code) - if err != nil { - return err - } - - out[tag] = formatted - } - - for tag, code := range out { - dir := path.Join(pwd, "h", tag) - if e := os.MkdirAll(dir, os.ModePerm); e != nil { - return e - } - - if e := ioutil.WriteFile(path.Join(dir, tag+".go"), []byte(code), os.ModePerm); e != nil { - return e - } - } - - return nil -} - -type data struct { - Tag string - Attrs []string -} - -func render(data *data) (string, error) { - // tpl, err := template.New(name).Funcs(templateMap).Parse(string(raw)) - tpl, err := template.New(data.Tag).Funcs(fns()).Parse(pkg()) - if err != nil { - return "", err - } - - var b bytes.Buffer - if e := tpl.Execute(&b, data); e != nil { - return "", e - } - - return string(b.Bytes()), nil -} - -func fns() template.FuncMap { - return template.FuncMap{ - "capitalize": func(s string) string { - return snaker.SnakeToCamelIdentifier(snaker.CamelToSnake(s)) - }, - "lowercase": func(s string) string { - if builtins[s] != "" { - return builtins[s] - } - return strings.ToLower(snaker.SnakeToCamelIdentifier(s)) - }, - } -} - -// format the output using goimports -func format(input string) (output string, err error) { - cmd := exec.Command("goimports") - stdin, err := cmd.StdinPipe() - - if err != nil { - return output, err - } - stdout, err := cmd.StdoutPipe() - if err != nil { - return output, err - } - stderr, err := cmd.StderrPipe() - if err != nil { - return output, err - } - - reader := bytes.NewBufferString(input) - - if e := cmd.Start(); e != nil { - return output, e - } - - io.Copy(stdin, reader) - stdin.Close() - - formatted, err := ioutil.ReadAll(stdout) - if err != nil { - return output, err - } - - formattingError, err := ioutil.ReadAll(stderr) - if err != nil { - return output, err - } - - stderr.Close() - stdout.Close() - - if e := cmd.Wait(); e != nil { - return output, errors.New(string(formattingError)) - } - - return string(formatted), nil -} - -func pkg() string { - return ` -{{ $c := capitalize .Tag }} -{{ $l := lowercase .Tag }} -package {{ $l }} - -import ( - "encoding/json" - "strings" - - "github.com/matthewmueller/joy/macro" - "github.com/matthewmueller/joy/vdom" -) - -// {{ $c }} struct -// js:"{{ $l }},omit" -type {{ $c }} struct { - vdom.Child - vdom.Node - - attrs map[string]interface{} - children []vdom.Child -} - -// Props struct -// js:"props,omit" -type Props struct { - attrs map[string]interface{} -} - -// New fn -func New(props *Props, children ...vdom.Child) *{{ $c }} { - macro.Rewrite("$1('{{ .Tag }}', $2 ? $2.JSON() : {}, $3)", vdom.Pragma(), props, children) - if props == nil { - props = &Props{attrs: map[string]interface{}{}} - } - return &{{ $c }}{ - attrs: props.attrs, - children: children, - } -} - -// Render fn -func (s *{{ $c }}) Render() vdom.Node { - return s -} - -func (s *{{ $c }}) String() string { - // props - var props []string - for key, val := range s.attrs { - bytes, e := json.Marshal(val) - // TODO: skip over errors? - if e != nil { - continue - } - props = append(props, key+"="+string(bytes)) - } - - // children - var children []string - for _, child := range s.children { - children = append(children, child.Render().String()) - } - - if len(props) > 0 { - return "<{{ $l }} " + strings.Join(props, " ") + ">" + strings.Join(children, "") + "" - } - - return "<{{ $l }}>" + strings.Join(children, "") + "" -} - -{{ range $i, $attr := .Attrs }} -{{- $ac := capitalize $attr -}} -{{- $al := lowercase $attr -}} -// {{ $ac }} fn -func {{ $ac }}({{ $al }} string) *Props { - macro.Rewrite("$1().Set('{{ $al }}', $2)", macro.Runtime("Map", "Set", "JSON"), {{ $al }}) - p := &Props{attrs: map[string]interface{}{}} - return p.{{ $ac }}({{ $al }}) -} - -// {{ $ac }} fn -func (p *Props) {{ $ac }}({{ $al }} string) *Props { - macro.Rewrite("$_.Set('{{ $al }}', $1)", {{ $al }}) - p.attrs["{{ $attr }}"] = {{ $al }} - return p -} -{{ end }} - -// Attr fn -func Attr(key string, value interface{}) *Props { - macro.Rewrite("$1().Set($2, $3)", macro.Runtime("Map", "Set", "JSON"), key, value) - p := &Props{attrs: map[string]interface{}{}} - return p.Attr(key, value) -} - -// Attr fn -func (p *Props) Attr(key string, value interface{}) *Props { - macro.Rewrite("$_.Set($1, $2)", key, value) - p.attrs[key] = value - return p -} -` -} - -var builtins = map[string]string{ - "bool": "boolean", - "byte": "b", - "complex64": "c64", - "complex128": "c128", - "error": "err", - "float32": "f32", - "float64": "f64", - "int": "integer", - "int8": "integer8", - "int16": "integer16", - "int32": "integer32", - "int64": "integer64", - "rune": "ru", - "string": "str", - "uint": "uinteger", - "uint8": "uinteger8", - "uint16": "uinteger16", - "uint32": "uinteger32", - "uint64": "uinteger64", - "uintptr": "uintpointer", - "true": "yes", - "false": "no", - "iota": "ita", - "nil": "null", - "append": "app", - "cap": "capacity", - "close": "cls", - "complex": "cpx", - "copy": "cpy", - "delete": "del", - "imag": "img", - "len": "l", - "make": "mk", - "new": "nw", - "panic": "pnc", - "print": "prt", - "println": "prtln", - "real": "rl", - "recover": "rec", - "break": "brk", - "default": "def", - "func": "fn", - "interface": "iface", - "select": "sel", - "case": "cs", - "defer": "dfr", - "go": "g", - "map": "mp", - "struct": "structure", - "chan": "chn", - "else": "els", - "goto": "gto", - "package": "pkg", - "switch": "swch", - "const": "cst", - "fallthrough": "flth", - "if": "ifs", - "range": "rng", - "type": "kind", - "continue": "cont", - "for": "fors", - "import": "imp", - "return": "ret", - "var": "v", -} diff --git a/internal/mdn/mdn.go b/internal/mdn/mdn.go deleted file mode 100644 index 28692de9..00000000 --- a/internal/mdn/mdn.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "github.com/PuerkitoBio/goquery" -) - -var domInterfaces = []string{ - "Attr", - "CharacterData", - "ChildNode ", - "Comment", - "CustomEvent", - "Document", - "DocumentFragment", - "DocumentType", - "DOMError", - "DOMException", - "DOMImplementation", - "DOMString", - "DOMTimeStamp", - "DOMSettableTokenList", - "DOMStringList", - "DOMTokenList", - "Element", - "Event", - "EventTarget", - "HTMLCollection", - "MutationObserver", - "MutationRecord", - "NamedNodeMap", - "Node", - "NodeFilter", - "NodeIterator", - "NodeList", - "NonDocumentTypeChildNode", - "ParentNode", - "ProcessingInstruction", - "Selection", - "Range", - "Text", - "TextDecoder ", - "TextEncoder ", - "TimeRanges", - "TreeWalker", - "URL", - "Window", - "Worker", - "XMLDocument ", -} - -func ExampleScrape() { - doc, err := goquery.NewDocument("https://developer.mozilla.org/en-US/docs/Web/API/Attr") - if err != nil { - log.Fatal(err) - } - - // Find the review items - doc.Find("#Properties + dl > dt").Each(func(i int, s *goquery.Selection) { - // For each item found, get the band and title - band := s.Find("a").Text() - // title := s.Find("i").Text() - fmt.Printf("Review %d: %s\n", i, band) - }) -} - -func main() { - ExampleScrape() -}