@@ -2,6 +2,7 @@ package bindings
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/dop251/goja"
78 "golang.org/x/xerrors"
@@ -733,8 +734,47 @@ func (b *Bindings) CommentGojaObject(comments []SyntheticComment, object *goja.O
733734 return nil , err
734735 }
735736
736- node := object
737+ // Group all comments that should be included into a JSDoc block.
738+ jsDoc := make ([]SyntheticComment , 0 )
739+ rest := make ([]SyntheticComment , 0 )
740+
737741 for _ , c := range comments {
742+ if ! c .DoNotFormat && c .Leading && c .SingleLine {
743+ jsDoc = append (jsDoc , c )
744+ continue
745+ }
746+ rest = append (rest , c )
747+ }
748+
749+ // JSDoc comments should be blocked together
750+ node := object
751+ if len (jsDoc ) > 0 {
752+ var jsDocComment strings.Builder
753+ // JSDoc requires '/**' start and ' */' end. The default synthetic comment only places 1 '*'.
754+ // So include the second '*', and start the comment line.
755+ jsDocComment .WriteString ("*\n *" )
756+ sep := ""
757+ for _ , cmt := range jsDoc {
758+ jsDocComment .WriteString (sep )
759+ jsDocComment .WriteString (cmt .Text )
760+ sep = "\n *"
761+ }
762+ jsDocComment .WriteString ("\n " )
763+
764+ res , err := commentF (goja .Undefined (),
765+ node ,
766+ b .vm .ToValue (true ),
767+ b .vm .ToValue (false ),
768+ b .vm .ToValue (jsDocComment .String ()),
769+ b .vm .ToValue (true ),
770+ )
771+ if err != nil {
772+ return nil , xerrors .Errorf ("call addSyntheticComment for JSDoc: %w" , err )
773+ }
774+ node = res .ToObject (b .vm )
775+ }
776+
777+ for _ , c := range rest {
738778 res , err := commentF (goja .Undefined (),
739779 node ,
740780 b .vm .ToValue (c .Leading ),
0 commit comments