Commit 0287647b authored by Mike Samuel's avatar Mike Samuel

exp/template/html: add doc comments for undocumented Err... constants.

Does some TODOs and changes the term "div" in an error message
to "division" to avoid confusion with "<div>".

R=nigeltao, r
CC=golang-dev
https://golang.org/cl/5141047
parent f3050dbb
...@@ -40,7 +40,7 @@ const ( ...@@ -40,7 +40,7 @@ const (
// OK indicates the lack of an error. // OK indicates the lack of an error.
OK ErrorCode = iota OK ErrorCode = iota
// ErrorAmbigContext: "... appears in an ambiguous URL context" // ErrAmbigContext: "... appears in an ambiguous URL context"
// Example: // Example:
// <a href=" // <a href="
// {{if .C}} // {{if .C}}
...@@ -57,7 +57,18 @@ const ( ...@@ -57,7 +57,18 @@ const (
// <a href="{{if .C}}/path/{{.X}}{{else}}/search?q={{.X}}"> // <a href="{{if .C}}/path/{{.X}}{{else}}/search?q={{.X}}">
ErrAmbigContext ErrAmbigContext
// TODO: document // ErrBadHTML: "expected space, attr name, or end of tag, but got ...",
// "... in unquoted attr", "... in attribute name"
// Example:
// <a href = /search?q=foo>
// <href=foo>
// <form na<e=...>
// <option selected<
// Discussion:
// This is often due to a typo in an HTML element, but some runes
// are banned in tag names, attribute names, and unquoted attribute
// values because they can tickle parser ambiguities.
// Quoting all attributes is the best policy.
ErrBadHTML ErrBadHTML
// ErrBranchEnd: "{{if}} branches end in different contexts" // ErrBranchEnd: "{{if}} branches end in different contexts"
...@@ -124,7 +135,16 @@ const ( ...@@ -124,7 +135,16 @@ const (
// EscapeSet(&set, "main") is called, this error will arise. // EscapeSet(&set, "main") is called, this error will arise.
ErrNoSuchTemplate ErrNoSuchTemplate
// TODO: document // ErrOutputContext: "cannot compute output context for template ..."
// Examples:
// {{define "t"}}{{if .T}}{{template "t" .T}}{{end}}{{.H}}",{{end}}
// Discussion:
// A recursive template does not end in the same context in which it
// starts, and a reliable output context cannot be computed.
// Look for typos in the named template.
// If the template should not be called in the named start context,
// look for calls to that template in unexpected contexts.
// Maybe refactor recursive templates to not be recursive.
ErrOutputContext ErrOutputContext
// ErrPartialCharset: "unfinished JS regexp charset in ..." // ErrPartialCharset: "unfinished JS regexp charset in ..."
...@@ -161,7 +181,19 @@ const ( ...@@ -161,7 +181,19 @@ const (
// <p class=foo<p class=bar // <p class=foo<p class=bar
ErrRangeLoopReentry ErrRangeLoopReentry
// TODO: document // ErrSlashAmbig: '/' could start a division or regexp.
// Example:
// <script>
// {{if .C}}var x = 1{{end}}
// /-{{.N}}/i.test(x) ? doThis : doThat();
// </script>
// Discussion:
// The example above could produce `var x = 1/-2/i.test(s)...`
// in which the first '/' is a mathematical division operator or it
// could produce `/-2/i.test(s)` in which the first '/' starts a
// regexp literal.
// Look for missing semicolons inside branches, and maybe add
// parentheses to make it clear which interpretation you intend.
ErrSlashAmbig ErrSlashAmbig
) )
......
...@@ -891,7 +891,7 @@ func TestErrors(t *testing.T) { ...@@ -891,7 +891,7 @@ func TestErrors(t *testing.T) {
// or `/-1\.5/i.test(x)` which is a method call on a // or `/-1\.5/i.test(x)` which is a method call on a
// case insensitive regular expression. // case insensitive regular expression.
`<script>{{if false}}var x = 1{{end}}/-{{"1.5"}}/i.test(x)</script>`, `<script>{{if false}}var x = 1{{end}}/-{{"1.5"}}/i.test(x)</script>`,
`'/' could start div or regexp: "/-"`, `'/' could start a division or regexp: "/-"`,
}, },
{ {
`{{template "foo"}}`, `{{template "foo"}}`,
......
...@@ -251,7 +251,7 @@ func tJS(c context, s []byte) (context, int) { ...@@ -251,7 +251,7 @@ func tJS(c context, s []byte) (context, int) {
default: default:
return context{ return context{
state: stateError, state: stateError,
err: errorf(ErrSlashAmbig, 0, "'/' could start div or regexp: %.32q", s[i:]), err: errorf(ErrSlashAmbig, 0, "'/' could start a division or regexp: %.32q", s[i:]),
}, len(s) }, len(s)
} }
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment