无法缩小 JS

Unable to minify JS

在实施 Firebase 身份验证之前,此 JS 文件已成功缩小,没有任何问题。

文件在使用 none-midifyed 版本时没有任何问题,我无法测试缩小版本,因为 Atom 不允许我缩小并保存,因为以下错误(见附件)!

我正在使用并遵循 Scotch.io 的建议:https://scotch.io/tutorials/declaring-angularjs-modules-for-minification

任何 pointers/advice 都很棒!

错误

控制器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');
  };
}]);

我很确定问题与 catch 的使用有关。请注意 catch 是 javascript 中的关键字,用于异常(错误)处理。 Promise 使用 catch 作为方法名称,这有点冲突。一般来说,间接使用它更安全:

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

同样适用于 finally 关键字。