• Daniel Martí's avatar
    text/template: add variable assignments · 28c1ad9d
    Daniel Martí authored
    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: 's avatarRob Pike <r@golang.org>
    28c1ad9d
doc.go 16.7 KB