Skip to content

Commit

Permalink
Revert "tpl: Support text/template/parse API change in go1.11"
Browse files Browse the repository at this point in the history
Go developers have undone the breaking API changes
in the following commit:

commit bedfa4e1c37bd08063865da628f242d27ca06ec4
Author: Daniel Theophanes <[email protected]>
Date:   Thu Jun 21 10:41:26 2018 -0700

    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í <[email protected]>
    Reviewed-by: Rob Pike <[email protected]>
    Run-TryBot: Daniel Martí <[email protected]>
    TryBot-Result: Gobot Gobot <[email protected]>

See golang/go#25968

This reverts commit 9f27091.

Closes #4784
Fixes #4873
  • Loading branch information
anthonyfok committed Jun 23, 2018
1 parent dc7bc7b commit 3d59288
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 136 deletions.
48 changes: 48 additions & 0 deletions tpl/tplimpl/template_ast_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,54 @@ func applyTemplateTransformers(templ *parse.Tree, lookupFn func(name string) *pa
return nil
}

// paramsKeysToLower is made purposely non-generic to make it not so tempting
// to do more of these hard-to-maintain AST transformations.
func (c *templateContext) paramsKeysToLower(n parse.Node) {
switch x := n.(type) {
case *parse.ListNode:
if x != nil {
c.paramsKeysToLowerForNodes(x.Nodes...)
}
case *parse.ActionNode:
c.paramsKeysToLowerForNodes(x.Pipe)
case *parse.IfNode:
c.paramsKeysToLowerForNodes(x.Pipe, x.List, x.ElseList)
case *parse.WithNode:
c.paramsKeysToLowerForNodes(x.Pipe, x.List, x.ElseList)
case *parse.RangeNode:
c.paramsKeysToLowerForNodes(x.Pipe, x.List, x.ElseList)
case *parse.TemplateNode:
subTempl := c.getIfNotVisited(x.Name)
if subTempl != nil {
c.paramsKeysToLowerForNodes(subTempl.Root)
}
case *parse.PipeNode:
for i, elem := range x.Decl {
if len(x.Cmds) > i {
// maps $site => .Site etc.
c.decl[elem.Ident[0]] = x.Cmds[i].String()
}
}

for _, cmd := range x.Cmds {
c.paramsKeysToLower(cmd)
}

case *parse.CommandNode:
for _, elem := range x.Args {
switch an := elem.(type) {
case *parse.FieldNode:
c.updateIdentsIfNeeded(an.Ident)
case *parse.VariableNode:
c.updateIdentsIfNeeded(an.Ident)
case *parse.PipeNode:
c.paramsKeysToLower(an)
}

}
}
}

func (c *templateContext) paramsKeysToLowerForNodes(nodes ...parse.Node) {
for _, node := range nodes {
c.paramsKeysToLower(node)
Expand Down
68 changes: 0 additions & 68 deletions tpl/tplimpl/template_ast_transformers_go1_10.go

This file was deleted.

68 changes: 0 additions & 68 deletions tpl/tplimpl/template_ast_transformers_go1_11.go

This file was deleted.

0 comments on commit 3d59288

Please sign in to comment.