From a73d51489146c07277c29330b04f9fc47669e414 Mon Sep 17 00:00:00 2001
From: Martin Staffa <mjstaffa@gmail.com>
Date: Wed, 24 Aug 2016 19:56:31 +0200
Subject: [PATCH] feat($compile): throw error when directive name or factory fn
 is invalid

Closes: #15056
---
 src/ng/compile.js      |  1 +
 test/ng/compileSpec.js | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/src/ng/compile.js b/src/ng/compile.js
index e61307f3760f..942eca582a26 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -1087,6 +1087,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
    * @returns {ng.$compileProvider} Self for chaining.
    */
   this.directive = function registerDirective(name, directiveFactory) {
+    assertArg(name, 'name');
     assertNotHasOwnProperty(name, 'directive');
     if (isString(name)) {
       assertValidDirectiveName(name);
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 800fb1be9d27..bc35c692c7a8 100755
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -214,6 +214,7 @@ describe('$compile', function() {
       });
       inject(function($compile) {});
     });
+
     it('should throw an exception if a directive name has leading or trailing whitespace', function() {
       module(function() {
         function assertLeadingOrTrailingWhitespaceInDirectiveName(name) {
@@ -230,6 +231,24 @@ describe('$compile', function() {
       inject(function($compile) {});
     });
 
+    it('should throw an exception if the directive name is not defined', function() {
+      module(function() {
+        expect(function() {
+          directive();
+        }).toThrowMinErr('ng','areq');
+      });
+      inject(function($compile) {});
+    });
+
+    it('should throw an exception if the directive factory is not defined', function() {
+      module(function() {
+        expect(function() {
+          directive('myDir');
+        }).toThrowMinErr('ng','areq');
+      });
+      inject(function($compile) {});
+    });
+
     it('should preserve context within declaration', function() {
       module(function() {
         directive('ff', function(log) {