From fb3f374de421d1483f300ca3d25b28002c4190bd Mon Sep 17 00:00:00 2001
From: "nweiz@google.com" <nweiz@google.com>
Date: Wed, 6 Nov 2013 22:49:18 +0000
Subject: [PATCH] Add a reserved namespace (himBHinitial identifiers) for
 transformer configuration.

R=rnystrom@google.com
BUG=14636

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@30007 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/pubspec.dart   |  9 +++++++++
 test/pubspec_test.dart | 12 ++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart
index ee910673..bcef655b 100644
--- a/lib/src/pubspec.dart
+++ b/lib/src/pubspec.dart
@@ -150,6 +150,15 @@ class Pubspec {
             _error('"$field.$library" field must be a map, but was '
                 '"$configuration".');
           }
+
+          var reservedKeys = configuration.keys
+              .where((key) => key is String && key.startsWith(r'$'))
+              .map((key) => '"$key"');
+          if (reservedKeys.isNotEmpty) {
+            _error('"$field.$library" field cannot contain reserved '
+                '${pluralize('field', reservedKeys.length)} '
+                '${toSentence(reservedKeys)}.');
+          }
         }
 
         var id = _wrapFormatException("transformer identifier",
diff --git a/test/pubspec_test.dart b/test/pubspec_test.dart
index a9d77798..afc04684 100644
--- a/test/pubspec_test.dart
+++ b/test/pubspec_test.dart
@@ -195,6 +195,18 @@ dependencies:
           (pubspec) => pubspec.transformers);
     });
 
+    test("throws if a transformer's configuration contains a top-level key "
+        "beginning with a dollar sign", () {
+      expectPubspecException('transformers: {pkg: {\$key: value}}',
+          (pubspec) => pubspec.transformers);
+    });
+
+    test("doesn't throw if a transformer's configuration contains a "
+        "non-top-level key beginning with a dollar sign", () {
+      expectPubspecException('transformers: {pkg: {\$key: value}}',
+          (pubspec) => pubspec.transformers);
+    });
+
     test("allows comment-only files", () {
       var pubspec = new Pubspec.parse('''
 # No external dependencies yet
-- 
GitLab