Skip to content

Commit 1bb8a39

Browse files
authored
chore: support attaching arbitrary comments to types (#57)
Adds a new type SupportsComments for handling comments on top level declarations and field properties. The original idea was to create an AST node for comments. This works well when constructing an AST, but makes traversing an AST more difficult. The comment nodes add extra unbounded levels of indirection. This solution keeps the comments on the related type.
1 parent c973c3f commit 1bb8a39

File tree

6 files changed

+153
-132
lines changed

6 files changed

+153
-132
lines changed

bindings/ast.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package bindings
22

33
import (
44
"fmt"
5-
"go/token"
65
"go/types"
7-
8-
"github.com/dop251/goja"
96
)
107

118
type Node interface {
@@ -47,12 +44,6 @@ func (i Identifier) Ref() string {
4744
return i.Prefix + i.Name
4845
}
4946

50-
// Source is the golang file that an entity is sourced from.
51-
type Source struct {
52-
File string
53-
Position token.Position
54-
}
55-
5647
type HeritageType string
5748

5849
const (
@@ -76,26 +67,6 @@ func HeritageClauseExtends(args ...ExpressionType) *HeritageClause {
7667
}
7768
}
7869

79-
func (s Source) Comment(n *goja.Object) Comment {
80-
return Comment{
81-
SingleLine: true,
82-
Text: fmt.Sprintf("From %s", s.File),
83-
TrailingNewLine: false,
84-
Node: n,
85-
}
86-
}
87-
88-
type Comment struct {
89-
// Single or multi-line comment
90-
SingleLine bool
91-
Text string
92-
TrailingNewLine bool
93-
94-
Node *goja.Object
95-
}
96-
97-
func (c *Comment) isNode() {}
98-
9970
type Modifier string
10071

10172
const (

0 commit comments

Comments
 (0)