MCPcopy Index your code
hub / github.com/github/gh-aw / removeJavaScriptComments

Function removeJavaScriptComments

pkg/workflow/js.go:71–96  ·  view source on GitHub ↗

Helper functions for formatting JavaScript in YAML

(code string)

Source from the content-addressed store, hash-verified

69// Helper functions for formatting JavaScript in YAML
70
71func removeJavaScriptComments(code string) string {
72 if jsLog.Enabled() {
73 jsLog.Printf("Removing JavaScript comments from %d bytes of code", len(code))
74 }
75 var result strings.Builder
76 lines := strings.Split(code, "\n")
77
78 inBlockComment := false
79
80 for _, line := range lines {
81 processedLine := removeJavaScriptCommentsFromLine(line, &inBlockComment)
82 result.WriteString(processedLine)
83 result.WriteString("\n")
84 }
85
86 // Remove the trailing newline we added
87 resultStr := result.String()
88 if len(resultStr) > 0 && resultStr[len(resultStr)-1] == '\n' {
89 resultStr = resultStr[:len(resultStr)-1]
90 }
91
92 if jsLog.Enabled() {
93 jsLog.Printf("Removed comments, result: %d bytes", len(resultStr))
94 }
95 return resultStr
96}
97
98// removeJavaScriptCommentsFromLine removes JavaScript comments from a single line
99// while preserving comments that appear within string literals and regex literals

Calls 4

EnabledMethod · 0.45
PrintfMethod · 0.45
StringMethod · 0.45