Skip to content

Commit

Permalink
add support for routeProvider annoatations
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed Jul 2, 2013
1 parent 3b40998 commit e157310
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var annotatorPass = exports.annotator = require('./passes/annotator');

var pdoAnnotatorPass = exports.pdo = require('./passes/pdo');
var ddoAnnotatorPass = exports.ddo = require('./passes/ddo');
var routeAnnotatorPass = exports.route = require('./passes/route');

// expose a convenience function to register all of the passes
module.exports = function (astral) {
Expand All @@ -14,7 +15,8 @@ module.exports = function (astral) {
annotatorPass,
refPass,
pdoAnnotatorPass,
ddoAnnotatorPass
ddoAnnotatorPass,
routeAnnotatorPass
].forEach(function (pass) {
astral.register(pass);
});
Expand Down
55 changes: 55 additions & 0 deletions passes/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// mark route objects

var annotateInjectable = require('../lib/annotate-injectable');
var deepApply = require('../lib/deep-apply');

var routeAnnotatorPass = module.exports = {};
routeAnnotatorPass.name = 'angular:annotator:route';
routeAnnotatorPass.prereqs = [
'angular:annotator:mark'
];

routeAnnotatorPass.run = function (ast, info) {
deepApply(ast, [{
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"ngModule": true
},
"property": {
"type": "Identifier",
"name": "config"
}
}
}], function (routeChunk) {
deepApply(routeChunk, [{
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"property": {
"type": "Identifier",
"name": "when"
}
},
"arguments": [ {},
{
"type": "ObjectExpression"
}
]
}],function (whenChunk) {
deepApply(whenChunk, [{
"type": "Property",
"key": {
"type": "Identifier",
"name": "controller"
},
"value": {
"type": "FunctionExpression"
}
}], function (controllerChunk) {
controllerChunk.value = annotateInjectable(controllerChunk.value);
});
});
});
};

0 comments on commit e157310

Please sign in to comment.