Source File
js.go
Belonging Package
html/template
package template
import (
)
for > 0 && [-1] == {
--
}
return jsCtxRegexp
}
return jsCtxDivOp
if != 1 && '0' <= [-2] && [-2] <= '9' {
return jsCtxDivOp
}
case ',', '<', '>', '=', '*', '%', '&', '|', '^', '?':
case '!', '~':
case '(', '[':
case ':', ';', '{':
case '}':
return jsCtxRegexp
:=
for > 0 && isJSIdentPart(rune([-1])) {
--
}
if regexpPrecederKeywords[string([:])] {
return jsCtxRegexp
}
return jsCtxDivOp
}
var regexpPrecederKeywords = map[string]bool{
"break": true,
"case": true,
"continue": true,
"delete": true,
"do": true,
"else": true,
"finally": true,
"in": true,
"instanceof": true,
"return": true,
"throw": true,
"try": true,
"typeof": true,
"void": true,
}
var jsonMarshalType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
func ( ...interface{}) string {
var interface{}
if len() == 1 {
= indirectToJSONMarshaler([0])
switch t := .(type) {
case JS:
return string()
return `"` + string() + `"`
return fmt.Sprintf(" /* %s */null ", strings.ReplaceAll(.Error(), "*/", "* /"))
}
return " null "
}
, := utf8.DecodeRune()
, := utf8.DecodeLastRune()
:= isJSIdentPart() || isJSIdentPart()
if {
.WriteByte(' ')
}
for := 0; < len(); {
, := utf8.DecodeRune([:])
:= ""
if == 0x2028 {
= `\u2028`
} else if == 0x2029 {
= `\u2029`
}
if != "" {
.Write([:])
.WriteString()
= +
}
+=
}
if .Len() != 0 {
.Write([:])
if {
.WriteByte(' ')
}
return .String()
}
return string()
}
func ( ...interface{}) string {
, := stringify(...)
if == contentTypeJSStr {
return replace(, jsStrNormReplacementTable)
}
return replace(, jsStrReplacementTable)
}
func ( ...interface{}) string {
, := stringify(...)
= replace(, jsRegexpReplacementTable)
return "(?:)"
}
return
}
, = utf8.DecodeRuneInString([:])
var string
switch {
case int() < len(lowUnicodeReplacementTable):
= lowUnicodeReplacementTable[]
case int() < len() && [] != "":
= []
case == '\u2028':
= `\u2028`
case == '\u2029':
= `\u2029`
default:
continue
}
if == 0 {
.Grow(len())
}
.WriteString([:])
.WriteString()
= +
}
if == 0 {
return
}
.WriteString([:])
return .String()
}
var lowUnicodeReplacementTable = []string{
0: `\u0000`, 1: `\u0001`, 2: `\u0002`, 3: `\u0003`, 4: `\u0004`, 5: `\u0005`, 6: `\u0006`,
'\a': `\u0007`,
'\b': `\u0008`,
'\t': `\t`,
'\n': `\n`,
'\v': `\u000b`, // "\v" == "v" on IE 6.
'\f': `\f`,
'\r': `\r`,
0xe: `\u000e`, 0xf: `\u000f`, 0x10: `\u0010`, 0x11: `\u0011`, 0x12: `\u0012`, 0x13: `\u0013`,
0x14: `\u0014`, 0x15: `\u0015`, 0x16: `\u0016`, 0x17: `\u0017`, 0x18: `\u0018`, 0x19: `\u0019`,
0x1a: `\u001a`, 0x1b: `\u001b`, 0x1c: `\u001c`, 0x1d: `\u001d`, 0x1e: `\u001e`, 0x1f: `\u001f`,
}
var jsStrReplacementTable = []string{
0: `\u0000`,
'\t': `\t`,
'\n': `\n`,
'\v': `\u000b`, // "\v" == "v" on IE 6.
'\f': `\f`,
'"': `\u0022`,
'&': `\u0026`,
'\'': `\u0027`,
'+': `\u002b`,
'/': `\/`,
'<': `\u003c`,
'>': `\u003e`,
'\\': `\\`,
}
var jsStrNormReplacementTable = []string{
0: `\u0000`,
'\t': `\t`,
'\n': `\n`,
'\v': `\u000b`, // "\v" == "v" on IE 6.
'\f': `\f`,
'"': `\u0022`,
'&': `\u0026`,
'\'': `\u0027`,
'+': `\u002b`,
'/': `\/`,
'<': `\u003c`,
'>': `\u003e`,
}
var jsRegexpReplacementTable = []string{
0: `\u0000`,
'\t': `\t`,
'\n': `\n`,
'\v': `\u000b`, // "\v" == "v" on IE 6.
'\f': `\f`,
'"': `\u0022`,
'$': `\$`,
'&': `\u0026`,
'\'': `\u0027`,
'(': `\(`,
')': `\)`,
'*': `\*`,
'+': `\u002b`,
'-': `\-`,
'.': `\.`,
'/': `\/`,
'<': `\u003c`,
'>': `\u003e`,
'?': `\?`,
'[': `\[`,
'\\': `\\`,
']': `\]`,
'^': `\^`,
'{': `\{`,
'|': `\|`,
'}': `\}`,
}
if := strings.Index(, ";"); >= 0 {
= [:]
}
= strings.ToLower()
= strings.TrimSpace()
switch {
case
"application/ecmascript",
"application/javascript",
"application/json",
"application/ld+json",
"application/x-ecmascript",
"application/x-javascript",
"module",
"text/ecmascript",
"text/javascript",
"text/javascript1.0",
"text/javascript1.1",
"text/javascript1.2",
"text/javascript1.3",
"text/javascript1.4",
"text/javascript1.5",
"text/jscript",
"text/livescript",
"text/x-ecmascript",
"text/x-javascript":
return true
default:
return false
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |