summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-05-05 11:22:58 -0400
committerRuss Cox <rsc@golang.org>2021-05-06 13:39:37 +0000
commit0e7a7a68cd2a29895eae345ce56145b780d4a06c (patch)
treee87ac5915938556bae407613f2c3693229a97a0e /src
parentba0f8ce50fd982fe6e51f77c515660fffdebe40c (diff)
downloadgo-git-0e7a7a68cd2a29895eae345ce56145b780d4a06c.tar.gz
text/template/parse: rename DeferFuncCheck to SkipFuncCheck
The proposal as accepted in #34652 named the bit SkipFuncCheck. It was renamed to DeferFuncCheck during the code review on a suggestion by Rob, along with a comment to “defer type checking functions until template is executed,” but this description is not accurate: the package has never type-checked functions, only verified their existence. And the effect of the bit in this package is to eliminate this check entirely, not to defer it to some later time. I was writing code using this new bit and was very confused about when the "type checking" was being deferred to and how to stop that entirely, since in my use case I wanted no checks at all. What I wanted is what the bit does, it just wasn't named accurately. Rename back to SkipFuncCheck. Change-Id: I8e62099c8a904ed04521eb5b86155290f6d5b12f Reviewed-on: https://go-review.googlesource.com/c/go/+/317269 Trust: Russ Cox <rsc@golang.org> Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/text/template/parse/parse.go6
-rw-r--r--src/text/template/parse/parse_test.go6
2 files changed, 6 insertions, 6 deletions
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go
index ff1358b001..1a63961c13 100644
--- a/src/text/template/parse/parse.go
+++ b/src/text/template/parse/parse.go
@@ -38,8 +38,8 @@ type Tree struct {
type Mode uint
const (
- ParseComments Mode = 1 << iota // parse comments and add them to AST
- DeferFuncCheck // defer type checking functions until template is executed
+ ParseComments Mode = 1 << iota // parse comments and add them to AST
+ SkipFuncCheck // do not check that functions are defined
)
// Copy returns a copy of the Tree. Any parsing state is discarded.
@@ -690,7 +690,7 @@ func (t *Tree) operand() Node {
func (t *Tree) term() Node {
switch token := t.nextNonSpace(); token.typ {
case itemIdentifier:
- checkFunc := t.Mode&DeferFuncCheck == 0
+ checkFunc := t.Mode&SkipFuncCheck == 0
if checkFunc && !t.hasFunction(token.val) {
t.errorf("function %q not defined", token.val)
}
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
index c4585f6912..9b1be272e5 100644
--- a/src/text/template/parse/parse_test.go
+++ b/src/text/template/parse/parse_test.go
@@ -379,12 +379,12 @@ func TestParseWithComments(t *testing.T) {
}
}
-func TestDeferFuncCheck(t *testing.T) {
+func TestSkipFuncCheck(t *testing.T) {
oldTextFormat := textFormat
textFormat = "%q"
defer func() { textFormat = oldTextFormat }()
- tr := New("defer func check")
- tr.Mode = DeferFuncCheck
+ tr := New("skip func check")
+ tr.Mode = SkipFuncCheck
tmpl, err := tr.Parse("{{fn 1 2}}", "", "", make(map[string]*Tree))
if err != nil {
t.Fatalf("unexpected error: %v", err)