aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/exec.go
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2018-06-21 10:41:26 -0700
committerDaniel Theophanes <kardianos@gmail.com>2018-06-22 08:05:11 +0000
commitbedfa4e1c37bd08063865da628f242d27ca06ec4 (patch)
tree24be31b8f4cecfcfc67c5e245c1210c521643465 /src/text/template/exec.go
parent4991bc6257a9e9d922f7b6e29e393d764c4e4295 (diff)
downloadgo-bedfa4e1c37bd08063865da628f242d27ca06ec4.tar.xz
text/template/parse: undo breaking API changes
golang.org/cl/84480 altered the API for the parse package for clarity and consistency. However, the changes also broke the API for consumers of the package. This CL reverts the API to the previous spelling, adding only a single new exported symbol. Fixes #25968 Change-Id: Ieb81054b61eeac7df3bc3864ef446df43c26b80f Reviewed-on: https://go-review.googlesource.com/120355 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/text/template/exec.go')
-rw-r--r--src/text/template/exec.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/text/template/exec.go b/src/text/template/exec.go
index 8f8b5fe218..214f72d51b 100644
--- a/src/text/template/exec.go
+++ b/src/text/template/exec.go
@@ -252,7 +252,7 @@ func (s *state) walk(dot reflect.Value, node parse.Node) {
// Do not pop variables so they persist until next end.
// Also, if the action declares variables, don't print the result.
val := s.evalPipeline(dot, node.Pipe)
- if len(node.Pipe.Vars) == 0 {
+ if len(node.Pipe.Decl) == 0 {
s.printValue(node, val)
}
case *parse.IfNode:
@@ -339,11 +339,11 @@ func (s *state) walkRange(dot reflect.Value, r *parse.RangeNode) {
mark := s.mark()
oneIteration := func(index, elem reflect.Value) {
// Set top var (lexically the second if there are two) to the element.
- if len(r.Pipe.Vars) > 0 {
+ if len(r.Pipe.Decl) > 0 {
s.setTopVar(1, elem)
}
// Set next var (lexically the first if there are two) to the index.
- if len(r.Pipe.Vars) > 1 {
+ if len(r.Pipe.Decl) > 1 {
s.setTopVar(2, index)
}
s.walk(elem, r.List)
@@ -432,11 +432,11 @@ func (s *state) evalPipeline(dot reflect.Value, pipe *parse.PipeNode) (value ref
value = reflect.ValueOf(value.Interface()) // lovely!
}
}
- for _, variable := range pipe.Vars {
- if pipe.Decl {
- s.push(variable.Ident[0], value)
- } else {
+ for _, variable := range pipe.Decl {
+ if pipe.IsAssign {
s.setVar(variable.Ident[0], value)
+ } else {
+ s.push(variable.Ident[0], value)
}
}
return value
@@ -461,7 +461,7 @@ func (s *state) evalCommand(dot reflect.Value, cmd *parse.CommandNode, final ref
case *parse.PipeNode:
// Parenthesized pipeline. The arguments are all inside the pipeline; final is ignored.
return s.evalPipeline(dot, n)
- case *parse.AssignNode:
+ case *parse.VariableNode:
return s.evalVariableNode(dot, n, cmd.Args, final)
}
s.at(firstWord)
@@ -530,7 +530,7 @@ func (s *state) evalChainNode(dot reflect.Value, chain *parse.ChainNode, args []
return s.evalFieldChain(dot, pipe, chain, chain.Field, args, final)
}
-func (s *state) evalVariableNode(dot reflect.Value, variable *parse.AssignNode, args []parse.Node, final reflect.Value) reflect.Value {
+func (s *state) evalVariableNode(dot reflect.Value, variable *parse.VariableNode, args []parse.Node, final reflect.Value) reflect.Value {
// $x.Field has $x as the first ident, Field as the second. Eval the var, then the fields.
s.at(variable)
value := s.varValue(variable.Ident[0])
@@ -771,7 +771,7 @@ func (s *state) evalArg(dot reflect.Value, typ reflect.Type, n parse.Node) refle
s.errorf("cannot assign nil to %s", typ)
case *parse.FieldNode:
return s.validateType(s.evalFieldNode(dot, arg, []parse.Node{n}, missingVal), typ)
- case *parse.AssignNode:
+ case *parse.VariableNode:
return s.validateType(s.evalVariableNode(dot, arg, nil, missingVal), typ)
case *parse.PipeNode:
return s.validateType(s.evalPipeline(dot, arg), typ)
@@ -889,7 +889,7 @@ func (s *state) evalEmptyInterface(dot reflect.Value, n parse.Node) reflect.Valu
return s.idealConstant(n)
case *parse.StringNode:
return reflect.ValueOf(n.Text)
- case *parse.AssignNode:
+ case *parse.VariableNode:
return s.evalVariableNode(dot, n, nil, missingVal)
case *parse.PipeNode:
return s.evalPipeline(dot, n)