diff options
author | Anthony Fok <foka@debian.org> | 2018-06-23 15:07:52 -0600 |
---|---|---|
committer | Anthony Fok <foka@debian.org> | 2018-06-23 15:07:52 -0600 |
commit | 3d5928889ad74ff88b80354b791e3a4dfb84f278 (patch) | |
tree | 6b8d5105a744f3c759587f949fe30dc5c9e96795 /tpl/tplimpl | |
parent | dc7bc7b4d2e1fe6feac153803420a56ed92cc014 (diff) |
Revert "tpl: Support text/template/parse API change in go1.11"
Go developers have undone the breaking API changes
in the following commit:
commit bedfa4e1c37bd08063865da628f242d27ca06ec4
Author: Daniel Theophanes <kardianos@gmail.com>
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à <mvdan@mvdan.cc>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
See https://github.com/golang/go/issues/25968
This reverts commit 9f27091e1067875e2577c331acc60adaef5bb234.
Closes #4784
Fixes #4873
Diffstat (limited to 'tpl/tplimpl')
-rw-r--r-- | tpl/tplimpl/template_ast_transformers.go | 48 | ||||
-rw-r--r-- | tpl/tplimpl/template_ast_transformers_go1_10.go | 68 | ||||
-rw-r--r-- | tpl/tplimpl/template_ast_transformers_go1_11.go | 68 |
3 files changed, 48 insertions, 136 deletions
diff --git a/tpl/tplimpl/template_ast_transformers.go b/tpl/tplimpl/template_ast_transformers.go index f0899dcbc..bbd0f28a4 100644 --- a/tpl/tplimpl/template_ast_transformers.go +++ b/tpl/tplimpl/template_ast_transformers.go @@ -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) diff --git a/tpl/tplimpl/template_ast_transformers_go1_10.go b/tpl/tplimpl/template_ast_transformers_go1_10.go deleted file mode 100644 index 4e2a34c9e..000000000 --- a/tpl/tplimpl/template_ast_transformers_go1_10.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2016 The Hugo Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build !go1.11 - -package tplimpl - -import ( - "text/template/parse" -) - -// 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) - } - - } - } -} diff --git a/tpl/tplimpl/template_ast_transformers_go1_11.go b/tpl/tplimpl/template_ast_transformers_go1_11.go deleted file mode 100644 index d7fdada0d..000000000 --- a/tpl/tplimpl/template_ast_transformers_go1_11.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2016 The Hugo Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build go1.11 - -package tplimpl - -import ( - "text/template/parse" -) - -// 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.Vars { - 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.AssignNode: - c.updateIdentsIfNeeded(an.Ident) - case *parse.PipeNode: - c.paramsKeysToLower(an) - } - - } - } -} |