GN: Don't allow nested things inside template invocations.

Previously we would allow this because "component" is a template:
  component("foo") {
    config("bar") {
    }
  }
This patch makes this construct illegal. Allowing this leads to weird errors because the template invocation will have default configs applied to it, and the inner config will pick those up and duplicate all of the target's configs inside of "bar".

Also removes unused "Type" enum which was never used.

BUG=536290

Review URL: https://codereview.chromium.org/1361263004

Cr-Original-Commit-Position: refs/heads/master@{#351000}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: c5598930514b13c0c36992e47d8b5170730001ce
diff --git a/tools/gn/functions.h b/tools/gn/functions.h
index f9c867d..262fc60 100644
--- a/tools/gn/functions.h
+++ b/tools/gn/functions.h
@@ -435,14 +435,6 @@
 // there is already another non-nestable block on the stack.
 class NonNestableBlock {
  public:
-  enum Type {
-    CONFIG,
-    DECLARE_ARGS,
-    TARGET,
-    TEMPLATE,
-    TOOLCHAIN,
-  };
-
   // type_description is a string that will be used in error messages
   // describing the type of the block, for example, "template" or "config".
   NonNestableBlock(Scope* scope,
diff --git a/tools/gn/template.cc b/tools/gn/template.cc
index 80d6c5c..3d58b9a 100644
--- a/tools/gn/template.cc
+++ b/tools/gn/template.cc
@@ -41,9 +41,20 @@
                             invocation->function().value().as_string(),
                             block, args, invocation_scope.get(), err))
     return Value();
-  block->Execute(invocation_scope.get(), err);
-  if (err->has_error())
-    return Value();
+
+  {
+    // Don't allow the block of the template invocation to include other
+    // targets configs, or template invocations. This must only be applied
+    // to the invoker's block rather than the whole function because the
+    // template execution itself must be able to define targets, etc.
+    NonNestableBlock non_nestable(scope, invocation, "template invocation");
+    if (!non_nestable.Enter(err))
+      return Value();
+
+    block->Execute(invocation_scope.get(), err);
+    if (err->has_error())
+      return Value();
+  }
 
   // Set up the scope to run the template and set the current directory for the
   // template (which ScopePerFileProvider uses to base the target-related