angularjsminifyatom-editoryui-compressor

Unable to minify JS


Before implementing Firebase authentication this JS file successfully minifyed without any problems.

The file works without any problems when using the none-midifyed version, I'm unable to test the minifyed version as Atom will not allow me to minify and save due to the following error (See attached)!

I'm using and following Scotch.io's advice: https://scotch.io/tutorials/declaring-angularjs-modules-for-minification

Any pointers/advice would be great!

Error enter image description here

Controller JS

var fbcontrollers = angular.module('fbcontrollers', []);
fbcontrollers.controller('authCtrl', ['$scope', 'Auth', '$location', function($scope, Auth, $location) {
  $scope.auth = Auth;
  $scope.user = $scope.auth.$getAuth();
  // Store User Data
  function userData() {
    var isNewUser = true;
    var fire = new Firebase('https://courtyard-bridal.firebaseio.com/');
    fire.onAuth(function(authData) {
      if (authData && isNewUser) {
        fire.child("users").child(authData.uid).set({
          name: getName(authData),
          email: getEmail(authData),
          provider: authData.provider
        });
      }
      function getName(authData) {
        switch (authData.provider) {
          case 'password':
            return authData.password.email.replace(/@.*/, '');
          case 'facebook':
            return authData.facebook.displayName;
        }
      }
      function getEmail(authData) {
        switch (authData.provider) {
          case 'password':
            return authData.password.email;
          case 'facebook':
            return authData.facebook.email;
        }
      }
    });
  }
  // Facebook Login
  $scope.fblogin = function() {
    var scope = {
      scope: 'email'
    };
    $scope.auth.$authWithOAuthPopup('facebook', scope).then(function(auth) {
      // Store Data
      userData();
      // Redirtect on Success
      $location.path('/dash');
    }).catch(function(error) {
      console.log('error');
    });
  };
  // Default Form Data
  $scope.form = ({
    'email': '',
    'password': ''
  });
  // Login Form
  $scope.login = function() {
    var email = $scope.form.email;
    var password = $scope.form.password;
    $scope.authData = null;
    $scope.auth.$authWithPassword({
      email: email,
      password: password
    }).then(function(Auth) {
      $scope.authData = Auth;
      $location.path('/dash');
    }).catch(function(error) {
      console.log(error);
    });
  };
  // Register (Create User) Form
  $scope.register = function() {
    var email = $scope.form.email;
    var password = $scope.form.password;
    // Create User
    $scope.auth.$createUser({
      email: email,
      password: password
    }).then(function(Auth) {
      // Store Data
      userData();
      // Login Created User
      $scope.authData = null;
      $scope.auth.$authWithPassword({
        email: email,
        password: password
      }).then(function(Auth) {
        $scope.authData = Auth;
        $location.path('/dash');
      }).catch(function(error) {
        console.log('error');
      });
    }).catch(function(error) {
      console.log(error);
    });
  };
}]);
fbcontrollers.controller('dashCtrl', ['$scope', 'Auth', '$location', function($scope, Auth, $location) {
  $scope.auth = Auth;
  $scope.user = $scope.auth.$getAuth();

  if($scope.user.provider === 'facebook') {
    $scope.id = $scope.user.uid;
    $scope.name = $scope.user.facebook.displayName;
    $scope.email = $scope.user.facebook.email;
    $scope.profile = $scope.user.facebook.profileImageURL;
  } else if ($scope.user.provider === 'password') {
    $scope.id = $scope.user.uid;
    $scope.name = $scope.user.password.email.replace(/@.*/, '');
    $scope.email = $scope.user.password.email;
    $scope.profile = $scope.user.password.profileImageURL;
  }
  console.log($scope.user);

  // Logout
  $scope.logout = function() {
    $scope.auth.$unauth();
    $location.path('/auth');
  };
}]);

Solution

  • I am pretty sure the problem is connected with the use of catch. Note that catch is a keyword in javascript, used in exception (error) handling. Promises use catch as a method name and that's a bit of a collision. In general it's safer to use it indirectly:

    }).then(function(...) {
       ...
    })['catch'](function(error) {
       ...
    });
    

    The same applies to the finally keyword.