aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/html/template/js.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/html/template/js.go')
-rw-r--r--libgo/go/html/template/js.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/libgo/go/html/template/js.go b/libgo/go/html/template/js.go
index 872f678..7025c1c 100644
--- a/libgo/go/html/template/js.go
+++ b/libgo/go/html/template/js.go
@@ -187,7 +187,7 @@ func jsValEscaper(args ...interface{}) string {
}
first, _ := utf8.DecodeRune(b)
last, _ := utf8.DecodeLastRune(b)
- var buf bytes.Buffer
+ var buf strings.Builder
// Prevent IdentifierNames and NumericLiterals from running into
// keywords: in, instanceof, typeof, void
pad := isJSIdentPart(first) || isJSIdentPart(last)
@@ -217,7 +217,7 @@ func jsValEscaper(args ...interface{}) string {
if pad {
buf.WriteByte(' ')
}
- b = buf.Bytes()
+ return buf.String()
}
return string(b)
}
@@ -253,7 +253,7 @@ func jsRegexpEscaper(args ...interface{}) string {
// It also replaces runes U+2028 and U+2029 with the raw strings `\u2028` and
// `\u2029`.
func replace(s string, replacementTable []string) string {
- var b bytes.Buffer
+ var b strings.Builder
r, w, written := rune(0), 0, 0
for i := 0; i < len(s); i += w {
// See comment in htmlEscaper.
@@ -269,6 +269,9 @@ func replace(s string, replacementTable []string) string {
default:
continue
}
+ if written == 0 {
+ b.Grow(len(s))
+ }
b.WriteString(s[written:i])
b.WriteString(repl)
written = i + w
@@ -394,6 +397,7 @@ func isJSType(mimeType string) bool {
"application/ld+json",
"application/x-ecmascript",
"application/x-javascript",
+ "module",
"text/ecmascript",
"text/javascript",
"text/javascript1.0",