Its easy to mess up angular module definitions. What if there was a simpler way to define them? It would prevent typo errors such as forgetting to update both references in the injects array.
Instead of trying to change the runtime... why not just generate what angular (1 and 2) wants with a new simple syntax.
My proposed implementation is a gulp plugin that does the following.
gulp.task('js', function() {
return gulp.src('modules/*.js')
.pipe(simpleAngularModules())
.pipe(gulp.dest('dist'));
});
Typical angular hello world:
angular.
module('myModule', []).
controller('MyController', ['$scope', function ($scope) {
$scope.hello = function() {
alert('hello world');
}
}]);
Using the proposed syntax this would be rewritten as:
/**
* @module MyModule
* @controller MyController
* @inject $scope
*/
$scope.hello = function() {
alert('hello world');
}
A couple things to note. The content of the simplified versions file would be run in a self calling function / scope. This means there aren't global variables.
For controllers, the contents of the file is the "exported" function. For directives, you must specify functions by name to be set as properties on the returned directive definition (eg. link, templateUrl).