-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin issue. Help request #163
Comments
Related to #111. Plugins need rework and documentation and I just don't have free bandwidth to do that so if you want to try them out then you're on your own basically. The starting point is to look at existing plugins (see angular-dashboard-framework.js in master) and match in ng-annotate-main.js (as well as its called functions). I strongly recommend you to just do |
@olov Unfortunately, in a real world, I cannot enforce new usage rules. Adding 'ngInject' by convention increases human error, since team already has developed conventions and is working like that for over a year. I am really grateful for low level API in ng-annotate since it allows adapt ng-annotate to project needs. Any ways, I have wrote a plugin that works for our project, since we know the structure of our application and existing conventions. It obviously is not generic. I simply mark all function expressions with angular-specific naming, since we don't use these names in our own classes. But again, I needed that for providers that were not captured. module.exports = new function() {
var context;
this.init = function(ctx) {
context = ctx;
};
this.match = function(node) {
var target = null;
var isMatch = (
node.type === "FunctionExpression" &&
node.id && node.id.name && (node.id.name[0] === '$')
);
if (isMatch) {
target = node;
}
return target;
}
}; |
@vatula Curious why your code could work... I try to return the exactly the function node I want to be annotated, but output is not annotated at all... class AppControllerProviderPlugin {
constructor() {
this.ctx = null
}
init (ctx) {
this.ctx = ctx;
// console.log('ctx.src===', ctx)
}
match (node) {
// app.$controllerProvider.register("foo", function($scope) {});
if (node.type !== 'FunctionExpression') { return false; }
const parent1 = node.$parent
if (parent1.type !== 'CallExpression') { return false; } // means parent1 is a caller, so has callee.property.name
if (parent1.callee.property.name !== 'register') { return false; }
console.log('==============================================')
console.log('==============================================')
console.log('==============================================')
console.log('==============================================')
console.log('==============================================')
console.log(node)
console.log('==============================================')
console.log('==============================================')
console.log('==============================================')
console.log('==============================================')
console.log('==============================================')
return node
}
} And console.log seems correct (49~75 is exactly
And I'm sure built-in implicit matching is working: /// INPUT FILE
var app = angular.module('webui')
app.controller('AAAAAAAAAAA', function ($scope) {})
app.controllerProvider.register('BBBBBBBBBBBB', function ($scope) {})
/// OUTPUT FILE
var app=angular.module("webui");
app.controller("AAAAAAAAAAA",["$scope",function($scope){}]);
app.controllerProvider.register("BBBBBBBBBBBB",function($scope){}) |
Found the point, the reason is for (const target of finalSuspects) {
if (target.$chained !== chainedRegular) {
continue;
}
... And It seems to be used to precisely judge the correct context / scope of a node.$chained = /* const chainedRegular = */ 4 // WORKAROUND, see ng-annotate-main.js |
I have a provider written in ES6 way using classes, like this:
Which Babeljs transforms into something like this:
And I am trying to write a plugin for ngAnnotate for our app that will annotate methods in the class. So suppose I have only that js file and I want to capture provider call.
What should I return from a match? :)
A match method of the plugin I wrote is similar to:
I want to annotate all methods in a
babelified
es5, like these:Returning
args[1].callee
does not help ngAnnotate to annotate itUsing prelude, comments etc are not welcomed since we want to use plugin in a non-intrusive, transparent way.
The text was updated successfully, but these errors were encountered: