Skip to content

Commit b4baf3b

Browse files
author
Andrew Schmadel
committed
Merge branch 'master' into gh-pages
2 parents 94a4cb9 + 35a7521 commit b4baf3b

6 files changed

Lines changed: 97 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# babel-plugin-angularjs-annotate changelog
22

3+
## v0.5.0 2016-08-04
4+
* bugfix: follow references in component definition objects (#7)
5+
* bugfix: remove superfluous dependency on `babel`
6+
* New Feature: Add annotations to injectable `template` and `templateUrl` component properties
7+
* New Feature: Adds a very simple REPL (see the `gh-pages` branch).
8+
9+
## v0.4.0 2016-07-25
10+
* New option: Disable implicit matching (only annotate functions marked up with `/* @ngInject */` or `'ngInject'`)
11+
312
## v0.3.0 2016-07-25
413
* Add support for ES6 arrow functions
514

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ To pass this option to the plugin, [add it to your Babel configuration](https://
4848

4949
See [ng-annotate](https://github.com/olov/ng-annotate)'s documentation and the [test sources](tests/) for details about the patterns that can be automatically detected by ng-annotate and this plugin, as well as information about how to explicitly mark functions and classes for annotation.
5050

51+
[Try it out in your browser](http://schmod.github.io/babel-plugin-angularjs-annotate/).
52+
5153
### ES6 Annotations
5254

5355
This plugin can annotate some ES6 classes and arrow functions that are not supported by ng-annotate:

ng-annotate-main.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,8 @@ function matchRegular(path, ctx) {
390390
args.length === 2 && t.isLiteral(args[0]) && is.string(args[0].value) && argPaths[1]);
391391

392392
if (method.name === "component") {
393-
const controllers = target.get("properties").filter(prop => prop.node.key.name == "controller");
394-
if(controllers.length === 1) {
395-
target = controllers[0].get("value");
396-
} else {
397-
return false;
398-
}
393+
target.node.$chained = chainedRegular;
394+
return matchComponent(target);
399395
}
400396

401397
if (target) {
@@ -453,6 +449,34 @@ function matchResolve(props) {
453449
return [];
454450
}
455451

452+
function matchComponent(path){
453+
let chained = path.node.$chained;
454+
if(t.isIdentifier(path)) {
455+
path = followReference(path);
456+
if(t.isVariableDeclarator(path)){
457+
path = path.get('init');
458+
}
459+
}
460+
if(t.isObjectExpression(path)){
461+
path.node.chained = chained;
462+
const props = path.get("properties");
463+
464+
const ctrl = matchProp("controller", props);
465+
const tmpl = matchProp("template", props);
466+
const tmplUrl = matchProp("templateUrl", props);
467+
468+
let res = [];
469+
ctrl && res.push(ctrl);
470+
tmpl && res.push(tmpl);
471+
tmplUrl && res.push(tmplUrl);
472+
473+
res.forEach(t => t.node.$chained = chained);
474+
return res;
475+
} else {
476+
return false;
477+
}
478+
}
479+
456480
function renamedString(ctx, originalString) {
457481
if (ctx.rename) {
458482
return ctx.rename.get(originalString) || originalString;

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"name": "babel-plugin-angularjs-annotate",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "Babel plugin to add angularjs dependency injection annotations",
55
"main": "babel-ng-annotate.js",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/schmod/babel-plugin-angularjs-annotate"
99
},
1010
"dependencies": {
11-
"babel": "^6.5.1",
1211
"babel-plugin-transform-es2015-function-name": "^6.9.0",
1312
"simple-is": "~0.2.0"
1413
},

tests/references.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,35 @@ module.exports = {
180180
});
181181
}
182182
}
183+
},
184+
{
185+
name: "chained component controller",
186+
implicit: true,
187+
input: function() {
188+
var tmplProvider = function(bar){};
189+
var testFeedback = {
190+
controller: testFeedbackController,
191+
template: tmplProvider
192+
};
193+
function testFeedbackController(foo) {}
194+
195+
angular.module("test.feedback.pkg", [])
196+
.component("testFeedback", testFeedback);
197+
},
198+
expected: function() {
199+
testFeedbackController.$inject = ["foo"];
200+
var tmplProvider = function(bar){};
201+
tmplProvider.$inject = ["bar"];
202+
var testFeedback = {
203+
controller: testFeedbackController,
204+
template: tmplProvider
205+
};
206+
function testFeedbackController(foo) {
207+
}
208+
209+
angular.module("test.feedback.pkg", [])
210+
.component("testFeedback", testFeedback);
211+
}
183212
}
184213
]
185214
}

tests/simple.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,32 @@ module.exports = {
563563
})();
564564
angular.module("MyMod").controller("MyCtrl", myCtrl10);
565565
}
566+
},
567+
{
568+
name: "injectable component templates/controller/templateurl",
569+
implicit: true,
570+
input: function(){
571+
angular.module("mod").component("cmp", {
572+
controller: function(a){},
573+
template: function(b){},
574+
templateUrl: function(c){},
575+
}).component("cmp2", {
576+
controller: "myCtrl",
577+
template: "tmpl",
578+
templateUrl: "template.html"
579+
});
580+
},
581+
expected: function(){
582+
angular.module("mod").component("cmp", {
583+
controller: ["a", function(a){}],
584+
template: ["b", function(b){}],
585+
templateUrl: ["c", function(c){}],
586+
}).component("cmp2", {
587+
controller: "myCtrl",
588+
template: "tmpl",
589+
templateUrl: "template.html"
590+
});
591+
}
566592
}
567593
]
568594
};

0 commit comments

Comments
 (0)