diff options
author | Daniel Martí <mvdan@mvdan.cc> | 2017-12-17 13:23:40 +0000 |
---|---|---|
committer | Daniel Martí <mvdan@mvdan.cc> | 2018-04-04 15:51:56 +0000 |
commit | 28c1ad9d35f27b3b57afff4ee78faac746a8ed0a (patch) | |
tree | 53786ed3cf374d17122a1d1b3511ba2be11482cd /api | |
parent | 804d03281c04096fca7f73dc33d1d62e09a86892 (diff) | |
download | go-28c1ad9d35f27b3b57afff4ee78faac746a8ed0a.tar.gz go-28c1ad9d35f27b3b57afff4ee78faac746a8ed0a.zip |
text/template: add variable assignments
Variables can be declared and shadowing is supported, but modifying
existing variables via assignments was not available.
This meant that modifying a variable from a nested block was not
possible:
{{ $v := "init" }}
{{ if true }}
{{ $v := "changed" }}
{{ end }}
v: {{ $v }} {{/* "init" */}}
Introduce the "=" assignment token, such that one can now do:
{{ $v := "init" }}
{{ if true }}
{{ $v = "changed" }}
{{ end }}
v: {{ $v }} {{/* "changed" */}}
To avoid confusion, rename PipeNode.Decl to PipeNode.Vars, as the
variables may not always be declared after this change. Also change a
few other names to better reflect the added ambiguity of variables in
pipelines.
Modifying the text/template/parse package in a backwards incompatible
manner is acceptable, given that the package godoc clearly states that
it isn't intended for general use. It's the equivalent of an internal
package, back when internal packages didn't exist yet.
To make the changes to the parse package sit well with the cmd/api test,
update except.txt with the changes that we aren't worried about.
Fixes #10608.
Change-Id: I1f83a4297ee093fd45f9993cebb78fc9a9e81295
Reviewed-on: https://go-review.googlesource.com/84480
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'api')
-rw-r--r-- | api/README | 1 | ||||
-rw-r--r-- | api/except.txt | 19 |
2 files changed, 19 insertions, 1 deletions
diff --git a/api/README b/api/README index d3ad7c1d74..ce24efcd31 100644 --- a/api/README +++ b/api/README @@ -11,4 +11,3 @@ compatibility. next.txt is the only file intended to be mutated. It's a list of features that may be added to the next version. It only affects warning output from the go api tool. - diff --git a/api/except.txt b/api/except.txt index b3429fe768..94043718ba 100644 --- a/api/except.txt +++ b/api/except.txt @@ -362,3 +362,22 @@ pkg syscall (openbsd-386-cgo), const SYS_KILL = 37 pkg syscall (openbsd-amd64), const SYS_KILL = 37 pkg syscall (openbsd-amd64-cgo), const SYS_KILL = 37 pkg unicode, const Version = "9.0.0" +pkg text/template/parse, method (*AssignNode) Copy() Node +pkg text/template/parse, method (*AssignNode) String() string +pkg text/template/parse, method (*VariableNode) Copy() Node +pkg text/template/parse, method (*VariableNode) String() string +pkg text/template/parse, method (AssignNode) Position() Pos +pkg text/template/parse, method (AssignNode) Type() NodeType +pkg text/template/parse, method (VariableNode) Position() Pos +pkg text/template/parse, method (VariableNode) Type() NodeType +pkg text/template/parse, type AssignNode struct +pkg text/template/parse, type AssignNode struct, Ident []string +pkg text/template/parse, type AssignNode struct, embedded NodeType +pkg text/template/parse, type AssignNode struct, embedded Pos +pkg text/template/parse, type PipeNode struct, Decl []*VariableNode +pkg text/template/parse, type PipeNode struct, Decl bool +pkg text/template/parse, type PipeNode struct, Vars []*AssignNode +pkg text/template/parse, type VariableNode struct +pkg text/template/parse, type VariableNode struct, Ident []string +pkg text/template/parse, type VariableNode struct, embedded NodeType +pkg text/template/parse, type VariableNode struct, embedded Pos |