babel-plugin-angularjs-annotate
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -116,2 +116,7 @@ 'use strict'; | ||
}, | ||
ObjectMethod: { | ||
enter(path) { | ||
ngInject.inspectFunction(path, ctx); | ||
} | ||
}, | ||
CallExpression: { | ||
@@ -118,0 +123,0 @@ enter(path) { |
# babel-plugin-angularjs-annotate changelog | ||
## v0.7.0 2017-01-09 | ||
* New Feature: Support for ES6 Object Method shorthand (#16) | ||
## v0.6.0 2016-10-14 | ||
@@ -4,0 +7,0 @@ * New Feature: print a warning if we ask to re-annotate an DI injection array if the new parameters do not match, and throw an exception if the number of parameters is wrong. |
@@ -436,3 +436,6 @@ // ng-annotate-main.js | ||
(t.isLiteral(prop.key) && prop.key.value === name)) { | ||
return (propOrPath.get && propOrPath.get("value")) || prop.value; // FunctionExpression or ArrayExpression | ||
if(t.isObjectMethod(prop)){ | ||
return propOrPath; | ||
} | ||
return (propOrPath.get && propOrPath.get("value")) || prop.value; // FunctionExpression or ArrayExpression | ||
} | ||
@@ -447,3 +450,6 @@ } | ||
return resolveObject.get("properties").map(function(prop) { | ||
return prop.get("value"); | ||
if(t.isObjectMethod(prop)){ | ||
return prop; | ||
} | ||
return prop.get("value"); | ||
}); | ||
@@ -562,2 +568,17 @@ } | ||
if(t.isObjectMethod(path) && target.params.length){ | ||
// Replace object method shorthand { foo(bar){} } with long-form { foo: function(bar){} } so we can annotate it | ||
const func = t.functionExpression(null, target.params, target.body, target.generator, target.async); | ||
func.returnType = target.returnType; | ||
path.replaceWith(t.objectProperty( | ||
target.key, | ||
func, | ||
target.computed | ||
)); | ||
path = path.get("value"); | ||
target = path.node; | ||
} | ||
if (isFunctionExpressionWithArgs(target) && !t.isVariableDeclarator(path.parent)) { | ||
@@ -564,0 +585,0 @@ insertArray(ctx, path); |
{ | ||
"name": "babel-plugin-angularjs-annotate", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Babel plugin to add angularjs dependency injection annotations", | ||
@@ -5,0 +5,0 @@ "main": "babel-ng-annotate.js", |
@@ -17,3 +17,3 @@ # babel-plugin-angularjs-annotate | ||
Most users will want to run | ||
Most users will want to run | ||
@@ -50,3 +50,3 @@ ```sh | ||
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. | ||
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. | ||
@@ -61,3 +61,3 @@ [Try it out in your browser](http://schmod.github.io/babel-plugin-angularjs-annotate/). | ||
Arrow functions may be annotated anywhere that a "regular" function expression may be used. | ||
Arrow functions may be annotated anywhere that a "regular" function expression may be used. | ||
@@ -142,2 +142,21 @@ **NOTE:** There are places where you _shouldn't_ use arrow functions in an Angular application. Inside of an arrow function, the value of `this` is inherited from the lexical scope enclosing the function. For this reason, arrow functions should not be used to declare Angular services or providers. | ||
#### Object Method Shorthand | ||
Object methods can be written with the new [shorthand](http://exploringjs.com/es6/ch_oop-besides-classes.html#object-literal-method-definitions) syntax: | ||
```js | ||
let foo = { | ||
bar($http){ | ||
'ngInject'; | ||
} | ||
}; | ||
``` | ||
```js | ||
$stateProvider.state('myState', { | ||
controller($scope) {} | ||
}); | ||
``` | ||
#### Exports | ||
@@ -154,6 +173,6 @@ | ||
This project/experiment does _not_ seek to replace ng-annotate. However, it does seek to provide similar | ||
This project/experiment does _not_ seek to replace ng-annotate. However, it does seek to provide similar | ||
functionality for Angular 1.x developers who are already using Babel and/or writing code in ES6. | ||
Because of some of the limitations presented by Babel's transformation process, this project does not aim to | ||
Because of some of the limitations presented by Babel's transformation process, this project does not aim to | ||
achieve feature parity, or provide identical output to ng-annotate. Notably, Babel does not preserve formatting | ||
@@ -163,3 +182,3 @@ and indentations like ng-annotate does, and this project does not seek to replicate the features of ng-annotate that remove or transform existing annotations. | ||
Initially, I had hoped to make very few modifications to the upstream sources, in the hopes of eventually | ||
merging babel support directly into ng-annotate. Unfortunately, Babylon appears to have diverged too | ||
merging babel support directly into ng-annotate. Unfortunately, Babylon appears to have diverged too | ||
far from Acorn to make that goal realistic. (I would love to be wrong here, and would welcome contributions that close the gap between the two projects!) | ||
@@ -166,0 +185,0 @@ |
@@ -154,4 +154,34 @@ "use strict"; | ||
} | ||
}, { | ||
name: "object method", | ||
explicit: true, | ||
input: function() { | ||
var foo = { | ||
bar(baz){ | ||
'ngInject'; | ||
} | ||
}; | ||
}, | ||
expected: function() { | ||
var foo = { | ||
bar: ['baz', function(baz) { | ||
'ngInject'; | ||
}] | ||
} | ||
} | ||
}, { | ||
name: "implicit object method", | ||
explicit: false, | ||
input: function() { | ||
angular.component('myComponent', { | ||
controller(a){} | ||
}); | ||
}, | ||
expected: function() { | ||
angular.component('myComponent', { | ||
controller: ['a', function(a){}] | ||
}); | ||
} | ||
} | ||
] | ||
}; |
@@ -14,2 +14,3 @@ module.exports = { | ||
translations: "translations", | ||
objMethod(a) { a } | ||
}, | ||
@@ -37,2 +38,7 @@ params: { | ||
}, | ||
viewc: { | ||
dontAlterMe(arg) {}, | ||
templateProvider($scope) {}, | ||
controller($scope) {} | ||
}, | ||
dontAlterMe: null, | ||
@@ -59,2 +65,3 @@ }, | ||
translations: "translations", | ||
objMethod: ["a", function(a) { a }] | ||
}, | ||
@@ -82,2 +89,7 @@ params: { | ||
}, | ||
viewc: { | ||
dontAlterMe(arg) {}, | ||
templateProvider: ["$scope", function($scope) {}], | ||
controller: ["$scope", function($scope) {}] | ||
}, | ||
dontAlterMe: null, | ||
@@ -240,2 +252,2 @@ }, | ||
] | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
193
1368864
45
36027