Can I use angular/di.js with an AngulrJS 1.3.0 project?
Maybe don't use di.js but instead transpile similarly styled code into valid angular 1.X syntax (during a build step)
A small example and a possible start:
var falafel = require('falafel');var traceur = require('traceur');var src = '@Inject(MyService,MyOtherService)' + 'class Thing{' + ' constructor(service,otherservice){' + ' }' + '}';src = traceur.compile(src, { annotations: true });//console.log(src);function tryGetPath(obj, path) { path.split('.').forEach(function(key) { obj = obj && obj[key]; }); return obj;}var output = falafel(src, function(node) { //find `Object.defineProperty for 'annotations'` if (node.type === 'CallExpression' && tryGetPath(node, 'arguments.1.value') === 'annotations') { var injectable = tryGetPath(node, 'arguments.0.name'); var $inject = (tryGetPath(node, 'arguments.2.properties.0.value.body.body.0.argument.elements') || []) .filter(function(a){return a.callee.name === 'Inject'}) .reduce(function(p,c){ p.push.apply(p,c.arguments); return p;},[]) .map(function(a){return "'"+a.name+"'";}); node.update(injectable + '.$inject = [' + $inject.toString() + '];'); }});console.log(output);
Perhaps you can even use certain attributes (eg @NgController
etc) to register it on your module as a controller.